from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
from kivy.clock import Clock
from requests import get
from kivy.uix.button import Button
import requests
Window.size = (360, 480)
Window.clearcolor = (0, .17, .55, 1)
notice_list = []
department = 'kmd'
Builder.load_string("""
<MenuScreen>:
BoxLayout:
orientation: 'vertical'
padding: 5, 10
spacing: 10
Button:
text: 'УВЕДОМЛЕНИЯ'
background_color: 0, .12, .52, 1
Button:
text: 'ЗАКАЗЫ В РАБОТЕ'
background_color: 0, .12, .52, 1
Button:
text: 'АРХИВ ЗАКАЗОВ'
background_color: 0, .12, .52, 1
Button:
text: 'СКАНИРОВАНИЕ QR'
background_color: 0, .12, .52, 1
on_press: root.manager.current = 'settings'
<ScanScreen>:
BoxLayout:
#:import ZBarCam kivy_garden.zbarcam.ZBarCam
orientation: 'vertical'
padding: 5, 10
spacing: 10
ZBarCam:
id: qrcodecam
Label:
size_hint: None, None
size: self.texture_size[0], 50
text: ' , '.join([str(symbol.data) for symbol in qrcodecam.symbols])
Button:
text: 'РАБОТА НАЧАТА'
background_color: 0, .12, .52, 1
on_press: root.manager.current = 'start'
Button:
text: 'РАБОТА ПРИОСТАНОВЛЕНА'
background_color: 0, .12, .52, 1
Button:
text: 'РАБОТА ЗАКОНЧЕНА'
background_color: 0, .12, .52, 1
on_press: root.manager.current = 'menu'
""")
class MenuScreen(Screen):
pass
class ScanScreen(Screen):
def __init__(self, **kwargs):
super(ScanScreen, self).__init__(**kwargs)
self.start = kwargs.get('start')
def start(self, *args, **kwargs):
response = requests.post(f'http://127.0.0.1:8000/api/notice/{department}', data = {'user': department, 'id': notice_list})
def get_notice(_):
for i in get(f'http://127.0.0.1:8000/api/notice/{department}').text.split(','):
if i != '':
notice_list.append(i)
print(notice_list)
class MainApp(App):
def build(self):
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(ScanScreen(name='settings'))
sm.add_widget(ScanScreen(name='start'))
return sm
if __name__=='__main__':
Clock.schedule_interval(get_notice, 1)
MainApp().run()
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
from kivy.clock import Clock
from requests import get, post
from kivy.uix.camera import Camera
Window.size = (360, 480)
Window.clearcolor = (0, .17, .55, 1)
notice_list = []
department = 'kmd'
Builder.load_string("""
<MenuScreen>:
BoxLayout:
orientation: 'vertical'
padding: 5, 10
spacing: 10
Button:
text: 'УВЕДОМЛЕНИЯ'
background_color: 0, .12, .52, 1
Button:
text: 'ЗАКАЗЫ В РАБОТЕ'
background_color: 0, .12, .52, 1
Button:
text: 'АРХИВ ЗАКАЗОВ'
background_color: 0, .12, .52, 1
Button:
text: 'СКАНИРОВАНИЕ QR'
background_color: 0, .12, .52, 1
on_press: root.manager.current = 'settings'
<ScanScreen>:
BoxLayout:
#:import ZBarCam kivy_garden.zbarcam.ZBarCam
orientation: 'vertical'
padding: 5, 10
spacing: 10
ZBarCam:
id: qrcodecam
Label:
size_hint: None, None
size: self.texture_size[0], 50
text: ' , '.join([str(symbol.data) for symbol in qrcodecam.symbols])
Button:
text: 'РАБОТА НАЧАТА'
background_color: 0, .12, .52, 1
on_press: app.start()
Button:
text: 'РАБОТА ПРИОСТАНОВЛЕНА'
background_color: 0, .12, .52, 1
Button:
text: 'РАБОТА ЗАКОНЧЕНА'
background_color: 0, .12, .52, 1
on_press: root.manager.current = 'menu'
""")
class MenuScreen(Screen):
pass
class ScanScreen(Screen):
pass
def get_notice(_):
for i in get(f'http://127.0.0.1:8000/api/notice/{department}').text.split(','):
if i != '':
notice_list.append(i)
class MainApp(App):
def build(self):
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(ScanScreen(name='settings'))
return sm
def start(self):
r = get(f'http://127.0.0.1:8000/api/give_csrf')
csrf = r.text.split('=')[-1][1:-2]
cookies = r.cookies.get_dict()
post(f'http://127.0.0.1:8000/api/qr_start/{department}',
data = {'id': notice_list, 'csrfmiddlewaretoken': csrf},
cookies = cookies)
if __name__=='__main__':
Clock.schedule_interval(get_notice, 3)
MainApp().run()