Git commit f74240807340807fe88df7d514f88272f4074ecf by Shaheed Haque. Committed on 22/09/2012 at 20:58. Pushed by shaheed into branch 'master'. Catch and display any unhandled exceptions raised by actions. Provide a common fallback GUI display for unhandled exceptions from actions. M +15 -0 kate/plugins/pate/src/kate/__init__.py http://commits.kde.org/kate/f74240807340807fe88df7d514f88272f4074ecf diff --git a/kate/plugins/pate/src/kate/__init__.py b/kate/plugins/pate/src= /kate/__init__.py index b4f37ae..b337d67 100644 --- a/kate/plugins/pate/src/kate/__init__.py +++ b/kate/plugins/pate/src/kate/__init__.py @@ -28,6 +28,8 @@ import traceback import functools import pydoc from inspect import getmembers, isfunction +from PyKDE4.kdecore import i18n +from PyKDE4.kdeui import KMessageBox = import pate import kate.gui @@ -276,6 +278,18 @@ def action(text, icon=3DNone, shortcut=3DNone, menu=3D= None): NOTE: Kate may need to be restarted for this decorator to take effect,= or to remove all traces of the plugin on removal. ''' + class catchAllHandler(object): + '''Standard error handling for plugin actions.''' + def __init__(self, f): + self.f =3D f + + def __call__(self): + try: + self.f() + except Exception, e: + txt =3D "".join(traceback.format_exception(*sys.exc_info()= )) + KMessageBox.error(None, txt, i18n("Error in action '{}'").= format(self.f.__name__)) + def decorator(func): a =3D kdeui.KAction(text, None) if shortcut is not None: @@ -286,6 +300,7 @@ def action(text, icon=3DNone, shortcut=3DNone, menu=3DN= one): if icon is not None: a.setIcon(kdeui.KIcon(icon)) a.menu =3D menu + func =3D catchAllHandler(func) a.connect(a, QtCore.SIGNAL('triggered()'), func) # delay till everything has been initialised action.actions.add(a)