Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
11-19-2017, 01:24 AM
#1
Member
Registered: Sep 2003
Location: Fort worth, TX
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196
Rep:
Python3 / GTK3 / AboutDialog Issue
Using Glade 3.18.3 to build a gui for some python3 code but having a problem with the aboutdialog. The issue is that if someone clicks the 'x' to close the dialog (rather than the button which works) and then later on opens the dialog again via the main window ... the aboutdialog opens but is empty and lots of errors on terminal.
I've mapped the 'response' signal, the 'destroy' signal and the 'delete-event' signal to about.hide()
Clicking the close button sends a response signal which goes to about.hide(). I can open the aboutdialog again and close it without issues.
Clicking the 'x' sends a 'delete-event' signal that I have connected to about.hide() ... the aboutdialog will close but when opened again the aboutdialog is blank and lots of error messages on terminal.
Anyone know what I need to do to make clicking the 'x' behave the same as clicking the 'Close' button on the aboutdialog?
11-19-2017, 04:28 PM
#2
Member
Registered: Sep 2003
Location: Fort worth, TX
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196
Original Poster
Rep:
Instructions to reproduce aboutdialog problem
Here's a example of the issue with the aboutdialog problem as a result of clicking the 'x'. Note that clicking the "Close" button works in the aboutdialog. Why not clicking the 'x'?
Save this as sample.py
Code:
#!/usr/bin/env python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# window1 defs:
def on_window1_delete_event(window, data):
print("on_window1_delete_event")
Gtk.main_quit()
def on_button_close_clicked(data):
print("on_button_close_clicked")
Gtk.main_quit()
# menu items:
def on_activate_new(menu):
print("on_activate_new")
def on_activate_save(menu):
print("on_activate_save")
def on_activate_saveas(menu):
print("on_activate_saveas")
def on_activate_quit(menu):
print("on_activate_quit")
Gtk.main_quit()
def on_activate_about(menu):
print("on_activate_about")
about.show()
def on_activate_update(menu):
print("on_activate_update")
# aboutdialog items:
def on_aboutdialog_response(about, data):
print("on_aboutdialog_response")
about.hide()
def on_aboutdialog_delete_event(about, data):
print("on_aboutdialog_delete_event")
about.hide()
# Pull in the GUI:
builder = Gtk.Builder()
builder.add_from_file("sample.glade")
window = builder.get_object("window1")
about = builder.get_object("aboutdialog")
# Connect signals:
handlers = {
"on_window1_delete_event": on_window1_delete_event,
"on_activate_new": on_activate_new,
"on_activate_save": on_activate_save,
"on_activate_saveas": on_activate_saveas,
"on_activate_quit": on_activate_quit,
"on_activate_about": on_activate_about,
"on_activate_update": on_activate_update,
"on_button_close_clicked": on_button_close_clicked,
"on_aboutdialog_response": on_aboutdialog_response,
"on_aboutdialog_delete_event": on_aboutdialog_delete_event
}
builder.connect_signals(handlers)
# Run the event loop:
window.show_all()
Gtk.main()
Save this as sample.glade:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-connect</property>
</object>
<object class="GtkWindow" id="window1">
<property name="width_request">400</property>
<property name="height_request">400</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_bottom">10</property>
<property name="title" translatable="yes">NCF Ticket Log</property>
<signal name="delete-event" handler="on_window1_delete_event" 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="topmenuitem-file">
<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="menu-file">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="menuitem-new">
<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>
<property name="always_show_image">True</property>
<signal name="activate" handler="on_activate_new" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menuitem-save">
<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>
<property name="always_show_image">True</property>
<signal name="activate" handler="on_activate_save" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menuitem-saveas">
<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>
<property name="always_show_image">True</property>
<signal name="activate" handler="on_activate_saveas" swapped="no"/>
</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="menuitem-quit">
<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>
<property name="always_show_image">True</property>
<signal name="activate" handler="on_activate_quit" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="topmenuitem-help">
<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="menu-help">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="menuitem-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>
<property name="always_show_image">True</property>
<signal name="activate" handler="on_activate_about" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menuitem-update">
<property name="label">Check for Update</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="image">image1</property>
<property name="use_stock">False</property>
<property name="always_show_image">True</property>
<signal name="activate" handler="on_activate_update" 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="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTextView" id="textview1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="pixels_above_lines">3</property>
<property name="pixels_below_lines">3</property>
<property name="left_margin">3</property>
<property name="right_margin">3</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">3</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">3</property>
<child>
<object class="GtkStatusbar" id="statusbar1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="margin_start">10</property>
<property name="margin_end">10</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_close">
<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>
<property name="always_show_image">True</property>
<signal name="clicked" handler="on_button_close_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">3</property>
<property name="position">2</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>
<object class="GtkAboutDialog" id="aboutdialog">
<property name="can_focus">True</property>
<property name="double_buffered">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="accept_focus">False</property>
<property name="focus_on_map">False</property>
<property name="deletable">False</property>
<property name="program_name">Ticket Log</property>
<property name="version">0.1</property>
<property name="copyright" translatable="yes">nws.noaa.gov</property>
<property name="comments" translatable="yes">Log for keeping up Trouble Tickets opened by the office.</property>
<property name="authors">sample@sample.org</property>
<property name="logo_icon_name">help-about</property>
<property name="license_type">gpl-3-0</property>
<signal name="delete-event" handler="on_aboutdialog_delete_event" swapped="no"/>
<signal name="response" handler="on_aboutdialog_response" swapped="no"/>
<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>
<child>
<placeholder/>
</child>
</object>
</child>
<accessibility>
<relation type="controlled-by" target="window1"/>
</accessibility>
</object>
</interface>
11-19-2017, 05:56 PM
#3
Member
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792
The glade file that you posted has the deletable property set to false for the about dialog.
After changing it to True, the following works on my box:
Code:
def on_aboutdialog_delete_event(about, data):
print("on_aboutdialog_delete_event")
about.hide()
return True
From the docs:
https://developer.gnome.org/gtkmm-tu...gation.html.en
Quote:
The event will propagate until it reaches the top-level widget, or until you stop the propagation by returning true from an event handler.
So you were hiding the dialog and then deleting it due to event propagation.
2 members found this post helpful.
11-19-2017, 07:00 PM
#4
Member
Registered: Sep 2003
Location: Fort worth, TX
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196
Original Poster
Rep:
Fixed
Thanks a lot! That fixed my issue! I need to read that link more to better understand how to handle the aboutdialog better.
All times are GMT -5. The time now is 08:16 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News