X-Git-Url: https://git.ucc.asn.au/?p=zanchey%2Fdispense2.git;a=blobdiff_plain;f=virtualvend%2Fvvend.py;h=c06970d258ed7b2fc3c19621191d3ac041f80e31;hp=f4d04cb55c6a41c1a8e437d367d29a36d22f91c3;hb=ab13f294b1ca0956f3793fe475d3793ed0e7a9fa;hpb=b30b69ee7796c69f25b96f063cadb160ba451f95 diff --git a/virtualvend/vvend.py b/virtualvend/vvend.py index f4d04cb..c06970d 100644 --- a/virtualvend/vvend.py +++ b/virtualvend/vvend.py @@ -22,6 +22,20 @@ except: print "/usr/local/lib/python2.2/site-packages/" sys.exit(1) +import pango + +class Switches: + def __init__(self): + self.misc_input = 0xff + self.switch_input = 0x3f + def door_open(self): + return self.switch_input & 0x20 + def set_door_open(self, open = True): + if open: + self.switch_input |= 0x20 + else: + self.switch_input &= ~0x20 + #now we have both gtk and gtk.glade imported #Also, we know we are running GTK v2 @@ -54,16 +68,33 @@ class appgui: "on_button9_clicked" : self.keypad_clicked, "on_button10_clicked" : self.keypad_clicked, "on_button11_clicked" : self.keypad_clicked, + "on_button11_clicked" : self.keypad_clicked, + "on_door_toggled" : self.door_changed, "on_vvend_destroy_event" : self.quit, "on_vvend_delete_event" : self.quit } self.wTree.signal_autoconnect (dic) display = self.wTree.get_widget("label1") + label_font = pango.FontDescription('monospace 28') + display.modify_font(label_font) + + label_style = display.get_style().copy() + fg_color = display.get_colormap().alloc_color('lightgreen') + label_style.fg[gtk.STATE_NORMAL] = fg_color + display.set_style(label_style) + + w = self.wTree.get_widget("eventbox1") + wstyle = w.get_style().copy() + bg_color = w.get_colormap().alloc_color('black') + wstyle.bg[gtk.STATE_NORMAL] = bg_color + w.set_style(wstyle) + display.set_text("*5N4CK0RZ*") # vending machine password set here self.vendpw = "AAAAAAAAAAAAAAAA" self.messageid = None + self.switches = Switches() #s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) @@ -98,6 +129,13 @@ class appgui: key = '0'+key self.do_send('2'+key+' keypress\n') + def door_changed(self, widget): + self.switches.set_door_open(not widget.get_active()) + if widget.get_active(): + self.do_send('401 door closed\n') + else: + self.do_send('400 door open\n') + def handleNewConnection(self,source,condition): #source is a socket in GTK v 1 and a fd in version 2 conn, addr = source.accept() @@ -198,6 +236,7 @@ class appgui: gtk.input_remove(tag) conn.close() self.sock.close() + self.sock.shutdown() gtk.mainquit() sys.stdout.write("quit!\n") @@ -245,7 +284,7 @@ Mark Tearle, June 2004 def do_vend_all(self): for i in range(11,99): - self.do_send("101 Vending "+i+"\n") + self.do_send("101 Vending "+str(i)+"\n") self.do_send("153 Home sensors failing\n") self.do_send("102 Vend all motors complete\n") @@ -254,16 +293,17 @@ Mark Tearle, June 2004 if fail: self.do_send("153 Home sensors failing\n") else: - self.insert("Vending ",command) + self.insert("Vending "+command) self.do_send("100 Vend successful\n") def do_display(self,string): display = self.wTree.get_widget("label1") - display.set_text("%10.10s" % (string)) + display.set_text("%-10.10s" % (string)) self.do_send('300 Written\n') def do_beep(self,command): sys.stdout.write("\a") + self.do_send('500 Beeped\n') def do_silence(self,command): pass