1 year ago

#292406

test-img

Éric

pyGTK3 issue refreshing combobox with button on Linux

I'm trying to implement a button that updates the content of the ListStore 'attached' to a ComboBox.

Here is the combo part :

class SelectCam(Gtk.Box):
   def __init__(self):
       Gtk.Box.__init__(self)
       self.cam_list = Gtk.ListStore(int, str)
       self.listbox = Gtk.ComboBox( model=self.cam_list )
       self.load(self.cam_list,self.listbox)
       self.cell = Gtk.CellRendererText()
       self.listbox.pack_start(self.cell, True)
       self.listbox.add_attribute(self.cell, 'text', 1)
       self.listbox.set_model( self.cam_list )
       self.listbox.connect('changed', self.changed_cb)
       self.pack_start(self.listbox, True, False, 0)

   def load(self,cl,lb):
       cl.clear()
       cl.append( [0, "Choose Camera"] )
       for cam in myfuncs.get_model(): self.cam_list.append( cam )
       lb.set_active(0)
       lb.set_entry_text_column(1)

   def changed_cb(self, combo):
      itr = combo.get_active_iter()
      status = self.cam_list.get_value(itr, 0)
      camtype = self.cam_list.get_value(itr, 1)
      camport = None
      if status == 1:
          camport = myfuncs.get_port( camtype )
          os.environ["EOS_MODEL"] = camtype
          os.environ["EOS_PORT"] = camport
      mylogger.info( "selected %s (%s) [ %s ]" % (camtype,camport ,status ) )

And here is the button part :

class Buttons(Gtk.Box):
   def __init__(self,cl):
       self.cl = cl
       self.labeltxt1 = "Load"
       self.labeltxt2 = "Quit"
       Gtk.Box.__init__(self)
       self.button1 = Gtk.Button(self.labeltxt1)
       self.button1.connect("clicked", self.load_camlist)
       self.pack_start(self.button1, True, False, 0)
       self.button2 = Gtk.Button(self.labeltxt2)
       self.button2.connect("clicked", self.on_close_clicked)
       self.pack_start(self.button2, True, False, 0)

   def load_camlist(self, button):
       self.cl.load(self.cl.cam_list,self.cl.listbox)

   def on_close_clicked(self, button):
       mylogger.info("Closing application")
       Gtk.main_quit()

The combo gets refreshed actually but I keep getting the error below :

Traceback (most recent call last):
  File "/path/to/git/eos-utility/eos-utility/classes/widgets.py", line 79, in changed_cb
    status = self.cam_list.get_value(itr, 0)
TypeError: Argument 1 does not allow None as a value

Do you guys have any idea of what I'm doing wrong ?

Thanks.

python

pygtk

0 Answers

Your Answer

Accepted video resources