[kupfer: 17/27] Use idle callbacks to update the progress dialog on the main thread
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer: 17/27] Use idle callbacks to update the progress dialog on the main thread
- Date: Tue, 16 Feb 2010 20:48:33 +0000 (UTC)
commit c72c0a9be4c3c5de239821973a43061b720a8c0d
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Sun Feb 14 23:57:09 2010 +0100
Use idle callbacks to update the progress dialog on the main thread
kupfer/ui/progress_dialog.py | 47 +++++++++++++++++++++++++++++++++---------
1 files changed, 37 insertions(+), 10 deletions(-)
---
diff --git a/kupfer/ui/progress_dialog.py b/kupfer/ui/progress_dialog.py
index 6404041..255ff79 100644
--- a/kupfer/ui/progress_dialog.py
+++ b/kupfer/ui/progress_dialog.py
@@ -1,16 +1,38 @@
+import functools
+
+import glib
import gtk
from kupfer import version, config, kupferstring
+def idle_call(func):
+ @functools.wraps(func)
+ def idle_wrapper(*args):
+ glib.idle_add(func, *args)
+ return idle_wrapper
+
_HEADER_MARKUP = '<span weight="bold" size="larger">%s</span>'
-class ProgressDialogController():
+class ProgressDialogController (object):
def __init__(self, title, header=None, label=None, max_value=100):
- """Load ui from data file"""
+ """Create a new progress dialog
+
+ @header: first line of dialog
+
+ The methods show, hide and update are all wrapped to be
+ safe to call from any thread.
+ """
+ self.aborted = False
+ self.max_value = float(max_value)
+ ui_file = config.get_data_file("progress_dialog.ui")
+ self._construct_dialog(ui_file, title, header)
+
+ @idle_call
+ def _construct_dialog(self, ui_file, title, header):
+
builder = gtk.Builder()
builder.set_translation_domain(version.PACKAGE_NAME)
- ui_file = config.get_data_file("progress_dialog.ui")
builder.add_from_file(ui_file)
builder.connect_signals(self)
@@ -20,9 +42,6 @@ class ProgressDialogController():
self.label_info = builder.get_object('label_info')
self.label_header = builder.get_object('label_header')
- self.aborted = False
- self.max_value = float(max_value)
-
self.window.set_title(title)
if header:
self.label_header.set_markup(_HEADER_MARKUP % header)
@@ -35,14 +54,22 @@ class ProgressDialogController():
self.aborted = True
self.button_abort.set_sensitive(False)
+ @idle_call
def show(self):
- return self.window.present()
+ self.window.present()
+ @idle_call
def hide(self):
- return self.window.hide()
+ self.window.hide()
+
+ @idle_call
+ def update(self, value, info):
+ """ Update dialog information.
- def update(self, value, label):
+ @value: value to set for progress bar
+ @info: information to show in dialog, above the progress bar
+ """
self.progressbar.set_fraction(min(value/self.max_value, 1.0))
- self.label_info.set_markup(kupferstring.toutf8(label))
+ self.label_info.set_markup(kupferstring.toutf8(info))
return self.aborted
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]