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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#!/usr/bin/env python
#
# toolbars.py - Simple example to demonstrate the usage of the editable
# toolbars framework in libexo.
#
# $Id: toolbars.py 20037 2006-02-24 21:48:18Z benny $
# vim:set ts=4 sw=4 et ai syntax=python:
#
# Copyright (c) 2005 os-cillation
#
# Written by Benedikt Meurer <benny@xfce.org>.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
import pygtk
pygtk.require('2.0')
import gobject
import gtk
import pyexo
pyexo.require('0.3')
import exo
class ToolbarsStore(exo.ToolbarsModel):
def __init__(self):
exo.ToolbarsModel.__init__(self)
self.set_actions(['up', 'down', 'forward', 'back', 'help', 'home'])
self.load_from_file('toolbars.ui')
class ToolbarsView(exo.ToolbarsView):
def __init__(self, manager):
exo.ToolbarsView.__init__(self, manager, ToolbarsStore())
self.connect('customize', lambda self: self.customize())
def customize(self):
self.set_editing(True)
dialog = exo.ToolbarsEditorDialog(self.get_ui_manager(), self.get_model())
dialog.set_title('Toolbar Editor')
dialog.set_transient_for(self.get_toplevel())
dialog.connect('destroy', lambda dialog: self.set_editing(False))
dialog.show()
class ToolbarsWindow(gtk.Window):
def __init__(self):
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
self.connect('destroy', lambda self: gtk.main_quit())
self.set_default_size(400, 300)
self.set_title('Toolbars example')
group = gtk.ActionGroup('toolbars-window')
group.add_actions([
('up', gtk.STOCK_GO_UP, 'Up', '<Control>u', None,
lambda btn, self: self.label.set_label('<big>Up</big>')),
('down', gtk.STOCK_GO_DOWN, 'Down', '<Control>d', None,
lambda btn, self: self.label.set_label('<big>Down</big>')),
('forward', gtk.STOCK_GO_FORWARD, 'Forward', '<Control>f', None,
lambda btn, self: self.label.set_label('<big>Forward</big>')),
('back', gtk.STOCK_GO_BACK, 'Back', '<Control>b', None,
lambda btn, self: self.label.set_label('<big>Back</big>')),
('help', gtk.STOCK_HELP, 'Help me', '<Control>h', None,
lambda btn, self: self.label.set_label('<big>Help ME!</big>')),
('home', gtk.STOCK_HOME, 'Home', '<Control>a', None,
lambda btn, self: self.label.set_label('<big>Anybody\'s Home?</big>'))
], self)
manager = gtk.UIManager()
manager.insert_action_group(group, 0)
self.add_accel_group(manager.get_accel_group())
vbox = gtk.VBox(False, 0)
self.add(vbox)
vbox.show()
view = ToolbarsView(manager)
vbox.pack_start(view, False, False, 0)
view.show()
frame = gtk.Frame()
frame.set_shadow_type(gtk.SHADOW_ETCHED_IN)
vbox.pack_start(frame, True, True, 0)
frame.show()
self.label = gtk.Label()
self.label.set_use_markup(True)
frame.add(self.label)
self.label.show()
def run(self):
self.show()
gtk.main()
window = ToolbarsWindow()
window.run()
|