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
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 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()
As a newbee I am trying to create a basic theme installer using Glade and python. Everything is working fine but i am not able to find anywhere how to use get_filename() method for gtkFileChooserButton.
My Glade File Looks Like this.
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="main">
<property name="title" translatable="yes">Maininin</property>
<property name="window_position">center</property>
<signal name="destroy" handler="on_main_destroy"/>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<object class="GtkLabel" id="INFO">
<property name="visible">True</property>
<property name="label" translatable="yes">Theme</property>
</object>
<packing>
<property name="expand">False</property>
<property name="padding">28</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<property name="layout_style">spread</property>
<child>
<object class="GtkFileChooserButton" id="DD">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox2">
<property name="visible">True</property>
<property name="layout_style">spread</property>
<child>
<object class="GtkButton" id="Add">
<property name="label">gtk-add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_Add_clicked"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="Quit">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_Quit_clicked"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="WARN">
<property name="visible">True</property>
<property name="label" translatable="yes">Warning</property>
</object>
<packing>
<property name="expand">False</property>
<property name="padding">37</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
`
And Python Code is:
import sys
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
except:
print("GTK Not Availible")
sys.exit(1)
class workplz(object):
def __init__( self ):
builder = gtk.Builder()
builder.add_from_file("heme.glade")
builder.connect_signals({"on_main_destroy" : self.quit, "on_Add_clicked" : self.add, "on_Quit_clicked" : self.quit})
self._window = builder.get_object("main")
self._window.show()
def add(self, widget):
target=DD.get_filename()
print target
def quit(self, widget):
sys.exit(0)
if __name__ == "__main__":
wine = workplz()
gtk.main()
what is the right way of doing it???
I believe if you would get your GtkFileChooserButton object from the builder and save a reference to it as a member of workplz class you could query it in the add signal handler. See if script below would work for you:
class workplz(object):
def __init__( self ):
builder = gtk.Builder()
builder.add_from_file("heme.glade")
builder.connect_signals({"on_main_destroy" : self.quit, "on_Add_clicked" : self.add, "on_Quit_clicked" : self.quit})
# get GtkFileChooserButton object
self.DD = builder.get_object('DD')
self._window = builder.get_object("main")
self._window.show()
def add(self, widget):
target = self.DD.get_filename()
print target
def quit(self, widget):
sys.exit(0)
hope this helps, regards