GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 30, 2014 11:25 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Opening About-dialog crashes on 2nd startup (GTK/Glade)
PostPosted: Wed Apr 02, 2014 10:42 pm 
Offline
Familiar Face

Joined: Mon Mar 31, 2014 9:59 pm
Posts: 16
I finally got the about dialog to open and close. When I open it a second time I get a lot of error messages. I am still having trouble finding a good structure for the program on which I can expand. The tutorials all look so different that I am very confused at the moment.

Here is my program:

Code:
#!/usr/bin/env python

from gi.repository import Gtk
from gi.repository import Gio
import sys

class glade_signals:
      #Main Window
      def on_mainwindow_destroy(self, widget):
            print("destroy window")
            Gtk.main_quit()
     
      #Menu items
      def on_menuquit_activate(self, menuitem):
            print("quit from menu")
            Gtk.main_quit()

      def on_menuabout_activate(self, menuitem):
            print("menu about activated")
            aboutdialog = builder.get_object("aboutdialog")
            aboutdialog.run()

      #About Dialog
      def on_aboutdialog_destroy(self, widget):
            print("destroy about")
            aboutdialog = builder.get_object("aboutdialog")
            aboutdialog.hide()

      def on_aboutdialog_action_area1_destroy(self, widget):
            print("destroy about action area 1")
            aboutdialog = builder.get_object("aboutdialog")
            aboutdialog.hide()

builder = Gtk.Builder()
builder.add_from_file("psn.glade")
builder.connect_signals(glade_signals())

window = builder.get_object("mainwindow")
window.show_all()

Gtk.main()


and here are my debug messages and the error that occurs after opening the winodw the second time:

Code:
menu about activated
destroy about
destroy about action area 1
menu about activated

(psn_main.py:24528): Gtk-CRITICAL **: gtk_widget_show: assertion 'GTK_IS_WIDGET (widget)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_widget_hide: assertion 'GTK_IS_WIDGET (widget)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_foreach: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(psn_main.py:24528): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

