[iagno] Use GtkBuilder.



commit 210d59f961af95877a2529d9f9768c7e38e0ecaf
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Sep 16 03:15:54 2014 +0200

    Use GtkBuilder.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=735053

 data/Makefile.am    |    4 +-
 data/iagno-menus.ui |   33 +++++++++
 data/iagno.ui       |  188 ++++++++++++++++++++++++++++++++++++++++++--------
 po/POTFILES.in      |    1 +
 src/iagno.vala      |  107 +++++++----------------------
 5 files changed, 220 insertions(+), 113 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 421fb1d..3e739f4 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,7 +1,9 @@
 SUBDIRS = icons
 
 uidir = $(datadir)/iagno
-ui_DATA = iagno.ui
+ui_DATA = \
+       iagno-menus.ui \
+       iagno.ui
 
 imagedir = $(datadir)/iagno/images
 image_DATA = \
diff --git a/data/iagno-menus.ui b/data/iagno-menus.ui
new file mode 100644
index 0000000..05fad5c
--- /dev/null
+++ b/data/iagno-menus.ui
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <menu id="app-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_New Game</attribute>
+        <attribute name="action">app.new-game</attribute>
+        <attribute name="accel">&lt;Primary&gt;n</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Preferences</attribute>
+        <attribute name="action">app.preferences</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Help</attribute>
+        <attribute name="action">app.help</attribute>
+        <attribute name="accel">F1</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_About</attribute>
+        <attribute name="action">app.about</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Quit</attribute>
+        <attribute name="action">app.quit</attribute>
+        <attribute name="accel">&lt;Primary&gt;q</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/data/iagno.ui b/data/iagno.ui
index a76abaa..805bb0c 100644
--- a/data/iagno.ui
+++ b/data/iagno.ui
@@ -1,33 +1,161 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
-  <menu id="iagno-menu">
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">_New Game</attribute>
-        <attribute name="action">app.new-game</attribute>
-        <attribute name="accel">&lt;Primary&gt;n</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">_Preferences</attribute>
-        <attribute name="action">app.preferences</attribute>
-      </item>
-    </section>
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">_Help</attribute>
-        <attribute name="action">app.help</attribute>
-        <attribute name="accel">F1</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">_About</attribute>
-        <attribute name="action">app.about</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">_Quit</attribute>
-        <attribute name="action">app.quit</attribute>
-        <attribute name="accel">&lt;Primary&gt;q</attribute>
-      </item>
-    </section>
-  </menu>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkApplicationWindow" id="iagno-window">
+    <property name="title" translatable="yes">Iagno</property>
+    <property name="border-width">25</property>
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="headerbar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="show_close_button">True</property>
+        <property name="title" translatable="yes">Iagno</property>
+        <child>
+          <object class="GtkButton">
+            <property name="visible">True</property>
+            <property name="sensitive">False</property>
+            <property name="valign">center</property>
+            <property name="tooltip-text" translatable="yes">Undo your most recent move</property>
+            <property name="can_focus">True</property>
+            <property name="focus_on_click">False</property>
+            <property name="action-name">app.undo-move</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="icon_name">edit-undo-symbolic</property>
+                <property name="visible">True</property>
+                <property name="icon_size">1</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAspectFrame">
+        <property name="visible">True</property>
+        <property name="shadow-type">GTK_SHADOW_NONE</property>
+        <property name="obey-child">false</property>
+        <property name="ratio">1.4</property>
+        <property name="xalign">0.5</property>
+        <property name="yalign">0.5</property>
+        <child>
+          <object class="GtkBox" id="game-box">
+            <property name="visible">True</property>
+            <property name="orientation">horizontal</property>
+            <property name="spacing">25</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkGrid">
+                    <property name="visible">True</property>
+                    <property name="halign">center</property>
+                    <property name="column-spacing">12</property>
+                    <property name="row-spacing">18</property>
+                    <property name="margin-end">12</property>
+                    <child>
+                      <object class="GtkImage" id="mark-icon-dark"> <!-- TODO use GResource -->
+                        <property name="visible">True</property>
+                      </object>
+                      <packing>
+                        <property name="left-attach">0</property>
+                        <property name="top-attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkImage" id="dark-image"> <!-- TODO use GResource -->
+                        <property name="visible">True</property>
+                      </object>
+                      <packing>
+                        <property name="left-attach">1</property>
+                        <property name="top-attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="dark-score-label">
+                        <property name="visible">True</property>
+                        <property name="label">00</property>
+                      </object>
+                      <packing>
+                        <property name="left-attach">2</property>
+                        <property name="top-attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkImage" id="mark-icon-light"> <!-- TODO use GResource -->
+                        <property name="visible">True</property>
+                      </object>
+                      <packing>
+                        <property name="left-attach">0</property>
+                        <property name="top-attach">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkImage" id="light-image"> <!-- TODO use GResource -->
+                        <property name="visible">True</property>
+                      </object>
+                      <packing>
+                        <property name="left-attach">1</property>
+                        <property name="top-attach">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="light-score-label">
+                        <property name="visible">True</property>
+                        <property name="label">00</property>
+                      </object>
+                      <packing>
+                        <property name="left-attach">2</property>
+                        <property name="top-attach">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="pack-type">start</property>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="padding">6</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton">
+                    <property name="visible">True</property>
+                    <property name="use_underline">True</property>
+                    <property name="label" translatable="yes">_Start Over</property>
+                    <property name="halign">center</property>
+                    <property name="valign">center</property>
+                    <property name="action-name">app.new-game</property>
+                    <property name="tooltip-text" translatable="yes">Start a new game</property>
+                    <property name="width-request">120</property>
+                    <property name="height-request">60</property>
+                  </object>
+                  <packing>
+                    <property name="pack-type">end</property>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="padding">0</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="pack-type">end</property>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="padding">0</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e5f9ed9..0acece1 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@
 [encoding: UTF-8]
 data/iagno.appdata.xml.in
 data/iagno.desktop.in
