You are not logged in.
Hi All,
i've been having problems with a small section of code that i have written.
the code works if it is in the main program file. but when i put it into it's own module i keep getting errors with the varables even thougth they are being used a few lines up the code.
i've been trying to sort this out all night.
def __init__(self,button):
self.pref_win = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.pref_win.set_border_width(0)
self.pref_win.set_title("Preferences")
self.pref_win.connect("destroy",self.destroy)
## Windows Stuff
box1 = gtk.VBox(False,0) ## Virtical Layout Box
self.pref_win.add(box1)
box1.show()
self.box2 = gtk.VBox(False,10)
box2.set_border_width(10)
box1.pack_start(box2,True,True,0)
box2.show()
## Setup Radio Buttons
radio_button = gtk.RadioButton(group=None, label="Only display an icon when battery is charging or discharging")
radio_button.connect("toggled",self.Radio_Call_Back,"show_charging_discharging")
box2.pack_start(radio_button,True,True,0)
radio_button.show()
##Button 2
radio_button = gtk.RadioButton(radio_button, label="Only show an icon when battery is discharging")
radio_button.connect("toggled",Radio_Call_Back,"Show_discharging_only")
box2.pack_start(radio_button,True,True,0)
radio_button.show()
##Button 3
radio_button = gtk.RadioButton(radio_button, label="Always display an icon")
radio_button.connect("toggled",Radio_Call_Back,"Always_show")
box2.pack_start(radio_button,True,True,0)
radio_button.show()
##Separtor
separator = gtk.HSeparator()
box1.pack_start(separator,False,True,0)
separator.show()
box2 = gtk.VBox(False,10)
box2.set_border_width(10)
box1.pack_start(box2,False,True,0)
box2.show()
#Okay Button
okay_button = gtk.Button("Okay")
okay_button.connect_object("clicked",self.okay_button_clicked,self.pref,None)
box2.pack_start(okay_button,True,True,0)
okay_button.show()
self.pref_win.show()
this is the error i'm getting.
File "/home/matthew/Projects/batterymon/branches/batterymon-hal/preferences.py", line 49, in prefs
radio_button = gtk.RadioButton(radio_button, label="Only show an icon when battery is discharging")
NameError: name 'radio_button' is not defined
but as you can see the radio_button is used just above line 49
Please HELP
Kind Regards
Matthew
"is adult entertainment killing our children or is killing our children entertaining adults?" Marilyn Manson
Offline
I'm not going to pretend to be a whiz with Python, but the only thing I noticed that varies between the seemingly successful implementation vs the unsuccessful line 49, is this (in bold)
radio_button = gtk.RadioButton(radio_button, label="Only show an icon when battery is discharging")
Where the line before it has group=none, try group=radio_button, and make sure the group exists, or enclose it in quotes if it's a string being passed to a method? That's the only idea I have. Also, it says the name is undefined, but doesn't specify which occurrence of the word it is.
Just my $0.02,
Lswest
P.S. on a slightly off-topic note...if you get that battery monitor working, care to share it? I'd be interested.
Last edited by lswest (2009-04-10 16:21:27)
Lswest <- the first letter of my username is a lowercase "L".
"...the Linux philosophy is "laugh in the face of danger". Oops. Wrong one. "Do it yourself". That's it." - Linus Torvalds
Offline