[gnome-calculator/wip/glade: 1/2] Migrate MathConverter to GtkBuilder and use GtkTemplate to define the UI layout
- From: Alberto Ruiz <aruiz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator/wip/glade: 1/2] Migrate MathConverter to GtkBuilder and use GtkTemplate to define the UI layout
- Date: Fri, 15 Jan 2016 12:51:00 +0000 (UTC)
commit 9fac30039df3603b8823cdfed4cc52d972853d72
Author: Alberto Ruiz <aruiz gnome org>
Date: Fri Jan 8 22:49:06 2016 +0000
Migrate MathConverter to GtkBuilder and use GtkTemplate to define the UI layout
data/Makefile.am | 1 +
data/gnome-calculator.gresource.xml | 1 +
data/math-converter.ui | 90 +++++++++++++++++++++++++++++++++++
po/POTFILES.in | 1 +
src/Makefile.am | 5 ++-
src/math-converter.vala | 56 +++++-----------------
6 files changed, 109 insertions(+), 45 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index dd09811..76fa087 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -18,6 +18,7 @@ EXTRA_DIST = \
buttons-advanced.ui \
buttons-financial.ui \
buttons-programming.ui \
+ math-converter.ui \
menu.ui \
calculator.css \
gnome-calculator.gresource.xml \
diff --git a/data/gnome-calculator.gresource.xml b/data/gnome-calculator.gresource.xml
index 3df5c51..b68e708 100644
--- a/data/gnome-calculator.gresource.xml
+++ b/data/gnome-calculator.gresource.xml
@@ -5,6 +5,7 @@
<file preprocess="xml-stripblanks">buttons-basic.ui</file>
<file preprocess="xml-stripblanks">buttons-financial.ui</file>
<file preprocess="xml-stripblanks">buttons-programming.ui</file>
+ <file preprocess="xml-stripblanks">math-converter.ui</file>
<file preprocess="xml-stripblanks">menu.ui</file>
<file>calculator.css</file>
</gresource>
diff --git a/data/math-converter.ui b/data/math-converter.ui
new file mode 100644
index 0000000..d94bf74
--- /dev/null
+++ b/data/math-converter.ui
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.19.0 -->
+<interface>
+ <requires lib="gtk+" version="3.16"/>
+ <template class="MathConverter" parent="GtkGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="row_spacing">6</property>
+ <property name="column_spacing">6</property>
+ <child>
+ <object class="GtkButton" id="swap_button">
+ <property name="label">⇆</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Switch conversion units</property>
+ <property name="relief">none</property>
+ <signal name="clicked" handler="swap_button_clicked_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">3</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="in_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes"> in </property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="from_combo">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <signal name="changed" handler="from_combobox_changed_cb" swapped="no"/>
+ <child>
+ <object class="GtkCellRendererText" id="from_renderer"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="to_combo">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="opacity">0.88</property>
+ <signal name="changed" handler="to_combobox_changed_cb" swapped="no"/>
+ <child>
+ <object class="GtkCellRendererText" id="to_renderer"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="result_label">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">False</property>
+ <property name="justify">center</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">4</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ </template>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index cc801af..4124820 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -7,6 +7,7 @@
[type: gettext/glade]data/buttons-programming.ui
data/gnome-calculator.desktop.in
data/gnome-calculator.appdata.xml.in
+data/math-converter.ui
[type: gettext/glade]data/menu.ui
data/org.gnome.calculator.gschema.xml
lib/currency.vala
diff --git a/src/Makefile.am b/src/Makefile.am
index bcab41b..e8df2e3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,9 +9,11 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/lib \
$(LIBCALCULATOR_CFLAGS)
+
+resources_file = $(top_srcdir)/data/gnome-calculator.gresource.xml
BUILT_SOURCES = resources.c
-resources.c: $(top_srcdir)/data/gnome-calculator.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES)
--generate-dependencies --sourcedir=$(top_srcdir)/data/ $(top_srcdir)/data/gnome-calculator.gresource.xml)
+resources.c: $(resources_file) $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies
--sourcedir=$(top_srcdir)/data/ $(top_srcdir)/data/gnome-calculator.gresource.xml)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(top_srcdir)/data/ --generate-source $<
gnome_calculator_SOURCES = \
@@ -33,6 +35,7 @@ gnome_calculator_VALAFLAGS = \
--pkg gtk+-3.0 \
--pkg gtksourceview-3.0 \
--pkg libxml-2.0 \
+ --gresources $(resources_file) \
$(top_builddir)/lib/libcalculator.vapi \
$(top_builddir)/lib/mpfr.vapi
diff --git a/src/math-converter.vala b/src/math-converter.vala
index 1a69dc8..c66ef98 100644
--- a/src/math-converter.vala
+++ b/src/math-converter.vala
@@ -8,15 +8,21 @@
* license.
*/
-public class MathConverter : Gtk.Box
+[GtkTemplate (ui = "/org/gnome/calculator/math-converter.ui")]
+public class MathConverter : Gtk.Grid
{
private MathEquation equation;
private string category;
+ [GtkChild]
+ private Gtk.CellRendererText from_renderer;
+
+ [GtkChild]
private Gtk.ComboBox from_combo;
+ [GtkChild]
private Gtk.ComboBox to_combo;
-
+ [GtkChild]
private Gtk.Label result_label;
public signal void changed ();
@@ -26,48 +32,7 @@ public class MathConverter : Gtk.Box
Object (orientation: Gtk.Orientation.HORIZONTAL);
this.equation = equation;
- spacing = 6;
-
- var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
- hbox.show ();
- pack_start (hbox, false, true, 0);
-
- from_combo = new Gtk.ComboBox ();
-
- var renderer = new Gtk.CellRendererText ();
- from_combo.pack_start (renderer, true);
- from_combo.add_attribute (renderer, "text", 0);
- from_combo.set_cell_data_func (renderer, from_cell_data_func);
- from_combo.changed.connect (from_combobox_changed_cb);
- from_combo.show ();
- hbox.pack_start (from_combo, false, true, 0);
-
- var label = new Gtk.Label (/* Label that is displayed between the two conversion combo boxes, e.g.
"[degrees] in [radians]" */
- _(" in "));
- label.show ();
- hbox.pack_start (label, false, true, 5);
-
- to_combo = new Gtk.ComboBox ();
- renderer = new Gtk.CellRendererText ();
- to_combo.pack_start (renderer, true);
- to_combo.add_attribute (renderer, "text", 0);
- to_combo.changed.connect (to_combobox_changed_cb);
- to_combo.show ();
- hbox.pack_start (to_combo, false, true, 0);
-
- var swap_button = new Gtk.Button.with_label ("⇆");
- swap_button.set_tooltip_text (/* Tooltip for swap conversion button */
- _("Switch conversion units"));
- swap_button.set_relief (Gtk.ReliefStyle.NONE);
- swap_button.clicked.connect (swap_button_clicked_cb);
- swap_button.show ();
- hbox.pack_start (swap_button, false, true, 0);
-
- result_label = new Gtk.Label ("");
- result_label.set_alignment (1.0f, 0.5f);
- result_label.sensitive = false;
- result_label.show ();
- pack_start (result_label, true, true, 0);
+ from_combo.set_cell_data_func (from_renderer, from_cell_data_func);
CurrencyManager.get_default ().updated.connect (() => { update_result_label (); });
equation.notify["display"].connect ((pspec) => { update_result_label (); });
@@ -206,6 +171,7 @@ public class MathConverter : Gtk.Box
return false;
}
+ [GtkCallback]
private void from_combobox_changed_cb ()
{
var model = from_combo.get_model ();
@@ -231,6 +197,7 @@ public class MathConverter : Gtk.Box
to_combo.set_active (0);
}
+ [GtkCallback]
private void to_combobox_changed_cb ()
{
/* Conversion must have changed */
@@ -243,6 +210,7 @@ public class MathConverter : Gtk.Box
cell.set ("sensitive", !tree_model.iter_has_child (iter));
}
+ [GtkCallback]
private void swap_button_clicked_cb ()
{
var x = equation.number;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]