[maemo-developers] Help with hildon.NumberEditor: IN PYTHON
From: Darren Enns darethehair at gmail.comDate: Fri Apr 4 23:23:33 EEST 2008
- Previous message: Looking for a maemo bugmaster
- Next message: [Announce] Release of the DCCP Plugin 0.5 for GStreamer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Darren Enns wrote: > 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 OK, no reply to my last question, so here is my own progress :) One of my other helpers suggested trying to find out a bit more about this widget by temporarily adjusting my method: def hildon_set_value(self,one,two,three): print "one = ",type(one)," = ",one print "two = ",type(two)," = ",two print "three = ",type(three)," = ",three return When I did this, I got the following: one = <type 'hildon.NumberEditor'> = <hildon.NumberEditor object at 0x408367b0 (HildonNumberEditor at 0x277030)> two = <type 'gobject.GParamSpec'> = <GParamInt 'value'> three = <type 'int'> = 0 This is mostly gibberish to me, but it suggested to me that my 'index' parameter was really supposed to be the *last* parameter, and not the 2nd last: def hildon_set_value(self, widget, data=None, index=0): print "index=",index self.value[index] = widget.get_value() return This *appears* to work, but I still am very confused about what is going on. Should I just ignore my confusion with using 'hildon.NumberEditor' and move on? It just seems silly to me to have this 'do-nothing' parameter in the middle of no-where i.e. 'data=None'. Also, the controls for the behavior of this widget seem very simplistic compared to, say, SpinButton. As a matter of fact, even though the appearance is *better* than with SpinButton, it is still very bad-looking (overlapping labels and controls) in a 'Dialog' context. This makes it all so difficult for a newbie like myself ;) Thanks
- Previous message: Looking for a maemo bugmaster
- Next message: [Announce] Release of the DCCP Plugin 0.5 for GStreamer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]