Hi all, [Python 2.3, pygtk & gnome-python 2.0.0, Linux 2.4.18]
I have a problem when sharing a value depending on the state of 2
widgets.
For example, there is a variable called self.opt, whose value is
controlled by a CheckButton and by a ToogleButton.
When I change the value with one widget I want the other changes its
state too, i.e. if I uncheck CheckButton, ToggleButton would have to
become unpressed, and viceversa.
But if I include code in the first callback to change the state of the
other, the second widget callback is also executed, so the variable gets
a bad value. Any ideas?
See the code below:
########################## PROBLEM EXAMPLE ##########################
import gtk
class App:
def __init__(self):
self.opt = 1
win = gtk.Window()
win.set_size_request(100, 100)
vbox = gtk.VBox()
self.label = gtk.Label('Option: %d' % self.opt)
vbox.pack_start(self.label)
self.check = gtk.CheckButton('Check')
self.check.set_active(self.opt)
self.check.connect('toggled', self.onCheckToggled)
vbox.pack_start(self.check)
self.toggle = gtk.ToggleButton('Toggle')
self.toggle.set_active(self.opt)
self.toggle.connect('toggled', self.onToggleToggled)
vbox.pack_start(self.toggle)
win.add(vbox)
win.show_all()
def onCheckToggled(self, check):
print self.opt,
if self.opt:
self.opt = 0
else:
self.opt = 1
print self.opt,
self.label.set_text('Option: %d' % self.opt)
# FIXME: this calls onToggleToggled, changing self.opt again
# how can I redraw the other widget state without calling the
# toggled callback? Indeed, does not this create an infinite
loop?
self.toggle.set_active(self.opt)
print self.opt
def onToggleToggled(self, toggle):
print self.opt,
if self.opt:
self.opt = 0
else:
self.opt = 1
self.label.set_text('Option: %d' % self.opt)
# FIXME: this calls onCheckToggled, changing self.opt again
# how can I redraw the other widget state without calling the
# toggled callback? Indeed, does not this create an infinite
loop?
self.check.set_active(self.opt)
print self.opt
def run(self):
gtk.mainloop()
app = App()
app.run()
########################## END ##########################
**************************************************************
And a second problem: libgnomecanvas.
I want to create a grid, so I add a group to the root canvas, keeping a
reference to be able to hide and show it. Then I create some "points"
(in fact short lines, btw why there si no GnomeCanvasPoint ;-) to
simulate the grid points, but I don't want to maintain references of
these items:
group_grid = canvas.root().add('GnomeCanvasGroup', x = 0, y = 0)
for i in xrange(0, 1280+1, 25):
for j in xrange(0, 1024+1, 25):
group_grid.add('GnomeCanvasLine',
points = (i, j, i+0.5, j+0.5),
fill_color = 'black',
width_pixels = 1)
Afterwards, I want to change the color of grid "points", but how can I
get references to canvas items?
group_grid.get_property('children') does not exist...
In C API struct GnomeCanvasGroup struct includes GList *item_list, but
it doesn't seem to be exposed to python bindings.
The solution I use now is to delete and re-create the grid, but I guess
it should be a better way.
Thanks in advance,
I�igo
signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
