I have developed a simple glade form that I mean to manipulate with python-3.10.
I thought I had the code right, but the controls just do not respond. (in particular, the buttons).
If anyone can help, I would be much obliged. I thought the "connect_symbols(self)" in the main Gui class would have taken care of it, but I'm still missing something.
Here is the program:
#!/usr/bin/env python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import sys
import os
builder = Gtk.Builder()
class GUI:
def __init__ (self):
builder.add_from_file('Form-10a.glade')
builder.connect_signals(self)
self.Pindir = None
self.Poutdir = None
self.Psortby = 'type'
self.Preport = 'False'
self.Pverbose = 'True'
window = builder.get_object('window1')
window.show_all()
#
def onSubmitButtonCli#cked(self, button):
inputdir = builder.get_object('inputdir').get_property('text')
print(f'inputdir = {inputdir}')
tv = os.path.exists(inputdir)
if (tv == False):
print(inputdir, "is not a vaild directory, try again.")
else:
self.Pindir = inputdir
outputdir = builder.get_object('outputdir').get_property('text')
print(f'outputdir = {outputdir}')
self.Poutdir=outputdir
name_button = builder.get_object('NameButton')
#print('[NameButton] active:', name_button.get_active())
#print('[NameButton] group :', name_button.get_group())
for item in name_button.get_group():
name = item.get_name()
truth_value = item.get_active()
print(name, '=', truth_value)
if (truth_value == True):
self.Psortby = name
i = self.Psortby.index('Button')
self.Psortby=self.Psortby[0:i]
report_button = builder.get_object('ReportY')
for item in report_button.get_group():
name = item.get_name()
truth_value = item.get_active()
print(name, '=' , truth_value)
self.Preport = truth_value
verbose_button = builder.get_object('VerboseY')
for item in verbose_button.get_group():
name = item.get_name()
truth_value = item.get_active()
print(name, '=', truth_value)
# tv = ((truth_value=='True')?1:0)
self.Pverbose = truth_value
with open('scripts-search.conf','w') as w:
w.write('[Main]\n')
outputdata = 'inputdir: ' + self.Pindir + '\n'
w.write(outputdata)
outputdata = 'outputdir: ' + self.Poutdir + '\n'
w.write(outputdata)
outputdata = 'sortby: ' + str(self.Psortby) + '\n'
w.write(outputdata)
outputdata = 'report: ' +str(self.Preport) + '\n'
w.write(outputdata)
outputdata = 'verbose: ' + str(self.Pverbose) + '\n'
w.write(outputdata)
w.write('\n')
Gtk.main_quit()
def onDestroy(self,menuitem):
Gtk.main_quit()
def onQuitButtonClicked(self,button):
Gtk.main_quit()
def main():
while True:
try:
app = GUI()
Gtk.main()
except Exception as e:
print ("Error!!")
print (e.inst)
Gtk.main_quit()
if __name__ == '__main__':
rv = 0
rv = main()
sys.exit(rv)
And, if anyone is interested, here is Form-10a.glade:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkWindow" id="window1">
<property name="name">GtkWindow</property>
<property name="can-focus">True</property>
<property name="window-position">center-always</property>
<property name="default-width">380</property>
<property name="default-height">200</property>
<property name="destroy-with-parent">True</property>
<property name="type-hint">dialog</property>
<property name="gravity">north-east</property>
<signal name="destroy" handler="onDestroy" swapped="no"/>
<child>
<!-- n-columns=2 n-rows=7 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">True</property>
<child>
<object class="GtkLabel">
<property name="name">label1</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">3</property>
<property name="margin-right">3</property>
<property name="margin-start">3</property>
<property name="margin-end">3</property>
<property name="margin-top">3</property>
<property name="margin-bottom">3</property>
<property name="label" translatable="yes">Scripts Search - Enter Parameters</property>
<property name="justify">fill</property>
<attributes>
<attribute name="font-desc" value="Serif 12"/>
<attribute name="style" value="normal"/>
<attribute name="weight" value="normal"/>
<attribute name="variant" value="normal"/>
<attribute name="stretch" value="normal"/>
<attribute name="scale" value="1"/>
</attributes>
<signal name="destroy" handler="onDestroy" swapped="no"/>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="GtkWindow">
<property name="name">GtkWindow</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="label" translatable="yes">
</property>
<property name="justify">center</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="label" translatable="yes">Directory to search:</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="label" translatable="yes">Direcotry for output:</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="label" translatable="yes">Sort by:</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="label" translatable="yes">Printed Report? (y/n):</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="label" translatable="yes">Verbose? (y/n):</property>
<property name="justify">right</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="inputdir">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="text" translatable="yes">/usr/bin</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="outputdir">
<property name="name">outputdir</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="text">/home/baz/misc/docs</property>
<signal name="destroy" handler="onDestroy" swapped="no"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="inputdi">
<property name="name">inputdir</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="layout-style">start</property>
<signal name="destroy" handler="onDestroy" swapped="no"/>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=1 -->
<object class="GtkGrid" id="radiobutton">
<property name="name">radiobutton</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<child>
<object class="GtkRadioButton" id="NameButton">
<property name="label" translatable="yes">Name </property>
<property name="name">NameButton</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="active">True</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="SizeButton">
<property name="label" translatable="yes">Size </property>
<property name="name">SizeButton</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
<property name="group">NameButton</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="TypeButton">
<property name="label" translatable="yes">Type </property>
<property name="name">TypeButton</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
<property name="group">NameButton</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkRadioButton" id="ReportY">
<property name="label" translatable="yes">Y </property>
<property name="name">ReportY</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="active">True</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="ReportN">
<property name="label" translatable="yes">N </property>
<property name="name">ReportN</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="active">True</property>
<property name="draw-indicator">True</property>
<property name="group">ReportY</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkRadioButton" id="VerboseY">
<property name="label" translatable="yes">Y </property>
<property name="name">VerboseY</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="active">True</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="VerboseN">
<property name="label" translatable="yes"></property>
<property name="name">VerboseN</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="active">True</property>
<property name="draw-indicator">True</property>
<property name="group">VerboseY</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="SaveButton">
<property name="label" translatable="yes">Save</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="QuitButton">
<property name="label" translatable="yes">Quit WIthout Saving</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="onQuitButtonClicked" swapped="no"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">6</property>
</packing>
</child>
<child>
<object class="GtkButton" id="SubmitButtton">
<property name="label" translatable="yes">Submit</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="onSubmitButtonClicked" swapped="no"/>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">6</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
I am a bit rusty with Python, but when I tried out your code and glade file, I got a different behavior. Whenever I clicked on buttons or tried to close down the application, new windows kept spawning. I had to manually kill the application. The small revision I did to get things to work was to simplify the main block by removing the "while True:" test.
def main():
try:
app = GUI()
Gtk.main()
except Exception as e:
print ("Error!!")
print (e.inst)
Gtk.main_quit()
After that, the "Submit" button produced output and the "Quit Without Saving" button worked. I noticed in your glade file that you had no signal set up yet for the "Save" button.
Hope that helps.
Regards.
Related
Note: I unfortunately use Google translate for translation. Please ignore my mistakes.
Hello there. I'm trying to develop an application with PyGTK. I am using Glade as UI designer. But unfortunately when I try to start my application I get an error like this.
[alperen#fedora merhaba-dunya]$ python main.py
Traceback (most recent call last):
File "/home/alperen/Projeler/merhaba-dunya/main.py", line 19, in do_activate
self.window = MainWindow(self) # MainWindow nesnemizi oluşturduk.
File "/home/alperen/Projeler/merhaba-dunya/MainWindow.py", line 19, in __init__
self.builder.add_from_file("Example.ui")
gi.repository.GLib.Error: gtk-builder-error-quark: Example.ui:7:1 Invalid object type 'HdyWindow' (6)
Example.ui file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<requires lib="libhandy" version="0.0"/>
<object class="HdyWindow">
<property name="can-focus">False</property>
<child>
<object class="HdyWindowHandle">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">15</property>
<property name="margin-right">15</property>
<property name="margin-start">15</property>
<property name="margin-end">15</property>
<property name="margin-top">15</property>
<property name="margin-bottom">15</property>
<property name="orientation">vertical</property>
<property name="spacing">13</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Selamlar!</property>
<property name="ellipsize">middle</property>
<attributes>
<attribute name="scale" value="2"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="tikla">
<property name="label" translatable="yes">Bana tıkla!</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<signal name="clicked" handler="on_tikla_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="kapat">
<property name="label" translatable="yes">Uygulamayı kapat</property>
<property name="width-request">71</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<signal name="clicked" handler="on_kapat_clicked" swapped="no"/>
<style>
<class name="destructive-action"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Bu bir örnek yazı
Bu alt
alta yazılmış bir yazı
Burası yazılarla dolu!</property>
<property name="justify">fill</property>
<property name="xalign">0.05999999865889549</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
<object class="GtkAboutDialog" id="hakkinda">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Hakkında</property>
<property name="type-hint">dialog</property>
<property name="program-name">Örnek uygulama</property>
<property name="version">0.1</property>
<property name="comments" translatable="yes">GTK+ ile yazılmış merhaba dünya tarzı bir uygulama</property>
<property name="website">github.com/Afacanc38/merhaba-dunya</property>
<property name="website-label" translatable="yes">Kaynak Kodu</property>
<property name="authors">Alperen İsa Nalbant</property>
<property name="logo-icon-name">help-about</property>
<property name="license-type">gpl-3-0</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
<object class="GtkMessageDialog" id="merhaba">
<property name="can-focus">False</property>
<property name="icon-name">face-smile</property>
<property name="type-hint">dialog</property>
<property name="buttons">close</property>
<property name="text" translatable="yes">Merhaba
Dünya</property>
<property name="secondary-text" translatable="yes">hemele hümele</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="homogeneous">True</property>
<property name="layout-style">expand</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
main.py file:
#!/usr/bin/env python3
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib, Gio
from MainWindow import MainWindow
class Uygulama(Gtk.Application):
def __init__(self, *args, **kwargs):
super().__init__(*args,
application_id="org.yapboz.example",
flags=Gio.ApplicationFlags.FLAGS_NONE,
**kwargs)
def do_activate(self):
self.window = MainWindow(self)
app = Uygulama()
app.run(sys.argv)
MainWindow.py file:
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Handy', '1')
from gi.repository import Gtk, GLib, Gio, Gdk
from gi.repository import Handy
# CSS dosyamızı ekleyelim.
screen = Gdk.Screen.get_default()
provider = Gtk.CssProvider()
provider.load_from_path("style.css")
Gtk.StyleContext.add_provider_for_screen(screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
class MainWindow:
def __init__(self, app):
self.builder = Gtk.Builder()
self.builder.add_from_file("Example.ui")
self.builder.connect_signals(self)
self.window = self.builder.get_object("window")
self.dialog_about = self.builder.get_object("hakkinda")
self.merhaba = self.builder.get_object("merhaba")
self.window.set_application(app)
self.window.set_icon_from_file('images/logo.png')
self.window.show_all()
def on_tikla_clicked(self, button):
self.merhaba.run()
self.merhaba.hide()
def on_kapat_clicked(self, button):
self.window.get_application().quit()
def on_about_clicked(self, button):
self.dialog_about.run()
self.dialog_about.hide()
Libhandy needs to be initialized before it can be recognized in UI files. Try adding Handy.init() in your main file.
I'm struggling with a GtkAssistant sidebar that is appearing automatically when I define a page title.
GtkAssistant does not accept Window Title. You need to define a Page Title but it enables that side bar.
I just want the Page Title. An example:
Considering this example, I would like to keep "Error Details" title but hide side bar. It is not useful for me. And there is no Gtk Doc mentions to remove that. Not sure if I can.
A glade example:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.2"/>
<object class="GtkAssistant" id="assistant">
<property name="can_focus">False</property>
<property name="use_header_bar">0</property>
<signal name="cancel" handler="on_destroy" swapped="no"/>
<signal name="close" handler="on_destroy" swapped="no"/>
<signal name="delete-event" handler="on_destroy" swapped="no"/>
<child>
<object class="GtkBox" id="page1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">7</property>
<property name="margin_right">7</property>
<property name="margin_top">7</property>
<property name="margin_bottom">7</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Name:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Surname:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="page_type">intro</property>
<property name="title" translatable="yes">User Info</property>
<property name="has_padding">False</property>
</packing>
</child>
<child>
<object class="GtkBox" id="page2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">7</property>
<property name="margin_right">7</property>
<property name="margin_top">7</property>
<property name="margin_bottom">7</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Address:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Telephone:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="title" translatable="yes">Extra Info</property>
<property name="has_padding">False</property>
</packing>
</child>
<child>
<object class="GtkBox" id="page3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Thanks for registering!</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.5"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="page_type">summary</property>
<property name="title" translatable="yes">Success</property>
<property name="has_padding">False</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</interface>
And the result is:
I would like to remove this weird side bar.
Question: How to disable GtkAssistant side bar with Page Title defined?
Using your glade.xml, i get the following error:
(Assistant.py:4515): Gtk-CRITICAL **: gtk_assistant_set_page_has_padding: assertion 'child != NULL' failed
and the Next Button keep stay insensitive.
Solved: Using assistant.set_page_complete(box, True) enables the Next Button.
However, using the following API Reference I get this result:
PyGObject API Reference:
Gtk.Assistant.signals.prepare
Gtk.Assistant.set_page_complete
Gtk.HeaderBar
Drawback:
The OS see the Gtk.Assistant. window title as undefined!
Using GtkAssistant.set_title(... has no result!
First add the signal "prepare" using Glade in GtkAssistant.
<signal name="prepare" handler="on_assistant_prepare" swapped="no"/>
Usage:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class GtkAssistant:
def __init__(self):
self.builder = Gtk.Builder()
self.builder.add_from_file(__file__.replace('.py', '.glade'))
self.builder.connect_signals(self)
assistant = self.builder.get_object("assistant")
# Preserve the page titels from glade
# Set page titles to empty '' to force not to show sidebar
for _id in ["page1", "page2", "page3"]:
box = self.builder.get_object(_id)
box.page_title = assistant.get_page_title(box)
assistant.set_page_title(box, '')
# Gtk.Assistant refuses to do .set_title even defined in glade
# <property name="title" translatable="yes">Registration-Assistant</property>
assistant.set_title('Registration-Assistant')
# Replace assistant.set_page_title(... with own function
assistant.set_page_title = self.set_page_title
# Replace the window decoration with a custom HeaderBar
self.title = Gtk.Label()
headerbar = Gtk.HeaderBar()
headerbar.set_show_close_button(True)
headerbar.set_custom_title(self.title)
assistant.set_titlebar(headerbar)
assistant.show_all()
def set_page_title(self, box, title):
self.title.set_text(title)
def on_assistant_prepare(self, assistant, box, user_data=None):
assistant.set_page_title(box, box.page_title)
# This will make update the buttons state
# to be able to continue the task.
assistant.set_page_complete(box, True)
def on_destroy(self, widget, data=None):
Gtk.main_quit()
if __name__ == '__main__':
assist = GtkAssistant()
Gtk.main()
Tested with Python: 3.5 - gi.__version__: 3.22.0 - Glade 3.20.0
I want to implement a Gtk.Menu that have horizontal menu items or buttons in it as in Google Chrome's menu how can I achieve this in GTK3?
This may not be exactly what you asked for, but it would be one way to do it.
Save this in a file and open it in glade to view the construction of the GUI.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkPopover" id="popover1">
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Zoom</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Print</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">More</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Cut</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Copy</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Paste</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkWindow">
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkMenuButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="popover">popover1</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</interface>
I recently made a code in python3.x and for the interface I used a .glade file but when I run the code the interpreter returns to me the error "AttributeError: Handler Gtk_main_quit not found" and so on for all other functions of the code.
Python code:
`import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class InverterApp():
def __init__(self):
builder = Gtk.Builder()
builder.add_from_file("Inverter.glade")
#Obter a janela principal
self.window = builder.get_object("window1")
# Obtendo o widget text_entry (a área de texto do nosso programa) pois
# iremos utiliza-la nas funções de inversão da URL e para adicionar o a
# URL já invertida
self.text_area = builder.get_object("text_entry")
# Obtendo o widget about_dialog (janelinha com as informações do programa)
self.about = builder.get_object("about_dialog")
#Exibe a janela do programa
self.window.show_all()
builder.connect_signals({"gtk_main_quit": Gtk.main_quit,
"on_button_invert_clicked": self.invert_url,
"on_text_entry_activate": self.invert_url,
"on_copy_activate": self.copy_text,
"on_paste_activate": self.paste_text,
"on_delete_activate": self.delete_text,
"on_about_activate": self.about_window,
})
def invert_url(self, widget):
url = self.text_area.get_text()
url = url[::-1]
self.text_area.set_text(url)
def copy_text(self, widget):
clipboard = Gtk.clipboard_get()
url = self.text_area.get_text()
clipboard.set_text(url)
clipboard.store()
def paste_text(self, widget):
clipboard = Gtk.clipboard_get()
url = clipboard.wait_for_text()
self.text_area.set_text(url)
def delete_text(self, widget):
self.text_area.set_text("")
def about_window(self, widget):
self.about.run()
self.about.hide()
if __name__ == "__main__":
app = InverterApp()
Gtk.main()`
Glade code:
`<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkAboutDialog" id="about_dialog">
<property name="width_request">320</property>
<property name="height_request">260</property>
<property name="can_focus">False</property>
<property name="type">popup</property>
<property name="resizable">False</property>
<property name="window_position">center</property>
<property name="type_hint">normal</property>
<property name="program_name">Inverter</property>
<property name="version">1.0</property>
<property name="comments" translatable="yes">Simples Inversor
Versão 1.0</property>
<property name="website">www.teste.com.br</property>
<property name="website_label" translatable="yes">Licença-web</property>
<property name="license" translatable="yes">Huehuehue</property>
<property name="authors">Guilherme</property>
<property name="logo">heart.png</property>
<property name="wrap_license">True</property>
<child internal-child="vbox">
<object class="GtkBox" id="aboutdialog-vbox1">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="aboutdialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkWindow" id="window1">
<property name="width_request">650</property>
<property name="height_request">110</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Teste</property>
<property name="resizable">False</property>
<property name="window_position">center</property>
<property name="icon">heart.png</property>
<signal name="destroy" handler="Gtk_main_quit" swapped="no"/>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar" id="menubar1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="Editar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Editar</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="Copy">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_Copy_activate" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="Paste">
<property name="label">gtk-paste</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_Paste_activate" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="Delete">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_Delete_activate" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="Ajuda">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Aj_uda</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="About">
<property name="label">gtk-about</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_About_activate" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="text_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="text" translatable="yes">Digite a URL aqui...</property>
<signal name="activate" handler="on_text_entry_activate" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">17</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="buttonbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="layout_style">start</property>
<child>
<object class="GtkButton" id="Button_invert">
<property name="label" translatable="yes">Inverter</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="relief">none</property>
<signal name="clicked" handler="on_Button_invert_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>`
This answer is pretty easy. You have a signal called Gtk_main_quit in the Glade file but are looking for a signal of gtk_main_quit in your .py file. And it seems most of the other strings are mismatched too. Always watch your cases when dealing with strings.
i want to handle the menu click event but,
this missing handler warning is occuring,
where i am wrong?
im connecting the signal ab with handler abcd
on menuitem6, on activate event,
is it correct for handling a click event?
here is the error:
abc.py:15: RuntimeWarning: missing handler 'a
bc'
builder.connect_signals({ "on_window_destroy" : gtk.main_quit })
None
here's the code :
abc.py:
import pygtk
pygtk.require("2.0")
import gtk
def inIta(col, cell, model, iter, mymodel):
s = model.get_string_from_iter(iter)
niter = mymodel.get_iter_from_string(s)
obj = mymodel.get_value(niter, 0)
cell.set_property('text', obj)
class TutorialApp(object):
def __init__(self):
builder = gtk.Builder()
builder.add_from_file("./tutorial.xml")
builder.connect_signals({ "on_window_destroy" : gtk.main_quit })
print builder.connect_signals({ "abc" : self.abcd })
self.window = builder.get_object("window")
self.widgets = {}
self.widgets['disasm'] = builder.get_object('disasm')
self.widgets['disasmw'] = builder.get_object('disassemblerWindow')
self.widgets['regw'] = builder.get_object('regWin')
self.widgets['stackw'] = builder.get_object('stackWin')
self.widgets['dumpw'] = builder.get_object('dumpWin')
self.widgets['stack'] = builder.get_object('stack')
self.widgets['dump'] = builder.get_object('dump')
self.widgets['registers'] = builder.get_object('registers')
""" add columns to disasm listview"""
rendererText = gtk.CellRendererText()
column = gtk.TreeViewColumn("Address", rendererText, text=0)
self.widgets['disasmw'].append_column(column)
rendererText = gtk.CellRendererText()
column = gtk.TreeViewColumn("Opcode", rendererText, text=1)
self.widgets['disasmw'].append_column(column)
rendererText = gtk.CellRendererText()
column = gtk.TreeViewColumn("Mneumonic", rendererText, text=2)
self.widgets['disasmw'].append_column(column)
rendererText = gtk.CellRendererText()
column = gtk.TreeViewColumn("Registers", rendererText, text=0)
self.widgets['regw'].append_column(column)
rendererText = gtk.CellRendererText()
column = gtk.TreeViewColumn("Stack", rendererText, text=0)
self.widgets['stackw'].append_column(column)
rendererText = gtk.CellRendererText()
column = gtk.TreeViewColumn("Dump", rendererText, text=0)
self.widgets['dumpw'].append_column(column)
self.widgets['disasm'].append(["alokkkkkkkkkkk","alokkkkkkkkkk","alokkkkkkkkkk"])
self.widgets['disasm'].append(["alokkkkkkkkkkk","alokkkkkkkkkk","alokkkkkkkkkk"])
self.widgets['disasm'].append(["alokkkkkkkkkkk","alokkkkkkkkkk","alokkkkkkkkkk"])
self.window.show()
def abcd(menuitem):
print "tst"
if __name__ == "__main__":
app = TutorialApp()
gtk.main()
and here is the xml:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkListStore" id="disasm">
<columns>
<!-- column-name gchararray1 -->
<column type="gchararray"/>
<!-- column-name gchararray2 -->
<column type="gchararray"/>
<!-- column-name gchararray3 -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkListStore" id="dump"/>
<object class="GtkListStore" id="registers"/>
<object class="GtkListStore" id="stack"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">untitled</property>
<property name="window_position">center</property>
<property name="default_width">440</property>
<property name="default_height">250</property>
<property name="icon">ico.ico</property>
<signal name="destroy" handler="on_window_destroy" swapped="no"/>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuBar" id="menubar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="menuitem1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_File</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem1">
<property name="label">gtk-new</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem2">
<property name="label">gtk-open</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem3">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem4">
<property name="label">gtk-save-as</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem5">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Edit</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem6">
<property name="label">gtk-cut</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem7">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem8">
<property name="label">gtk-paste</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem9">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_View</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Options</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="menuitem6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Settings</property>
<property name="use_underline">True</property>
<signal name="activate" handler="abc" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Help</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem10">
<property name="label">gtk-about</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTreeView" id="disassemblerWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">disasm</property>
<property name="enable_grid_lines">both</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTreeView" id="regWin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">registers</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTreeView" id="dumpWin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">dump</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTreeView" id="stackWin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">stack</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkStatusbar" id="statusbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
You can use builder.connect_signals(self). Then you just have to make methods that are named like the handler in your xml file. So in this case:
class TutorialApp(object):
def __init__(self):
builder = gtk.Builder()
builder.add_from_file('./tutorial.xml')
builder.connect_signals(self)
self.window = builder.get_object('disasm')
##rest of you __init__
def abc(self, menuitem):
print "tst"
def on_window_destroy(self, window):
gtk.main_quit()