Repository: beeware/toga

Issue:
Progressbar crash on start
## Expected Behavior
<!--- If you're describing a bug, tell us what you expect to happen. -->
Progress bar to load
<!--- If you're requesting a new feature, tell us why you'd like this feature. -->


## Current Behavior
<!--- If you're describing a bug, what currently happens? -->
```
python -m progressbar
Unhandled Exception: Python.Runtime.PythonException: TypeError : 'NoneType' value cannot be converted to System.Int32
   at Python.Runtime.Dispatcher.Dispatch(ArrayList args)
   at __System_Threading_ThreadStartDispatcher.Invoke()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
```
## Steps to reproduce
<!--- Provide a set of steps describing how to reproduce this bug. If you have a live example, provide the link below -->
1. launch progressbar

## Your Environment
<!--- Provide details on your current environment you found the bug in -->

* Python Version (list the specific version number) 3.6.5

* Operating System and Version (select from the following and list the specific version number; if your OS is not listed, list that as well)

  - [ ] macOS - version: 
  - [ ] Linux - distro:   - version:
  - [ * ] Windows - version: Win10 1607
  - [ ] Other - name:  - version:

* Toga Target (the type of app you are trying to generate)
 
  - [ ] android
  - [ ] cocoa
  - [ ] django 
  - [ ] gtk
  - [ ] iOS
  - [ ] tvOS
  - [ ] watchOS
  - [ * ] winforms 
  - [ ] win32
  - [ ] Other (please specify)



Discussion:
Had the same error when tried to run the "progressbar" example on windows. Had the following error:

```
Traceback (most recent call last):
  File "c:\users\saroa\repositories\toga\src\winforms\toga_winforms\app.py", line 143, in run_app
    self.create()
  File "c:\users\saroa\repositories\toga\src\winforms\toga_winforms\app.py", line 65, in create
    self.interface.startup()
  File "C:\Users\saroa\repositories\toga\examples\progressbar\progressbar\app.py", line 16, in startup
    self.progress_runner = toga.ProgressBar(max=None)
  File "c:\users\saroa\repositories\toga\src\core\toga\widgets\progressbar.py", line 34, in __init__
    self.max = max
  File "c:\users\saroa\repositories\toga\src\core\toga\widgets\progressbar.py", line 113, in max
    self._impl.set_max(value)
  File "c:\users\saroa\repositories\toga\src\winforms\toga_winforms\widgets\progressbar.py", line 27, in set_max
    self.native.Maximum = value
TypeError: 'NoneType' value cannot be converted to System.Int32
```

What should be the right behavior when "max" is set to None?
Maybe I could implement it.
macOS handles the "max=None" case as "this is a progress bar of indeterminate length", and displays a "throbbing bar".

Resolving patch:
diff --git a/examples/progressbar/progressbar/app.py b/examples/progressbar/progressbar/app.py
--- a/examples/progressbar/progressbar/app.py
+++ b/examples/progressbar/progressbar/app.py
@@ -2,6 +2,8 @@
 from toga.style import Pack
 from toga.constants import ROW, COLUMN
 
+MAX_PROGRESSBAR_VALUE = 100
+
 
 class ProgressBarApp(toga.App):
 
@@ -10,10 +12,7 @@ def startup(self):
         self.main_window = toga.MainWindow(title=self.name, size=(500, 500))
 
         # the user may change the value with +/- buttons
-        self.progress_adder = toga.ProgressBar()
-
-        # the user may switch between "running" mode and a set value
-        self.progress_runner = toga.ProgressBar(max=None)
+        self.progress_adder = toga.ProgressBar(max=MAX_PROGRESSBAR_VALUE)
 
         # set up common styles
         label_style = Pack(flex=1, padding_right=24)
@@ -55,12 +54,18 @@ def startup(self):
 
             toga.Box(style=row_box_style, children=[
                 toga.Label("determinate ProgressBar", style=label_style),
-                toga.ProgressBar(max=1, running=False, value=0.5),
+                toga.ProgressBar(
+                    max=MAX_PROGRESSBAR_VALUE,
+                    running=False,
+                    value=0.5 * MAX_PROGRESSBAR_VALUE),
             ]),
 
             toga.Box(style=row_box_style, children=[
                 toga.Label("running determinate ProgressBar", style=label_style),
-                toga.ProgressBar(max=1, running=True, value=0.5),
+                toga.ProgressBar(
+                    max=MAX_PROGRESSBAR_VALUE,
+                    running=True,
+                    value=0.5 * MAX_PROGRESSBAR_VALUE),
             ]),
         ])
 
@@ -79,7 +84,7 @@ def toggle_running(self, switch, **kw):
             self.progress_adder.max = None
             self.progress_adder.start()
         else:
-            self.progress_adder.max = 1
+            self.progress_adder.max = MAX_PROGRESSBAR_VALUE
             self.progress_adder.stop()
 
 
diff --git a/src/winforms/toga_winforms/widgets/progressbar.py b/src/winforms/toga_winforms/widgets/progressbar.py
--- a/src/winforms/toga_winforms/widgets/progressbar.py
+++ b/src/winforms/toga_winforms/widgets/progressbar.py
@@ -10,21 +10,31 @@ def create(self):
         self.native = WinForms.ProgressBar()
 
     def start(self):
-        '''Not supported for WinForms implementation'''
-        self.interface.factory.not_implemented('ProgressBar.start()')
-
-        # possible implementation (not tested):
-        # self.native.Style = ProgressBarStyle.Marquee
+        self.set_running_style()
 
     def stop(self):
-        '''Not supported for WinForms implementation'''
-        self.interface.factory.not_implemented('ProgressBar.stop()')
+        self.set_stopping_style()
 
-        # possible implementation (not tested):
-        # self.native.Style = ProgressBarStyle.Continuous
+    @property
+    def max(self):
+        return self.interface.max
 
     def set_max(self, value):
-        self.native.Maximum = value
+        if value is not None:
+            self.native.Maximum = value
+        if self.interface.is_running:
+            self.set_running_style()
+        else:
+            self.set_stopping_style()
+
+    def set_running_style(self):
+        if self.max is None:
+            self.native.Style = WinForms.ProgressBarStyle.Marquee
+        else:
+            self.native.Style = WinForms.ProgressBarStyle.Blocks
+
+    def set_stopping_style(self):
+        self.native.Style = WinForms.ProgressBarStyle.Continuous
 
     def set_value(self, value):
         self.native.Value = value


Test patch: