[pygtk-web] 2011-08-06 Dieter Verfaillie <dieterv optionexplicit be>



commit 10f721637e78bdadcb7e0bb25fc745fec3047c17
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date:   Sat Aug 6 10:36:16 2011 +0200

    2011-08-06  Dieter Verfaillie  <dieterv optionexplicit be>
    
    	* articles/subclassing-gobject: Update documentation links
    	and add missing Python source files

 ChangeLog                                          |    5 +++
 articles/subclassing-gobject/resources/car1.py     |   32 +++++++++++++++++
 articles/subclassing-gobject/resources/car2.py     |   18 ++++++++++
 articles/subclassing-gobject/resources/car4.py     |   17 +++++++++
 articles/subclassing-gobject/resources/car5.py     |   26 ++++++++++++++
 .../subclassing-gobject/resources/evilentry.py     |   28 +++++++++++++++
 .../subclassing-gobject/resources/long-names.py    |   36 ++++++++++++++++++++
 .../subclassing-gobject/resources/luxurycar.py     |   15 ++++++++
 .../sub-classing-gobject-in-python.htm             |   20 +++++-----
 9 files changed, 187 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 340f821..569b484 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-08-06  Dieter Verfaillie  <dieterv optionexplicit be>
+
+	* articles/subclassing-gobject: Update documentation links
+	and add missing Python source files
+
 2011-08-06  Rafael Villar Burke  <pachi rvburke com>
 
 	* applications.src: Add ReliaFree
