/usr/share/doc/python-gtk2-tutorial/html/examples/basicaction.py is in python-gtk2-tutorial 2.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
class BasicAction:
def __init__(self):
# Create the toplevel window
window = gtk.Window()
window.connect('destroy', lambda w: gtk.main_quit())
vbox = gtk.VBox()
vbox.show()
window.add(vbox)
# Create an accelerator group
accelgroup = gtk.AccelGroup()
# Add the accelerator group to the toplevel window
window.add_accel_group(accelgroup)
# Create an action for quitting the program using a stock item
action = gtk.Action('Quit', '_Quit me!', 'Quit the Program',
gtk.STOCK_QUIT)
action.set_property('short-label', '_Quit')
# Connect a callback to the action
action.connect('activate', self.quit_cb)
# Create an ActionGroup named BasicAction
actiongroup = gtk.ActionGroup('BasicAction')
# Add the action to the actiongroup with an accelerator
# None means use the stock item accelerator
actiongroup.add_action_with_accel(action, None)
# Have the action use accelgroup
action.set_accel_group(accelgroup)
# Create a MenuBar
menubar = gtk.MenuBar()
menubar.show()
vbox.pack_start(menubar, False)
# Create the File Action and MenuItem
file_action = gtk.Action('File', '_File', None, None)
actiongroup.add_action(file_action)
file_menuitem = file_action.create_menu_item()
menubar.append(file_menuitem)
# Create the File Menu
file_menu = gtk.Menu()
file_menuitem.set_submenu(file_menu)
# Create a proxy MenuItem
menuitem = action.create_menu_item()
file_menu.append(menuitem)
# Create a Toolbar
toolbar = gtk.Toolbar()
toolbar.show()
vbox.pack_start(toolbar, False)
# Create a proxy ToolItem
toolitem = action.create_tool_item()
toolbar.insert(toolitem, 0)
# Create and pack a Label
label = gtk.Label('''
Select File->Quit me! or
click the toolbar Quit button or
click the Quit button below or
press Control+q
to quit.
''')
label.show()
vbox.pack_start(label)
# Create a button to use as another proxy widget
quitbutton = gtk.Button()
# add it to the window
vbox.pack_start(quitbutton, False)
# Connect the action to its proxy widget
action.connect_proxy(quitbutton)
# Have to set tooltip after toolitem is added to toolbar
action.set_property('tooltip', action.get_property('tooltip'))
tooltips = gtk.Tooltips()
tooltips.set_tip(quitbutton, action.get_property('tooltip'))
window.show()
return
def quit_cb(self, b):
print 'Quitting program'
gtk.main_quit()
if __name__ == '__main__':
ba = BasicAction()
gtk.main()
|