"For" loops with GTK boxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phub11
    New Member
    • Feb 2008
    • 127

    "For" loops with GTK boxes

    Hi,

    I have a variable number of check buttons and comboboxes I want to add to a window; however, I keep getting memory faults when I try to horizontal box a check button and combobox and then box each one of these vertically. Any help would be appreciated:

    Code:
    	window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    	combobox = gtk.combo_box_new_text()
    	box1_vbox = gtk.VBox(False, 2)
    	list_vbox = gtk.VBox(True, 6)
    	check_hbox = gtk.HBox(True, 6)
    	buttons_hbox = gtk.HBox(True, 6)
    	title = gtk.Label("Superimpose models")
    	for imol in molecule_number_list():
    		combobox_name = molecule_name(imol)
    		combobox.append_text(combobox_name)
    	combobox.connect('changed', sel_ref_mol)
    	
    	box1_vbox.pack_start(title, False, False)
    	box1_vbox.pack_start(combobox, False, False)
    	
    	box1_vbox.pack_start(check_hbox, False, False)
    	
    	for imol in molecule_number_list():
    		button_name = molecule_name(imol)
    		button_imol = gtk.CheckButton(button_name)
    		combobox_imol = gtk.combo_box_new_text()
    		button_imol.connect("toggled", moving_mol, imol)
    		combobox_imol.append_text(combobox_name)
    		check_hbox_imol = gtk.HBox(True, 6)
    		check_hbox_imol.pack_start(button_imol, False, False)
    		check_hbox_imol.pack_start(combobox_imol, False, False)
    	#for imol in molecule_number_list():
    	box1_vbox.pack_start(check_hbox_imol, False, False)
    	ok_button = gtk.Button("   Go!  ")
    	cancel_button = gtk.Button("    Cancel    ")
    	cancel_button.connect("clicked", delete_event)
    
    	
    	buttons_hbox.pack_start(ok_button, False, False)
    	buttons_hbox.pack_start(cancel_button, False, False)
    	box1_vbox.pack_start(buttons_hbox, False, False)
    
    	window.add(box1_vbox)
    	
    	window.show_all()
    Thanks!
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Python does not have memory faults AFAIK so please post the entire error message which includes the offending line. In the snippet you posted, molecule_number _list and molecule_name have not been declared prior to the for() loop so may or may not be the problem.

    You should also be using ComboBoxText instead of combo_box_new_t ext(), which is deprecated. Try printing the molecule data as you create the widgets as the data itself may be corrupt. Obviously we can not test this without some test data so that would help as well.
    Code:
        for imol in molecule_number_list():
             combobox_name = molecule_name(imol)  ## <----- not declared

    Comment

    • phub11
      New Member
      • Feb 2008
      • 127

      #3
      Thanks for the reply. The trick was to put "combobox.conne ct('changed', sel_ref_mol)" in to the For loop.

      Comment

      Working...