[gnome-clocks] Use an ui template for the stopwatch
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Use an ui template for the stopwatch
- Date: Fri, 16 Aug 2013 20:25:43 +0000 (UTC)
commit 7b3dbd8043446fb0ef6bfe58d6b55abc4d739fde
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Aug 16 21:31:21 2013 +0200
Use an ui template for the stopwatch
data/ui/stopwatch.ui | 185 ++++++++++++++++++++++++++------------------------
src/stopwatch.vala | 25 +++----
2 files changed, 105 insertions(+), 105 deletions(-)
---
diff --git a/data/ui/stopwatch.ui b/data/ui/stopwatch.ui
index c0ebe69..9940cfc 100644
--- a/data/ui/stopwatch.ui
+++ b/data/ui/stopwatch.ui
@@ -1,140 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.6 -->
- <object class="GtkGrid" id="stopwatch_panel">
+ <template class="ClocksStopwatchMainPanel" parent="GtkBox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="hexpand">True</property>
<child>
- <object class="ClocksStopwatchFrame" id="analog_frame">
+ <object class="GtkGrid" id="stopwatch_panel">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="margin_left">48</property>
- <property name="margin_right">48</property>
- <property name="margin_top">48</property>
- <property name="margin_bottom">48</property>
+ <property name="hexpand">True</property>
<child>
- <object class="GtkGrid" id="top_grid">
+ <object class="ClocksStopwatchFrame" id="analog_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="hexpand">True</property>
- <property name="valign">center</property>
- <property name="row_spacing">24</property>
- <property name="column_homogeneous">True</property>
- <child>
- <object class="GtkLabel" id="time_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <style>
- <class name="clocks-stopwatch-label"/>
- </style>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
+ <property name="margin_left">48</property>
+ <property name="margin_right">48</property>
+ <property name="margin_top">48</property>
+ <property name="margin_bottom">48</property>
<child>
- <object class="GtkBox" id="button_box">
+ <object class="GtkGrid" id="top_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="halign">center</property>
<property name="hexpand">True</property>
- <property name="homogeneous">True</property>
- <property name="spacing">16</property>
+ <property name="valign">center</property>
+ <property name="row_spacing">24</property>
+ <property name="column_homogeneous">True</property>
<child>
- <object class="GtkButton" id="left_button">
- <property name="label" translatable="yes">Start</property>
- <property name="width_request">132</property>
+ <object class="GtkLabel" id="time_label">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can_focus">False</property>
<style>
- <class name="clocks-button"/>
- <class name="clocks-go"/>
+ <class name="clocks-stopwatch-label"/>
</style>
</object>
<packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">0</property>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
</packing>
</child>
<child>
- <object class="GtkButton" id="right_button">
- <property name="label" translatable="yes">Reset</property>
- <property name="width_request">132</property>
+ <object class="GtkBox" id="button_box">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <style>
- <class name="clocks-button"/>
- </style>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="homogeneous">True</property>
+ <property name="spacing">16</property>
+ <child>
+ <object class="GtkButton" id="left_button">
+ <property name="label" translatable="yes">Start</property>
+ <property name="width_request">132</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="on_left_button_clicked" swapped="no"/>
+ <style>
+ <class name="clocks-button"/>
+ <class name="clocks-go"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="right_button">
+ <property name="label" translatable="yes">Reset</property>
+ <property name="width_request">132</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="on_right_button_clicked" swapped="no"/>
+ <style>
+ <class name="clocks-button"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">1</property>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
</packing>
</child>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
</object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
</child>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkGrid" id="laps_panel">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="vexpand">True</property>
<child>
- <object class="GtkScrolledWindow" id="laps_scrollwin">
- <property name="width_request">220</property>
+ <object class="GtkGrid" id="laps_panel">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hexpand">True</property>
+ <property name="can_focus">False</property>
<property name="vexpand">True</property>
- <property name="margin_right">48</property>
- <property name="margin_top">120</property>
- <property name="margin_bottom">120</property>
- <property name="shadow_type">in</property>
<child>
- <object class="GtkListBox" id="laps_list">
+ <object class="GtkScrolledWindow" id="laps_scrollwin">
+ <property name="width_request">220</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="hexpand">True</property>
<property name="vexpand">True</property>
+ <property name="margin_right">48</property>
+ <property name="margin_top">120</property>
+ <property name="margin_bottom">120</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkListBox" id="laps_list">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="vexpand">True</property>
+ </object>
+ </child>
</object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
</child>
</object>
<packing>
- <property name="left_attach">0</property>
+ <property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
- </object>
+ </template>
</interface>
diff --git a/src/stopwatch.vala b/src/stopwatch.vala
index be04cee..28d620d 100644
--- a/src/stopwatch.vala
+++ b/src/stopwatch.vala
@@ -89,6 +89,7 @@ private class LapsRow : Gtk.ListBoxRow {
}
}
+[GtkTemplate (ui = "/org/gnome/clocks/ui/stopwatch.ui")]
public class MainPanel : Gtk.Box, Clocks.Clock {
private enum State {
RESET,
@@ -111,11 +112,17 @@ public class MainPanel : Gtk.Box, Clocks.Clock {
private uint tick_id;
private int current_lap;
private double last_lap_time;
+ [GtkChild]
private Frame analog_frame;
+ [GtkChild]
private Gtk.Label time_label;
+ [GtkChild]
private Gtk.Button left_button;
+ [GtkChild]
private Gtk.Button right_button;
+ [GtkChild]
private Gtk.ScrolledWindow laps_scrollwin;
+ [GtkChild]
private Gtk.ListBox laps_list;
public MainPanel (HeaderBar header_bar) {
@@ -124,19 +131,6 @@ public class MainPanel : Gtk.Box, Clocks.Clock {
timer = new GLib.Timer ();
tick_id = 0;
- var builder = Utils.load_ui ("stopwatch.ui");
-
- var stopwatch_panel = builder.get_object ("stopwatch_panel") as Gtk.Widget;
- analog_frame = builder.get_object ("analog_frame") as Frame;
- time_label = builder.get_object ("time_label") as Gtk.Label;
- left_button = builder.get_object ("left_button") as Gtk.Button;
- right_button = builder.get_object ("right_button") as Gtk.Button;
- laps_scrollwin = builder.get_object ("laps_scrollwin") as Gtk.ScrolledWindow;
- laps_list = builder.get_object ("laps_list") as Gtk.ListBox;
-
- left_button.clicked.connect (on_left_button_clicked);
- right_button.clicked.connect (on_right_button_clicked);
-
map.connect ((w) => {
if (state == State.RUNNING) {
update_time_label ();
@@ -151,11 +145,9 @@ public class MainPanel : Gtk.Box, Clocks.Clock {
});
reset ();
-
- add (stopwatch_panel);
- show_all ();
}
+ [GtkCallback]
private void on_left_button_clicked (Gtk.Button button) {
switch (state) {
case State.RESET:
@@ -170,6 +162,7 @@ public class MainPanel : Gtk.Box, Clocks.Clock {
}
}
+ [GtkCallback]
private void on_right_button_clicked (Gtk.Button button) {
switch (state) {
case State.STOPPED:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]