I am having trouble trying to port a pygtk/python2.6/linux-fedora-14 
application to use pygobject.

My first try was to convert using pygi-convert.sh, and when I ran that 
converted .py,  I got
       File "/home/lumby/pythonapps/togglegobj_from_convert.py", line 17, in 
<module>
            pyGtk.require('2.0')
       NameError: name 'pyGtk' is not defined
The converter had converted the line
   pygtk.require('2.0')
into the
   pyGtk.require('2.0')

I don't know the converter would leave calls to anything named pygtk if the 
objective is to
remove all reference to pygtk.    Anyway,  I commented that line out and then I 
got
  File "/home/lumby/pythonapps/togglegobj_from_convert_plus_chg1.py", line 89, 
in <module>
    instance = ToggleBut()
  File "/home/lumby/pythonapps/togglegobj_from_convert_plus_chg1.py", line 35, 
in __init__
    self.vbox = Gtk.VBox(False, 85)
TypeError: GObject.__init__() takes exactly 0 arguments (2 given)

Now I am completely baffled.    The TypeError error message displays line 27 
which reads
        gobject.GObject.__init__(self)
but the previous line in the traceback refers to line 35, the one instantiating 
self.vbox.

I've attached the original and converted files at the end.


I then turned to the examples provided by pygobject and found one that includes 
gtk functions:
         cairo-demo.py

so I ran that and I got

  File "/usr/share/doc/pygobject2-2.21.5/examples/cairo-demo.py", line 81, in 
expose
    ctx = Gdk.cairo_create(da.window)
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/types.py", line 40, in 
function
    return info.invoke(*args)
TypeError: argument 0: Must be Gdk.Drawable, not NoneType
Traceback (most recent call last):
  File "/usr/share/doc/pygobject2-2.21.5/examples/cairo-demo.py", line 81, in 
expose
    ctx = Gdk.cairo_create(da.window)
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/types.py", line 40, in 
function
    return info.invoke(*args)
TypeError: argument 0: Must be Gdk.Drawable, not NoneType
Traceback (most recent call last):
  File "/usr/share/doc/pygobject2-2.21.5/examples/cairo-demo.py", line 81, in 
expose
    ctx = Gdk.cairo_create(da.window)
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/types.py", line 40, in 
function
    return info.invoke(*args)
TypeError: argument 0: Must be Gdk.Drawable, not NoneType
Traceback (most recent call last):
  File "/usr/share/doc/pygobject2-2.21.5/examples/cairo-demo.py", line 81, in 
expose
    ctx = Gdk.cairo_create(da.window)
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/types.py", line 40, in 
function
    return info.invoke(*args)
TypeError: argument 0: Must be Gdk.Drawable, not NoneType
Traceback (most recent call last):
  File "/usr/share/doc/pygobject2-2.21.5/examples/cairo-demo.py", line 81, in 
expose
    ctx = Gdk.cairo_create(da.window)
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/types.py", line 40, in 
function
    return info.invoke(*args)
TypeError: argument 0: Must be Gdk.Drawable, not NoneType
Traceback (most recent call last):
  File "/usr/share/doc/pygobject2-2.21.5/examples/cairo-demo.py", line 81, in 
expose
    ctx = Gdk.cairo_create(da.window)
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/types.py", line 40, in 
function
    return info.invoke(*args)
TypeError: argument 0: Must be Gdk.Drawable, not NoneType
Traceback (most recent call last):
  File "/usr/share/doc/pygobject2-2.21.5/examples/cairo-demo.py", line 81, in 
expose
    ctx = Gdk.cairo_create(da.window)
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/types.py", line 40, in 
function
    return info.invoke(*args)
TypeError: argument 0: Must be Gdk.Drawable, not NoneType
Traceback (most recent call last):
  File "/usr/share/doc/pygobject2-2.21.5/examples/cairo-demo.py", line 81, in 
expose
    ctx = Gdk.cairo_create(da.window)
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/types.py", line 40, in 
function
    return info.invoke(*args)
TypeError: argument 0: Must be Gdk.Drawable, not NoneType
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/gtk-2.0/gi/types.py", line 40, in 
function
    return info.invoke(*args)
TypeError: main_quit() takes exactly 0 argument(s) (1 given)

At this point I am not confident I can get this working.    Can anyone help me?
I am looking for an example of a working python app that uses pygobject to 
perform
gtk functions.   And/Or some definitive rules on what a python skeleton for this
looks like.


If the answer is along the lines of
 "the converter, examples and doc are a bit out of date, they will be updated"
then that's fine,   if someone can state that.


Cheers    John Lumby

----------------------------------------------------------------

some package versions  (up to date Fedora 14 )

