[gnome-devel-docs] Vala samples: changed button example
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] Vala samples: changed button example
- Date: Sun, 22 Apr 2012 02:22:12 +0000 (UTC)
commit 3ae1ecaa2104c19ee02e36fea54ddc167451ebec
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date: Sat Apr 21 22:21:11 2012 -0400
Vala samples: changed button example
Updated the example to use GtkApplicationWindow
platform-demos/C/button.vala.page | 56 ++++++++++++++++------------------
platform-demos/C/media/button.png | Bin 5122 -> 5789 bytes
platform-demos/C/samples/button.vala | 52 ++++++++++++++-----------------
3 files changed, 50 insertions(+), 58 deletions(-)
---
diff --git a/platform-demos/C/button.vala.page b/platform-demos/C/button.vala.page
index b577883..b013d69 100644
--- a/platform-demos/C/button.vala.page
+++ b/platform-demos/C/button.vala.page
@@ -17,49 +17,45 @@
<title>Button widget</title>
<media type="image" mime="image/png" src="media/button.png"/>
- <p>A button widget connected to stdout.printf (), and a modal window.</p>
+ <p>A button widget connected to a simple callback function.</p>
<code mime="text/x-vala" style="numbered"><![CDATA[
-/*callback for the "clicked" signal.*/
-void button_clicked_cb () {
- stdout.printf ("You clicked the button!\n");
- //TODO: add a modal window
-}
-
-int main (string[] args) {
-
- Gtk.init (ref args);
+public class MyWindow : Gtk.ApplicationWindow {
+ void reverse_label (Gtk.Button button) {
+ button.label = button.label.reverse ();
+ }
- var window = new Gtk.Window ();
- window.title = "GNOME Button";
- window.set_default_size (250,50);
+ internal MyWindow (MyApplication app) {
+ Object (application: app, title: "GNOME Button");
- var button = new Gtk.Button.with_label ("Click Me");
- window.add (button);
+ var button = new Gtk.Button.with_label ("Click Me");
+ button.clicked.connect (reverse_label);
+ button.show ();
- window.window_position = Gtk.WindowPosition.CENTER;
+ this.window_position = Gtk.WindowPosition.CENTER;
+ this.set_default_size (250,50);
+ this.add (button);
- /* The "clicked" signal is emitted when the
- button is clicked. The signal is connected to
- the button_clicked_cb method defined above.*/
- button.clicked.connect (button_clicked_cb);
+ }
+}
- /*The "destroy" signal is emitted when the x
- in the top right of the window is clicked.
- The destroy signal is connected to the
- main_quit method, which destroys the window
- and exits the program.*/
- window.destroy.connect (Gtk.main_quit);
+public class MyApplication : Gtk.Application {
+ protected override void activate () {
+ new MyWindow (this).show ();
+ }
- window.show_all ();
+ internal MyApplication () {
+ Object (application_id: "org.example.MyApplication");
+ }
+}
- Gtk.main ();
- return 0;
+public int main (string[] args) {
+ return new MyApplication ().run (args);
}
]]></code>
<p>
In this sample we used the following:
- <link xref="window.vala">Gtk.Window</link>,
+ <link xref="GtkApplicationWindow.vala">Gtk.ApplicationWindow</link>,
<link href="http://www.valadoc.org/#!api=gtk+-2.0/Gtk.Button">Gtk.Button</link>
</p>
</page>
diff --git a/platform-demos/C/media/button.png b/platform-demos/C/media/button.png
index e1993a9..d40396a 100644
Binary files a/platform-demos/C/media/button.png and b/platform-demos/C/media/button.png differ
diff --git a/platform-demos/C/samples/button.vala b/platform-demos/C/samples/button.vala
index 060fb72..184969e 100644
--- a/platform-demos/C/samples/button.vala
+++ b/platform-demos/C/samples/button.vala
@@ -1,36 +1,32 @@
-/*callback for the "clicked" signal.*/
-void button_clicked_cb () {
- stdout.printf ("You clicked the button!\n");
- //TODO: add a modal window
-}
-
-int main (string[] args) {
-
- Gtk.init (ref args);
+public class MyWindow : Gtk.ApplicationWindow {
+ void reverse_label (Gtk.Button button) {
+ button.label = button.label.reverse ();
+ }
- var window = new Gtk.Window ();
- window.title = "GNOME Button";
- window.set_default_size (250,50);
+ internal MyWindow (MyApplication app) {
+ Object (application: app, title: "GNOME Button");
- var button = new Gtk.Button.with_label ("Click Me");
- window.add (button);
+ var button = new Gtk.Button.with_label ("Click Me");
+ button.clicked.connect (reverse_label);
+ button.show ();
- window.window_position = Gtk.WindowPosition.CENTER;
+ this.window_position = Gtk.WindowPosition.CENTER;
+ this.set_default_size (250,50);
+ this.add (button);
- /* The "clicked" signal is emitted when the
- button is clicked. The signal is connected to
- the button_clicked_cb method defined above.*/
- button.clicked.connect (button_clicked_cb);
+ }
+}
- /*The "destroy" signal is emitted when the x
- in the top right of the window is clicked.
- The destroy signal is connected to the
- main_quit method, which destroys the window
- and exits the program.*/
- window.destroy.connect (Gtk.main_quit);
+public class MyApplication : Gtk.Application {
+ protected override void activate () {
+ new MyWindow (this).show ();
+ }
- window.show_all ();
+ internal MyApplication () {
+ Object (application_id: "org.example.MyApplication");
+ }
+}
- Gtk.main ();
- return 0;
+public int main (string[] args) {
+ return new MyApplication ().run (args);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]