Skip to content
This repository has been archived by the owner on Aug 15, 2017. It is now read-only.

toga-demo error in windows with python3.5 32-bit #4

Open
aeroaks opened this issue Jun 24, 2016 · 15 comments
Open

toga-demo error in windows with python3.5 32-bit #4

aeroaks opened this issue Jun 24, 2016 · 15 comments

Comments

@aeroaks
Copy link

aeroaks commented Jun 24, 2016

executing toga-demo in command prompt gives the following error:

REQUEST FOR MIN MAX INFO
1 1771694
2 1771694
Traceback (most recent call last):
  File "c:\python35-32\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python35-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python35-32\Scripts\toga-demo.exe\__main__.py", line 9, in <module>
  File "c:\python35-32\lib\site-packages\toga_demo\__main__.py", line 90, in main
    app = DemoApp('Toga Demo', 'org.pybee.toga-demo')
  File "c:\python35-32\lib\site-packages\toga_win32\app.py", line 19, in __init__
    self._startup()
  File "c:\python35-32\lib\site-packages\toga_win32\app.py", line 25, in _startup
    self.startup()
  File "c:\python35-32\lib\site-packages\toga_demo\__main__.py", line 13, in startup
    left_container = toga.OptionContainer()
AttributeError: module 'toga' has no attribute 'OptionContainer'
@freakboy3742
Copy link
Member

Thanks for the report - this is a known problem; Windows support for Toga is fairly limited at the moment. If you've got experience with Windows GUI development, it's an area where we need a lot of help.

@aeroaks
Copy link
Author

aeroaks commented Sep 28, 2016

@freakboy3742 Would be interested in working on it but would need some guidance on how to approach it! (newbie in contributing)

@freakboy3742
Copy link
Member

freakboy3742 commented Sep 28, 2016

Repeating some info provided in Gitter, as a guide to anyone interested in helping:

The Windows backend that is there right now uses Win32 APIs, which are really old - so the apps look really old when they run.

The problem, though, is that all the newer windows APIs are either C++ or C#. C++/C# APIs can’t use the ctypes trick that works on macOS, because there isn’t a common calling convention for C++ or C#.

The C# bindings are the most interesting, because all the most recent APIs are C#. So - the first problem to tackle: How do you invoke a C# method from Python?

There are two approaches I can think of.

We could either:

  1. Write a bridge layer with a C API that enables you to invoke C# class reflection APIs in the C# runtime. You could then use that bridge to invoke any C# API.
  2. Write a compiler to convert Python bytecode into CIL bytecode, so that Python becomes a native .net assembly.

(2) might sound complex, but it’s exactly what we’re doing with VOC to support Python on Android (except that it’s Java bytecode there) but before we go down that rabbit hole, I’d like to rule out whether (1) can be done.

So - the initial exploratory task: Write a C# module with a C api that lets you get a reference to a C# class, invoke a method on the C# class, and so on. Call that C API from Python, using CTypes.

@freakboy3742
Copy link
Member

On Gitter, @ethanhs pointed me at pythonnet, which may be exactly what we need here.

@aeroaks
Copy link
Author

aeroaks commented Oct 12, 2016

Sound promising, Will give it a try!

@beltiras
Copy link

I'm interested in working on this. I can take a look at https://github.com/pythonnet/pythonnet before we meet up in Amsterdam in a week's time. Looks like a promising solution.

@ethanhs
Copy link

ethanhs commented Oct 25, 2016

I was initially looking at doing a backend that leverages WPF, but I'm not sure if that is the right thing to do. WPF was really meant to be used with XAML, so while one can use it without, it seems to be using it for something it isn't meant for.

Also, we could use WinForms, but at that point, I think using the Common Controls through ctypes or such might be faster...

I suppose just because no one uses WPF widgets solely outside of XAML shouldn't discourage us...

@arnists if you are interested in working on it, I will defer to you to start the bindings if you want, I'm pretty busy anyway.

@den-run-ai
Copy link

You can look at pywebview to see how pythonnet can be used to write WinForms apps:

https://github.com/r0x0r/pywebview

Pythonnet repository has 3 demo GUI apps using WinForms, which should also run on Mono.

Windows 10 has UWP, but the path for Python is not clear.

@ethanhs
Copy link

ethanhs commented Mar 9, 2017

I mean, Martin Loewis was able to port Python to WinRT (The Windows 8 app ecosystem). It shouldn't be too hard to port Python to UWP. I will point out WPF scales much better on HiDPI displays than WinForms.

@den-run-ai
Copy link

pythonnet also works with WPF, but I have not finished the demo yet:

pythonnet/pythonnet#280

I did not find examples of WPF without XAML. XAML compiles to BAML binaries and has very tight coupling to WPF and .NET.

@gautamkrishnar
Copy link

gautamkrishnar commented Apr 2, 2017

I can't even use toga-demo app:

C:\WINDOWS\system32>toga-demo
Traceback (most recent call last):
  File "c:\program files\python35\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\program files\python35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python35\Scripts\toga-demo.exe\__main__.py", line 5, in <module>
  File "c:\program files\python35\lib\site-packages\toga_demo\__main__.py", line 6, in <module>
    from .app import TogaDemo
  File "c:\program files\python35\lib\site-packages\toga_demo\app.py", line 4, in <module>
    import toga
ImportError: No module named 'toga'

@ghost
Copy link

ghost commented Apr 23, 2017

Should a new issue be opened to track implementing OptionContainer? (which is what the demo currently crashes on)

@freakboy3742
Copy link
Member

@voltagex It's not essential; referencing the WIP PR on this ticket is essential. However, if you think a ticket will aid coordination, feel free.

@den-run-ai
Copy link

CPython on UWP:

https://github.com/ms-iot/python/releases

@ethanhs
Copy link

ethanhs commented Jun 26, 2017

Does that run on Desktop UWP though? Last I heard it was Raspberry Pi/Arm only.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants