6 sys
.stderr
.write('The pygtk2 package must be ' +
7 'installed to use this program!')
13 app_dir
= os
.path
.dirname(sys
.argv
[0])
16 "Display message in an error box."
18 box
= g
.MessageDialog(None, 0, g
.MESSAGE_ERROR
, g
.BUTTONS_OK
, message
)
19 box
.set_position(g
.WIN_POS_CENTER
)
20 box
.set_title('Error')
26 "Display message in an error box, then die."
31 "Display informational message."
33 box
= g
.MessageDialog(None, 0, g
.MESSAGE_INFO
, g
.BUTTONS_OK
, message
)
34 box
.set_position(g
.WIN_POS_CENTER
)
35 box
.set_title('Information')
40 def confirm(message
, stock_icon
, action
= None):
41 "Display a <Cancel>/<Action> dialog. Returns 1 if the user chooses the "
44 box
= g
.MessageDialog(None, 0, g
.MESSAGE_QUESTION
,
45 g
.BUTTONS_CANCEL
, message
)
47 button
= ButtonMixed(stock_icon
, action
)
49 button
= g
.Button(stock
= stock_icon
)
50 button
.set_flags(g
.CAN_DEFAULT
)
52 box
.add_action_widget(button
, g
.RESPONSE_OK
)
53 box
.set_position(g
.WIN_POS_CENTER
)
54 box
.set_title('Confirm:')
55 box
.set_default_response(g
.RESPONSE_OK
)
59 return resp
== g
.RESPONSE_OK
61 def report_exception():
63 type, value
, tb
= sys
.exc_info()
64 traceback
.print_exception(type, value
, tb
)
65 ex
= traceback
.format_exception_only(type, value
)
68 class ButtonMixed(g
.Button
):
69 "A button with a stock icon, but any label."
70 def __init__(self
, stock
, message
):
71 g
.Button
.__init
__(self
)
74 label
.set_text_with_mnemonic(message
)
75 label
.set_mnemonic_widget(self
)
77 image
= g
.image_new_from_stock(stock
, g
.ICON_SIZE_BUTTON
)
78 box
= g
.HBox(FALSE
, 2)
79 align
= g
.Alignment(0.5, 0.5, 0.0, 0.0)
81 box
.pack_start(image
, FALSE
, FALSE
, 0)
82 box
.pack_end(label
, FALSE
, FALSE
, 0)
91 global _toplevel_windows
, _in_mainloops
95 while _toplevel_windows
:
101 global _toplevel_windows
102 _toplevel_windows
+= 1
104 def toplevel_unref():
105 global _toplevel_windows
106 assert _toplevel_windows
> 0
107 _toplevel_windows
-= 1
108 if _toplevel_windows
== 0 and _in_mainloops
:
113 from socket
import gethostbyaddr
, gethostname
118 (host
, alias
, ips
) = gethostbyaddr(gethostname())
119 for name
in [host
] + alias
:
120 if find(name
, '.') != -1:
126 "*** ROX-Lib gethostbyaddr(gethostname()) failed!\n")
129 def get_local_path(uri
):
130 "Convert uri to a local path and return, if possible. Otherwise,"
137 return uri
# A normal Unix pathname
140 return None # //something
142 return uri
[2:] # ///path
143 remote_host
= uri
[2:i
]
144 if remote_host
== our_host_name():
145 return uri
[i
:] # //localhost/path
147 elif uri
[:5].lower() == 'file:':
149 return get_local_path(uri
[5:])
150 elif uri
[:2] == './' or uri
[:3] == '../':
155 def setup_app_options(program
, leaf
= 'Options.xml'):
157 assert not app_options
158 from options
import OptionGroup
159 app_options
= OptionGroup(program
, leaf
)
162 def edit_options(options_file
= None):
163 """Edit the app_options using the GUI specified in 'options_file'
164 (default <app_dir>/Options.xml)"""
169 _options_box
.present()
173 options_file
= os
.path
.join(app_dir
, 'Options.xml')
176 _options_box
= OptionsBox
.OptionsBox(app_options
, options_file
)
180 assert _options_box
== widget
182 _options_box
.connect('destroy', closed
)
188 alert("You do not have the Python 'xml' module installed, which " \
189 "ROX-Lib2 requires. You need to install python-xmlbase " \
190 "(this is a small package; the full PyXML package is not " \