+++ /dev/null
-<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
-<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
-
-<glade-interface>
-
-<widget class="GtkWindow" id="vvend">
- <property name="visible">True</property>
- <property name="title" translatable="yes">Virtual Vend</property>
- <property name="type">GTK_WINDOW_TOPLEVEL</property>
- <property name="window_position">GTK_WIN_POS_NONE</property>
- <property name="modal">False</property>
- <property name="resizable">False</property>
- <property name="destroy_with_parent">False</property>
- <property name="decorated">True</property>
- <property name="skip_taskbar_hint">False</property>
- <property name="skip_pager_hint">False</property>
- <property name="type_hint">GDK_WINDOW_TYPE_HINT_UTILITY</property>
- <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
- <signal name="delete_event" handler="on_vvend_delete_event" last_modification_time="Sun, 27 Jun 2004 03:56:03 GMT"/>
- <signal name="destroy_event" handler="on_vvend_destroy_event" last_modification_time="Sun, 27 Jun 2004 03:56:19 GMT"/>
-
- <child>
- <widget class="GtkVBox" id="vbox1">
- <property name="visible">True</property>
- <property name="homogeneous">False</property>
- <property name="spacing">0</property>
-
- <child>
- <widget class="GtkEventBox" id="eventbox1">
- <property name="visible">True</property>
- <property name="visible_window">True</property>
- <property name="above_child">False</property>
-
- <child>
- <widget class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="label" translatable="yes">label1</property>
- <property name="use_underline">False</property>
- <property name="use_markup">False</property>
- <property name="justify">GTK_JUSTIFY_LEFT</property>
- <property name="wrap">False</property>
- <property name="selectable">False</property>
- <property name="xalign">0</property>
- <property name="yalign">0.5</property>
- <property name="xpad">40</property>
- <property name="ypad">0</property>
- </widget>
- </child>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkTable" id="table1">
- <property name="visible">True</property>
- <property name="n_rows">3</property>
- <property name="n_columns">4</property>
- <property name="homogeneous">False</property>
- <property name="row_spacing">0</property>
- <property name="column_spacing">0</property>
-
- <child>
- <widget class="GtkButton" id="button1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">1</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button1_clicked" last_modification_time="Sat, 26 Jun 2004 16:27:10 GMT"/>
- <accelerator key="1" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">0</property>
- <property name="right_attach">1</property>
- <property name="top_attach">0</property>
- <property name="bottom_attach">1</property>
- <property name="x_options">fill</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button3">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">3</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button3_clicked" last_modification_time="Sat, 26 Jun 2004 16:28:05 GMT"/>
- <accelerator key="3" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">0</property>
- <property name="bottom_attach">1</property>
- <property name="x_options">fill</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button4">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">4</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button4_clicked" last_modification_time="Sat, 26 Jun 2004 17:04:43 GMT"/>
- <accelerator key="4" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">3</property>
- <property name="right_attach">4</property>
- <property name="top_attach">0</property>
- <property name="bottom_attach">1</property>
- <property name="x_options">fill</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button5">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">5</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button5_clicked" last_modification_time="Sat, 26 Jun 2004 16:29:26 GMT"/>
- <accelerator key="5" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">0</property>
- <property name="right_attach">1</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">fill</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button6">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">6</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button6_clicked" last_modification_time="Sat, 26 Jun 2004 16:29:35 GMT"/>
- <accelerator key="6" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">fill</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button7">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">7</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button7_clicked" last_modification_time="Sat, 26 Jun 2004 17:05:04 GMT"/>
- <accelerator key="7" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">fill</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button8">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">8</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button8_clicked" last_modification_time="Sat, 26 Jun 2004 16:31:06 GMT"/>
- <accelerator key="8" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">3</property>
- <property name="right_attach">4</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">fill</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button11">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">RESET</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button11_clicked" last_modification_time="Sat, 26 Jun 2004 16:31:58 GMT"/>
- <accelerator key="r" modifiers="0" signal="clicked"/>
- <accelerator key="R" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">2</property>
- <property name="right_attach">4</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button10">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">0</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button10_clicked" last_modification_time="Sat, 26 Jun 2004 16:31:41 GMT"/>
- <accelerator key="0" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button9">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">9</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button9_clicked" last_modification_time="Sat, 26 Jun 2004 17:05:10 GMT"/>
- <accelerator key="9" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">0</property>
- <property name="right_attach">1</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button2">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">2</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button2_clicked" last_modification_time="Sat, 26 Jun 2004 16:27:29 GMT"/>
- <accelerator key="2" modifiers="0" signal="clicked"/>
- </widget>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">0</property>
- <property name="bottom_attach">1</property>
- <property name="x_options">fill</property>
- <property name="y_options"></property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkHBox" id="hbox1">
- <property name="visible">True</property>
- <property name="homogeneous">False</property>
- <property name="spacing">0</property>
-
- <child>
- <widget class="GtkButton" id="button13">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">0.05</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button13_clicked" last_modification_time="Sat, 26 Jun 2004 16:32:28 GMT"/>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button14">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">0.10</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button14_clicked" last_modification_time="Sat, 26 Jun 2004 16:32:38 GMT"/>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button15">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">0.25</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button15_clicked" last_modification_time="Sat, 26 Jun 2004 16:32:49 GMT"/>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button16">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">$1</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button16_clicked" last_modification_time="Sat, 26 Jun 2004 16:32:55 GMT"/>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkButton" id="button17">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">MODE</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <signal name="clicked" handler="on_button17_clicked" last_modification_time="Sat, 26 Jun 2004 16:33:01 GMT"/>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkHBox" id="hbox2">
- <property name="visible">True</property>
- <property name="homogeneous">False</property>
- <property name="spacing">0</property>
-
- <child>
- <widget class="GtkToggleButton" id="togglebutton1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">DIP1</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkToggleButton" id="togglebutton2">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">DIP2</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkToggleButton" id="togglebutton3">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">DIP3</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkToggleButton" id="togglebutton4">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">DIP4</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkToggleButton" id="togglebutton5">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">DIP5</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkToggleButton" id="togglebutton6">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">DIP6</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkToggleButton" id="togglebutton7">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">DIP7</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkToggleButton" id="togglebutton8">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">DIP8</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">False</property>
- <property name="inconsistent">False</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">True</property>
- <property name="fill">True</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkToggleButton" id="door">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="label" translatable="yes">DOOR</property>
- <property name="use_underline">True</property>
- <property name="relief">GTK_RELIEF_NORMAL</property>
- <property name="focus_on_click">True</property>
- <property name="active">True</property>
- <property name="inconsistent">False</property>
- <signal name="toggled" handler="on_door_toggled" last_modification_time="Sat, 26 Jun 2004 16:33:37 GMT"/>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
-
- <child>
- <widget class="GtkStatusbar" id="statusbar1">
- <property name="visible">True</property>
- <property name="has_resize_grip">True</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
- </widget>
- </child>
-</widget>
-
-</glade-interface>
+++ /dev/null
-#!/usr/bin/env python
-
-import sys
-import socket
-import string
-
-try:
- import pygtk
- #tell pyGTK, if possible, that we want GTKv2
- pygtk.require("2.0")
-except:
- #Some distributions come with GTK2, but not pyGTK
- pass
-
-try:
- import gtk
- import gtk.glade
-except:
- print "You need to install pyGTK or GTKv2 ",
- print "or set your PYTHONPATH correctly."
- print "try: export PYTHONPATH=",
- 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
-
-class appgui:
- def __init__(self):
- """
- In this init we are going to display the main
- serverinfo window
- """
- gladefile="vvend.glade"
- windowname="vvend"
- self.wTree=gtk.glade.XML (gladefile,windowname)
- # we only have two callbacks to register, but
- # you could register any number, or use a
- # special class that automatically
- # registers all callbacks. If you wanted to pass
- # an argument, you would use a tuple like this:
- # dic = { "on button1_clicked" :
- # (self.button1_clicked, arg1,arg2) , ...
-
- dic = {
- "on_button1_clicked" : self.keypad_clicked,
- "on_button2_clicked" : self.keypad_clicked,
- "on_button3_clicked" : self.keypad_clicked,
- "on_button4_clicked" : self.keypad_clicked,
- "on_button5_clicked" : self.keypad_clicked,
- "on_button6_clicked" : self.keypad_clicked,
- "on_button7_clicked" : self.keypad_clicked,
- "on_button8_clicked" : self.keypad_clicked,
- "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)
-#
-# listenhost=""
-# listenport=5150
-# s.bind((listenhost, listenport))
-# # only one connection
-# s.listen(1)
-# s.setblocking(1)
-# #GDK->gtk.gdk in GTK V 2.0
-# id=gtk.input_add(s, gtk.gdk.INPUT_READ, self.handleNewConnection)
-
- self.server()
-
-
- return
-
- def __del__(self):
- try:
- self.sock.close()
- self.sock.shutdown()
- except:
- pass
-
-#####CALLBACKS
- def keypad_clicked(self,widget):
- key = widget.get_label()
- if key == 'RESET':
- key = '11'
- else:
- 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()
- sys.stdout.write(conn.recv(1))
- conn.send("bing\n")
- return gtk.TRUE
-
-# from http://www.pythonbrasil.com.br/moin.cgi/MonitorandoSocketsComPygtk
-
-
- def send(self, data=None, widget=None):
- text = self.entry.get_text()
- self.do_send(text)
- self.entry.set_text('')
-
- #
-
- def do_send(self, data):
-
- # envia ''data'' para todos os clientes conectados
-
- for addr, (conn, tag) in self.clients.iteritems():
- conn.send(data)
-
- def server(self):
-
- # inicializa o servidor
- 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
-
- #
- #
-
- self.server_tag = gtk.input_add(self.sock, gtk.gdk.INPUT_READ, self.accept)
-
- # mantemos uma lista dos clientes conectados
-
- self.clients = {}
-
- def accept(self, source, condition):
-
- #
- # esperando para ser aceito
-
- conn, addr = source.accept()
- self.insert("%s:%s conectado\n" % addr)
-
- # insere o cliente na lista e registra o método self.write como
- # callback para quando existirem dados esperando para serem lidos
-
- self.do_prompt()
- self.clients[addr] = (conn, gtk.input_add(conn, gtk.gdk.INPUT_READ, self.write))
-
- def write(self, source, condition):
-
- # método chamado quando um cliente envia dados
-
- data = source.recv(1024)
- if data.strip() == 'bye' or not len(data):
-
- # se o cliente enviar um ''bye'', desconecte-o :)
-
- source.close()
- for addr, (conn, tag) in self.clients.iteritems():
- if source is conn:
- gtk.input_remove(tag)
- self.insert('%s:%s desconectado\n' % addr)
- del self.clients[addr]
-
- self.server_tag = gtk.input_add(self.sock, gtk.gdk.INPUT_READ, self.accept)
- break
- elif data.strip() == 'quit':
- self.quit()
- else:
- for (addr, port), (conn, tag) in self.clients.iteritems():
- if source is conn:
- self.insert('%s:%s >>> %s\n'%(addr, port, data.strip()))
- self.handle_command(data.strip())
- break
-
- return gtk.TRUE
-
- def insert(self, data):
- statusbar = self.wTree.get_widget("statusbar1")
- if self.messageid:
- statusbar.remove(1, self.messageid)
- self.messageid=statusbar.push(1,data)
-
- def quit(self, *args):
- sys.stdout.write("quiting...\n")
- gtk.input_remove(self.server_tag)
- for addr, (conn, tag) in self.clients.iteritems():
- gtk.input_remove(tag)
- conn.close()
- self.sock.close()
- self.sock.shutdown()
-
- gtk.mainquit()
- sys.stdout.write("quit!\n")
-
- def do_prompt(self):
- self.do_send("# ")
-
- def do_help(self):
- help = """
-
-Valid commands are:
- ABOUT ROM information
- B[S][nn] beep [synchronously] for a duration nn (optional)
- C[S][nn] silence [synchronously] for a duration nn (optional)
- Dxxxxxxxxxx show a message on the display
- ECHO {ON|OFF} turn echo on or off
- GETROM download the ROM source code using xmodem
- H[...] this help screen
-*JUMPxxxx jumps to a subroutine at location xxxx
-*PEEKxxxx returns the value of the byte at location xxxx
-*POKExxxxyy sets the value of location xxxx to yy
- PING pongs
- S[...] query all internal switch states
-+Vnn vend an item
-+VALL vend all items
-*Wxxxxxxxxxxxx set a new password for authenticated vends. xxx=16 chars
- password will be converted to uppercase
-
-Very few functions are available when the machine is in standalone
-mode (DIP SW 1 is set)
-+ denotes that this item requires authentication if DIP SW 2 is set
-* denotes that DIP SW 3 must be set to use these
-Commands starting with # are ignored (comments)
-"""
- self.do_send(help)
-
- def do_about(self):
- about = """
-
-The Virtual Vending Machine Company
-
-Mark Tearle, June 2004
-"""
- self.do_send(about)
-
- def do_vend_all(self):
- for i in range(11,99):
- 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):
- 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))
- 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)
- print command
- if string.find(command, "HELP",0) == 0:
- 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, "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:])
- self.do_prompt()
-
-
-# we start the app like this...
-app=appgui()
-gtk.main()
-
-
-# notes
-# http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq20.011.htp