Repository: beeware/toga

Issue:
toga-demo alias doesn't work on Windows
## Expected Behavior
Examples in the documentation should work.  I have to specify version 0.2.15 for anything to run properly - the normal pip installation of toga installs the dev builds that are not functioning.


## Current Behavior
They all fail with various errors of missing items, etc.
```
C:\Users\bubth\Development\togatest> pip install --pre toga-demo
Collecting toga-demo
  Downloading https://files.pythonhosted.org/packages/33/05/61d94bccdfe6831eb60fc59cd79c60d7780983d07df984d82e2a8f298b8b
/toga_demo-0.3.0.dev19-py3-none-any.whl (616kB)
     |████████████████████████████████| 624kB 819kB/s
Collecting toga==0.3.0.dev18 (from toga-demo)
  Downloading https://files.pythonhosted.org/packages/9c/cd/4ec127b063c9b1c6f045791e7613e05247dc30e0cb817bccf09de9377ecf
/toga-0.3.0.dev18-py3-none-any.whl
Collecting toga-winforms==0.3.0.dev18; sys_platform == "win32" (from toga==0.3.0.dev18->toga-demo)
  Downloading https://files.pythonhosted.org/packages/81/67/6e16ddc4c4286a4b6f08005c66006524e305c3befca01df34f509ef76202
/toga_winforms-0.3.0.dev18-py3-none-any.whl
Collecting toga-core==0.3.0.dev18 (from toga-winforms==0.3.0.dev18; sys_platform == "win32"->toga==0.3.0.dev18->toga-dem
o)
/toga_core-0.3.0.dev18-py3-none-any.whl (512kB)
     |████████████████████████████████| 522kB 6.8MB/s
Requirement already satisfied: pythonnet in c:\program files\python37\lib\site-packages (from toga-winforms==0.3.0.dev18Requirement already satisfied: importlib-metadata; python_version < "3.8" in c:\users\bubth\appdata\roaming\python\pythotoga-demo) (0.18)
Collecting travertino>=0.1.0 (from toga-core==0.3.0.dev18->toga-winforms==0.3.0.dev18; sys_platform == "win32"->toga==0.3.0.dev18->toga-demo)
  Downloading https://files.pythonhosted.org/packages/4c/78/b33e38d372707fbf2c461d1bde6797a12c8d20f97279db63cb57dc24eacb/travertino-0.1.3-py3-none-any.whl
Requirement already satisfied: zipp>=0.5 in c:\users\bubth\appdata\roaming\python\python37\site-packages (from importlib-metadata; python_version < "3.8"->toga-core==0.3.0.dev18->toga-winforms==0.3.0.dev18; sys_platform == "win32"->toga==0.3.0.dev18->toga-demo) (0.5.2)
Installing collected packages: travertino, toga-core, toga-winforms, toga, toga-demo
  Found existing installation: toga-core 0.2.15
    Uninstalling toga-core-0.2.15:
      Successfully uninstalled toga-core-0.2.15
  Found existing installation: toga-winforms 0.2.15
    Uninstalling toga-winforms-0.2.15:
      Successfully uninstalled toga-winforms-0.2.15
  Found existing installation: toga 0.2.15
    Uninstalling toga-0.2.15:
      Successfully uninstalled toga-0.2.15
Successfully installed toga-0.3.0.dev18 toga-core-0.3.0.dev18 toga-demo-0.3.0.dev19 toga-winforms-0.3.0.dev18 travertino-0.1.3
WARNING: You are using pip version 19.2.1, however version 20.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\bubth\Development\togatest> python --versoin
unknown option --versoin
usage: C:\Program Files\Python37\python.exe [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.
C:\Users\bubth\Development\togatest> python --version
Python 3.7.3
C:\Users\bubth\Development\togatest> toga-demo
Traceback (most recent call last):
  File "c:\program files\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\program files\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python37\Scripts\toga-demo.exe\__main__.py", line 9, in <module>
  File "c:\program files\python37\lib\site-packages\toga_demo\__main__.py", line 5, in run
    main().main_loop()
  File "c:\program files\python37\lib\site-packages\toga_demo\app.py", line 98, in main
    return TogaDemo('Toga Demo', 'org.beeware.toga-demo')
  File "c:\program files\python37\lib\site-packages\toga\app.py", line 184, in __init__
    self.icon = 'resources/{app_name}'.format(app_name=self.app_name)
  File "c:\program files\python37\lib\site-packages\toga\app.py", line 317, in icon
    self._icon.bind(self.factory)
  File "c:\program files\python37\lib\site-packages\toga\icons.py", line 41, in bind
    resource_path = factory.paths.app
  File "c:\program files\python37\lib\site-packages\toga_winforms\paths.py", line 10, in app
    return Path(sys.modules[App.app.module_name].__file__).parent
KeyError: ''
C:\Users\bubth\Development\togatest>
```

