Rename door
[uccvend-vendserver.git] / virtualvend / vvend.py
index 4f64af0..bb38c58 100644 (file)
@@ -22,6 +22,8 @@ except:
   print "/usr/local/lib/python2.2/site-packages/"
   sys.exit(1)
 
+import pango
+
 #now we have both gtk and gtk.glade imported
 #Also, we know we are running GTK v2
 
@@ -58,6 +60,8 @@ class appgui:
         "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)
     display.set_text("*5N4CK0RZ*")
 
     # vending machine password set here
@@ -81,13 +85,22 @@ class appgui:
 
 
     return
-  
+
+    def __del__(self):
+       try:
+           self.sock.close()
+           self.sock.shutdown()
+       except:
+           pass
+
 #####CALLBACKS
   def keypad_clicked(self,widget):
-    print "button clicked"
-    print widget.get_label()
-    self.do_send(widget.get_label())
-    sys.stdout.write("\a")
+    key = widget.get_label()
+    if key == 'RESET':
+       key = '11'
+    else:
+       key = '0'+key
+    self.do_send('2'+key+' keypress\n')
 
   def handleNewConnection(self,source,condition):
     #source is a socket in GTK v 1 and a fd in version 2
@@ -119,6 +132,7 @@ class appgui:
      port = 5150
 
      self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+     self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
      self.sock.bind(('localhost', port))
      self.sock.listen(0)
      print "listening on ", port
@@ -235,23 +249,35 @@ Mark Tearle, June 2004
 
   def do_vend_all(self):
      for i in range(11,99):
-       self.do_send("101 Vending ",i)
-       self.do_send("153 Home sensors failing")
-     self.do_send("102 Vend all motors complete")
+       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")
   
   def do_vend(self,command):
-     self.do_send("153 Home sensors failing")
+     fail = None
+     if fail:
+       self.do_send("153 Home sensors failing\n")
+     else:
+        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
 
+  def do_switches(self):
+     self.do_send("600 3F 3F\n")
+
+  def do_pong(self):
+     self.do_send("000 PONG!\n")
 
   def handle_command(self, command):
      command = string.upper(command)
@@ -260,16 +286,20 @@ Mark Tearle, June 2004
        self.do_help()
      elif string.find(command, "ABOUT",0) == 0:
        self.do_about()
+     elif string.find(command, "PING",0) == 0:
+       self.do_pong()
      elif string.find(command, "VALL",0) == 0:
        self.do_vend_all()
      elif string.find(command, "V",0) == 0:
        self.do_vend(command)
      elif string.find(command, "B",0) == 0:
        self.do_beep(command)
-     elif string.find(command, "S",0) == 0:
+     elif string.find(command, "C",0) == 0:
        self.do_silence(command)
+     elif string.find(command, "S",0) == 0:
+       self.do_switches()
      elif string.find(command, "D",0) == 0:
-       self.do_display(command[1:-1])
+       self.do_display(command[1:])
      self.do_prompt()
        
 

UCC git Repository :: git.ucc.asn.au