+[type: gettext/glade]data/iagno-menus.ui
 [type: gettext/glade]data/iagno.ui
 data/org.gnome.iagno.gschema.xml
 src/computer-player.vala
diff --git a/src/iagno.vala b/src/iagno.vala
index 073ce95..0d646d3 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -87,9 +87,11 @@ public class Iagno : Gtk.Application
             return;
         }
 
+        // TODO use GResource & Gtk.Builder.from_resource()
         var builder = new Gtk.Builder ();
         try
         {
+            builder.add_from_file (DATA_DIRECTORY + "/iagno-menus.ui");
             builder.add_from_file (DATA_DIRECTORY + "/iagno.ui");
         }
         catch (Error e)
@@ -97,106 +99,47 @@ public class Iagno : Gtk.Application
             stderr.printf ("Could not load UI: %s\n", e.message);
             return;
         }
-        set_app_menu (builder.get_object ("iagno-menu") as MenuModel);
-        window = new Gtk.ApplicationWindow (this);
-        window.set_border_width (25);
-        window.set_title (_("Iagno"));
-        window.icon_name = "iagno";
+        set_app_menu (builder.get_object ("app-menu") as MenuModel);
+        // end of TODO
+
+        window = builder.get_object ("iagno-window") as Gtk.ApplicationWindow;
         window.configure_event.connect (window_configure_event_cb);
         window.window_state_event.connect (window_state_event_cb);
         window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
         if (settings.get_boolean ("window-is-maximized"))
             window.maximize ();
