[hamster-applet/2_28_no_bars] just a rectangle
- From: Toms Baugis <tbaugis src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hamster-applet/2_28_no_bars] just a rectangle
- Date: Tue, 10 Nov 2009 20:09:52 +0000 (UTC)
commit 75660b48d44bf29d998676f54455d38e20fb040f
Author: Toms Bauģis <toms baugis gmail com>
Date: Tue Nov 10 20:09:46 2009 +0000
just a rectangle
hamster/rectangle.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 89 insertions(+), 0 deletions(-)
---
diff --git a/hamster/rectangle.py b/hamster/rectangle.py
new file mode 100755
index 0000000..be9b950
--- /dev/null
+++ b/hamster/rectangle.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+import graphics
+
+import pygtk
+import gtk
+
+class Rectangle(graphics.Area):
+ def __init__(self, **args):
+ graphics.Area.__init__(self)
+
+ def draw_bar(self, x, y, w, h):
+ """ draws a simple bar"""
+ base_color = (0, 255, 0)
+ self.fill_area(x, y, w, h, base_color)
+
+
+ def _render(self):
+ context = self.context
+ #TODO - use system colors and fonts
+
+ self.draw_bar(10,10,100,100)
+
+ context.stroke()
+
+
+class HelloWorld:
+
+ # This is a callback function. The data arguments are ignored
+ # in this example. More on callbacks below.
+ def hello(self, widget, data=None):
+ print "Hello World"
+
+ def delete_event(self, widget, event, data=None):
+ # If you return FALSE in the "delete_event" signal handler,
+ # GTK will emit the "destroy" signal. Returning TRUE means
+ # you don't want the window to be destroyed.
+ # This is useful for popping up 'are you sure you want to quit?'
+ # type dialogs.
+ print "delete event occurred"
+
+ # Change FALSE to TRUE and the main window will not be destroyed
+ # with a "delete_event".
+ return False
+
+ def destroy(self, widget, data=None):
+ print "destroy signal occurred"
+ gtk.main_quit()
+
+ def __init__(self):
+ # create a new window
+ self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+
+ # When the window is given the "delete_event" signal (this is given
+ # by the window manager, usually by the "close" option, or on the
+ # titlebar), we ask it to call the delete_event () function
+ # as defined above. The data passed to the callback
+ # function is NULL and is ignored in the callback function.
+ self.window.connect("delete_event", self.delete_event)
+
+ # Here we connect the "destroy" event to a signal handler.
+ # This event occurs when we call gtk_widget_destroy() on the window,
+ # or if we return FALSE in the "delete_event" callback.
+ self.window.connect("destroy", self.destroy)
+
+ rectangle = Rectangle()
+
+ ebox = gtk.EventBox()
+ ebox.set_size_request(100,100)
+ ebox.add(rectangle)
+
+
+ self.window.add(ebox)
+
+ # Sets the border width of the window.
+ self.window.set_border_width(50)
+ # and the window
+ self.window.show_all()
+
+ def main(self):
+ # All PyGTK applications must have a gtk.main(). Control ends here
+ # and waits for an event to occur (like a key press or mouse event).
+ gtk.main()
+
+# If the program is run directly or passed as an argument to the python
+# interpreter then create a HelloWorld instance and show it
+if __name__ == "__main__":
+ hello = HelloWorld()
+ hello.main()
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]