python-devel-2.7-8.fc14.1.i686
dbus-python-0.83.0-7.fc14.i686
python-libs-2.7-8.fc14.1.i686
pygobject2-devel-2.21.5-3.fc14.i686
gobject-introspection-devel-0.9.3-1.fc14.i686
pygtk2-devel-2.17.0-7.fc14.i686
gobject-introspection-0.9.3-1.fc14.i686
python-2.7-8.fc14.1.i686
pygobject2-2.21.5-3.fc14.i686
pygtk2-2.17.0-7.fc14.i686

----------------------------------------------------------------------

working pygtk file  ( I don't claim it's good code but it works)
#!/usr/bin/env python
""" Toggle Button

GtkToggleButton provides an on/off mechanism. 
The user can control which state should be active
by clicking the empty area or by dragging the handle.
"""

import sys
import os.path
# pygtklibdir = os.path.join("/usr/gtk3/lib", "pygtk", "2.0")
# sys.path.insert(0, pygtklibdir)

import string
import re
import pygtk
pygtk.require('2.0')
#  pygtk.require('3.0')
import gobject
import gtk
#  import pango


class ToggleBut(gtk.Window):
    def __init__(self, parent=None):

        gtk.Window.__init__(self)

        self.connect('delete-event', self._on_delete_event)
        
        self.connect("destroy", self.destroy)

        gtk.Window.set_border_width(self,10)

        self.vbox = gtk.VBox(False, 85)
        self.add(self.vbox)

        self.vbox.set_border_width(8)
        self.vbox.show()

        self.toggle_but = gtk.ToggleButton(label="Toggle Me")

        self.vbox.pack_start(self.toggle_but, True, True, 0)

        self.light_image = gtk.image_new_from_file ("light_on.png")
        self.vbox.pack_start(self.light_image, False, False, 0)

        self.toggle_but.set_active(True)
        self.toggle_but.connect('notify::active', self.turn_light_on_off ,  
self.light_image)

        status = gtk.Statusbar()
        self.vbox.pack_end(status, expand=False)
        status.show()
        self.statusbar = status

        self.show_all()

    def turn_light_on_off(self, paramspec , maybe , this_light_image):
#   extract active state of the switch and set the lightbulb image accordingly
        on_off = self.toggle_but.get_active()
        this_light_image.set_sensitive(on_off)

    def main(self):
        self.show()
        gtk.main()

    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 _on_delete_event(self, window, event):
        self.quit()

    def destroy(self, widget, data=None):
        gtk.main_quit()

    def quit(self):
        gtk.main_quit()


if __name__ == '__main__':
    instance = ToggleBut()
    instance.main()

----------------------------------------------------------------

file as converted by converter

#!/usr/bin/env python
""" Toggle Button

GtkToggleButton provides an on/off mechanism. 
The user can control which state should be active
by clicking the empty area or by dragging the handle.
"""

import sys
import os.path
# pygtklibdir = os.path.join("/usr/gtk3/lib", "pygtk", "2.0")
# sys.path.insert(0, pygtklibdir)

import string
import re
import pygtk
pyGtk.require('2.0')
#  pyGtk.require('3.0')
import gobject
from gi.repository import Gtk
#  from gi.repository import Pango


class ToggleBut(Gtk.Window):
    def __init__(self, parent=None):

        gobject.GObject.__init__(self)

        self.connect('delete-event', self._on_delete_event)
        
        self.connect("destroy", self.destroy)

        Gtk.Window.set_border_width(self,10)

        self.vbox = Gtk.VBox(False, 85)
        self.add(self.vbox)

        self.vbox.set_border_width(8)
        self.vbox.show()

        self.toggle_but = Gtk.ToggleButton(label="Toggle Me")

        self.vbox.pack_start(self.toggle_but, True, True, 0)

        self.light_image = Gtk.image_new_from_file ("light_on.png")
        self.vbox.pack_start(self.light_image, False, False, 0)

        self.toggle_but.set_active(True)
        self.toggle_but.connect('notify::active', self.turn_light_on_off ,  
self.light_image)

        status = Gtk.Statusbar()
        self.vbox.pack_end(status, expand=False)
        status.show()
        self.statusbar = status

        self.show_all()

    def turn_light_on_off(self, paramspec , maybe , this_light_image):
#   extract active state of the switch and set the lightbulb image accordingly
        on_off = self.toggle_but.get_active()
        this_light_image.set_sensitive(on_off)

    def main(self):
        self.show()
        Gtk.main()

    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 _on_delete_event(self, window, event):
        self.quit()

    def destroy(self, widget, data=None):
        Gtk.main_quit()

    def quit(self):
        Gtk.main_quit()


if __name__ == '__main__':
    instance = ToggleBut()
    instance.main()

                                          
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to