import sys
import traceback
-import datetime
+import functools
import contextlib
import warnings
self._respond(position)
+def make_idler(func):
+ """
+ Decorator that makes a generator-function into a function that will continue execution on next call
+ """
+ a = []
+
+ @functools.wraps(func)
+ def decorated_func(*args, **kwds):
+ if not a:
+ a.append(func(*args, **kwds))
+ try:
+ a[0].next()
+ return True
+ except StopIteration:
+ del a[:]
+ return False
+
+ return decorated_func
+
+
+def asynchronous_gtk_message(original_func):
+ """
+ @note Idea came from http://www.aclevername.com/articles/python-webgui/
+ """
+
+ def execute(allArgs):
+ args, kwargs = allArgs
+ original_func(*args, **kwargs)
+
+ @functools.wraps(original_func)
+ def delayed_func(*args, **kwargs):
+ gobject.idle_add(execute, (args, kwargs))
+
+ return delayed_func
+
+
+def synchronous_gtk_message(original_func):
+ """
+ @note Idea came from http://www.aclevername.com/articles/python-webgui/
+ """
+
+ @functools.wraps(original_func)
+ def immediate_func(*args, **kwargs):
+ with gtk_lock():
+ return original_func(*args, **kwargs)
+
+ return immediate_func
+
+
class LoginWindow(object):
def __init__(self, widgetTree):
def push_exception(self, exception = None):
if exception is None:
- userMessage = sys.exc_value.message
- warningMessage = traceback.format_exc()
+ userMessage = str(sys.exc_value)
+ warningMessage = str(traceback.format_exc())
else:
- userMessage = exception.message
- warningMessage = exception
+ userMessage = str(exception)
+ warningMessage = str(exception)
self.push_message(userMessage)
warnings.warn(warningMessage, stacklevel=3)
win.show_all()
if False:
+ import datetime
cal = PopupCalendar(None, datetime.datetime.now())
cal._popupWindow.connect("destroy", lambda w: gtk.main_quit())
cal.run()