Browse Source

Display now has scrolling text implemented in a python thread and error-screens, etc

Florian Streibelt 9 years ago
parent
commit
665ba7cc5e
1 changed files with 69 additions and 2 deletions
  1. 69
    2
      client-barcode/freitagskasse.py

+ 69
- 2
client-barcode/freitagskasse.py View File

@@ -18,6 +18,9 @@ import os
18 18
 import time
19 19
 import urllib2
20 20
 
21
+from thread import start_new_thread, allocate_lock
22
+import time
23
+
21 24
 
22 25
 COLOR_HINT = Fore.YELLOW + Style.BRIGHT
23 26
 COLOR_ERROR = Fore.RED
@@ -32,8 +35,62 @@ COLOR_RESET = Style.RESET_ALL
32 35
 
33 36
 display_fifo = None
34 37
 
38
+scroll_line1 = None
39
+scroll_line2 = None
35 40
 
36
-def print_display(s):
41
+
42
+lock = allocate_lock()
43
+
44
+def display_handle_scroll(line,text,offset):
45
+	if (text):
46
+		send_display("\x1f\x24\x01%c%s" % (chr(line),text[offset:(20+offset)]))
47
+		l = len(text)
48
+		missing_chars=20+offset-l
49
+		if (missing_chars>0):
50
+			send_display(text[:missing_chars])
51
+		offset=((offset+1)%l)
52
+	else:
53
+		offset=0	#reset offset
54
+	return offset
55
+
56
+def display_scroll_text(line,text):
57
+	global scroll_line1,scroll_line2
58
+	lock.acquire()
59
+	if (line==1): #clear the line on invocation:
60
+		send_display("\x1f\x24\x01%c\x18" % chr(line) )
61
+		scroll_line1 = text
62
+	if (line==2): #clear the line on invocation:
63
+		send_display("\x1f\x24\x01%c\x18" % chr(line) )
64
+		scroll_line2 = text
65
+	lock.release()
66
+
67
+def display_screen(title,message):
68
+	if (len(title)<21):
69
+		send_display("\x1f\x24\x01%c\x18%s" % (chr(1),'\xdb'*20) )
70
+		if (len(title)<20):
71
+			pos=1+(20-len(title))/2
72
+		else:
73
+			pos=1
74
+		send_display("\x1f\x24%c%c%s" % (chr(pos),chr(1),title) )
75
+	else:
76
+		display_scroll_text(1,title)
77
+	display_scroll_text(2,message)
78
+	
79
+
80
+
81
+def display_thread(x):
82
+	global scroll_line1,scroll_line2
83
+	offset_line1=0
84
+	offset_line2=0
85
+	while(True):
86
+		lock.acquire()
87
+		offset_line1 = display_handle_scroll(1,scroll_line1,offset_line1)
88
+		offset_line2 = display_handle_scroll(2,scroll_line2,offset_line2)
89
+		lock.release()
90
+		time.sleep(.5)
91
+
92
+
93
+def send_display(s):
37 94
 	global display_fifo
38 95
 	if not display_fifo:
39 96
 		try:
@@ -55,6 +112,12 @@ def print_display(s):
55 112
 		pass
56 113
 		return
57 114
 
115
+def print_display(s):
116
+	lock.acquire()
117
+#	scroll_line1=None
118
+#	scroll_line2=None
119
+#	send_display(s)
120
+	lock.release()
58 121
 
59 122
 def clear():
60 123
 	os.system('clear')
@@ -399,9 +462,13 @@ def handle(line, status):
399 462
 def main():
400 463
 	colorama.init()
401 464
 	status = Status()
402
-
465
+	global scroll_line1,scroll_line2
403 466
 	print_display("\x1b\x40Kassensystem \n startet...")
467
+	start_new_thread(display_thread,(1,))
404 468
 
469
+	#display_scroll_text(1,"Line1: Text, dumm scrollend!")
470
+	#display_scroll_text(4,"Line2: Und hier Text, auch dumm scrollend!")
471
+	display_screen("HINWEIS","Herzlich willkommen bei der Freitagsrunde! *** ")
405 472
 	while True:
406 473
 		clear()
407 474
 		status.dump()

Loading…
Cancel
Save