[maemo-developers] Help with hildon.NumberEditor: IN PYTHON
From: Darren Enns darethehair at gmail.comDate: Thu Apr 3 02:21:20 EEST 2008
- Previous message: Help with hildon.NumberEditor: IN PYTHON
- Next message: Training for Maemo Development
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Lauro Moura wrote: > On Wed, Apr 2, 2008 at 4:28 PM, Darren Enns <darethehair at gmail.com> wrote: > >> Help please! >> >> I am slowly learning OOP-style PyGTK code, and have recently discovered how >> 'nasty' gtk.Spinbutton looks on Maemo :( >> >> OK, so I was just going to make some quick changed to my Python code to use >> 'hildon.NumberEditor' instead, but it is not as much a 'drop-in-replacement' >> as a newbie like me requires... >> >> """ subclass the gtk.Digalog() class to create a new dialog window """ >> class spin_window(gtk.Dialog) : >> value = [0] * SPIN_BUTTON_COUNT >> >> def hildon_set_value(self,widget,index): >> self.value[index] = widget.get_value() >> return >> >> # a callback to remember the values of the spin buttons. >> # the 'index' is setup when connecting the callback >> def set_value(self,widget,index): >> self.value[index] = widget.get_value_as_int() >> return >> >> def __init__(self,window): >> # init the parent class to create the dialog >> super(spin_window, self).__init__("set spin values", >> window, >> gtk.DIALOG_DESTROY_WITH_PARENT | >> gtk.DIALOG_MODAL, >> (gtk.STOCK_OK, gtk.RESPONSE_OK)) >> >> number_editor = hildon.NumberEditor(-90,90) >> #number_editor.connect("changed",self.set_value, 0) >> #number_editor.connect("notify::value",self.set_value, 0) >> >> number_editor.connect("notify::value",self.hildon_set_value,0) >> number_editor.set_value(0) >> self.vbox.pack_start(number_editor) >> self.value[0] = 0 >> number_editor.show() >> >> label = gtk.Label('Latitude Degrees:') >> self.vbox.pack_start(label) >> #label.modify_font(pango.FontDescription("sans 30")) >> label.show() >> >> adjustment = gtk.Adjustment(0, -90, 90, 1, 1, 1) >> spinbutton = gtk.SpinButton(adjustment,0,0) >> spinbutton.connect("changed",self.set_value, 1) >> self.vbox.pack_start(spinbutton) >> self.value[1] = 0 >> spinbutton.show() >> ... >> >> Notice my feeble attempts to add 'special' code for the numbereditor -- but >> the code above does not work: >> >> "TypeError: hildon_set_value() takes exactly 3 arguments (4 given)" >> >> So I am getting all confused! It *looks* like I am using the correct >> signal value, and passing three parameters... >> >> There are very few Python examples out on Google for me to learn the >> solution with. >> >> > > Try replacing the argument list on the callback to > > def set_value(self, widget, index, data=None) > > Now data will take the extra data passed when the signal is received. > > Thanks for the suggestion! It got me a bit further, but my parameter offsets must be wrong. This is what my 'hildon' callback looks like now: > def hildon_set_value(self, widget, index, data=None): When I use it that way, I get complaints that 'index' is not an integer (which of course it is): Traceback (most recent call last): File "mephemeris.22.py", line 2480, in hildon_set_value self.value[index] = widget.get_value() TypeError: list indices must be integers This suggests to me that I have the correct number of parameters, but not in the position I am expecting them in. Dare
- Previous message: Help with hildon.NumberEditor: IN PYTHON
- Next message: Training for Maemo Development
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]