[gnome-devel-docs] tutorials python: a button that emits a signal when clicked
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] tutorials python: a button that emits a signal when clicked
- Date: Sat, 5 May 2012 20:10:41 +0000 (UTC)
commit c5c16a556522a9e7901e13c2d6c21bf443abbb9d
Author: Marta Maria Casetti <mmcasetti gmail com>
Date: Sat May 5 16:45:09 2012 +0100
tutorials python: a button that emits a signal when clicked
platform-demos/C/samples/button.py | 44 ++++++++++++++++++++++-------------
1 files changed, 28 insertions(+), 16 deletions(-)
---
diff --git a/platform-demos/C/samples/button.py b/platform-demos/C/samples/button.py
index a6dcd26..66b8879 100644
--- a/platform-demos/C/samples/button.py
+++ b/platform-demos/C/samples/button.py
@@ -1,21 +1,33 @@
+from gi.repository import GLib
from gi.repository import Gtk
+from gi.repository import Gio
+import sys
-class ButtonWindow(Gtk.Window):
+class MyWindow(Gtk.ApplicationWindow):
+ def __init__(self, app):
+ Gtk.Window.__init__(self, title="GNOME Button", application=app)
+
+class MyButton(Gtk.Button):
+ def __init__(self):
+ Gtk.Button.__init__(self, label="Click me", stock=None, use_underline=True)
+ def do_clicked(self):
+ print "You clicked me!"
+
+class MyApplication(Gtk.Application):
def __init__(self):
- Gtk.Window.__init__(self, title="GNOME Button")
-
- self.set_default_size(250, 50)
- self.set_position(Gtk.WindowPosition.CENTER)
+ Gtk.Application.__init__(self, application_id="org.gtk.example.grid")
- self.button = Gtk.Button(label="Click me")
- self.button.connect("clicked", self.button_clicked)
- self.add(self.button)
-
- def button_clicked(self, widget):
- print "\"Click me\" button was clicked"
-
-win = ButtonWindow()
-win.connect("destroy", Gtk.main_quit)
-win.show_all()
-Gtk.main()
+ def do_activate(self):
+ win = MyWindow(self)
+ win.set_default_size(250, 50)
+ win.set_position(Gtk.WindowPosition.CENTER)
+ win.add(MyButton())
+ win.show_all()
+
+ def do_startup (self):
+ Gtk.Application.do_startup (self)
+
+app = MyApplication()
+exit_status = app.run(sys.argv)
+sys.exit(exit_status)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]