```
Traceback (most recent call last):
  File ".\test.py", line 2, in <module>
    from toga.style.pack import Pack, ROW, CENTER, COLUMN
ModuleNotFoundError: No module named 'toga.style'
```

```
C:\Users\bubth\Development\togatest> python .\test.py
Traceback (most recent call last):
  File ".\test.py", line 24, in <module>
    main().main_loop()
  File "C:\Program Files\Python37\lib\site-packages\toga_winforms\app.py", line 49, in main_loop
    self._startup()
  File "C:\Program Files\Python37\lib\site-packages\toga_winforms\app.py", line 41, in _startup
    self.startup()
  File "C:\Program Files\Python37\lib\site-packages\toga\interface\app.py", line 144, in startup
    self.main_window.content = self._startup_method(self)
  File ".\test.py", line 9, in build
    box = toga.Box()
  File "C:\Program Files\Python37\lib\site-packages\toga_winforms\widgets\box.py", line 10, in __init__
    super().__init__(id=id, style=style, children=children)
  File "C:\Program Files\Python37\lib\site-packages\toga\interface\widgets\box.py", line 21, in __init__
    super().__init__(id=id, style=style, children=children)
  File "C:\Program Files\Python37\lib\site-packages\toga\interface\widgets\base.py", line 144, in __init__
    self.style = CSS()
  File "C:\Program Files\Python37\lib\site-packages\toga\interface\widgets\base.py", line 170, in style
    self._style = value.bind(self)
AttributeError: 'CSS' object has no attribute 'bind'
```

## 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. Be on windows

2. install toga

3. Follow the browser tutorial or hello world tutorial


## Your Environment
<!--- Provide details on your current environment you found the bug in -->

* Python Version (list the specific version number)
```
C:\Users\bubth\Development\togatest> python --version
Python 3.7.3
```

* Operating System and Version (select from the following and list the specific version number; if your OS is not listed, list that as well)

```
OS Name	Microsoft Windows 10 Pro
Version	10.0.19041 Build 19041
Other OS Description 	Not Available
OS Manufacturer	Microsoft Corporation
System Name	LAPPYTOPPY
System Manufacturer	Micro-Star International Co., Ltd.
System Model	GP73 Leopard 8RF
System Type	x64-based PC
System SKU	17C5.1
Processor	Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz, 2201 Mhz, 6 Core(s), 12 Logical Processor(s)
BIOS Version/Date	American Megatrends Inc. E17C5IMS.10A, 7/13/2018
SMBIOS Version	3.1
Embedded Controller Version	255.255
BIOS Mode	UEFI
BaseBoard Manufacturer	Micro-Star International Co., Ltd.
BaseBoard Product	MS-17C5
BaseBoard Version	REV:1.0
Platform Role	Mobile
Secure Boot State	On
PCR7 Configuration	Elevation Required to View
Windows Directory	C:\WINDOWS
System Directory	C:\WINDOWS\system32
Boot Device	\Device\HarddiskVolume3
Locale	United States
Hardware Abstraction Layer	Version = "10.0.19041.1"
User Name	LAPPYTOPPY\bubth
Time Zone	Mountain Daylight Time
Installed Physical Memory (RAM)	16.0 GB
Total Physical Memory	15.8 GB
Available Physical Memory	4.19 GB
Total Virtual Memory	18.2 GB
Available Virtual Memory	4.69 GB
Page File Space	2.38 GB
Page File	C:\pagefile.sys
Kernel DMA Protection	Off
Virtualization-based security	Running
Virtualization-based security Required Security Properties	
Virtualization-based security Available Security Properties	Base Virtualization Support, Secure Boot, DMA Protection, SMM Security Mitigations 1.0, Mode Based Execution Control
Virtualization-based security Services Configured	
Virtualization-based security Services Running	
Device Encryption Support	Elevation Required to View
A hypervisor has been detected. Features required for Hyper-V will not be displayed.	
```