diff --git a/articles/subclassing-gobject/resources/car1.py b/articles/subclassing-gobject/resources/car1.py
new file mode 100644
index 0000000..945662a
--- /dev/null
+++ b/articles/subclassing-gobject/resources/car1.py
@@ -0,0 +1,32 @@
+import pygtk
+pygtk.require('2.0')
+import gobject
+
+class Car(gobject.GObject):
+    __gproperties__ = {
+        'fuel' : (gobject.TYPE_FLOAT,                        # type
+                  'fuel of the car',                         # nick name
+                  'amount of fuel that remains in the tank', # description
+                  0,                                         # minimum value
+                  60,                                        # maximum value
+                  50,                                        # default value
+                  gobject.PARAM_READWRITE)                   # flags
+    }
+
+    def __init__(self):
+        gobject.GObject.__init__(self)
+        self.fuel = 50
+
+    def do_get_property(self, property):
+        if property.name == 'fuel':
+            return self.fuel
+        else:
+            raise AttributeError, 'unknown property %s' % property.name
+
+    def do_set_property(self, property, value):
+        if property.name == 'fuel':
+            self.fuel = value
+        else:
+            raise AttributeError, 'unknown property %s' % property.name
+
+gobject.type_register(Car)
diff --git a/articles/subclassing-gobject/resources/car2.py b/articles/subclassing-gobject/resources/car2.py
new file mode 100644
index 0000000..cf62f9d
--- /dev/null
+++ b/articles/subclassing-gobject/resources/car2.py
@@ -0,0 +1,18 @@
+import pygtk
+pygtk.require('2.0')
+import gobject
+
+from car1 import Car
+
+def myCallback(obj, property):
+    if property.name == 'fuel':
+        if obj.get_property('fuel') < 10:
+            print 'we are running out of fuel!!'
+
+def test():
+    aCar = Car()
+    aCar.connect('notify', myCallback)
+    aCar.set_property('fuel', 5.0)
+
+if __name__ == '__main__':
+    test()
diff --git a/articles/subclassing-gobject/resources/car4.py b/articles/subclassing-gobject/resources/car4.py
new file mode 100644
index 0000000..6280e7b
--- /dev/null
+++ b/articles/subclassing-gobject/resources/car4.py
@@ -0,0 +1,17 @@
+import pygtk
+pygtk.require('2.0')
+import gobject
+
+from car1 import Car
+
+def myCallback(obj, property):
+    if obj.get_property('fuel') < 10:
+        print 'we are running out of fuel!!'
+
+def test():
+    aCar = Car()
+    aCar.connect('notify::fuel', myCallback)
+    aCar.set_property('fuel', 5.0)
+
+if __name__ == '__main__':
+    test()
diff --git a/articles/subclassing-gobject/resources/car5.py b/articles/subclassing-gobject/resources/car5.py
new file mode 100644
index 0000000..cf337ab
--- /dev/null
+++ b/articles/subclassing-gobject/resources/car5.py
@@ -0,0 +1,26 @@
+import pygtk
+pygtk.require('2.0')
+import gobject
+
+from car4 import Car
+
+def myCallback(obj, remaining_fuel, data=None):
+    print '***** Beginning of User callback *****'
+    print 'The engine is starting and we still have %f of fuel' % remaining_fuel
+    print '***** End of User callback *****'
+
+def lastCallback(obj, remaining_fuel, data=None):
+    print '***** Callback connected with connect_after *****'
+    obj.set_property('fuel', remaining_fuel - 10)
+    print 'Now we have %f of fuel' % obj.get_property('fuel')
+    print '***** End of this callback *****'
+
+def test():
+    aCar = Car()
+    aCar.connect('engine-started', myCallback)
+    aCar.connect_after('engine-started', lastCallback)
+
+    aCar.start()
+
+if __name__ == '__main__':
+    test()
diff --git a/articles/subclassing-gobject/resources/evilentry.py b/articles/subclassing-gobject/resources/evilentry.py
new file mode 100644
index 0000000..15b2112
--- /dev/null
+++ b/articles/subclassing-gobject/resources/evilentry.py
@@ -0,0 +1,28 @@
+import pygtk
+pygtk.require('2.0')
+import gtk
+import gobject
+
+class EvilEntry(gtk.Entry):
+    __gsignals__ = {
+        'paste_clipboard' : 'override'
+        }
+
+    def __init__(self):
+        gobject.GObject.__init__(self)
+
+    def do_paste_clipboard(self):
+        print "You tried to paste something but you can't!! muHAHAHA"
+
+gobject.type_register(EvilEntry)
+
+if __name__ == '__main__':
+    win = gtk.Window()
+    win.connect('destroy', lambda e: gtk.main_quit())
+
+    entry = EvilEntry()
+    entry.show()
+    win.add(entry)
+    win.show()
+
+    gtk.main()
diff --git a/articles/subclassing-gobject/resources/long-names.py b/articles/subclassing-gobject/resources/long-names.py
new file mode 100644
index 0000000..b319b6e
--- /dev/null
+++ b/articles/subclassing-gobject/resources/long-names.py
@@ -0,0 +1,36 @@
+import pygtk
+pygtk.require('2.0')
+import gobject
+
+class Style(gobject.GObject):
+    __gproperties__ = {
+        'foreground_color' : (gobject.TYPE_STRING, 'foreground color',
+                  'string that represents the foreground color',
+                  'black', gobject.PARAM_READWRITE),
+        'background_color' : (gobject.TYPE_STRING, 'background color',
+                  'string that represents the background color',
+                  'white', gobject.PARAM_READWRITE),
+        }
+
+    def __init__(self):
+        gobject.GObject.__init__(self)
+        self.foreground_color = 'black'
+        self.background_color = 'white'
+
+    def do_get_property(self, property):
+        if property.name == 'foreground-color':
+            return self.foreground_color
+        elif property.name == 'background-color':
+            return self.background_color
+        else:
+            raise AttributeError, 'unknown property %s' % property.name
+
+    def do_set_property(self, property, value):
+        if property.name == 'foreground-color':
+            self.foreground_color = value
+        elif property.name == 'background-color':
+            self.background_color = value
+        else:
+            raise AttributeError, 'unknown property %s' % property.name
+
+gobject.type_register(Style)
diff --git a/articles/subclassing-gobject/resources/luxurycar.py b/articles/subclassing-gobject/resources/luxurycar.py
new file mode 100644
index 0000000..3b19dce
--- /dev/null
+++ b/articles/subclassing-gobject/resources/luxurycar.py
@@ -0,0 +1,15 @@
+import pygtk
+pygtk.require('2.0')
+import gobject
+
+from car4 import Car
+
+class LuxuryCar(Car):
+    def do_engine_started(self, remaining_fuel):
+        Car.do_engine_started(self, remaining_fuel)
+        print 'Welcome to the Luxury Car'
+
+
+if __name__ == '__main__':
+    luxuryCar = LuxuryCar()
+    luxuryCar.start()
diff --git a/articles/subclassing-gobject/sub-classing-gobject-in-python.htm b/articles/subclassing-gobject/sub-classing-gobject-in-python.htm
index b856eaa..e438ca2 100644
--- a/articles/subclassing-gobject/sub-classing-gobject-in-python.htm
+++ b/articles/subclassing-gobject/sub-classing-gobject-in-python.htm
@@ -160,7 +160,7 @@
       second goal GNOME is based on a set of libraries which are very easy to
       access from a large amount of programming languages.</p>
 
-      <p>The library most modules depend on is <a href="http://library.gnome.org/devel/glib/unstable/index.html"; target="_top">GLib</a> which provides a lot of useful functionality
+      <p>The library most modules depend on is <a href="http://developer.gnome.org/glib/stable/index.html"; target="_top">GLib</a> which provides a lot of useful functionality
       embedded and used in the GNOME framework; this document in particular
       discussed the Object system defined in Glib that allow us to use Object
       Orientation throughout the GNOME framework. The Glib library, as most of
@@ -171,7 +171,7 @@
       or Python. But this does not mean that you can not program in an Object
       Oriented way with C, it's only that you have to do some extra work. And
       it's your lucky day, because GLib does most of this work for you.
-      <a href="http://library.gnome.org/devel/gobject/unstable/index.html"; target="_top">GObject</a> is commonly known as the part of GLib that
+      <a href="http://developer.gnome.org/gobject/stable/index.html"; target="_top">GObject</a> is commonly known as the part of GLib that
       provides the Object Oriented features that C lacks.</p>
 
       <p>One of the nice things that GObject provides is a class mechanism
