Hi

Actually, this does not work at the moment. pyFltk is using the Swig type 
system to keep track of classes, therefore, only Fltk classes are supported. If 
need by, I can have a look at supporting Python classes as well, if so, please 
add an item to the pyFltk feature tracker.

As a work-around, the method suggested by Greg should be the only one I could 
think of.

Regards

Andreas
http://pyfltk.sourceforge.net

> Sorry if this is a bit off topic as it's a pyFLTK question.
> I cannot seem to access any of the attributes of my Fl_Button subclass
> in a callback through the widget variable.
> 
> Shouldn't the widget variable in the callback refer to a MyButton object?
> 
> #!/usr/bin/python
> from fltk import *
> 
> class MyButton(Fl_Button):
>       def __init__(self,x,y,w,h,label=None):
>               Fl_Button.__init__(self,x,y,w,h,label)
>               self.secret="ssss"
> 
> class MyWindow(Fl_Window):
>       def __init__(self,x,y,w,h,label=None):
>               Fl_Window.__init__(self,x,y,w,h,label)
> 
>               self.begin()
>               self.but=MyButton(30,30,50,50)
>               self.but.callback(self.but_cb)
>               self.end()
> 
>       def but_cb(self, widget):
>               widget.label("okay")
>               print widget.secret  #this line pukes
> 
> win=MyWindow(200,200,200,200)
> win.show()
> Fl.run()
> 
> When I click on the MyButton object I get this error
> 
> Traceback (most recent call last):
>   File "ginhert.py", line 23, in but_cb
>     print widget.secret
>   File "/usr/lib/python2.3/site-packages/fltk.py", line 91, in <lambda>
>     __getattr__ = lambda self, name: _swig_getattr(self, Fl_Widget, name)
>   File "/usr/lib/python2.3/site-packages/fltk.py", line 38, in _swig_getattr
>     raise AttributeError,name
> AttributeError: secret
> 
> After trying some more testing, it seems that the widget variable is
> not even an Fl_Button object but rather an Fl_Widget. In C++ I would
> employ a cast but I don't think I can do this in Python. Any help is
> appreciated.
> 
> --
> Robert Arkiletian
> Eric Hamber Secondary, Vancouver, Canada
> Fl_TeacherTool http://www3.telus.net/public/robark/Fl_TeacherTool/
> C++ GUI tutorial http://www3.telus.net/public/robark/
> 

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to