1 from os
import _exit
, fork
, execvp
, waitpid
, dup2
4 from traceback
import format_exception_only
6 from string
import find
, lower
, join
7 from socket
import gethostbyaddr
, gethostname
29 def load_pixmap(window
, path
):
31 p
, m
= create_pixmap_from_xpm(window
, None, path
)
33 print "Warning: failed to load icon '%s'" % path
34 p
, m
= create_pixmap_from_xpm_d(window
, None, bad_xpm
)
42 (host
, alias
, ips
) = gethostbyaddr(gethostname())
43 for name
in [host
] + alias
:
44 if find(name
, '.') != -1:
49 def get_local_path(uri
):
50 "Convert uri to a local path and return, if possible. Otherwise,"
52 host
= our_host_name()
59 return uri
# A normal Unix pathname
62 return None # //something
64 return uri
[2:] # ///path
65 remote_host
= uri
[2:i
]
66 if remote_host
== host
:
67 return uri
[i
:] # //localhost/path
69 elif lower(uri
[:5]) == 'file:':
71 return get_local_path(uri
[5:])
72 elif uri
[:2] == './' or uri
[:3] == '../':
76 # Open a modal dialog box showing a message.
77 # The user can choose from a selection of buttons at the bottom.
78 # Returns -1 if the window is destroyed, or the number of the button
79 # if one is clicked (starting from zero).
81 # If a dialog is already open, returns -1 without waiting AND
82 # brings the current dialog to the front.
84 def get_choice(message
, title
, buttons
):
85 global current_dialog
, choice_return
92 current_dialog
= GtkWindow(WINDOW_DIALOG
)
93 current_dialog
.unset_flags(CAN_FOCUS
)
94 current_dialog
.set_modal(TRUE
)
95 current_dialog
.set_title(title
)
96 current_dialog
.set_position(WIN_POS_CENTER
)
97 current_dialog
.set_border_width(2)
99 vbox
= GtkVBox(FALSE
, 0)
100 current_dialog
.add(vbox
)
101 action_area
= GtkHBox(TRUE
, 5)
102 action_area
.set_border_width(2)
103 vbox
.pack_end(action_area
, FALSE
, TRUE
, 0)
104 vbox
.pack_end(GtkHSeparator(), FALSE
, TRUE
, 2)
106 text
= GtkLabel(message
)
107 text
.set_line_wrap(TRUE
)
108 text_container
= GtkEventBox()
109 text_container
.set_border_width(40) # XXX
110 text_container
.add(text
)
112 vbox
.pack_start(text_container
, TRUE
, TRUE
, 0)
114 default_button
= None
118 label
.set_padding(16, 2)
121 button
.set_flags(CAN_DEFAULT
)
122 action_area
.pack_start(button
, TRUE
, TRUE
, 0)
123 def cb(widget
, n
= n
):
126 button
.connect('clicked', cb
)
127 if not default_button
:
128 default_button
= button
131 default_button
.grab_focus()
132 default_button
.grab_default()
133 action_area
.set_focus_child(default_button
)
138 current_dialog
.connect('destroy', cb
)
142 current_dialog
.show_all()
144 while choice_return
== -2:
147 retval
= choice_return
150 current_dialog
.destroy()
152 current_dialog
= None
156 def report_error(message
, title
= 'Error'):
157 get_choice(message
, title
, ['OK'])
159 def report_exception():
160 ex
= format_exception_only(sys
.exc_type
, sys
.exc_value
)
161 report_error(join(ex
, ''))
164 """Spawn a new process. Connect stderr to stdout."""
170 execvp(argv
[0], argv
)
173 print "Warning: exec('%s') failed!" % argv
[0]
176 print "Error: fork() failed!"