After going through the PyGTK libraries and tutorials, I haven’t managed to find an exact answer I’m looking for, or maybe I’m just doing something wrong…
Anyway, I’m learning PyGTK and Glade, I’m in the process of scripting a simple downloader application. The GUI of the application has three check boxes, and then a submit button.
What I’m trying to do is get the status of the check boxes after the submit button is pressed, that way I can continue my script to download applications based on whether the checkboxes are true or false.
Here’s what I have so far. (Still very early stages and learning from mistakes)
Python Script:
import sys
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
class GladeTest:
def __init__(self):
#Set the Glade file
filename = "gui.glade"
builder = gtk.Builder()
builder.add_from_file(filename)
builder.connect_signals(self)
#Create our dictionay and connect it
dic = { "btnSubmit_clicked" : self.btnSubmit_clicked,
"chkboxDropbox_toggled" : self.chkboxDropbox_toggled,
"MainWindow_destroy" : gtk.main_quit }
def btnSubmit_clicked(self, widget):
self.button = gtk.ToggleButton("chkboxDropbox_toggled")
status = self.button.get_active()
print status
def chkboxDropbox_toggled(self, widget):
print ""
if __name__ == "__main__":
hwg = GladeTest()
gtk.main()
Glade 3 XML (gui.glade):
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkAction" id="action1"/>
<object class="GtkWindow" id="MainWindow">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">MainWindow</property>
<property name="resizable">False</property>
<property name="window_position">center</property>
<signal name="destroy" handler="MainWindow_destroy" swapped="no"/>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Downloader</property>
<attributes>
<attribute name="style" value="normal"/>
<attribute name="size" value="300"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="chkboxDropbox">
<property name="label" translatable="yes">Dropbox</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="chkboxDropbox_toggled" swapped="no"/>
<signal name="activate" handler="chkboxDropbox_active" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="chkboxPython">
<property name="label" translatable="yes">Python</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="chkboxPython_checked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="chkboxChrome">
<property name="label" translatable="yes">Google Chrome</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="chkboxChrome_checked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnSubmit">
<property name="label" translatable="yes">Download/Run</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="btnSubmit_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
Either I can’t find the proper method of calling for the status, or I have found it and I’m just using it wrong… Any help is greatly appreciated, thanks in advance!
you just need to call “get_active” method of gtk checkbox, get object of check button from glade file and call “get_active” method on click event of submit button.
here, code snippet to be more descriptive:
hope, it would help you.