Commit 68ed74fa authored by sumpfralle's avatar sumpfralle

fixed handling of multiple layers of progress bars


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1168 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 652eba5c
...@@ -27,6 +27,7 @@ import datetime ...@@ -27,6 +27,7 @@ import datetime
import pycam.Plugins import pycam.Plugins
class ProgressBar(pycam.Plugins.PluginBase): class ProgressBar(pycam.Plugins.PluginBase):
UI_FILE = "progress_bar.ui" UI_FILE = "progress_bar.ui"
...@@ -54,8 +55,12 @@ class ProgressBar(pycam.Plugins.PluginBase): ...@@ -54,8 +55,12 @@ class ProgressBar(pycam.Plugins.PluginBase):
class ProgressGTK(object): class ProgressGTK(object):
_PROGRESS_STACK = []
def __init__(self, core, gui): def __init__(self, core, gui):
ProgressGTK._PROGRESS_STACK.append(self)
import gtk import gtk
self._finished = False
self._gtk = gtk self._gtk = gtk
self._gui = gui self._gui = gui
self.core = core self.core = core
...@@ -73,6 +78,8 @@ class ProgressGTK(object): ...@@ -73,6 +78,8 @@ class ProgressGTK(object):
self._progress_button = self._gui.get_object("ShowToolpathProgressButton") self._progress_button = self._gui.get_object("ShowToolpathProgressButton")
self._start_time = time.time() self._start_time = time.time()
self._progress_button.show() self._progress_button.show()
self._last_text = None
self._last_percent = None
self.update(text="", percent=0) self.update(text="", percent=0)
self._cancel_button.set_sensitive(True) self._cancel_button.set_sensitive(True)
self._progress_button.hide() self._progress_button.hide()
...@@ -93,13 +100,14 @@ class ProgressGTK(object): ...@@ -93,13 +100,14 @@ class ProgressGTK(object):
if count > 1: if count > 1:
self._multi_maximum = count self._multi_maximum = count
self.update_multiple(increment=False) self.update_multiple(increment=False)
self._multi_widget.show()
else: else:
self._multi_maximum = 0 self._multi_maximum = 0
def update_multiple(self, increment=True): def update_multiple(self, increment=True):
if self._multi_maximum <= 1: if self._multi_maximum <= 1:
self._multi_widget.hide()
return return
self._multi_widget.show()
if increment: if increment:
self._multi_counter += 1 self._multi_counter += 1
self._progress_bar.set_fraction(0) self._progress_bar.set_fraction(0)
...@@ -119,6 +127,18 @@ class ProgressGTK(object): ...@@ -119,6 +127,18 @@ class ProgressGTK(object):
self._cancel_requested = True self._cancel_requested = True
def finish(self): def finish(self):
if self._finished:
self.log.debug("Called progressbar 'finish' twice: %s" % self)
return
ProgressGTK._PROGRESS_STACK.remove(self)
if ProgressGTK._PROGRESS_STACK:
# restore the latest state of the previous progress
current = ProgressGTK._PROGRESS_STACK[-1]
current.update(text=current._last_text,
percent=current._last_percent)
current.update_multiple(increment=False)
else:
# hide the widget
self._main_widget.hide() self._main_widget.hide()
self._multi_widget.hide() self._multi_widget.hide()
widget = self._main_widget widget = self._main_widget
...@@ -129,11 +149,16 @@ class ProgressGTK(object): ...@@ -129,11 +149,16 @@ class ProgressGTK(object):
widget.check_resize() widget.check_resize()
widget = widget.get_parent() widget = widget.get_parent()
self.core.emit_event("gui-enable") self.core.emit_event("gui-enable")
self._finished = True
def __del__(self): def __del__(self):
self.finish() self.finish()
def update(self, text=None, percent=None): def update(self, text=None, percent=None):
if text:
self._last_text = text
if percent:
self._last_percent = percent
if not percent is None: if not percent is None:
percent = min(max(percent, 0.0), 100.0) percent = min(max(percent, 0.0), 100.0)
self._progress_bar.set_fraction(percent/100.0) self._progress_bar.set_fraction(percent/100.0)
......
...@@ -198,6 +198,10 @@ def get_exception_report(): ...@@ -198,6 +198,10 @@ def get_exception_report():
+ "text below to the developers of PyCAM. Thanks a lot!" \ + "text below to the developers of PyCAM. Thanks a lot!" \
+ os.linesep + traceback.format_exc() + os.linesep + traceback.format_exc()
def print_stack_trace():
# for debug purposes
traceback.print_stack()
class ProgressCounter(object): class ProgressCounter(object):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment