|
From: <umg...@us...> - 2007-07-24 19:30:20
|
Revision: 494
http://svn.sourceforge.net/pybridge/?rev=494&view=rev
Author: umgangee
Date: 2007-07-24 12:30:16 -0700 (Tue, 24 Jul 2007)
Log Message:
-----------
Improvements to the logic and appearance of tableview and userview widgets, plus a fix for https://bugs.launchpad.net/pybridge/+bug/127974
Modified Paths:
--------------
trunk/pybridge/glade/pybridge.glade
trunk/pybridge/pybridge/ui/window_main.py
Modified: trunk/pybridge/glade/pybridge.glade
===================================================================
--- trunk/pybridge/glade/pybridge.glade 2007-07-24 17:22:23 UTC (rev 493)
+++ trunk/pybridge/glade/pybridge.glade 2007-07-24 19:30:16 UTC (rev 494)
@@ -5,7 +5,7 @@
<widget class="GtkWindow" id="window_main">
<property name="visible">True</property>
<property name="title" translatable="yes">PyBridge</property>
- <signal name="delete_event" handler="on_window_main_delete_event"/>
+ <signal name="delete_event" handler="on_delete_event"/>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
@@ -189,7 +189,7 @@
<property name="border_width">8</property>
<property name="spacing">8</property>
<child>
- <widget class="GtkScrolledWindow" id="scrolledwindow5">
+ <widget class="GtkScrolledWindow" id="scrolled_tableview">
<property name="width_request">320</property>
<property name="height_request">240</property>
<property name="visible">True</property>
@@ -208,103 +208,33 @@
</widget>
</child>
<child>
- <widget class="GtkVBox" id="vbox16">
- <property name="width_request">160</property>
+ <widget class="GtkToolbar" id="toolbar_tables">
<property name="visible">True</property>
- <property name="spacing">4</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+ <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
<child>
- <widget class="GtkButton" id="newtable">
+ <widget class="GtkToolButton" id="newtable">
<property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="can_focus">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label">New Table...</property>
+ <property name="stock_id">gtk-new</property>
<signal name="clicked" handler="on_newtable_clicked"/>
- <child>
- <widget class="GtkAlignment" id="alignment19">
- <property name="visible">True</property>
- <property name="xscale">0</property>
- <property name="yscale">0</property>
- <child>
- <widget class="GtkHBox" id="hbox24">
- <property name="visible">True</property>
- <property name="spacing">2</property>
- <child>
- <widget class="GtkImage" id="image322">
- <property name="visible">True</property>
- <property name="stock">gtk-new</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label55">
- <property name="visible">True</property>
- <property name="label" translatable="yes">New Table...</property>
- <property name="use_underline">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
- </child>
</widget>
<packing>
<property name="expand">False</property>
- <property name="fill">False</property>
</packing>
</child>
<child>
- <widget class="GtkButton" id="jointable">
+ <widget class="GtkToolButton" id="jointable">
<property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="can_focus">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label">Join Table</property>
+ <property name="stock_id">gtk-jump-to</property>
<signal name="clicked" handler="on_jointable_clicked"/>
- <child>
- <widget class="GtkAlignment" id="alignment20">
- <property name="visible">True</property>
- <property name="xscale">0</property>
- <property name="yscale">0</property>
- <child>
- <widget class="GtkHBox" id="hbox25">
- <property name="visible">True</property>
- <property name="spacing">2</property>
- <child>
- <widget class="GtkImage" id="image323">
- <property name="visible">True</property>
- <property name="stock">gtk-jump-to</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label56">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Join This Table</property>
- <property name="use_underline">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
- </child>
</widget>
<packing>
<property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
</packing>
</child>
</widget>
@@ -321,7 +251,7 @@
<child>
<widget class="GtkLabel" id="label_tabletab">
<property name="visible">True</property>
- <property name="label" translatable="yes">Tables</property>
+ <property name="label" translatable="yes">Open Tables</property>
</widget>
<packing>
<property name="type">tab</property>
@@ -335,7 +265,7 @@
<property name="border_width">8</property>
<property name="spacing">8</property>
<child>
- <widget class="GtkScrolledWindow" id="scrolledwindow9">
+ <widget class="GtkScrolledWindow" id="scrolled_userview">
<property name="width_request">320</property>
<property name="height_request">240</property>
<property name="visible">True</property>
@@ -354,20 +284,21 @@
</widget>
</child>
<child>
- <widget class="GtkVButtonBox" id="buttonbox_users">
+ <widget class="GtkToolbar" id="toolbar_users">
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="layout_style">GTK_BUTTONBOX_START</property>
+ <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+ <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
<child>
- <widget class="GtkButton" id="button_userinfo">
+ <widget class="GtkToolButton" id="userinfo">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="label" translatable="yes">User Information</property>
+ <property name="stock_id">gtk-info</property>
<signal name="clicked" handler="on_userinfo_clicked"/>
</widget>
+ <packing>
+ <property name="expand">False</property>
+ </packing>
</child>
</widget>
<packing>
@@ -384,7 +315,7 @@
<child>
<widget class="GtkLabel" id="label_usertab">
<property name="visible">True</property>
- <property name="label" translatable="yes">Users</property>
+ <property name="label" translatable="yes">Users Online</property>
</widget>
<packing>
<property name="type">tab</property>
@@ -435,23 +366,30 @@
<property name="column_spacing">8</property>
<property name="row_spacing">4</property>
<child>
- <widget class="GtkEntry" id="entry_portnum">
- <property name="width_request">80</property>
+ <widget class="GtkLabel" id="label_portnum">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="max_length">5</property>
- <property name="invisible_char">*</property>
- <signal name="changed" handler="on_field_changed"/>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Port:</property>
</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">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
+ <widget class="GtkLabel" id="label_hostname">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Host Name:</property>
+ </widget>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
<widget class="GtkEntry" id="entry_hostname">
<property name="width_request">140</property>
<property name="visible">True</property>
@@ -466,26 +404,19 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label_hostname">
+ <widget class="GtkEntry" id="entry_portnum">
+ <property name="width_request">80</property>
<property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Host Name:</property>
+ <property name="can_focus">True</property>
+ <property name="max_length">5</property>
+ <property name="invisible_char">*</property>
+ <signal name="changed" handler="on_field_changed"/>
</widget>
<packing>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label_portnum">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Port:</property>
- </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">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
@@ -528,20 +459,26 @@
<property name="column_spacing">8</property>
<property name="row_spacing">4</property>
<child>
- <widget class="GtkEntry" id="entry_password">
- <property name="width_request">120</property>
+ <widget class="GtkLabel" id="label_username">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="max_length">40</property>
- <property name="visibility">False</property>
- <property name="invisible_char">*</property>
- <signal name="changed" handler="on_field_changed"/>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">User Name:</property>
</widget>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label_password">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Password:</property>
+ </widget>
+ <packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
@@ -561,29 +498,23 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label_password">
+ <widget class="GtkEntry" id="entry_password">
+ <property name="width_request">120</property>
<property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Password:</property>
+ <property name="can_focus">True</property>
+ <property name="max_length">40</property>
+ <property name="visibility">False</property>
+ <property name="invisible_char">*</property>
+ <signal name="changed" handler="on_field_changed"/>
</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">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
- <child>
- <widget class="GtkLabel" id="label_username">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">User Name:</property>
- </widget>
- <packing>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
</widget>
</child>
<child>
@@ -708,53 +639,53 @@
<property name="column_spacing">8</property>
<property name="row_spacing">4</property>
<child>
- <widget class="GtkLabel" id="label_tablename">
+ <widget class="GtkLabel" id="label_gamelist">
<property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Table Name:</property>
+ <property name="label" translatable="yes">Game at Table:</property>
</widget>
<packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkEntry" id="tablename">
- <property name="width_request">140</property>
+ <widget class="GtkComboBox" id="gamelist">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="invisible_char">*</property>
- <signal name="changed" handler="on_tablename_changed"/>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <signal name="changed" handler="on_gamelist_changed"/>
</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="y_options">GTK_FILL</property>
</packing>
</child>
<child>
- <widget class="GtkComboBox" id="gamelist">
+ <widget class="GtkEntry" id="tablename">
+ <property name="width_request">140</property>
<property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <signal name="changed" handler="on_gamelist_changed"/>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">*</property>
+ <signal name="changed" handler="on_tablename_changed"/>
</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="y_options">GTK_FILL</property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label_gamelist">
+ <widget class="GtkLabel" id="label_tablename">
<property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Game at Table:</property>
+ <property name="label" translatable="yes">Table Name:</property>
</widget>
<packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
@@ -835,6 +766,72 @@
<property name="column_spacing">8</property>
<property name="row_spacing">4</property>
<child>
+ <widget class="GtkFileChooserButton" id="background">
+ <property name="width_request">160</property>
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <signal name="selection_changed" handler="on_background_changed"/>
+ </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>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkComboBox" id="cardstyle">
+ <property name="width_request">160</property>
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <signal name="changed" handler="on_cardstyle_changed"/>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label_background">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Background:</property>
+ </widget>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label_cardstyle">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Card Style:</property>
+ </widget>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label_suitcolours">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Suit Colours:</property>
+ </widget>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
<widget class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@@ -931,72 +928,6 @@
<property name="bottom_attach">3</property>
</packing>
</child>
- <child>
- <widget class="GtkLabel" id="label_suitcolours">
- <property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Suit Colours:</property>
- </widget>
- <packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label_cardstyle">
- <property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Card Style:</property>
- </widget>
- <packing>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label_background">
- <property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Background:</property>
- </widget>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkComboBox" id="cardstyle">
- <property name="width_request">160</property>
- <property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <signal name="changed" handler="on_cardstyle_changed"/>
- </widget>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- </packing>
- </child>
- <child>
- <widget class="GtkFileChooserButton" id="background">
- <property name="width_request">160</property>
- <property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <signal name="selection_changed" handler="on_background_changed"/>
- </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>
- </packing>
- </child>
</widget>
<packing>
<property name="expand">False</property>
Modified: trunk/pybridge/pybridge/ui/window_main.py
===================================================================
--- trunk/pybridge/pybridge/ui/window_main.py 2007-07-24 17:22:23 UTC (rev 493)
+++ trunk/pybridge/pybridge/ui/window_main.py 2007-07-24 19:30:16 UTC (rev 494)
@@ -28,6 +28,7 @@
from pybridge.network.client import client
from eventhandler import SimpleEventHandler
+from excepthook import exceptdialog
from manager import wm
from dialog_connection import DialogConnection
@@ -39,33 +40,29 @@
# TODO: import all Window*Table classes automatically.
from pybridge.games.bridge.ui.window_bridgetable import WindowBridgeTable
-TABLE_ICON = env.find_pixmap("table.png")
-USER_ICON = env.find_pixmap("user.png")
+TABLE_ICON = env.find_pixmap('table.png')
+USER_ICON = env.find_pixmap('user.png')
class WindowMain(GladeWrapper):
glade_name = 'window_main'
- tableview_icon = gtk.gdk.pixbuf_new_from_file_at_size(TABLE_ICON, 48, 48)
- userview_icon = gtk.gdk.pixbuf_new_from_file_at_size(USER_ICON, 48, 48)
+ table_icon = gtk.gdk.pixbuf_new_from_file_at_size(TABLE_ICON, 48, 48)
+ user_icon = gtk.gdk.pixbuf_new_from_file_at_size(USER_ICON, 48, 48)
def setUp(self):
- # Set up table model and icon view.
- self.tableview.set_text_column(0)
- self.tableview.set_pixbuf_column(1)
- model = gtk.ListStore(str, gtk.gdk.Pixbuf)
- model.set_sort_column_id(0, gtk.SORT_ASCENDING)
- self.tableview.set_model(model)
+ # Track iters in ListStore objects, for O(1) lookups.
+ self.tableview_iters, self.userview_iters = {}, {}
+ # Set up tableview and userview.
+ for view in self.tableview, self.userview:
+ view.set_text_column(0)
+ view.set_pixbuf_column(1)
+ model = gtk.ListStore(str, gtk.gdk.Pixbuf)
+ model.set_sort_column_id(0, gtk.SORT_ASCENDING)
+ view.set_model(model)
- # Set up user model and icon view.
- self.userview.set_text_column(0)
- self.userview.set_pixbuf_column(1)
- model = gtk.ListStore(str, gtk.gdk.Pixbuf)
- model.set_sort_column_id(0, gtk.SORT_ASCENDING)
- self.userview.set_model(model)
-
# Attach event handler to listen for events.
self.eventHandler = SimpleEventHandler(self)
client.attach(self.eventHandler)
@@ -75,25 +72,23 @@
def tearDown(self):
- # TODO: detach event handler from all attached subjects.
-
- # Close all windows.
- for window in wm.values():
- wm.close(window)
client.disconnect()
+ client.detach(self.eventHandler)
+ # Terminate.
+ reactor.stop()
+ gtk.main_quit()
def quit(self):
"""Shut down gracefully."""
- client.detach(self.eventHandler)
- wm.close(self)
- reactor.stop()
- gtk.main_quit()
+ # TODO: if playing a game, ensure that user really wants to quit.
+ wm.close(self) # Triggers tearDown.
def errback(self, failure):
- print "Error: %s" % failure.getErrorMessage()
- print failure.getTraceback()
+ message = "Network error: %s\n\n%s" % (failure.getErrorMessage(),
+ failure.getTraceback())
+ exceptdialog(message)
# Event handlers.
@@ -104,7 +99,10 @@
self.menu_connect.set_property('visible', False)
self.menu_disconnect.set_property('visible', True)
self.menu_newtable.set_property('sensitive', True)
+
self.newtable.set_property('sensitive', True)
+ self.jointable.set_property('sensitive', False)
+ self.userinfo.set_property('sensitive', False)
def event_loggedOut(self):
@@ -116,10 +114,9 @@
self.menu_connect.set_property('visible', True)
self.menu_disconnect.set_property('visible', False)
self.menu_newtable.set_property('sensitive', False)
- #self.newtable.set_property('sensitive', False)
- self.tableview.get_model().clear()
- self.userview.get_model().clear()
+ self.tableview.get_model().clear(); self.tableview_iters.clear()
+ self.userview.get_model().clear(); self.userview_iters.clear()
def event_connectionLost(self, host, port):
@@ -143,54 +140,48 @@
def event_gotRoster(self, name, roster):
- lookup = {'tables' : (self.tableview.get_model(), self.tableview_icon),
- 'users' : (self.userview.get_model(), self.userview_icon)}
-
+ lookup = {'tables' : (self.tableview.get_model(), self.table_icon, self.tableview_iters),
+ 'users' : (self.userview.get_model(), self.user_icon, self.userview_iters)}
try:
- model, icon = lookup[name]
+ model, icon, view_iters = lookup[name]
for id, info in roster.items():
- model.append([id, icon])
+ iter = model.append([id, icon])
+ view_iters[id] = iter
roster.attach(self.eventHandler)
except KeyError:
pass # Ignore an unrecognised roster.
def event_openTable(self, tableid, info):
- """Adds a table to the table listing."""
# Only display table if it supported by client.
if info['gamename'] in SUPPORTED_GAMES:
- self.tableview.get_model().append([tableid, self.tableview_icon])
+ model = self.tableview.get_model()
+ iter = model.append([tableid, self.table_icon])
+ self.tableview_iters[tableid] = iter
def event_closeTable(self, tableid):
- """Removes a table from the table listing."""
-
- def func(model, path, iter, user_data):
- if model.get_value(iter, 0) in user_data:
- model.remove(iter)
- return True
+ iter = self.tableview_iters.get(tableid)
+ if iter:
+ model = self.tableview.get_model()
+ model.remove(iter)
+ del self.tableview_iters[tableid]
- model = self.tableview.get_model()
- model.foreach(func, tableid)
-
def event_userLogin(self, username, info):
- """Adds a user to the people listing."""
- self.userview.get_model().append([username, self.userview_icon])
+ model = self.userview.get_model()
+ iter = model.append([username, self.user_icon])
+ self.userview_iters[username] = iter
def event_userLogout(self, username):
- """Removes a user from the people listing."""
-
- def func(model, path, iter, user_data):
- if model.get_value(iter, 0) in user_data:
- model.remove(iter)
- return True
+ iter = self.userview_iters.get(username)
+ if iter:
+ model = self.userview.get_model()
+ model.remove(iter)
+ del self.userview_iters[username]
- model = self.userview.get_model()
- model.foreach(func, username)
-
# Signal handlers.
@@ -199,16 +190,16 @@
def on_tableview_item_activated(self, iconview, path, *args):
+ model = self.tableview.get_model()
+ iter = model.get_iter(path)
+ tableid = model.get_value(iter, 0)
def joinedTable(table):
# TODO: select correct table window class.
window = wm.open(WindowBridgeTable, id=tableid)
window.setTable(table)
- model = self.tableview.get_model()
- iter = model.get_iter(path)
- tableid = model.get_value(iter, 0)
- if tableid not in client.tables:
+ if tableid not in client.tables: # Already joined table?
d = client.joinTable(tableid)
d.addCallbacks(joinedTable, self.errback)
self.jointable.set_property('sensitive', False)
@@ -236,27 +227,20 @@
winid = (DialogUserInfo, username)
def gotUserInfo(info):
- w = wm.open(DialogUserInfo, winid)
+ w = wm.open(DialogUserInfo, id=winid)
w.setUserInfo(username, info)
if not wm.get(winid):
- # TODO: if user info in cache, do not request again from server.
d = client.getUserInformation(username)
d.addCallback(gotUserInfo)
def on_userview_selection_changed(self, iconview, *args):
cursor = self.userview.get_cursor()
- if cursor: # Ensure cursor contains a path, not None.
- self.buttonbox_users.set_property('sensitive', True)
- else:
- self.buttonbox_users.set_property('sensitive', False)
+ # If cursor contains a path, enable User Info button.
+ self.userinfo.set_property('sensitive', bool(cursor))
- def on_window_main_delete_event(self, widget, *args):
- self.quit()
-
-
def on_newtable_clicked(self, widget, *args):
if not wm.get(DialogNewtable):
wm.open(DialogNewtable)
@@ -335,3 +319,8 @@
about.connect('response', dialog_response_cb)
about.show()
+
+ def on_delete_event(self, widget, *args):
+ self.quit()
+ return True # Stops window deletion taking place.
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|