@@ -254,7 +254,7 @@
 
       <p><a id="d0e127" name="d0e127">So let's get some action and create our
       first example. We are going to create a Car class with a <span class="emphasis"><em>fuel</em></span> property that indicates the amount of
-      fuel that our car has. This is the</a> <a href="http://userpage.chemie.fu-berlin.de/%7Echrbecke/gobject-tutorial/car1.py"; target="_top">code</a></p>
+      fuel that our car has. This is the</a> <a href="./resources/car1.py" target="_top">code</a></p>
 
       <table bgcolor="#d9eefc" border="0" width="100%">
         <tbody>
@@ -578,7 +578,7 @@ Now the car has 20.000000 of fuel
 
       <p><a id="d0e412" name="d0e412">What I think is really useful is
       connecting a callback to the <span class="emphasis"><em>notify</em></span> signal of a property. In the next</a>
-      <a href="http://userpage.chemie.fu-berlin.de/%7Echrbecke/gobject-tutorial/car2.py"; target="_top">example</a> we will create a function that will check if
+      <a href="./resources/car2.py" target="_top">example</a> we will create a function that will check if
       we are running out of fuel using the notify mechanism of GObject:</p>
 
       <table bgcolor="#d9eefc" border="0" width="100%">
@@ -615,7 +615,7 @@ Now the car has 20.000000 of fuel
       have 4 different properties in a <tt>Car</tt>, that's why we need the if
       clause at the beginning of the callback.</p>
 
-      <p>Now we will <a href="http://userpage.chemie.fu-berlin.de/%7Echrbecke/gobject-tutorial/car4.py"; target="_top">see in</a> another way of doing the same as in the
+      <p>Now we will <a href="./resources/car4.py" target="_top">see in</a> another way of doing the same as in the
       previous example but using a nice feature of GObject signal names:</p>
 
       <table bgcolor="#d9eefc" border="0" width="100%">
@@ -696,7 +696,7 @@ Now the car has 20.000000 of fuel
         its internal and valid name will be <tt>background-color</tt>. The
         places where you have to be careful about this are the
         <tt>do_get_property()</tt> and <tt>do_set_property()</tt> methods and
-        the signal connection calls. Let's see an</a> <a href="http://userpage.chemie.fu-berlin.de/%7Echrbecke/gobject-tutorial/long-names.py"; target="_top">example:</a></p>
+        the signal connection calls. Let's see an</a> <a href="./resources/long-names.py" target="_top">example:</a></p>
 
         <table bgcolor="#d9eefc" border="0" width="100%">
           <tbody>
@@ -885,7 +885,7 @@ Now the car has 20.000000 of fuel
       won't be explained here.</a></p>
 
       <p><a id="d0e570" name="d0e570">I think this is enough theory for now so
-      let's jump into some real</a> <a href="http://userpage.chemie.fu-berlin.de/%7Echrbecke/gobject-tutorial/car4.py"; target="_top">code</a>. We can use the signal concept to improve our car
+      let's jump into some real</a> <a href="./resources/car4.py" target="_top">code</a>. We can use the signal concept to improve our car
       class. We can have an <tt>engine-started</tt> signal that will be
       emitted when the car's engine is started so other parts of the car can
       connect to this signal and do something useful.</p>
@@ -1071,7 +1071,7 @@ Now the car has 20.000000 of fuel
       </div>
 
       <p><a id="d0e723" name="d0e723">Now that we have our own signal we can
-      connect callbacks to it to make it a little bit more</a> <a href="http://userpage.chemie.fu-berlin.de/%7Echrbecke/gobject-tutorial/car5.py"; target="_top">useful:</a></p>
+      connect callbacks to it to make it a little bit more</a> <a href="./resources/car5.py" target="_top">useful:</a></p>
 
       <table bgcolor="#d9eefc" border="0" width="100%">
         <tbody>
@@ -1160,7 +1160,7 @@ Now the car has 20.000000 of fuel
       <tt>Car</tt> class with a <tt>LuxuryCar</tt> class and you want to do
       something more when the engine is started. In this particular case when
       you subclass a Python class with another Python class there is nothing
-      special with this. Let's see an</a> <a href="http://userpage.chemie.fu-berlin.de/%7Echrbecke/gobject-tutorial/luxurycar.py"; target="_top">example:</a></p>
+      special with this. Let's see an</a> <a href="./resources/luxurycar.py" target="_top">example:</a></p>
 
       <table bgcolor="#d9eefc" border="0" width="100%">
         <tbody>
@@ -1200,7 +1200,7 @@ Now the car has 20.000000 of fuel
       that will not allow the user to paste anything into it. In the regular
       <tt>gtk.Entry</tt> the class closure of the 'paste_clipboard' signal has
       the function that handles the paste behavior. So our class need to
-      override this class closure. <a href="http://userpage.chemie.fu-berlin.de/%7Echrbecke/gobject-tutorial/evilentry.py"; target="_top">This</a> is the code you need to write:</p>
+      override this class closure. <a href="./resources/evilentry.py" target="_top">This</a> is the code you need to write:</p>
 
       <table bgcolor="#d9eefc" border="0" width="100%">
         <tbody>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]