|
From: Gustavo J. A. M. C. <gu...@us...> - 2002-04-14 17:36:36
|
Update of /cvsroot/numexp/gnumexp/src/xygraph
In directory usw-pr-cvs1:/tmp/cvs-serv20848
Added Files:
Bonobo_Sample_Hello.xml hello.py
Log Message:
Copied a sample program from gnome-python's source and modified it to embebed
the xygraph control instead of a button.
--- NEW FILE ---
<Root>
<commands>
<cmd name="FileNew" stockid="gtk-new"/>
<cmd name="FileOpen" stockid="gtk-open" priority="1"/>
<cmd name="FileSave" stockid="gtk-save" priority="1"/>
<cmd name="FileSaveAs" stockid="gtk-save-as"/>
<cmd name="FileClose" stockid="gtk-close"/>
<cmd name="FileExit" stockid="gtk-quit"/>
<cmd name="EditUndo" stockid="gtk-undo"/>
<cmd name="EditRedo" stockid="gtk-redo"/>
<cmd name="EditCut" stockid="gtk-cut"/>
<cmd name="EditCopy" stockid="gtk-copy"/>
<cmd name="EditPaste" stockid="gtk-paste"/>
<cmd name="EditSelect" _label="_Select" _tip="Select"/>
<cmd name="EditClear" stockid="gtk-clear"/>
<cmd name="HelpAbout" _label="_About..."
_tip="About this application"
pixtype="stock" pixname="gtk-preferences"/>
</commands>
<menu>
<submenu name="File" _label="_File">
<placeholder/>
<separator/>
<menuitem name="FileNew" verb=""/>
<menuitem name="FileOpen" verb=""/>
<menuitem name="FileSave" verb=""/>
<menuitem name="FileSaveAs" verb=""/>
<menuitem name="FileClose" verb=""/>
<menuitem name="FileExit" verb=""/>
</submenu>
<submenu name="Edit" _label="_Edit">
<placeholder/>
<separator/>
<menuitem name="EditUndo" verb=""/>
<menuitem name="EditRedo" verb=""/>
<separator/>
<menuitem name="EditCut" verb=""/>
<menuitem name="EditCopy" verb=""/>
<menuitem name="EditPaste" verb=""/>
<menuitem name="EditSelect" verb=""/>
<menuitem name="EditClear" verb=""/>
</submenu>
<submenu name="Help" stockid="gtk-help">
<menuitem name="HelpAbout" verb=""/>
</submenu>
</menu>
<dockitem name="Toolbar" relief="none" homogeneous="1"
behavior="exclusive" look="text">
<toolitem name="FileOpen" verb=""/>
<toolitem name="FileSave" verb=""/>
<toolitem name="FileExit" verb=""/>
<placeholder/>
</dockitem>
</Root>
--- NEW FILE ---
#!/usr/bin/env python
#
# hello.py
#
# A hello world application using the Bonobo UI handler
#
# Original Authors:
# Michael Meeks <mi...@xi...>
# Murray Cumming <mu...@us...>
# Havoc Pennington <hp...@re...>
#
# Converted to Python by:
# Johan Dahlin <jd...@te...>
#
import sys
import bonobo
import bonobo.ui
import gtk
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 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)
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', gtk.FALSE)
frame = gtk.Frame ()
frame.set_shadow_type (gtk.SHADOW_IN)
xy = bonobo.get_object('OAFIID:Numexp_XYGraph', 'Bonobo/Control')
wid = bonobo.ui.bonobo_widget_new_control_from_objref(xy, win.get_ui_container().corba_objref())
#frame.add (button)
frame.add(wid)
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 ()
|