summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2007-12-01 23:12:30 +0100
committerGuillaume Seguin <guillaume@segu.in>2007-12-01 23:12:30 +0100
commita8db0c69633daccb04344dc8d6b7d163469f59cb (patch)
treee86d58e268b239220cd733571bb5168a58f45ab4
parent88f9137e34b070f9583e91ad7d7dbbb0344e54a6 (diff)
downloadcamlui-a8db0c69633daccb04344dc8d6b7d163469f59cb.tar.gz
camlui-a8db0c69633daccb04344dc8d6b7d163469f59cb.tar.bz2
* Nicely handle fatal toplevel errors
-rw-r--r--camlui/dialogs.py16
-rw-r--r--camlui/gui.py10
-rw-r--r--camlui/process.py11
3 files changed, 34 insertions, 3 deletions
diff --git a/camlui/dialogs.py b/camlui/dialogs.py
index eccdc73..0320b6a 100644
--- a/camlui/dialogs.py
+++ b/camlui/dialogs.py
@@ -108,3 +108,19 @@ def yes_no_dialog (parent, message):
if response == gtk.RESPONSE_YES:
return True
return False
+
+def error_dialog (parent, message, cb = None):
+ '''Display an error dialog'''
+ dialog = gtk.MessageDialog (parent,
+ gtk.DIALOG_DESTROY_WITH_PARENT,
+ gtk.MESSAGE_ERROR,
+ gtk.BUTTONS_CLOSE)
+ dialog.set_position (gtk.WIN_POS_CENTER)
+ dialog.set_markup (message)
+ dialog.set_title (_("CamlUI Error"))
+ dialog.set_icon (parent.get_icon ())
+ dialog.set_transient_for (parent)
+ dialog.show_all ()
+ if cb:
+ dialog.connect ("response", cb)
+ dialog.connect ("response", lambda *args: dialog.destroy ())
diff --git a/camlui/gui.py b/camlui/gui.py
index 7e1c26e..5e7f6c4 100644
--- a/camlui/gui.py
+++ b/camlui/gui.py
@@ -116,7 +116,8 @@ class CamlUI:
self.process = Process (run_cb = self.output.push_input,
stdout_cb = self.output.push_output,
stderr_cb = self.output.push_error,
- queue_empty_cb = self.on_queue_empty)
+ queue_empty_cb = self.on_queue_empty,
+ write_error_cb = self.on_write_error)
self.window.show ()
self.window.connect ("configure-event", self.update_geometry)
self.window.connect ("window-state-event", self.update_state)
@@ -394,6 +395,13 @@ class CamlUI:
'''Empty queue callback, disable interrupt action'''
self.update_action ("interrupt", False)
+ def on_write_error (self):
+ '''Write error callback, pop error box'''
+ error_dialog (self.window,
+ _('''A fatal error occured inside the camllight \
+interpreter, closing this dialog will reset the interpreter.'''),
+ self.reset)
+
def tab_selected_cb (self, *args):
'''A tab was selected, update some sensitivies, etc'''
tab = self.tabs.get_current ()
diff --git a/camlui/process.py b/camlui/process.py
index 2737778..422b602 100644
--- a/camlui/process.py
+++ b/camlui/process.py
@@ -81,14 +81,17 @@ class Process:
stdout_cb = None
stderr_cb = None
queue_empty_cb = None
+ write_error_cb = None
def __init__ (self, run_cb = None, stdout_cb = None,
- stderr_cb = None, queue_empty_cb = None):
+ stderr_cb = None, queue_empty_cb = None,
+ write_error_cb = None):
'''Initiate object and run process'''
self.run_cb = run_cb
self.stdout_cb = stdout_cb
self.stderr_cb = stderr_cb
self.queue_empty_cb = queue_empty_cb
+ self.write_error_cb = write_error_cb
if not win32:
# Check camllight & camlmktop availability
process = subprocess.Popen (["which", "camlmktop"],
@@ -260,7 +263,11 @@ toplevels, using normal toplevel")
else: data += ";;\n"
if self.run_cb:
self.run_cb (" " + data)
- os.write (self.process.stdin.fileno (), data)
+ try:
+ os.write (self.process.stdin.fileno (), data)
+ except OSError:
+ if self.write_error_cb:
+ self.write_error_cb ()
elif self.queue_empty_cb:
self.queue_empty_cb ()