[gnome-games/sudoku-tube] Port main.py to use GtkBuilder



commit 8c2477ceef1389e189b84d6efd3601a75f769d87
Author: Zhang Sen <zh jesse gmail com>
Date:   Thu Jul 2 09:32:59 2009 +0800

    Port main.py to use GtkBuilder
    
    * Accelerators are not working.
    * Move the definition of sudoku_maker _before_ setup_gui, or else
        toggle_generator_cb will cause crash.

 gnome-sudoku/data/main.ui    |  557 ++++++++++++++++++++++++++++++++++++++++++
 gnome-sudoku/src/lib/main.py |  217 ++++-------------
 2 files changed, 604 insertions(+), 170 deletions(-)
---
diff --git a/gnome-sudoku/data/main.ui b/gnome-sudoku/data/main.ui
new file mode 100644
index 0000000..93a939d
--- /dev/null
+++ b/gnome-sudoku/data/main.ui
@@ -0,0 +1,557 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkWindow" id="window">
+    <child>
+      <object class="GtkVBox" id="vbox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkMenuBar" id="menubar">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkMenuItem" id="menuitem_game">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Game</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu_game">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_new">
+                        <property name="visible">True</property>
+                        <property name="related_action">New</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_new_with_contact">
+                        <property name="visible">True</property>
+                        <property name="related_action">NewWithContact</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="separatormenuitem11">
+                        <property name="visible">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_puzzleinfo">
+                        <property name="visible">True</property>
+                        <property name="related_action">PuzzleInfo</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="separatormenuitem12">
+                        <property name="visible">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_print">
+                        <property name="visible">True</property>
+                        <property name="related_action">Print</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_printmany">
+                        <property name="visible">True</property>
+                        <property name="related_action">PrintMany</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="separatormenuitem13">
+                        <property name="visible">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_close">
+                        <property name="visible">True</property>
+                        <property name="related_action">Close</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuItem" id="menuitem_edit">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Edit</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu_edit">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_undo">
+                        <property name="visible">True</property>
+                        <property name="related_action">Undo</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_redo">
+                        <property name="visible">True</property>
+                        <property name="related_action">Redo</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="separatormenuitem21">
+                        <property name="visible">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_clear">
+                        <property name="visible">True</property>
+                        <property name="related_action">Clear</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_clear_notes">
+                        <property name="visible">True</property>
+                        <property name="related_action">ClearNotes</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuItem" id="menuitem_view">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_View</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu_view">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_fullscreen">
+                        <property name="visible">True</property>
+                        <property name="related_action">FullScreen</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="separatormenuitem31">
+                        <property name="visible">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkCheckMenuItem" id="mi_show_toolbar">
+                        <property name="visible">True</property>
+                        <property name="related_action">ToggleToolbar</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkCheckMenuItem" id="mi_toggle_highlighter">
+                        <property name="visible">True</property>
+                        <property name="related_action">ToggleHighlight</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuItem" id="menuitem_tools">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Tools</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu_tools">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_show_possible">
+                        <property name="visible">True</property>
+                        <property name="related_action">ShowPossible</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_auto_fill">
+                        <property name="visible">True</property>
+                        <property name="related_action">Autofill</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_auto_fill_current_square">
+                        <property name="visible">True</property>
+                        <property name="related_action">AutofillCurrentSquare</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="separatormenuitem41">
+                        <property name="visible">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkCheckMenuItem" id="mi_always_show_possible">
+                        <property name="visible">True</property>
+                        <property name="related_action">AlwaysShowPossible</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkCheckMenuItem" id="mi_show_impossible_implications">
+                        <property name="visible">True</property>
+                        <property name="related_action">ShowImpossibleImplications</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="separatormenuitem42">
+                        <property name="visible">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_generator">
+                        <property name="visible">True</property>
+                        <property name="related_action">Generator</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkCheckMenuItem" id="mi_background_generator">
+                        <property name="visible">True</property>
+                        <property name="related_action">BackgroundGenerator</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="separatormenuitem43">
+                        <property name="visible">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkCheckMenuItem" id="mi_tracker">
+                        <property name="visible">True</property>
+                        <property name="related_action">ToggleTracker</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuItem" id="menuitem_help">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Help</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu_help">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_show_help">
+                        <property name="visible">True</property>
+                        <property name="related_action">ShowHelp</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="mi_about">
+                        <property name="visible">True</property>
+                        <property name="related_action">About</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkToolbar" id="toolbar">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkToolButton" id="tb_new">
+                <property name="visible">True</property>
+                <property name="related_action">New</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolButton" id="tb_print">
+                <property name="visible">True</property>
+                <property name="related_action">Print</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSeparatorToolItem" id="separatortoolitem1">
+                <property name="visible">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolButton" id="tb_undo">
+                <property name="visible">True</property>
+                <property name="related_action">Undo</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolButton" id="tb_redo">
+                <property name="visible">True</property>
+                <property name="related_action">Redo</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSeparatorToolItem" id="separatortoolitem2">
+                <property name="visible">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolButton" id="tb_show_possible">
+                <property name="visible">True</property>
+                <property name="related_action">ShowPossible</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolButton" id="tb_auto_fill_current_square">
+                <property name="visible">True</property>
+                <property name="related_action">AutofillCurrentSquare</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSeparatorToolItem" id="separatortoolitem3">
+                <property name="visible">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToggleToolButton" id="tb_toggle_highlighter">
+                <property name="visible">True</property>
+                <property name="related_action">ToggleHighlight</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToggleToolButton" id="tb_toggle_tracker">
+                <property name="visible">True</property>
+                <property name="related_action">ToggleTracker</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHBox" id="main_area">
+            <property name="visible">True</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkStatusbar" id="statusbar">
+            <property name="visible">True</property>
+            <property name="spacing">2</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkAction" id="New">
+    <property name="label">_New</property>
+    <property name="tooltip">New game</property>
+    <property name="stock_id">gtk-new</property>
+  </object>
+  <object class="GtkAction" id="NewWithContact">
+    <property name="label">New with contact</property>
+    <property name="tooltip">New game with contact</property>
+    <property name="stock_id">gtk-new</property>
+  </object>
+  <object class="GtkAction" id="Print">
+    <property name="label">_Print</property>
+    <property name="tooltip">Print current game</property>
+    <property name="stock_id">gtk-print</property>
+  </object>
+  <object class="GtkAction" id="PrintMany">
+    <property name="label">Print _Multiple Sudokus</property>
+    <property name="tooltip">Print more than one sudoku at a time</property>
+    <property name="stock_id">gtk-print</property>
+  </object>
+  <object class="GtkAction" id="Close">
+    <property name="label">Close</property>
+    <property name="tooltip">Close Sudoku</property>
+    <property name="stock_id">gtk-close</property>
+  </object>
+  <object class="GtkAction" id="ShowPossible">
+    <property name="label">Hint</property>
+    <property name="tooltip">Show which numbers could go in the current square</property>
+    <property name="stock_id">gtk-dialog-info</property>
+  </object>
+  <object class="GtkAction" id="AutofillCurrentSquare">
+    <property name="label">Fill</property>
+    <property name="tooltip">Automatically fill in the current square if possible</property>
+    <property name="stock_id">gtk-apply</property>
+  </object>
+  <object class="GtkAction" id="Autofill">
+    <property name="label">Fill _all squares</property>
+    <property name="tooltip">Automatically fill in all squares for which there is only one valid value</property>
+    <property name="stock_id">gtk-refresh</property>
+  </object>
+  <object class="GtkAction" id="FullScreen">
+    <property name="label">FullScreen</property>
+    <property name="stock_id">gtk-fullscreen</property>
+  </object>
+  <object class="GtkAction" id="Generator">
+    <property name="label">_Generate new puzzles</property>
+    <property name="tooltip">Generate new puzzles</property>
+    <property name="stock_id">gtk-new</property>
+  </object>
+  <object class="GtkAction" id="PuzzleInfo">
+    <property name="label">Puzzle _Statistics</property>
+    <property name="tooltip">Show statistics about current puzzle</property>
+    <property name="stock_id">gtk-about</property>
+  </object>
+  <object class="GtkAction" id="About">
+    <property name="label">About</property>
+    <property name="stock_id">gtk-about</property>
+  </object>
+  <object class="GtkAction" id="ShowHelp">
+    <property name="label">_Contents</property>
+    <property name="stock_id">gtk-help</property>
+  </object>
+  <object class="GtkAction" id="Undo">
+    <property name="label">_Undo</property>
+    <property name="tooltip">Undo last action</property>
+    <property name="stock_id">gtk-undo</property>
+  </object>
+  <object class="GtkAction" id="Redo">
+    <property name="label">_Redo</property>
+    <property name="tooltip">Redo last action</property>
+    <property name="stock_id">gtk-redo</property>
+  </object>
+  <object class="GtkAction" id="Clear">
+    <property name="label">_Clear</property>
+    <property name="tooltip">Clear entries you've filled in</property>
+    <property name="stock_id">gtk-clear</property>
+  </object>
+  <object class="GtkAction" id="ClearNotes">
+    <property name="label">Clear _Notes</property>
+    <property name="tooltip">Clear notes and hints</property>
+    <property name="stock_id">gtk-clear</property>
+  </object>
+  <object class="GtkToggleAction" id="AlwaysShowPossible">
+    <property name="label">_Always show hint</property>
+    <property name="tooltip">Always show possible numbers in a square</property>
+  </object>
+  <object class="GtkToggleAction" id="ShowImpossibleImplications">
+    <property name="label">Warn about _unfillable squares</property>
+    <property name="tooltip">Warn about squares made unfillable by a move</property>
+    <property name="active">True</property>
+  </object>
+  <object class="GtkToggleAction" id="ToggleTracker">
+    <property name="label">_Track additions</property>
+    <property name="tooltip">Mark new additions in a separate color so you can keep track of them</property>
+    <property name="icon_name">trackers</property>
+  </object>
+  <object class="GtkToggleAction" id="ToggleToolbar">
+    <property name="label">Show _Toolbar</property>
+    <property name="active">True</property>
+  </object>
+  <object class="GtkToggleAction" id="ToggleHighlight">
+    <property name="label">_Highlighter</property>
+    <property name="tooltip">Highlight the current row, column and box</property>
+    <property name="stock_id">gtk-select-color</property>
+  </object>
+  <object class="GtkToggleAction" id="BackgroundGenerator">
+    <property name="label">Generate new puzzles _while you play</property>
+    <property name="tooltip">Generate new puzzles in the background while you play. This will automatically pause when the game goes idle</property>
+  </object>
+</interface>
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index 10b9183..da9ca14 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -52,64 +52,6 @@ gtk.stock_add([('tracks',
 
 
 class UI (gconf_wrapper.GConfWrapper):
-    ui = '''<ui>
-    <menubar name="MenuBar">
-      <menu name="Game" action="Game">
-        <menuitem action="New"/>
-        <menuitem action="NewWithContact"/>
-        <separator/>
-        <menuitem action="PuzzleInfo"/>
-        <separator/>
-        <menuitem action="Print"/>
-        <menuitem action="PrintMany"/>
-        <separator/>
-        <menuitem action="Close"/>
-      </menu>
-      <menu action="Edit">
-        <menuitem action="Undo"/>
-        <menuitem action="Redo"/>
-        <separator/>
-        <menuitem action="Clear"/>
-        <menuitem action="ClearNotes"/>
-      </menu>
-      <menu action="View">
-        <menuitem action="FullScreen"/>
-        <separator/>
-        <menuitem action="ToggleToolbar"/>
-        <menuitem action="ToggleHighlight"/>
-      </menu>
-      <menu action="Tools">
-        <menuitem action="ShowPossible"/>
-        <menuitem action="AutofillCurrentSquare"/>
-        <menuitem action="Autofill"/>
-        <separator/>
-        <menuitem action="AlwaysShowPossible"/>
-        <menuitem action="ShowImpossibleImplications"/>
-        <separator/>
-        <menuitem action="Generator"/>
-        <menuitem action="BackgroundGenerator"/>
-        <separator/>
-        <menuitem action="Tracker"/>
-        </menu>
-      <menu action="Help">
-        <menuitem action="ShowHelp"/>
-        <menuitem action="About"/>
-      </menu>
-    </menubar>
-    <toolbar name="Toolbar">
-      <toolitem action="New"/>
-      <toolitem action="Print"/>
-      <separator/>
-      <toolitem action="Undo"/>
-      <toolitem action="Redo"/>
-      <separator/>
-      <toolitem action="ShowPossible"/>
-      <toolitem action="AutofillCurrentSquare"/>
-      <separator/>
-      <toolitem action="ToggleHighlight"/>
-      <toolitem action="Tracker"/>
-    </toolbar>
-    </ui>'''
 
     initial_prefs = {'group_size':9,
                      'always_show_hints':0,
@@ -137,6 +79,8 @@ class UI (gconf_wrapper.GConfWrapper):
         gconf_wrapper.GConfWrapper.__init__(self,
                                             gconf_wrapper.GConf('gnome-sudoku')
                                             )
+        self.sudoku_maker = sudoku_maker.SudokuMaker()
+        self.sudoku_tracker = saver.SudokuTracker()
         self.setup_gui()
 
         self.tube_handler = tube_handler.TubeHandler(self.tube_service,
@@ -147,10 +91,6 @@ class UI (gconf_wrapper.GConfWrapper):
         self.worker_connections = []
         self.is_fullscreen = False
 
-        # setup sudoku maker...
-        self.sudoku_maker = sudoku_maker.SudokuMaker()
-        self.sudoku_tracker = saver.SudokuTracker()
-
         self._game = None
         self._auto_load_saved()
         if not self._game: # no game loaded
@@ -234,104 +174,59 @@ class UI (gconf_wrapper.GConfWrapper):
         self.setup_actions()
         self.setup_undo()
         self.setup_autosave()
-        self.w.add_accel_group(self.uimanager.get_accel_group())
+        #TODO
+#        self.w.add_accel_group(self.uimanager.get_accel_group())
         self.setup_main_boxes()
         self.setup_tracker_interface()
         self.setup_toggles()
 
     def setup_main_window (self):
         gtk.window_set_default_icon_name('gnome-sudoku')
-        self.w = gtk.Window()
+        self.builder = gtk.Builder()
+        self.builder.add_from_file(os.path.join(UI_DIR, 'main.ui'))
+        self.w = self.builder.get_object("window")
         self.w.set_default_size(self.gconf['width'], self.gconf['height'])
         self.w.set_title(APPNAME_SHORT)
         self.w.connect('configure-event', self.resize_cb)
         self.w.connect('delete-event', self.quit_cb)
-        self.uimanager = gtk.UIManager()
+        self.statusbar = self.builder.get_object("statusbar")
 
     def setup_actions (self):
-        self.main_actions = gtk.ActionGroup('MainActions')
-        self.main_actions.add_actions([
-            ('Game', None, _('_Game')),
-            ('New', gtk.STOCK_NEW, None,
-             '<Control>n', _('New game'), self.new_cb),
-            ('NewWithContact', gtk.STOCK_NEW, _('New with contact'),
-                None, _('New with contact'), self._new_with_contact_cb),
-            ('Print', gtk.STOCK_PRINT, None,
-             None, _('Print current game'), self.print_game),
-            ('PrintMany', gtk.STOCK_PRINT, _('Print _Multiple Sudokus'),
-             None, _('Print more than one sudoku at a time.'), self.print_multiple_games),
-            ('Close', gtk.STOCK_CLOSE, None, '<Control>w',
-             _('Close Sudoku'), self.quit_cb),
-            ('Tools', None, _('_Tools')),
-            ('View', None, _('_View')),
-            ('ShowPossible', gtk.STOCK_DIALOG_INFO, _('_Hint'),
-             '<Control>h',
-             _('Show which numbers could go in the current square.'),
-             self.show_hint_cb),
-            ('AutofillCurrentSquare', gtk.STOCK_APPLY, _('_Fill'), '<Control>f',
-             _('Automatically fill in the current square if possible.'),
-             self.auto_fill_current_square_cb),
-            ('Autofill', gtk.STOCK_REFRESH, _('Fill _all squares'), '<Control>a',
-             _('Automatically fill in all squares for which there is only one valid value.'),
-             self.auto_fill_cb),
-            ('FullScreen', gtk.STOCK_FULLSCREEN, None,
-             'F11', None, self.full_screen_cb),
-            ('Generator', None, _('_Generate new puzzles'), None, _('Generate new puzzles.'),
-              self.generate_puzzle_gui, ),
-            ('PuzzleInfo', gtk.STOCK_ABOUT, _('Puzzle _Statistics'),
-             None, _('Show statistics about current puzzle'),
-             self.show_info_cb),
-            ('Help', None, _('_Help'),
-             None, None, None),
-            ('About', gtk.STOCK_ABOUT, None,
-             None, None, self.show_about),
-            ('ShowHelp', gtk.STOCK_HELP, _('_Contents'),
-             'F1', None, self.show_help),
-            ])
-        self.main_actions.add_toggle_actions([
-            ('AlwaysShowPossible',
-             None,
-             _('_Always show hint'),
-             None,
-             _('Always show possible numbers in a square'),
-             self.auto_hint_cb),
-            ('ShowImpossibleImplications',
-             None,
-             _('Warn about _unfillable squares'),
-             None,
-             _('Warn about squares made unfillable by a move'),
-             self.impossible_implication_cb),
-            ('Tracker', 'tracks', _('_Track additions'),
-             '<Control>T',
-             _('Mark new additions in a separate color so you can keep track of them.'),
-             self.tracker_toggle_cb, False),
-            ('ToggleToolbar', None, _('Show _Toolbar'), None, None, self.toggle_toolbar_cb, True),
-            ('ToggleHighlight', gtk.STOCK_SELECT_COLOR, _('_Highlighter'),
-             None, _('Highlight the current row, column and box'), self.toggle_highlight_cb, False),
-            ('BackgroundGenerator', None, _('Generate new puzzles _while you play'),
-             None,
-             _('Generate new puzzles in the background while you play. This will automatically pause when the game goes into the background.'),
-             self.toggle_generator_cb, True),
-            ])
-
-        self.edit_actions = gtk.ActionGroup('EditActions')
-        self.edit_actions.add_actions(
-            [('Edit', None, _('_Edit')),
-             ('Undo', gtk.STOCK_UNDO, _('_Undo'), '<Control>z', _('Undo last action'), self.stop_dancer),
-             ('Redo', gtk.STOCK_REDO, _('_Redo'), '<Shift><Control>z', _('Redo last action')),
-             ('Clear', gtk.STOCK_CLEAR, _('_Clear'), '<Control>b', _("Clear entries you've filled in"), self.clear_cb),
-             ('ClearNotes', None, _('Clear _Notes'), None, _("Clear notes and hints"), self.clear_notes_cb),
-             ])
-        self.uimanager.insert_action_group(self.main_actions, 0)
-        self.uimanager.insert_action_group(self.edit_actions, 0)
-        self.uimanager.add_ui_from_string(self.ui)
+        toggle_actions = [
+                ("AlwaysShowPossible", self.auto_hint_cb),
+                ("ShowImpossibleImplications", self.impossible_implication_cb),
+                ("ToggleTracker", self.tracker_toggle_cb),
+                ("ToggleToolbar", self.toggle_toolbar_cb),
+                ("ToggleHighlight", self.toggle_highlight_cb),
+                ("BackgroundGenerator", self.toggle_generator_cb)]
+        for action_name, callback in toggle_actions:
+            action = self.builder.get_object(action_name)
+            action.connect("toggled", callback)
+
+        actions = [
+                ("New", self.new_cb),
+                ("NewWithContact", self._new_with_contact_cb),
+                ("Print", self.print_game),
+                ("PrintMany", self.print_multiple_games),
+                ("Close", self.quit_cb),
+                ("ShowPossible", self.show_hint_cb),
+                ("AutofillCurrentSquare", self.auto_fill_current_square_cb),
+                ("Autofill", self.auto_fill_cb),
+                ("FullScreen", self.full_screen_cb),
+                ("Generator", self.generate_puzzle_gui),
+                ("PuzzleInfo", self.show_info_cb),
+                ("About", self.show_about),
+                ("ShowHelp", self.show_help)]
+        for action_name, callback in actions:
+            action = self.builder.get_object(action_name)
+            action.connect("activate", callback)
 
     def setup_undo (self):
         self.cleared = [] # used for Undo memory
         self.cleared_notes = [] # used for Undo memory
         # Set up our UNDO stuff
-        undo_widg = self.edit_actions.get_action('Undo')
-        redo_widg = self.edit_actions.get_action('Redo')
+        undo_widg = self.builder.get_object('Undo')
+        redo_widg = self.builder.get_object('Redo')
         self.history = Undo.UndoHistoryList(undo_widg, redo_widg)
         for entry in self.gsd.__entries__.values():
             Undo.UndoableGenericWidget(entry, self.history,
@@ -361,42 +256,24 @@ class UI (gconf_wrapper.GConfWrapper):
                             self.autosave)
 
     def setup_main_boxes (self):
-        vb = gtk.VBox()
-        # Add menu bar and toolbar...
-        mb = self.uimanager.get_widget('/MenuBar')
-        mb.show()
-        vb.pack_start(mb, fill = False, expand = False)
-        self.tb = self.uimanager.get_widget('/Toolbar')
-        vb.pack_start(self.tb, fill = False, expand = False)
-        main_area = gtk.HBox()
-        vb.pack_start(main_area, True, padding = 12)
-        main_area.pack_start(self.gsd, padding = 6)
-        self.main_actions.set_visible(True)
-        self.game_box = gtk.VBox()
-        main_area.show()
-        vb.show()
-        self.game_box.show()
-        main_area.pack_start(self.game_box, False, padding = 12)
-        self.statusbar = gtk.Statusbar()
-        self.statusbar.show()
-        vb.pack_end(self.statusbar, fill = False, expand = False)
-        self.w.add(vb)
+        self.main_area = self.builder.get_object("main_area")
+        self.main_area.pack_start(self.gsd, padding = 6)
 
     def setup_toggles (self):
         # sync up toggles with gconf values...
         map(lambda tpl: self.gconf_wrap_toggle(*tpl),
             [('always_show_hints',
-              self.main_actions.get_action('AlwaysShowPossible')),
+              self.builder.get_object('AlwaysShowPossible')),
              ('show_impossible_implications',
-              self.main_actions.get_action('ShowImpossibleImplications')),
+              self.builder.get_object('ShowImpossibleImplications')),
              ('generate_puzzles_in_background',
-              self.main_actions.get_action('BackgroundGenerator')),
+              self.builder.get_object('BackgroundGenerator')),
              ('show_toolbar',
-              self.main_actions.get_action('ToggleToolbar')),
+              self.builder.get_object('ToggleToolbar')),
              ('highlight',
-              self.main_actions.get_action('ToggleHighlight')),
+              self.builder.get_object('ToggleHighlight')),
              ('show_tracker',
-              self.main_actions.get_action('Tracker')),
+              self.builder.get_object('ToggleTracker')),
              ])
 
     def start_worker_thread (self, *args):
@@ -629,7 +506,7 @@ class UI (gconf_wrapper.GConfWrapper):
         self.tracker_ui = TrackerBox(self)
         self.tracker_ui.show_all()
         self.tracker_ui.hide()
-        self.game_box.add(self.tracker_ui)
+        self.main_area.pack_start(self.tracker_ui, expand=False)
 
     def tracker_toggle_cb (self, widg):
         if widg.get_active():



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