From 254dbd1a6bfaf6ea4bef52ab45990f7fe909009f Mon Sep 17 00:00:00 2001 From: Alexander Gordeyev Date: Sat, 31 Oct 2015 19:45:28 +0300 Subject: [PATCH] add option to disable progress bar animation on Windows 7 --- gooey/_tmp/example_progress_bar_2.py | 3 +- gooey/_tmp/example_progress_bar_4.py | 39 +++++++++++++++++++++++ gooey/gui/windows/base_window.py | 14 +++++++- gooey/python_bindings/config_generator.py | 1 + gooey/python_bindings/gooey_decorator.py | 3 +- 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 gooey/_tmp/example_progress_bar_4.py diff --git a/gooey/_tmp/example_progress_bar_2.py b/gooey/_tmp/example_progress_bar_2.py index 30e0b60..ae70555 100644 --- a/gooey/_tmp/example_progress_bar_2.py +++ b/gooey/_tmp/example_progress_bar_2.py @@ -9,7 +9,8 @@ from gooey import Gooey, GooeyParser @Gooey(progress_regex=r"^progress: (\d+)/(\d+)$", - progress_expr="x[0] / x[1] * 100") + progress_expr="x[0] / x[1] * 100", + progress_animation=False) def main(): parser = GooeyParser(prog="example_progress_bar_2") parser.add_argument("steps", type=int, default=15) diff --git a/gooey/_tmp/example_progress_bar_4.py b/gooey/_tmp/example_progress_bar_4.py new file mode 100644 index 0000000..c322ffa --- /dev/null +++ b/gooey/_tmp/example_progress_bar_4.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from __future__ import unicode_literals +from __future__ import print_function +import sys +from time import sleep +from gooey import Gooey, GooeyParser + + +@Gooey(progress_regex=r"^progress: (-?\d+)%$", + progress_animation=False) +def main(): + parser = GooeyParser(prog="example_progress_bar_1") + _ = parser.parse_args(sys.argv[1:]) + + print("Step 1") + + for i in range(1, 101): + print("progress: {}%".format(i)) + sys.stdout.flush() + sleep(0.05) + + print("Step 2") + + print("progress: -1%") # pulse + sys.stdout.flush() + sleep(3) + + print("Step 3") + + for i in range(1, 101): + print("progress: {}%".format(i)) + sys.stdout.flush() + sleep(0.05) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/gooey/gui/windows/base_window.py b/gooey/gui/windows/base_window.py index 34872ab..647e241 100644 --- a/gooey/gui/windows/base_window.py +++ b/gooey/gui/windows/base_window.py @@ -3,6 +3,8 @@ Created on Jan 19, 2014 @author: Chris ''' +import sys + import wx from gooey.gui.pubsub import pub @@ -158,7 +160,17 @@ class BaseWindow(wx.Frame): if value < 0: pb.Pulse() else: - pb.SetValue(min(value, pb.GetRange())) + value = min(int(value), pb.GetRange()) + if pb.GetValue() != value: + # Windows 7 progress bar animation hack + if not self.build_spec["progress_animation"] \ + and sys.platform.startswith("win"): + if pb.GetRange() == value: + pb.SetValue(value) + pb.SetValue(value-1) + else: + pb.SetValue(value+1) + pb.SetValue(value) if __name__ == '__main__': diff --git a/gooey/python_bindings/config_generator.py b/gooey/python_bindings/config_generator.py index 4a51daa..06d8e93 100644 --- a/gooey/python_bindings/config_generator.py +++ b/gooey/python_bindings/config_generator.py @@ -28,6 +28,7 @@ def create_from_parser(parser, source_path, **kwargs): 'monospace_display': kwargs.get('monospace_display', False), 'progress_regex': kwargs.get('progress_regex'), 'progress_expr': kwargs.get('progress_expr'), + 'progress_animation': kwargs.get('progress_animation'), } if show_config: diff --git a/gooey/python_bindings/gooey_decorator.py b/gooey/python_bindings/gooey_decorator.py index 73405b5..f048459 100644 --- a/gooey/python_bindings/gooey_decorator.py +++ b/gooey/python_bindings/gooey_decorator.py @@ -35,7 +35,8 @@ def Gooey(f=None, load_build_config=None, monospace_display=False, progress_regex=None, - progress_expr=None): + progress_expr=None, + progress_animation=True): ''' Decorator for client code's main function. Serializes argparse data to JSON for use with the Gooey front end