Virtual vend
authorMark Tearle <[email protected]>
Sun, 27 Jun 2004 10:09:37 +0000 (10:09 +0000)
committerMark Tearle <[email protected]>
Sun, 27 Jun 2004 10:09:37 +0000 (10:09 +0000)
virtualvend/vvend.glade [new file with mode: 0644]
virtualvend/vvend.py [new file with mode: 0644]

diff --git a/virtualvend/vvend.glade b/virtualvend/vvend.glade
new file mode 100644 (file)
index 0000000..cac8393
--- /dev/null
@@ -0,0 +1,583 @@
+<?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">True</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="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.5</property>
+         <property name="yalign">0.5</property>
+         <property name="xpad">0</property>
+         <property name="ypad">0</property>
+       </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="togglebutton9">
+         <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_togglebutton9_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>
diff --git a/virtualvend/vvend.py b/virtualvend/vvend.py
new file mode 100644 (file)
index 0000000..ac9de42
--- /dev/null
@@ -0,0 +1,193 @@
+#!/usr/bin/env python
+
+import sys
+import socket
+
+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)
+
+#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_vvend_destroy_event" : self.quit,
+        "on_vvend_delete_event" : self.quit }
+    self.wTree.signal_autoconnect (dic)
+    display = self.wTree.get_widget("label1")
+    display.set_text("*5N4CK0RZ*")
+
+    self.messageid = None
+
+    #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
+  
+#####CALLBACKS
+  def keypad_clicked(self,widget):
+    print "button clicked"
+    print widget.get_label()
+    self.do_send(widget.get_label())
+    sys.stdout.write("\a")
+
+  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
+
+     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+     self.sock.bind(('localhost', 5051))
+     self.sock.listen(0)
+
+     # 
+     #
+
+     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.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()))
+                    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()
+
+     gtk.mainquit()
+     sys.stdout.write("quit!\n")
+
+# we start the app like this...
+app=appgui()
+gtk.mainloop()
+
+
+# notes
+# http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq20.011.htp

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