problem with GKT module?

A

alister ware

I am using gtk.builder with a glade generated GUI

I have a simple call back defined for a radio button widget when I use
widget.name in linux I get a value of None, windows returns the widget
name as I would expect.

is this a bug?
if not how should i find the name of the widget that has triggered a call
back?

(I would like all my radio buttons to go to the same callback routine if
possible to make code maintenance easier)


--
101-ism:
The tendency to pick apart, often in minute detail, all
aspects of life using half-understood pop psychology as a tool.
-- Douglas Coupland, "Generation X: Tales for an
Accelerated
Culture"
 
A

Alister Ware

I am using gtk.builder with a glade generated GUI

I have a simple call back defined for a radio button widget when I use
widget.name in linux I get a value of None, windows returns the widget
name as I would expect.

is this a bug?
if not how should i find the name of the widget that has triggered a
call back?

(I would like all my radio buttons to go to the same callback routine if
possible to make code maintenance easier)
So nobody has any Ideas on this at all?
 
H

harrismh777

Alister said:
I have a simple call back defined for a radio button widget when I use

First, not familiar with your issue...

.... but might be able to help you think through it...

I am assuming that you are building a Python script using a glade
interface that provides the widgets drag-an-drop style and then allowing
you to take the default code, add to it, or otherwise modify it.

I am also assuming that the /call back/ is returning a Python None, on
the linux platform... otherwise you're getting the widget name from the
same script on the windows platform?? right?

It might be helpful to examine both scripts to see where (if any) they
differ. More likely than not, this little snag is a difference in the
way that the windows version of gtk+ libraries are working, than the
original ones on the linux platform.

On the other hand, the Python wrappers for the gtk+ library on the linux
platform may be hiding the return values. Python functions return 'None'
if the 'return' is not explicitly coded. The gtk+ libraries may be
returning a value but the 'builder' is not generating the right Python
wrapper. I'm making this up, but you get the idea, and you can probably
check from here.

On the other hand, folks here can enter into a discussion with you
regarding the generated Python code (output from the builder) if you
provide relevant code snippets.


Kind regards,
m harris
 
A

alister ware

First, not familiar with your issue...

... but might be able to help you think through it...

I am assuming that you are building a Python script using a glade
interface that provides the widgets drag-an-drop style and then allowing
you to take the default code, add to it, or otherwise modify it.

I am also assuming that the /call back/ is returning a Python None, on
the linux platform... otherwise you're getting the widget name from the
same script on the windows platform?? right?

It might be helpful to examine both scripts to see where (if any) they
differ. More likely than not, this little snag is a difference in the
way that the windows version of gtk+ libraries are working, than the
original ones on the linux platform.

On the other hand, the Python wrappers for the gtk+ library on the linux
platform may be hiding the return values. Python functions return 'None'
if the 'return' is not explicitly coded. The gtk+ libraries may be
returning a value but the 'builder' is not generating the right Python
wrapper. I'm making this up, but you get the idea, and you can probably
check from here.

On the other hand, folks here can enter into a discussion with you
regarding the generated Python code (output from the builder) if you
provide relevant code snippets.


Kind regards,
m harris

glade generates an xml file that is processed by the python script

it is the same ml file & the same python script running on both platforms

the basic structure of my call back for testing is:-

import gtk
class GUI:
def __init__(self):
builder=gtk.Builder()
builder.add_from_file('glade.test') # xml file from glade
builder.get_object('window1').show()
builder.connect_signals(self)


def callback(self,widget,data=None):
print widget #gives reference to radio button ok
print widget.name #widget name on windoze, None on linux
def main (self):
gtk.main()

def main():
gui=GUI()
gui.main()

if __name__ =='__main__':main()

I can provide more detailed sample code if required (including the xml
from glade)


--
Has everyone noticed that all the letters of the word "database" are
typed with the left hand? Now the layout of the QWERTYUIOP typewriter
keyboard was designed, among other things, to facilitate the even use
of both hands. It follows, therefore, that writing about databases is
not only unnatural, but a lot harder than it appears.
 
H

harrismh777

alister said:
def callback(self,widget,data=None):
print widget #gives reference to radio button ok
print widget.name #widget name on windoze, None on linux

Well, you're obviously using Python 2.x ...

... have you tried this in Python 3.x ?


Neither here nor there... you need to know who/what is generating
'widget'. Is widget buried in gtk where you can't see how it works, or
is widget a Python class (or wrapper) where you can see what its doing?

The fact that widget.name returns None on the linux platform tells me
that widget is a Python class (or wrapper) ... so you probably have a
widget.py file somewhere... or some other module that widget is a class
definition in... who knows... (at this point).

It seems to me that the 'builder' is behaving differently on the two
platforms (rather than Python is behaving differently on the two platforms).

What happens if you change the data=None pair?

What happens if you omit data=None pair?

Do you see this difference with *all* widgets, or just radio buttons?



kind regards,
m harris
 
A

Alister Ware

linux

Well, you're obviously using Python 2.x ...

... have you tried this in Python 3.x ?


Neither here nor there... you need to know who/what is generating
'widget'. Is widget buried in gtk where you can't see how it works, or
is widget a Python class (or wrapper) where you can see what its doing?

The fact that widget.name returns None on the linux platform tells me
that widget is a Python class (or wrapper) ... so you probably have a
widget.py file somewhere... or some other module that widget is a class
definition in... who knows... (at this point).

It seems to me that the 'builder' is behaving differently on the two
platforms (rather than Python is behaving differently on the two
platforms).

What happens if you change the data=None pair?

What happens if you omit data=None pair?

Do you see this difference with *all* widgets, or just radio buttons?



kind regards,
m harris

It seems it was introduced in pygtk 2.1.7 as a side effect of correcting
something to do with widget id's and the fact that widget names do not
have to be unique (although glade insists that they are).

looks like i have to modify my code & use gtk.buildable.get_name(widget)
instead, not really a big change but may break someone else's code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,428
Latest member
RosalieQui

Latest Threads

Top