_________________
I am learning to develop GTK+ (GTK 3.10) programs written in Python 3.4.0, designed with Glade 3.16.1, with plots using Matplotlib 1.4. I program and test using Ubuntu 14.04 (64bit) and Gedit. (http://gtk3-matplotlib-cookbook.readthedocs.org)


Last edited by spiessbuerger on Sun Apr 06, 2014 9:27 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Opening About-dialog crashes the program the second time
PostPosted: Thu Apr 03, 2014 10:29 pm 
Offline
Familiar Face

Joined: Sat Mar 22, 2014 1:47 pm
Posts: 5
Im not sure I do not use python but, in your psn.glade you have "many" widgets and/or signals which are not "declared" in your python file and gtk complains about that.


Top
 Profile  
 
 Post subject: Re: Opening About-dialog crashes the program the second time
PostPosted: Fri Apr 04, 2014 6:35 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 767
Location: UK
Hello,

Vido is incorrect. It is not a python or that there are many widgets and signals defined in the Glade file.

It is a memory management problem.

This is what is happening :-
- GtkBuilder creates the widgets and keeps references to the widgets
- The signals are connected via GtkBuilder
- The "about dialog" is shown and run
- The "about dialog" is destroyed - Note that GtkBuilder keeps references to the widgets still. They are just now not pointing to a valid widget.

- Second time around the reference to the about dialog is obtained from GtkBuilder and attempted to be show. Since GtkBuilder does not hold valid references any more each usage of a widget will fail.

I am definitely no Python guru but I hope that this helps. What I have done is create another class for the "about dialog" where the Glade file is re-read to re-create the widget every time. Here I use GtkBuilder to create the "about dialog" only by forcing GtkBuilder to read only part of the Glade file. I have done similar to the mainwindow just to keep memory usage down.
Code:
#!/usr/bin/env python

from gi.repository import Gtk
from gi.repository import Gio
import sys

class About:
    def __init__(self):
        self.builder = Gtk.Builder()
        self.builder.add_objects_from_file("psn.glade", ("aboutdialog"))
        self.ab = self.builder.get_object("aboutdialog")
        self.builder.connect_signals(self)
    def on_aboutdialog_destroy(self, widget):
        self.ab.hide()
    def on_aboutdialog_action_area1_destroy(self, widget):
        self.ab.hide()
    def run(self)
        self.ab.run()

class glade_signals:
      #Main Window
      def on_mainwindow_destroy(self, widget):
            print("destroy window")
            Gtk.main_quit()
     
      #Menu items
      def on_menuquit_activate(self, menuitem):
            print("quit from menu")
            Gtk.main_quit()

      def on_menuabout_activate(self, menuitem):
            print("menu about activated")
            about = About();
            about.run()

builder = Gtk.Builder()
builder.add_objects_from_file("psn.glade", ("mainwindow"))
builder.connect_signals(glade_signals())

window = builder.get_object("mainwindow")
window.show_all()

Gtk.main()

_________________
E.


Top
 Profile  
 
 Post subject: Re: Opening About-dialog crashes the program the second time
PostPosted: Fri Apr 04, 2014 10:06 pm 
Offline
Familiar Face

Joined: Mon Mar 31, 2014 9:59 pm
Posts: 16
Thanks errol! The code is of great help to me and I finally have understood what structure the file should have. I got some mistakes but finally arrived at this. It still doesn't work completley (see below), but the about dialog now opens and closes (although not without protest):

Code:
#!/usr/bin/env python

from gi.repository import Gtk
from gi.repository import Gio
import sys

class About:
    def __init__(self):
        print("\nclass about called\n")
        self.builder = Gtk.Builder()
        #self.builder.add_objects_from_file("psn.glade", ("aboutdialog"))
        self.builder.add_from_file("psn.glade")
        self.ab = self.builder.get_object("aboutdialog")
        self.builder.connect_signals(self)

    #About dialog handlers
    def on_aboutdialog_destroy(self, widget):
        print("about-dialog destroyed")
        self.ab.hide()
    def on_aboutdialog_close(self, dialog):
        print("about destroyed with close button")
        self.ab.hide()
    def run(self):
        print("run about dialog")
        self.ab.run()

class Mainsignals:
      print("\nclass mainsignals called\n")
      #Main Window
      def on_mainwindow_destroy(self, widget):
            print("destroy window")
            Gtk.main_quit()
     
      #Menu items
      def on_menuquit_activate(self, menuitem):
            print("quit from menu")
            Gtk.main_quit()

      def on_menuabout_activate(self, menuitem):
            print("menu about activated")
            about = About()
            about.run()

builder = Gtk.Builder()
builder.add_from_file("psn.glade")
builder.connect_signals(Mainsignals())

window = builder.get_object("mainwindow")
#builder.add_objects_from_file("psn.glade", ("mainwindow"))
window = builder.get_object("mainwindow")
window.show_all()

Gtk.main()


I tried the usual searching for the error but I couldn't come up with a solution. The pattern is interesting. When the main window opens, the about-dialog handlers are not found. When the about-dialog window is called, the main-window handlers are not found. Really weird :/

Quote:
class mainsignals called

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 403, in _full_callback
handler, args = self._extract_handler_and_args(obj_or_map, handler_name)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 376, in _extract_handler_and_args
raise AttributeError('Handler %s not found' % handler_name)
AttributeError: Handler on_aboutdialog_close not found
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 403, in _full_callback
handler, args = self._extract_handler_and_args(obj_or_map, handler_name)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 376, in _extract_handler_and_args
raise AttributeError('Handler %s not found' % handler_name)
AttributeError: Handler on_aboutdialog_destroy not found
menu about activated

class about called

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 403, in _full_callback
handler, args = self._extract_handler_and_args(obj_or_map, handler_name)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 376, in _extract_handler_and_args
raise AttributeError('Handler %s not found' % handler_name)
AttributeError: Handler on_mainwindow_destroy not found
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 403, in _full_callback
handler, args = self._extract_handler_and_args(obj_or_map, handler_name)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 376, in _extract_handler_and_args
raise AttributeError('Handler %s not found' % handler_name)
AttributeError: Handler on_menuabout_activate not found
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 403, in _full_callback
handler, args = self._extract_handler_and_args(obj_or_map, handler_name)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 376, in _extract_handler_and_args
raise AttributeError('Handler %s not found' % handler_name)
AttributeError: Handler on_menuquit_activate not found
run about dialog
about-dialog destroyed
destroy window


_________________
I am learning to develop GTK+ (GTK 3.10) programs written in Python 3.4.0, designed with Glade 3.16.1, with plots using Matplotlib 1.4. I program and test using Ubuntu 14.04 (64bit) and Gedit. (http://gtk3-matplotlib-cookbook.readthedocs.org)


Top
 Profile  
 
 Post subject: Re: Opening About-dialog crashes on 2nd startup (GTK/Glade)
PostPosted: Sun Apr 06, 2014 9:28 am 
Offline
Familiar Face

Joined: Mon Mar 31, 2014 9:59 pm
Posts: 16
I'm beginning to think that this is a bug or some kind of version conflict. I tried around for a whole day with no success.

_________________
I am learning to develop GTK+ (GTK 3.10) programs written in Python 3.4.0, designed with Glade 3.16.1, with plots using Matplotlib 1.4. I program and test using Ubuntu 14.04 (64bit) and Gedit. (http://gtk3-matplotlib-cookbook.readthedocs.org)


Top
 Profile  
 
 Post subject: Re: Opening About-dialog crashes on 2nd startup (GTK/Glade)
PostPosted: Mon Apr 07, 2014 7:24 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 767
Location: UK
This is unlikely to be a bug or version conflict.

It looks more like you are defining signals in the Glade file and not having any handlers in the Python source.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Opening About-dialog crashes on 2nd startup (GTK/Glade)
PostPosted: Sun May 11, 2014 8:48 pm 
Offline
Familiar Face

Joined: Tue Oct 08, 2013 5:16 am
Posts: 20
I think you can only call connect_signals once, so you might need to use a single dictionary to connect ALL of the signals in one place. Kind of like this;

Code:
        menu = {
            "on_window_delete_event": self.on_window_destroy,
            # The File menu
            "on_new_activate": self.on_new_activate,
            "on_open_activate": self.on_open_activate,
            "on_save_activate": self.on_save_activate,
            "on_saveas_activate": self.on_saveas_activate,
            "on_quit_activate": self.on_quit_activate,
            # The Edit menu
            "on_cut_activate": self.on_cut_activate,
            "on_copy_activate": self.on_copy_activate,
            "on_paste_activate": self.on_paste_activate,
            "on_delete_activate": self.on_delete_activate,
        }
        self.builder.connect_signals(menu)


If you're looking for structure, you might check out MVC. Here are a couple of simple examples to get you started, hope this answers your question.

http://wiki.wxpython.org/ModelViewController
http://www.blog.pythonlibrary.org/2011/ ... -and-crud/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group