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:
Drawback:
The OS see theGtk.Assistant.
window title asundefined
!
UsingGtkAssistant.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