From: <umg...@us...> - 2007-06-18 11:53:45
|
Revision: 423 http://svn.sourceforge.net/pybridge/?rev=423&view=rev Author: umgangee Date: 2007-06-18 04:53:43 -0700 (Mon, 18 Jun 2007) Log Message: ----------- Add support for user-specifiable suit colours, switch to ConfigObj configuration management. Modified Paths: -------------- trunk/pybridge/pybridge/ui/dialog_preferences.py Modified: trunk/pybridge/pybridge/ui/dialog_preferences.py =================================================================== --- trunk/pybridge/pybridge/ui/dialog_preferences.py 2007-06-18 11:51:35 UTC (rev 422) +++ trunk/pybridge/pybridge/ui/dialog_preferences.py 2007-06-18 11:53:43 UTC (rev 423) @@ -21,8 +21,8 @@ from wrapper import GladeWrapper import pybridge.environment as env +from config import config from manager import wm -from pybridge.ui import settings from pybridge.bridge.symbols import Suit @@ -57,7 +57,7 @@ self.cardstyle.pack_start(cell, True) self.cardstyle.add_attribute(cell, 'text', 0) - activedeck = settings.appearance.get('deck', 'bonded.png') + activedeck = config['Appearance'].get('CardStyle', 'bonded.png') # Populate list of card decks. path = env.find_pixmap('') for filename in os.listdir(path): @@ -66,7 +66,17 @@ if filename == activedeck: self.cardstyle.set_active_iter(iter) + self.suit_colours = {} + for suit in Suit: + rgb = config['Appearance']['Colours'].get(suit.key, (0, 0, 0)) + colour = gtk.gdk.Color(*rgb) + self.suit_colours[suit] = colour + # Set button label colour from self.suit_colours. + hexrep = gtk.color_selection_palette_to_string([colour]) + label = getattr(self, 'label_%scolour' % suit.key.lower()) + label.set_markup(SUIT_LABEL_TEMPLATE % (hexrep, SUIT_SYMBOLS[suit])) + # Signal handlers. @@ -80,30 +90,25 @@ def on_suitcolour_clicked(self, widget, *args): # Get symbol in Suit corresponding to button clicked. - suit_buttons = {self.button_clubcolour: Suit.Club, - self.button_diamondcolour: Suit.Diamond, - self.button_heartcolour: Suit.Heart, - self.button_spadecolour: Suit.Spade } - suit = suit_buttons[widget] + suit = [s for s in Suit if s.key.lower() in widget.get_name()][0] title = _("Select colour for %s symbol" % SUIT_NAMES[suit]) dialog = gtk.ColorSelectionDialog(title) - dialog.colorsel.set_current_color(gtk.gdk.color_parse('#888888')) + dialog.colorsel.set_current_color(self.suit_colours[suit]) def dialog_response_cb(dialog, response_id): if response_id == gtk.RESPONSE_OK: colour = dialog.colorsel.get_current_color() - + self.suit_colours[suit] = colour # Set button label to colour selected by user. - label = widget.get_children()[0] hexrep = gtk.color_selection_palette_to_string([colour]) + label = getattr(self, 'label_%scolour' % suit.key.lower()) label.set_markup(SUIT_LABEL_TEMPLATE % (hexrep, SUIT_SYMBOLS[suit])) dialog.destroy() dialog.connect('response', dialog_response_cb) - #dialog.show() - dialog.run() + dialog.run() # show() def on_cancelbutton_clicked(self, widget, *args): @@ -111,6 +116,10 @@ def on_okbutton_clicked(self, widget, *args): - print "SAVE SETTINGS" + # Save preferences to config file. + for suit, colour in self.suit_colours.items(): + rgb = (colour.red, colour.green, colour.blue) + config['Appearance']['Colours'][suit.key] = rgb + print "TODO: background and card style" wm.close(self) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |