gnome-games r7821 - in trunk/glchess: data src/lib src/lib/gtkui



Author: rancell
Date: Thu Aug 14 14:50:08 2008
New Revision: 7821
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7821&view=rev

Log:
Watch configuration in preferences dialog so widgets update when config values change (Bug #546699)


Modified:
   trunk/glchess/data/glchess.schemas.in
   trunk/glchess/src/lib/config.py
   trunk/glchess/src/lib/gtkui/dialogs.py
   trunk/glchess/src/lib/gtkui/gtkui.py

Modified: trunk/glchess/data/glchess.schemas.in
==============================================================================
--- trunk/glchess/data/glchess.schemas.in	(original)
+++ trunk/glchess/data/glchess.schemas.in	Thu Aug 14 14:50:08 2008
@@ -182,7 +182,7 @@
     </schema>
 
     <schema>
-      <key>/schemas/apps/glchess/board_side</key>
+      <key>/schemas/apps/glchess/board_view</key>
       <applyto>/apps/glchess/board_side</applyto>
       <owner>glchess</owner>
       <type>string</type>

Modified: trunk/glchess/src/lib/config.py
==============================================================================
--- trunk/glchess/src/lib/config.py	(original)
+++ trunk/glchess/src/lib/config.py	Thu Aug 14 14:50:08 2008
@@ -187,11 +187,8 @@
         try:
             watchers = _notifiers[name]
         except KeyError:
-            watchers = []
-            
+            watchers = _notifiers[name] = []            
         watchers.append(function)
-            
-        _notifiers[name] = watchers
 
 def _save():
     """Save the current configuration"""

Modified: trunk/glchess/src/lib/gtkui/dialogs.py
==============================================================================
--- trunk/glchess/src/lib/gtkui/dialogs.py	(original)
+++ trunk/glchess/src/lib/gtkui/dialogs.py	Thu Aug 14 14:50:08 2008
@@ -547,8 +547,7 @@
         
         self.__gui.get_widget('preferences').set_transient_for(mainUI.mainWindow)
 
-        # Load preferences for move_format
-        moveFormat = glchess.config.get('move_format')
+        # Make model for move format
         moveModel = gtk.ListStore(str, str)
         widget = self.__gui.get_widget('move_format_combo')
         widget.set_model(moveModel)
@@ -557,12 +556,9 @@
                         ('san', _('Standard Algebraic'))]
         for (key, label) in move_formats:
             iter = moveModel.append()
-            if key == moveFormat:
-                widget.set_active_iter(iter)
             moveModel.set(iter, 0, label, 1, key)
 
-        # Load preferences for board orientation
-        boardView = glchess.config.get('board_view')
+        # Make modelfor board orientation
         boardModel = gtk.ListStore(str, str)
         widget = self.__gui.get_widget('board_combo')
         widget.set_model(boardModel)
@@ -572,12 +568,9 @@
                      ('current', _('Current Player'))]
         for (key, label) in view_list:
             iter = boardModel.append()
-            if key == boardView:
-                widget.set_active_iter(iter)
             boardModel.set(iter, 0, label, 1, key)
 
-        # Load preferences for promotion type
-        promotionType = glchess.config.get('promotion_type')
+        # Make modelfor promotion type
         promotionModel = gtk.ListStore(str, str)
         widget = self.__gui.get_widget('promotion_type_combo')
         widget.set_model(promotionModel)
@@ -587,30 +580,58 @@
                           ('bishop', _('Bishop'))]
         for (key, label) in promotion_list:
             iter = promotionModel.append()
-            if key == promotionType:
-                widget.set_active_iter(iter)
             promotionModel.set(iter, 0, label, 1, key)
+            
+        # Watch for config changes
+        for key in ['show_3d', 'show_toolbar', 'show_history', 
+                    'show_move_hints', 'show_numbering',
+                    'move_format', 'board_view', 'promotion_type']:
+            glchess.config.watch(key, self.__applyConfig)
+            try:
+                value = glchess.config.get(key)
+            except glchess.config.Error:
+                pass
+            else:
+                self.__applyConfig(key, value)
+        
+    def __applyConfig(self, name, value):
+        """
+        """        
+        if name == 'show_3d':
+            self.__gui.get_widget('show_3d').set_active(value)
+
+        elif name == 'show_toolbar':
+            self.__gui.get_widget('show_toolbar').set_active(value)
+                
+        elif name == 'show_history':
+            self.__gui.get_widget('show_history').set_active(value)
+
+        elif name == 'show_move_hints':
+            self.__gui.get_widget('show_move_hints').set_active(value)
+
+        elif name == 'show_numbering':
+            self.__gui.get_widget('show_numbering').set_active(value)
+
+        elif name == 'move_format':
+            widget = self.__gui.get_widget('move_format_combo')
+            for row in widget.get_model():
+                if row[1] == value:
+                    widget.set_active_iter(row.iter)
+                
+        elif name == 'promotion_type':
+            widget = self.__gui.get_widget('promotion_type_combo')
+            for row in widget.get_model():
+                if row[1] == value:
+                    widget.set_active_iter(row.iter)
+    
+        elif name == 'board_view':
+            widget = self.__gui.get_widget('board_combo')
+            for row in widget.get_model():
+                if row[1] == value:
+                    widget.set_active_iter(row.iter)
 
-        # Load preferences for View settings.
-        pref = glchess.config.get('show_3d')
-        widget = self.__gui.get_widget('show_3d')
-        widget.set_active(pref)
-
-        pref = glchess.config.get('show_toolbar')
-        widget = self.__gui.get_widget('show_toolbar')
-        widget.set_active(pref)
-
-        pref = glchess.config.get('show_history')
-        widget = self.__gui.get_widget('show_history')
-        widget.set_active(pref)
-
-        pref = glchess.config.get('show_move_hints')
-        widget = self.__gui.get_widget('show_move_hints')
-        widget.set_active(pref)
-
-        pref = glchess.config.get('show_numbering')
-        widget = self.__gui.get_widget('show_numbering')
-        widget.set_active(pref)
+        else:
+            assert(False), 'Unknown config item: %s' % name
 
     def setVisible(self, isVisible):
         window = self.__gui.get_widget('preferences')

Modified: trunk/glchess/src/lib/gtkui/gtkui.py
==============================================================================
--- trunk/glchess/src/lib/gtkui/gtkui.py	(original)
+++ trunk/glchess/src/lib/gtkui/gtkui.py	Thu Aug 14 14:50:08 2008
@@ -589,9 +589,8 @@
                 glchess.config.set('show_3d', False)
                 value = False
             self.__renderGL = value
-            menuItem = self.__getWidget('menu_view_3d')
-            menuItem.set_active(self.__renderGL)
-            self.view.viewWidget.setRenderGL(self.__renderGL)
+            self.__getWidget('menu_view_3d').set_active(value)
+            self.view.viewWidget.setRenderGL(value)
                 
         elif name == 'show_comments':
             self.view.setShowComments(value)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]