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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#!/usr/bin/env python
#
# hello.py
#
# A hello world application using the Bonobo UI handler
#
# Original Authors:
# Michael Meeks <michael@ximian.com>
# Murray Cumming <murrayc@usa.net>
# Havoc Pennington <hp@redhat.com>
#
# Converted to Python by:
# Johan Dahlin <jdahlin@telia.com>
#
# Recent file support by:
# Gustavo Carneiro <gjc@gnome.org>
#
import sys
import bonobo
import bonobo.ui
import gtk
import egg.recent
HELLO_UI_XML = "./Bonobo_Sample_Hello.xml"
# Keep a list of all open application windows
app_list = []
def strreverse (text):
l = list (text)
l.reverse ()
return ''.join (l)
def show_nothing_dialog (widget):
dialog = gtk.MessageDialog (widget,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
'This does nothing; it is only a demonstration')
dialog.run ()
dialog.destroy ()
def hello_on_menu_file_new (uic, verbname, win):
hello = hello_new ()
hello.show_all ()
def hello_on_menu_file_open (uic, verbname, win):
show_nothing_dialog (win)
def hello_on_menu_file_save (uic, verbname, win):
show_nothing_dialog (win)
def hello_on_menu_file_saveas (uic, verbname, win):
show_nothing_dialog (win)
def hello_on_menu_file_exit (uic, verbname, win):
sys.exit (0)
def hello_on_menu_file_close (uic, verbname, win):
app_list.remove (app)
app.destroy ()
if not app_list:
hello_on_menu_file_exit (uic, verbname, win)
def hello_on_menu_edit_undo (uic, verbname, win):
show_nothing_dialog (win)
def hello_on_menu_edit_redo (uic, verbname, win):
show_nothing_dialog (win)
def hello_on_menu_help_about (uic, verbname, win):
dialog = gtk.MessageDialog (win,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
'BonoboUI-Hello')
dialog.run ()
dialog.destroy ()
def hello_on_button_click (w, label):
text = label.get_text ()
label.set_text (strreverse (text))
# These verb names are standard, see libonobobui/doc/std-ui.xml
# to find a list of standard verb names.
# The menu items are specified in Bonobo_Sample_Hello.xml and
# given names which map to these verbs here.
hello_verbs = [
('FileNew', hello_on_menu_file_new),
('FileOpen', hello_on_menu_file_open),
('FileSave', hello_on_menu_file_save),
('FileSaveAs', hello_on_menu_file_saveas),
('FileClose', hello_on_menu_file_close),
('FileExit', hello_on_menu_file_exit),
('EditUndo', hello_on_menu_edit_undo),
('EditRedo', hello_on_menu_edit_redo),
('HelpAbout', hello_on_menu_help_about)
]
def open_recent_cb(recent_view, item):
dialog = gtk.MessageDialog (widget,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
'I have a feeling you want to open the following recent'
' file:\n%s' % item.get_uri())
dialog.run ()
dialog.destroy ()
def hello_create_main_window ():
window = bonobo.ui.Window ('Title', 'test')
window.show_all ()
ui_container = window.get_ui_container ()
engine = window.get_ui_engine ()
engine.config_set_path ('/hello-app/UIConfig/kvps')
ui_component = bonobo.ui.Component ('test')
ui_component.set_container (ui_container.corba_objref ())
bonobo.ui.util_set_ui (ui_component, '',
HELLO_UI_XML,
'bonobo-hello')
ui_component.add_verb_list (hello_verbs, window)
## *** Here's the important stuff, add recent files to the UI
## ----------------------------------------------------------
## Setup the EggRecentModel stuff
model = egg.recent.RecentModel(egg.recent.RECENT_MODEL_SORT_MRU)
#model.set_filter_groups(["Bonobo Test"])
# try these if you want
#model.set_filter_mime_types(["text/plain"])
#model.set_filter_uri_schemes(["mailto", "http", "ftp"])
view = egg.recent.RecentViewBonobo(ui_component,
"/menu/File/EggRecentDocuments/")
view.show_icons(True)
view.set_model(model)
view.connect("activate", open_recent_cb)
return window
def delete_event_cb (window, event):
return gtk.TRUE
def hello_new ():
win = hello_create_main_window ()
button = gtk.Button ()
button.set_border_width (10)
label = gtk.Label ('Hello World')
button.add (label)
button.connect ('clicked', hello_on_button_click, label)
win.set_size_request (250, 350)
win.set_resizable (gtk.TRUE)
win.set_property ('allow-shrink', False)
frame = gtk.Frame ()
frame.set_shadow_type (gtk.SHADOW_IN)
frame.add (button)
win.set_contents (frame)
win.connect ('delete_event', delete_event_cb)
app_list.append (win)
return win
if __name__ == '__main__':
app = hello_new ()
app.show_all ()
bonobo.main ()
|