-
-        var image = new Gtk.Image ();
-        image.icon_size = Gtk.IconSize.BUTTON;
-        if (Gtk.Widget.get_default_direction () == Gtk.TextDirection.RTL)
-            image.icon_name = "edit-undo-rtl-symbolic";
-        else
-            image.icon_name = "edit-undo-symbolic";
-
-        var undo_button = new Gtk.Button ();
-        undo_button.image = image;
-        undo_button.valign = Gtk.Align.CENTER;
-        undo_button.action_name = "app.undo-move";
-        undo_button.tooltip_text = _("Undo your most recent move");
-        undo_button.show ();
-
-        headerbar = new Gtk.HeaderBar ();
-        headerbar.show_close_button = true;
-        headerbar.set_title (_("Iagno"));
-        headerbar.pack_start (undo_button);
-        headerbar.show ();
-        window.set_titlebar (headerbar);
-
-        var frame = new Gtk.AspectFrame (null, (float) 0.5, (float) 0.5, (float) 1.4, false);
-        frame.shadow_type = Gtk.ShadowType.NONE;
-        frame.show ();
-        window.add (frame);
-
-        var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 25);
-        hbox.halign = Gtk.Align.FILL;
-        hbox.show ();
-        frame.add (hbox);
+        add_window (window);
 
         view = new GameView ();
         view.game = game;
         view.move.connect (player_move_cb);
         var tile_set = settings.get_string ("tileset");
         view.theme = Path.build_filename (DATA_DIRECTORY, "themes", tile_set);
-        view.halign = Gtk.Align.END;
+        view.halign = Gtk.Align.CENTER;
         view.show ();
-        hbox.pack_start (view, true, true, 0);
 
-        var side_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
-        side_box.show ();
-        hbox.pack_end (side_box, false, true, 0);
+        var game_box = builder.get_object ("game-box") as Gtk.Box;
+        game_box.pack_start (view, true, true, 0);
 
-        var grid = new Gtk.Grid ();
-        grid.halign = Gtk.Align.CENTER;
-        grid.vexpand = true;
-        grid.hexpand = true;
-        grid.set_column_spacing (12);
-        grid.set_row_spacing (18);
-        grid.margin_end = 12;
-        grid.show ();
-        side_box.pack_start (grid, false, true, 6);
+        headerbar = builder.get_object ("headerbar") as Gtk.HeaderBar;
+        light_score_label = builder.get_object ("light-score-label") as Gtk.Label;
+        dark_score_label = builder.get_object ("dark-score-label") as Gtk.Label;
 
+        // TODO use GResource
         var dark = Path.build_filename (DATA_DIRECTORY, "images", "dark.svg");
-        var dark_icon = new Gtk.Image.from_file (dark);
-        dark_icon.show ();
-        grid.attach (dark_icon, 1, 0, 1, 1);
-
-        dark_score_label = new Gtk.Label ("00");
-        dark_score_label.show ();
-        grid.attach (dark_score_label, 2, 0, 1, 1);
+        var dark_image = builder.get_object ("dark-image") as Gtk.Image;
+        dark_image.set_from_file (dark);
 
         var light = Path.build_filename (DATA_DIRECTORY, "images", "light.svg");
-        var light_icon = new Gtk.Image.from_file (light);
-        light_icon.show ();
-        grid.attach (light_icon, 1, 1, 1, 1);
-
-        light_score_label = new Gtk.Label ("00");
-        light_score_label.show ();
-        grid.attach (light_score_label, 2, 1, 1, 1);
+        var light_image = builder.get_object ("light-image") as Gtk.Image;
+        light_image.set_from_file (light);
 
         var mark = Path.build_filename (DATA_DIRECTORY, "images", "mark.svg");
-        mark_icon_dark = new Gtk.Image.from_file (mark);
-        mark_icon_light = new Gtk.Image.from_file (mark);
-        grid.attach (mark_icon_dark, 0, 0, 1, 1);
-        grid.attach (mark_icon_light, 0, 1, 1, 1);
-
-        var new_game_button = new Gtk.Button ();
-        new_game_button.label = _("_Start Over");
-        new_game_button.use_underline = true;
-        new_game_button.width_request = 120;
-        new_game_button.height_request = 60;
-        new_game_button.valign = Gtk.Align.END;
-        new_game_button.halign = Gtk.Align.END;
-        new_game_button.action_name = "app.new-game";
-        new_game_button.tooltip_text = _("Start a new game");
-        new_game_button.show_all ();
-        side_box.pack_end (new_game_button, false, false, 0);
+        mark_icon_dark = builder.get_object ("mark-icon-dark") as Gtk.Image;
+        mark_icon_dark.set_from_file (mark);
+        mark_icon_light = builder.get_object ("mark-icon-light") as Gtk.Image;
+        mark_icon_light.set_from_file (mark);
+        // end of TODO
 
         start_game ();
 


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