diff options
Diffstat (limited to 'portato')
-rw-r--r-- | portato/gui/gtk/__init__.py | 12 | ||||
-rw-r--r-- | portato/gui/gtk/uncaughtException.py | 80 | ||||
-rw-r--r-- | portato/gui/gtk/windows.py | 1 |
3 files changed, 90 insertions, 3 deletions
diff --git a/portato/gui/gtk/__init__.py b/portato/gui/gtk/__init__.py index 17d6299..22e5f76 100644 --- a/portato/gui/gtk/__init__.py +++ b/portato/gui/gtk/__init__.py @@ -14,14 +14,20 @@ import gtk from portato import plugin from portato.backend import system from windows import MainWindow, SearchWindow, EbuildWindow +from uncaughtException import register_ex_handler def run (): - m = MainWindow() - m.main() + try: + m = MainWindow() + register_ex_handler() + m.main() + except KeyboardInterrupt: + pass def show_ebuild (pkg): plugin.load_plugins("gtk") - + register_ex_handler() + def _show (pkg): gtk.main_quit() diff --git a/portato/gui/gtk/uncaughtException.py b/portato/gui/gtk/uncaughtException.py new file mode 100644 index 0000000..d8ea13d --- /dev/null +++ b/portato/gui/gtk/uncaughtException.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +# +# File: portato/gui/gtk/uncaughtException.py +# This file is part of the Portato-Project, a graphical portage-frontend. +# +# Copyright (C) 2007 René 'Necoro' Neumann +# This is free software. You may redistribute copies of it under the terms of +# the GNU General Public License version 2. +# There is NO WARRANTY, to the extent permitted by law. +# +# Written by Gustavo Carneiro +# original code: http://www.daa.com.au/pipermail/pygtk/attachments/20030828/2d304204/gtkexcepthook.py +# +# Modified by René 'Necoro' Neumann + +import sys +import gtk, pango +from StringIO import StringIO +import traceback +from portato.helper import error + +class UncaughExceptionDialog(gtk.MessageDialog): + + def __init__(self, type, value, tb): + + super(UncaughExceptionDialog,self).__init__(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_NONE, message_format="A programming error has been detected during the execution of this program.") + self.set_title("Bug Detected") + self.format_secondary_text("It probably isn't fatal, but should be reported to the developers nonetheless.") + + self.add_button("Show Details", 1) + self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) + + # Details + self.textview = gtk.TextView() + self.textview.set_editable(False) + self.textview.modify_font(pango.FontDescription("Monospace")) + + self.sw = gtk.ScrolledWindow(); + self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + self.sw.add(self.textview) + + self.tbFrame = gtk.Frame() + self.tbFrame.set_shadow_type(gtk.SHADOW_IN) + self.tbFrame.add(self.sw) + self.tbFrame.set_border_width(6) + + self.vbox.add(self.tbFrame) + + textbuffer = self.textview.get_buffer() + textbuffer.set_text(get_trace(type, value, tb)) + self.textview.set_size_request(gtk.gdk.screen_width()/2, gtk.gdk.screen_height()/3) + + self.details = self.tbFrame + self.set_position(gtk.WIN_POS_CENTER) + self.set_gravity(gtk.gdk.GRAVITY_CENTER) + + def run (self): + while True: + resp = super(UncaughExceptionDialog, self).run() + if resp == 1: + self.details.show_all() + self.set_response_sensitive(1, False) + else: + break + self.destroy() + +def get_trace(type, value, tb): + trace = StringIO() + traceback.print_exception(type, value, tb, None, trace) + traceStr = trace.getvalue() + trace.close() + return traceStr + +def register_ex_handler(): + + def handler(*args): + error("An uncaught exception has occured: %s", get_trace(*args)) + UncaughExceptionDialog(*args).run() + + sys.excepthook = handler diff --git a/portato/gui/gtk/windows.py b/portato/gui/gtk/windows.py index 8cf9fb7..a2efc85 100644 --- a/portato/gui/gtk/windows.py +++ b/portato/gui/gtk/windows.py @@ -1307,6 +1307,7 @@ class MainWindow (Window): return True def cb_sync_clicked (self, action): + raise Exception, "Bla" if not am_i_root(): not_root_dialog() else: |