* Toga Version (list the specific version number or git hash)

```
C:\Users\bubth\Development\togatest> python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import toga
>>> toga.__version__
'0.3.0.dev18'
```

* Toga Target (the type of app you are trying to generate)

  - [ ] android
  - [ ] cocoa
  - [ ] django
  - [ ] gtk
  - [ ] iOS
  - [ ] tvOS
  - [ ] watchOS
  - [x ] winforms
  - [ ] win32
  - [ ] Other (please specify)



Discussion:
Thanks for the report. I can confirm I'm seeing the same problem with `toga-demo` on Windows; not sure what is going on there, but it's working fine on Cocoa, so there's something odd going on there. The problem seems to be entirely related to the `toga-demo` alias; if you run `python -m toga_demo`, it works fine (or, at least, it does for me).

As for the other tutorial problems you're reporting - `No module named 'toga.style'` and `'CSS' object has no attribute 'bind'` - that indicates you're using Toga 0.2 to run tutorial code that requires Toga 0.3. The install log that you've provided with toga-demo also shows that you have at some point installed toga 0.2.15. I'm not sure how you've got into that position, but if you've got toga 0.2 installed at all, it means you've strayed from the tutorial instructions somewhere.

The original errors were after doing the normal pip install toga, with no
arguments - I must have missed the --pre argument.

On Fri, May 29, 2020, 12:39 AM Russell Keith-Magee <notifications@github.com>
wrote:

> Thanks for the report. I can confirm I'm seeing the same problem with
> toga-demo on Windows; not sure what is going on there, but it's working
> fine on Cocoa, so there's something odd going on there. The problem seems
> to be entirely related to the toga-demo alias; if you run python -m
> toga_demo, it works fine (or, at least, it does for me).
>
> As for the other tutorial problems you're reporting - No module named
> 'toga.style' and 'CSS' object has no attribute 'bind' - that indicates
> you're using Toga 0.2 to run tutorial code that requires Toga 0.3. The
> install log that you've provided with toga-demo also shows that you have at
> some point installed toga 0.2.15. I'm not sure how you've got into that
> position, but if you've got toga 0.2 installed at all, it means you've
> strayed from the tutorial instructions somewhere.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/beeware/toga/issues/927#issuecomment-635790456>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AC5CHILSHO74KKGKJKJITUDRT5KCZANCNFSM4NNXMURQ>
> .
>

I've worked out what is going on with toga-demo, too; Due to a packaging error, toga-demo 0.3.0dev19 has pinned toga 0.3.0.dev18 as a requirement; as a result, it's installing a version of toga that is incompatible, which is exposing a bug on Windows. I'll commit a fix shortly. Apologies for the inconvenience.

As a workaround, you can `pip install toga==0.3.0dev19`; you'll get a warning about an inconsistency with toga-demo, but the problem will go away.

Resolving patch:
diff --git a/demo/setup.py b/demo/setup.py
--- a/demo/setup.py
+++ b/demo/setup.py
@@ -23,7 +23,7 @@
         'toga_demo': ['resources/*.icns', 'resources/*.png'],
     },
     install_requires=[
-        'toga==0.3.0.dev18'
+        'toga==0.3.0.dev20'
     ],
     entry_points={
         'console_scripts': [


Test patch: