Question

When Canonical-Quickly sets up a new project it has the following line for the "About dialog":

    self.AboutDialog = AboutNewAppDialog

I edited the menu item in glade and added the following code to the python code for the main window:

    self.menuabout = self.builder.get_object("menuabout")

and

   def on_menuabout_activate(self, menuitem, data=None):
        print("About activated")
        self.response = self.AboutDialog.run()
        self.AboutDialog.hide()

But this produces the error:

   self.response = self.AboutDialog.run()
   TypeError: run() takes exactly 1 argument (0 given)

I am also working through this tutorial which is using a similar syntax: http://gnipsel.com/glade/glade02b.html

When I place Gtk.Dialog into the brackets the program crashes:

   self.response = self.AboutDialog.run(Gtk.Dialog)

My second try:

  #!/usr/bin/env python
  from gi.repository import Gtk
  class Handler:
        def on_mainwindow_destroy(self, menuitem):
              print("destroy window")
              Gtk.main_quit()

        def on_menuquit_activate(self, menuitem):
              print("quit from menu")
              Gtk.main_quit()

        def on_menuabout_activate(self, menuitem, data=None):
              print("menu about activated")
              response = aboutdialog.run()
              aboutdialog.hide()

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

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

  Gtk.main()

Error:

"Traceback (most recent call last): File "psn_main.py", line 21, in on_menuabout_activate response = aboutdialog.run() NameError: name 'aboutdialog' is not defined"

Was it helpful?

Solution

I got it to work using the following code. The function is activated by a menu item which calls "on_menuabout_activate". It prints a debug message to the console. Then it gets the aboutdialog-window from the glade file and runs it:

  def on_menuabout_activate(self, menuitem, data=None):
        print("menu about activated")
        aboutdialog = builder.get_object("aboutdialog")
        aboutdialog.run()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top