|
Packit |
1470ea |
from gi.repository import Gtk
|
|
Packit |
1470ea |
from gi.repository import Gio
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# constructor for a window (the parent window)
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="AboutDialog Example", application=app)
|
|
Packit |
1470ea |
self.set_default_size(200, 200)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# create the about_action (a Gio.SimpleAction)
|
|
Packit |
1470ea |
about_action = Gio.SimpleAction.new("about", None)
|
|
Packit |
1470ea |
# connect the signal from the action to the function about_cb()
|
|
Packit |
1470ea |
about_action.connect("activate", self.about_cb)
|
|
Packit |
1470ea |
# add the action to the application
|
|
Packit |
1470ea |
app.add_action(about_action)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback function for the about_action's "activate" signal
|
|
Packit |
1470ea |
def about_cb(self, action, parameter):
|
|
Packit |
1470ea |
# a Gtk.AboutDialog
|
|
Packit |
1470ea |
aboutdialog = Gtk.AboutDialog()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# lists of authors and documenters (will be used later)
|
|
Packit |
1470ea |
authors = ["GNOME Documentation Team"]
|
|
Packit |
1470ea |
documenters = ["GNOME Documentation Team"]
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# we fill in the aboutdialog
|
|
Packit |
1470ea |
aboutdialog.set_program_name("AboutDialog Example")
|
|
Packit |
1470ea |
aboutdialog.set_copyright(
|
|
Packit |
1470ea |
"Copyright \xc2\xa9 2012 GNOME Documentation Team")
|
|
Packit |
1470ea |
aboutdialog.set_authors(authors)
|
|
Packit |
1470ea |
aboutdialog.set_documenters(documenters)
|
|
Packit |
1470ea |
aboutdialog.set_website("http://developer.gnome.org")
|
|
Packit |
1470ea |
aboutdialog.set_website_label("GNOME Developer Website")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# we do not want to show the title, which by default would be "About AboutDialog Example"
|
|
Packit |
1470ea |
# we have to reset the title of the messagedialog window after setting
|
|
Packit |
1470ea |
# the program name
|
|
Packit |
1470ea |
aboutdialog.set_title("")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# to close the aboutdialog when "close" is clicked we connect the
|
|
Packit |
1470ea |
# "response" signal to on_close
|
|
Packit |
1470ea |
aboutdialog.connect("response", self.on_close)
|
|
Packit |
1470ea |
# show the aboutdialog
|
|
Packit |
1470ea |
aboutdialog.show()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# destroy the aboutdialog
|
|
Packit |
1470ea |
def on_close(self, action, parameter):
|
|
Packit |
1470ea |
action.destroy()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication(Gtk.Application):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self):
|
|
Packit |
1470ea |
Gtk.Application.__init__(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_activate(self):
|
|
Packit |
1470ea |
win = MyWindow(self)
|
|
Packit |
1470ea |
win.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def quit_cb(self, action, parameter):
|
|
Packit |
1470ea |
self.quit()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# create a menu (a Gio.Menu)
|
|
Packit |
1470ea |
menu = Gio.Menu()
|
|
Packit |
1470ea |
# append a menu item with label "About" and action "app.about"
|
|
Packit |
1470ea |
menu.append("About", "app.about")
|
|
Packit |
1470ea |
# append a menu item with label "Quit" and action "app.quit"
|
|
Packit |
1470ea |
menu.append("Quit", "app.quit")
|
|
Packit |
1470ea |
# set menu as the menu for the application
|
|
Packit |
1470ea |
self.set_app_menu(menu)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a new simpleaction - for the application
|
|
Packit |
1470ea |
quit_action = Gio.SimpleAction.new("quit", None)
|
|
Packit |
1470ea |
quit_action.connect("activate", self.quit_cb)
|
|
Packit |
1470ea |
self.add_action(quit_action)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = MyApplication()
|
|
Packit |
1470ea |
exit_status = app.run(sys.argv)
|
|
Packit |
1470ea |
sys.exit(exit_status)
|