Skip to content

Commit

Permalink
touch screen without any action
Browse files Browse the repository at this point in the history
  • Loading branch information
vanguardmaster01 committed Sep 16, 2023
1 parent cb118ed commit 82af71c
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 51 deletions.
Binary file modified DbFuncs/sql.db
Binary file not shown.
20 changes: 15 additions & 5 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from dotenv import load_dotenv
load_dotenv()
from config.global_vars import global_ads, global_machines, global_produts
from config.utils import lockList
from config.utils import lockList, stopWebsocket


hostName = os.environ.get('hostName')
Expand Down Expand Up @@ -116,7 +116,7 @@ async def connect_to_server():
print('connected')
sendData = {'action': 'MachineConnect'}
await websocket.send(json.dumps(sendData))

# Receive data
response = await websocket.recv()
responseData = json.loads(response)
Expand All @@ -128,6 +128,11 @@ async def connect_to_server():

if machineConnectStatus == 'success':
while True:

if stopWebsocket:
print('http_request_close')
break

statusData = {
'action': "MachineSendStatus",
'payload': {
Expand Down Expand Up @@ -156,9 +161,14 @@ async def connect_to_server():
time.sleep(600)
else:
pass

if stopWebsocket:
print('websocket_close')
await websocket.close()
except:
global_ads = db.get_ad()
global_produts = db.get_products()
global_machines = db.get_machines()
pass
# global_ads = db.get_ad()
# global_produts = db.get_products()
# global_machines = db.get_machines()

# asyncio.get_event_loop().run_until_complete(connect_to_server())
4 changes: 3 additions & 1 deletion config/global_vars.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
global_produts = []
global_machines = []
global_ads = []
global_ads = []

stop_websocket = True
5 changes: 4 additions & 1 deletion config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ def write_to_file(data, filename):
lockList = []
def initLock(lock):
global lockList
lockList.append(lock)
lockList.append(lock)


stopWebsocket = False
20 changes: 14 additions & 6 deletions list.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, **kwargs):
super(ListScreen, self).__init__(**kwargs)
self.timer = Clock.schedule_interval(self.retrieve_image_layout, 0.03)
Clock.schedule_once(self.retrieve_up_and_down_image)
Clock.schedule_interval(self.retrieve_category_layout, 0.03)
self.categoryTimer = Clock.schedule_interval(self.retrieve_category_layout, 0.05)
# self.imageList = []

self.screenX = int(os.environ.get('screenX'))
Expand Down Expand Up @@ -143,12 +143,20 @@ def retrieve_category_layout(self, dt):
categoryLayout = self.ids.category_layout # Access the image_layout widget
machines = db.get_machines()
lockList[0].release()

# machines = global_machines
for machine in machines:
image = self.on_draw_category_item(machine)
categoryLayout.add_widget(image)
categoryLayout.width += image.width
if machines:
for machine in machines:
image = self.on_draw_category_item(machine)
categoryLayout.add_widget(image)
categoryLayout.width += image.width

#stop clock
if self.categoryTimer != None:
self.categoryTimer.cancel()
else:
categoryLayout.add_widget(Label(text='Image not found', color=(0,0,0,1)))


def on_draw_category_item(self, machine):
boxlayout = BoxLayout(orientation='vertical')
Expand Down
97 changes: 59 additions & 38 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
from kivy.app import App
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.button import ButtonBehavior
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.core.image import Image as CoreImage
from kivy.clock import Clock
from kivy.graphics import Color, Rectangle
# from kivy.graphics.texture import Texture
from kivy.properties import StringProperty
from PIL import Image as PILImage
import io
import math

from DbFuncs import db
from DbFuncs import db_create
from model.Product import Product
from model.Ad import Ad

from item import ItemScreen
from list import ListScreen
Expand All @@ -34,16 +21,22 @@
import threading
import time
from config.utils import initLock
from config.utils import stopWebsocket

mutex = 0
# connectThread = threading.Thread(target=api.connect_to_server())

_thread = None
stop_thread = False
loop = None
delta = 0
def between_callback():
global stop_thread
global loop
# while not stop_thread:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

loop.run_until_complete(api.connect_to_server())
loop.close()
loop.create_task(api.connect_to_server())
loop.run_forever()
# loop.close()


class WindowManager(ScreenManager):
Expand All @@ -59,9 +52,13 @@ def update_rect(self, *args):
self.rect.size = self.size

kv = Builder.load_file('./kv/list.kv')

sm = WindowManager()
adScreen = AdScreen(name='Ad')
listScreen = ListScreen(name='List')
itemScreen = ItemScreen(name='Item')

class MainApp(App):

# Main Application
def build(self):

Expand All @@ -71,39 +68,63 @@ def build(self):
#connect db
db.openDatabase()

global _thread

_thread = threading.Thread(target=between_callback)
_thread.start()


width = int(os.environ.get('screenX'))
height = int(os.environ.get('screenY'))

db_create.create_tables()

print('windownamager')
Window.size = (width, height)

# asyncio.get_event_loop().run_until_complete(api.connect_to_server())

sm = WindowManager()
sm.add_widget(AdScreen(name='Ad'))
sm.add_widget(ListScreen(name='List'))
sm.add_widget(ItemScreen(name='Item'))
# asyncio.get_event_loop().run_until_complete(api.connect_to_server())

sm.add_widget(adScreen)
sm.add_widget(listScreen)
sm.add_widget(itemScreen)

# Clock.schedule_interval(self.periodic_task, 10)
Clock.schedule_interval(self.count_time, 1)

adScreen.bind(on_touch_down=self.touch_screen)
listScreen.bind(on_touch_down=self.touch_screen)
itemScreen.bind(on_touch_down=self.touch_screen)

return sm

# def connect_to_server(self, dt):
# api.connect_to_server()

async def connect_to_server(self):
await api.connect_to_server()
print('Connected to server')

def periodic_task(self, dt):
asyncio.create_task(self.connect_to_server())

def touch_screen(self, instance, touch):
global delta
delta = 0

def on_stop(self):
print('here')
global _thread
global stop_thread
global loop

stopWebsocket = True
# stop_thread = True

# process = multiprocessing.current_process()
# process.kill()

loop.stop()

print('222')

def count_time(self, dt):
global delta
delta += 1
print(f'delta:{delta}')
if delta > 10:
sm.current = 'Ad'
listScreen.clear_widgets()
listScreen.__init__()
itemScreen.clear_widgets()
itemScreen.__init__()
delta = 0

if __name__ == '__main__':
MainApp().run()
Expand Down

0 comments on commit 82af71c

Please sign in to comment.