Browse Source

add option to disable progress bar animation on Windows 7

pull/120/head
Alexander Gordeyev 9 years ago
parent
commit
254dbd1a6b
5 changed files with 57 additions and 3 deletions
  1. 3
      gooey/_tmp/example_progress_bar_2.py
  2. 39
      gooey/_tmp/example_progress_bar_4.py
  3. 14
      gooey/gui/windows/base_window.py
  4. 1
      gooey/python_bindings/config_generator.py
  5. 3
      gooey/python_bindings/gooey_decorator.py

3
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)

39
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())

14
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__':

1
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:

3
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

Loading…
Cancel
Save