From: <umg...@us...> - 2007-04-03 11:59:11
|
Revision: 395 http://svn.sourceforge.net/pybridge/?rev=395&view=rev Author: umgangee Date: 2007-04-03 04:59:11 -0700 (Tue, 03 Apr 2007) Log Message: ----------- Make DialogConnection a child of WindowMain by adding appropriate logic to WindowMain; change utils references to manager. Modified Paths: -------------- trunk/pybridge/pybridge/ui/window_main.py Modified: trunk/pybridge/pybridge/ui/window_main.py =================================================================== --- trunk/pybridge/pybridge/ui/window_main.py 2007-04-03 11:57:29 UTC (rev 394) +++ trunk/pybridge/pybridge/ui/window_main.py 2007-04-03 11:59:11 UTC (rev 395) @@ -19,15 +19,24 @@ import gtk from wrapper import GladeWrapper +from twisted.internet import reactor import webbrowser -from pybridge import __version__ as version +from pybridge import __version__ as PYBRIDGE_VERSION import pybridge.environment as env from pybridge.network.client import client -from eventhandler import eventhandler -import utils +from eventhandler import SimpleEventHandler +from manager import WindowManager, wm +from pybridge.ui import settings +from dialog_connection import DialogConnection +from dialog_newtable import DialogNewtable +from dialog_preferences import DialogPreferences +from window_bridgetable import WindowBridgetable + +from eventhandler import SimpleEventHandler, eventhandler # TODO: remove + TABLE_ICON = env.find_pixmap("table.png") USER_ICON = env.find_pixmap("user.png") @@ -42,8 +51,9 @@ peopleview_icon = gtk.gdk.pixbuf_new_from_file_at_size(USER_ICON, 48, 48) - def new(self): - self.tables = {} # For each observed table, reference to window. + def setUp(self): + # Use a private WindowManager for table window instances. + self.tables = WindowManager() # Set up table model and icon view. self.tableview.set_text_column(0) @@ -61,20 +71,41 @@ self.peopleview.set_model(self.peopleview_model) # Register event callbacks. - eventhandler.registerCallbacksFor(self, self.callbacks) + self.eventHandler = SimpleEventHandler(self) + client.attach(self.eventHandler) + client.setEventHandler(eventhandler) # REMOVE + eventhandler.registerCallbacksFor(self, self.callbacks) # REMOVE + if not wm.get(DialogConnection): + wm.open(DialogConnection, parent=self) - def cleanup(self): - eventhandler.unregister(self, self.callbacks) - for instance in self.tables.values(): - utils.windows.close('window_bridgetable', instance) + def tearDown(self): + #eventhandler.unregister(self, self.callbacks) + # Close all windows. + for window in wm.values(): + wm.close(window) + client.disconnect() + + settings.save() # Save configuration. + + + def quit(self): + """Shut down gracefully.""" + wm.close(self) + reactor.stop() + gtk.main_quit() + + + def errback(self, failure): + print "Error: %s" % failure.getErrorMessage() + + def joinTable(self, tableid, host=False): def success(table): - window = utils.windows.open('window_bridgetable', parent=self) - self.tables[table.id] = window + window = self.tables.open(WindowBridgetable, id=tableid) window.setTable(table) d = client.joinTable(tableid, host) @@ -95,6 +126,27 @@ # Registered event handlers. + def event_connect(self): + self.notebook.set_property('sensitive', True) + self.menu_connect.set_property('visible', False) + self.menu_disconnect.set_property('visible', True) + + + def event_disconnect(self): + for table in self.tables.values(): + self.tables.close(table) + + self.notebook.set_property('sensitive', False) + self.menu_connect.set_property('visible', True) + self.menu_disconnect.set_property('visible', False) + self.tableview_model.clear() + self.peopleview_model.clear() + + + def event_leaveTable(self, tableid): + self.tables.close(self.tables[tableid]) + + def event_tableOpened(self, tableid): """Adds a table to the table listing.""" self.tableview_model.append([tableid, self.tableview_icon]) @@ -174,13 +226,12 @@ def on_window_main_delete_event(self, widget, *args): - utils.quit() -# return True + self.quit() def on_newtable_clicked(self, widget, *args): - if not utils.windows.get('dialog_newtable'): - utils.windows.open('dialog_newtable', parent=self) + if not wm.get(DialogNewtable): + wm.open(DialogNewtable) def on_jointable_clicked(self, widget, *args): @@ -188,18 +239,41 @@ self.on_tableview_item_activated(self.tableview, path) + def on_connect_activate(self, widget, *args): + if not wm.get(DialogConnection): + wm.open(DialogConnection) + + def on_disconnect_activate(self, widget, *args): - client.disconnect() - utils.windows.close(self.glade_name) - utils.windows.open('dialog_connection') + do_disconnect = True + #if len([True for table in self.tables if table.player]) > 0: + if self.tables: + dialog = gtk.MessageDialog(parent=self.window, + flags=gtk.DIALOG_MODAL, + type=gtk.MESSAGE_QUESTION) + dialog.set_title(_('Disconnect from Server')) + dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) + dialog.add_button(gtk.STOCK_DISCONNECT, gtk.RESPONSE_OK) + dialog.set_markup(_('Are you sure you wish to disconnect?')) + dialog.format_secondary_text(_('You are playing a game. Disconnecting may forfeit the game, or incur penalties.')) + do_disconnect = (dialog.run() == gtk.RESPONSE_OK) + dialog.destroy() + + if do_disconnect: + # Close all table windows, triggers stoppedObserving() on all tables. + # TODO: should do this on_disconnected + client.disconnect() + + def on_quit_activate(self, widget, *args): - utils.quit() + self.quit() def on_preferences_activate(self, widget, *args): - utils.windows.open('dialog_preferences') + if not wm.get(DialogPreferences): + wm.open(DialogPreferences) def on_homepage_activate(self, widget, *args): @@ -209,7 +283,7 @@ def on_about_activate(self, widget, *args): about = gtk.AboutDialog() about.set_name('PyBridge') - about.set_version(version) + about.set_version(PYBRIDGE_VERSION) about.set_copyright('Copyright (C) 2004-2007 Michael Banks') about.set_comments(_('A free online bridge game.')) about.set_website('http://pybridge.sourceforge.net/') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <umg...@us...> - 2007-04-06 20:07:11
|
Revision: 405 http://svn.sourceforge.net/pybridge/?rev=405&view=rev Author: umgangee Date: 2007-04-06 13:07:13 -0700 (Fri, 06 Apr 2007) Log Message: ----------- Remove joinTable and leaveTable methods (use the ones in NetworkClient instead). Listen for 'joinTable' and 'leaveTable' events: when received, act accordingly. Modified Paths: -------------- trunk/pybridge/pybridge/ui/window_main.py Modified: trunk/pybridge/pybridge/ui/window_main.py =================================================================== --- trunk/pybridge/pybridge/ui/window_main.py 2007-04-06 18:04:49 UTC (rev 404) +++ trunk/pybridge/pybridge/ui/window_main.py 2007-04-06 20:07:13 UTC (rev 405) @@ -96,27 +96,6 @@ print "Error: %s" % failure.getErrorMessage() - def joinTable(self, tableid, host=False): - - def success(table): - window = self.tables.open(WindowBridgetable, id=tableid) - window.setTable(table) - - d = client.joinTable(tableid, host) - d.addCallback(success) - return d - - - def leaveTable(self, tableid): - - def success(r): - del self.tables[tableid] - - d = client.leaveTable(tableid) - d.addCallback(success) - return d - - # Event handlers. @@ -155,6 +134,11 @@ pass # Ignore an unrecognised roster. + def event_joinTable(self, tableid, table): + window = self.tables.open(WindowBridgetable, id=tableid) + window.setTable(table) + + def event_leaveTable(self, tableid): self.tables.close(self.tables[tableid]) # Close window. @@ -202,7 +186,8 @@ iter = self.tableview_model.get_iter(path) tableid = self.tableview_model.get_value(iter, 0) if tableid not in client.tables: - self.joinTable(tableid) + d = client.joinTable(tableid) + d.addErrback(self.errback) self.jointable.set_property('sensitive', False) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <umg...@us...> - 2007-06-18 11:55:02
|
Revision: 424 http://svn.sourceforge.net/pybridge/?rev=424&view=rev Author: umgangee Date: 2007-06-18 04:55:03 -0700 (Mon, 18 Jun 2007) Log Message: ----------- Display disconnect confirm dialog only when user is playing at a table, switch to ConfigObj configuration management. Modified Paths: -------------- trunk/pybridge/pybridge/ui/window_main.py Modified: trunk/pybridge/pybridge/ui/window_main.py =================================================================== --- trunk/pybridge/pybridge/ui/window_main.py 2007-06-18 11:53:43 UTC (rev 423) +++ trunk/pybridge/pybridge/ui/window_main.py 2007-06-18 11:55:03 UTC (rev 424) @@ -28,7 +28,6 @@ from eventhandler import SimpleEventHandler from manager import WindowManager, wm -from pybridge.ui import settings from dialog_connection import DialogConnection from dialog_newtable import DialogNewtable @@ -82,9 +81,7 @@ wm.close(window) client.disconnect() - settings.save() # Save configuration. - def quit(self): """Shut down gracefully.""" wm.close(self) @@ -244,16 +241,15 @@ def on_disconnect_activate(self, widget, *args): do_disconnect = True - #if len([True for table in self.tables if table.player]) > 0: - if self.tables: + if len([True for table in self.tables.values() if table.player]) > 0: dialog = gtk.MessageDialog(parent=self.window, flags=gtk.DIALOG_MODAL, type=gtk.MESSAGE_QUESTION) - dialog.set_title(_('Disconnect from Server')) + dialog.set_title(_('Disconnect from server')) dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dialog.add_button(gtk.STOCK_DISCONNECT, gtk.RESPONSE_OK) dialog.set_markup(_('Are you sure you wish to disconnect?')) - dialog.format_secondary_text(_('You are playing a game. Disconnecting may forfeit the game, or incur penalties.')) + dialog.format_secondary_text(_('You are playing at a table. Disconnecting may forfeit the game, or incur penalties.')) do_disconnect = (dialog.run() == gtk.RESPONSE_OK) dialog.destroy() @@ -292,7 +288,10 @@ logo_path = env.find_pixmap('pybridge.png') logo = gtk.gdk.pixbuf_new_from_file(logo_path) about.set_logo(logo) - - about.run() - about.destroy() + def dialog_response_cb(dialog, response_id): + dialog.destroy() + + about.connect('response', dialog_response_cb) + about.show() + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <umg...@us...> - 2007-06-20 15:10:34
|
Revision: 430 http://svn.sourceforge.net/pybridge/?rev=430&view=rev Author: umgangee Date: 2007-06-20 08:10:30 -0700 (Wed, 20 Jun 2007) Log Message: ----------- Display notification dialog when connection is lost unexpectedly. Modified Paths: -------------- trunk/pybridge/pybridge/ui/window_main.py Modified: trunk/pybridge/pybridge/ui/window_main.py =================================================================== --- trunk/pybridge/pybridge/ui/window_main.py 2007-06-20 15:09:13 UTC (rev 429) +++ trunk/pybridge/pybridge/ui/window_main.py 2007-06-20 15:10:30 UTC (rev 430) @@ -96,7 +96,7 @@ # Event handlers. - def event_connectedAsUser(self, username): + def event_loggedIn(self, username): self.notebook.set_property('sensitive', True) self.menu_connect.set_property('visible', False) self.menu_disconnect.set_property('visible', True) @@ -104,7 +104,7 @@ self.newtable.set_property('sensitive', True) - def event_connectionLost(self, reason): + def event_loggedOut(self): for table in self.tables.values(): self.tables.close(table) @@ -118,6 +118,23 @@ self.peopleview_model.clear() + def event_connectionLost(self, host, port): + dialog = gtk.MessageDialog(parent=self.window, flags=gtk.DIALOG_MODAL, + type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK) + dialog.set_title(_('Connection to server lost')) + dialog.set_markup(_('The connection to %s was lost unexpectedly.' % host)) + dialog.format_secondary_text(_('Please check your computer\'s network connection status. If you cannot reconnect, the server may be offline.')) + # If this problem persists... + + #dialog.add_button() + + def dialog_response_cb(dialog, response_id): + dialog.destroy() + + dialog.connect('response', dialog_response_cb) + dialog.show() + + def event_gotRoster(self, name, roster): lookup = {'tables' : (self.tableview_model, self.tableview_icon), 'users' : (self.peopleview_model, self.peopleview_icon)} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <umg...@us...> - 2007-06-20 18:04:17
|
Revision: 434 http://svn.sourceforge.net/pybridge/?rev=434&view=rev Author: umgangee Date: 2007-06-20 11:04:19 -0700 (Wed, 20 Jun 2007) Log Message: ----------- When connection fails unexpectedly, provide a Reconnect option to user. Modified Paths: -------------- trunk/pybridge/pybridge/ui/window_main.py Modified: trunk/pybridge/pybridge/ui/window_main.py =================================================================== --- trunk/pybridge/pybridge/ui/window_main.py 2007-06-20 15:15:27 UTC (rev 433) +++ trunk/pybridge/pybridge/ui/window_main.py 2007-06-20 18:04:19 UTC (rev 434) @@ -120,17 +120,20 @@ def event_connectionLost(self, host, port): dialog = gtk.MessageDialog(parent=self.window, flags=gtk.DIALOG_MODAL, - type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK) + type=gtk.MESSAGE_ERROR) dialog.set_title(_('Connection to server lost')) dialog.set_markup(_('The connection to %s was lost unexpectedly.' % host)) - dialog.format_secondary_text(_('Please check your computer\'s network connection status. If you cannot reconnect, the server may be offline.')) + dialog.format_secondary_text(_('Please check your computer\'s network connection status before reconnecting. If you cannot reconnect, the server may be offline.')) # If this problem persists... - #dialog.add_button() - def dialog_response_cb(dialog, response_id): dialog.destroy() + if response_id == gtk.RESPONSE_OK: + wm.open(DialogConnection, parent=self) + dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) + dialog.add_button(gtk.STOCK_CONNECT, gtk.RESPONSE_OK) + dialog.connect('response', dialog_response_cb) dialog.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |