-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
executable file
·79 lines (63 loc) · 2.23 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import wx
import wx.html2
import requests
from threading import Thread
import ConfigParser
def load_config():
config = ConfigParser.ConfigParser()
config.read("config")
return config
class MyBrowser(wx.Dialog):
def __init__(self, *args, **kwds):
wx.Dialog.__init__(self, *args, **kwds)
sizer = wx.BoxSizer(wx.VERTICAL)
self.browser = wx.html2.WebView.New(self)
sizer.Add(self.browser, 1, wx.EXPAND, 10)
self.SetSizer(sizer)
self.SetSize(wx.GetDisplaySize())
def scanner_read(device_file):
with open(device_file) as device:
return device.readline().strip("\2\3\r\n")
def send_scanner_data(user, book):
self.browser.RunScript("send_scanner_data({!r}, {!r})".format(user, book))
def scan_user(device_file):
global curent_user, curent_book
user = scanner_read(device_file)
if curent_user is not None and curent_book is None:
curent_user = user
return
if curent_user is None and curent_book is None:
curent_user = user
else:
curent_user = user
send_scanner_data(curent_user, curent_book)
curent_user is None and curent_book is None
def scan_book(device_file):
global curent_user, curent_book
book = scanner_read(device_file)
if curent_book is not None and curent_user is None:
curent_book = book
return
if curent_user is None and curent_book is None:
curent_book = book
else:
curent_book = book
send_scanner_data(curent_user, curent_book)
curent_user is None and curent_book is None
def main():
config = load_config()
terminal_uuid = requests.get("http://localhost:5000/connect").json()["terminal_uuid"]
thread_user = Thread(target=scan_user, args=config.get("Demon", "userScanner"))
thread_book = Thread(target=scan_book, args=config.get("Demon", "bookScanner"))
thread_book.start()
thread_user.start()
app = wx.App()
dialog = MyBrowser(None, -1)
dialog.browser.LoadURL(config.get("Demon", "url"))
dialog.SetTitle("Библиотека Московского Химического Лицея")
dialog.Show()
app.MainLoop()
if __name__ == '__main__':
main()