473,395 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

"For" loops with GTK boxes

127 100+
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:

Expand|Select|Wrap|Line Numbers
  1.     window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  2.     combobox = gtk.combo_box_new_text()
  3.     box1_vbox = gtk.VBox(False, 2)
  4.     list_vbox = gtk.VBox(True, 6)
  5.     check_hbox = gtk.HBox(True, 6)
  6.     buttons_hbox = gtk.HBox(True, 6)
  7.     title = gtk.Label("Superimpose models")
  8.     for imol in molecule_number_list():
  9.         combobox_name = molecule_name(imol)
  10.         combobox.append_text(combobox_name)
  11.     combobox.connect('changed', sel_ref_mol)
  12.  
  13.     box1_vbox.pack_start(title, False, False)
  14.     box1_vbox.pack_start(combobox, False, False)
  15.  
  16.     box1_vbox.pack_start(check_hbox, False, False)
  17.  
  18.     for imol in molecule_number_list():
  19.         button_name = molecule_name(imol)
  20.         button_imol = gtk.CheckButton(button_name)
  21.         combobox_imol = gtk.combo_box_new_text()
  22.         button_imol.connect("toggled", moving_mol, imol)
  23.         combobox_imol.append_text(combobox_name)
  24.         check_hbox_imol = gtk.HBox(True, 6)
  25.         check_hbox_imol.pack_start(button_imol, False, False)
  26.         check_hbox_imol.pack_start(combobox_imol, False, False)
  27.     #for imol in molecule_number_list():
  28.     box1_vbox.pack_start(check_hbox_imol, False, False)
  29.     ok_button = gtk.Button("   Go!  ")
  30.     cancel_button = gtk.Button("    Cancel    ")
  31.     cancel_button.connect("clicked", delete_event)
  32.  
  33.  
  34.     buttons_hbox.pack_start(ok_button, False, False)
  35.     buttons_hbox.pack_start(cancel_button, False, False)
  36.     box1_vbox.pack_start(buttons_hbox, False, False)
  37.  
  38.     window.add(box1_vbox)
  39.  
  40.     window.show_all()
  41.  
Thanks!
Oct 21 '12 #1
2 1647
dwblas
626 Expert 512MB
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_text(), 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.
Expand|Select|Wrap|Line Numbers
  1.     for imol in molecule_number_list():
  2.          combobox_name = molecule_name(imol)  ## <----- not declared 
Oct 21 '12 #2
phub11
127 100+
Thanks for the reply. The trick was to put "combobox.connect('changed', sel_ref_mol)" in to the For loop.
Oct 22 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
15
by: adomas.paltanavicius | last post by:
Hi there, I am quite new to Python, and have a straight & simple question. In C, there is for (init; cond; advance). We all know that. In Python there are two ways to loop over i=A..B...
9
by: adam | last post by:
hello Does exist in SQL language "for" loop ? If yes, what syntax does it has ? best wishes Adam
12
by: Robbie Hatley | last post by:
I'm getting a bizarre error with this code: ... case WM_COMMAND: { switch (LOWORD(wParam)) // switch (control ID) { ... case IDC_RAIN_ENABLE_SIMPLE: {
5
by: Fabian Vilers | last post by:
Hi again... I'm wondering what could be better in terms of performance between: var my_array = new Array(); // populate array for (index in my_array) { // do something with my_array
34
by: Frederick Gotham | last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to simple incrementation? Here's a very simple program that prints out the bit-numbers in a byte. #include <stdio.h> #include...
1
by: Ralgoth | last post by:
using Flash, I'm sending a bunch of variables to my php script that have ordered names. What I want is to use a "for" loop to identify each variable. This is how I would do it in Flash but don't...
2
by: marsarden | last post by:
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if
4
by: MDR | last post by:
Hello I have three "for" loops, two nested into the outer one and they depend on each other, like this: for (x=1; x<100; x++) { .... for (i=1; i<10; i++) {....} for (j=1; j<10;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.