pfalcon / picotui

Lightweight, pure-Python Text User Interface (TUI) widget toolkit with minimal dependencies. Dedicated to the Pycopy project.
https://github.com/pfalcon/pycopy
MIT License
811 stars 70 forks source link

How do you use this? #1

Closed dhylands closed 8 years ago

dhylands commented 9 years ago

I tried this:

2087 >python3 ./widgets_test.py
Traceback (most recent call last):
  File "./widgets_test.py", line 1, in <module>
    from .screen import *
SystemError: Parent module '' not loaded, cannot perform relative import

How should I go about running widgets_test.py ?

pfalcon commented 9 years ago

Ah, right, this hits on the one the biggest Python's warts I consider to exist. I run it with https://github.com/pfalcon/py-runinpkg , see https://code.activestate.com/lists/python-ideas/34866/ (and around it) for the whole story. Or you can move that file level up in dir structure and remove leading dots from imports. Again, I dislike needing to do that so much then I'd be happy to patch that up in MicroPython, if upstream can't handle it.

pfalcon commented 9 years ago

Ah, removing dots won't help - in front of dots, "picotui" should be added, e.g. "from .screen" -> "from picotui.screen".

And that's exactly the problem - that it's wildly context-dependent what you need to use in imports!

dhylands commented 9 years ago

I tried copying widgets_test.py up a level, replacing .screen etal with picotui.screen and from that directory:

2136 >python3 ./widgets_test.py 
Traceback (most recent call last):
  File "./widgets_test.py", line 3, in <module>
    from picotui.menu import *
ImportError: No module named 'picotui.menu'

I also grabbed py-runinpkg and tried it from within the picotui directory:

2139 >PYTHONPATH=../py-runinpkg/ python3 -m runinpkg ./widgets_test.py 
Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/dhylands/Dropbox/micropython/py-runinpkg/runinpkg.py", line 28, in <module>
    exec(open(fname).read(), _org_globals)
  File "<string>", line 3, in <module>
ImportError: No module named '.menu', 

I get the same error if I use an absolute path in PYTHONPATH pointing to py-runinpkg

pfalcon commented 9 years ago

Sorry about this, widgets_test.py was just internal test which I just code-dropped when I started to mention this library to people. .menu isn't yet ready (at all), and is not in repo, nor really used in widgets_test, so just remove it (I committed the fix). Thanks for reports!

pfalcon commented 9 years ago

And after that, it works with python3, but not micropython due to various integration issue. Fun ;-)

pfalcon commented 9 years ago

Well, it does, micropython-lib tty (maybe others too) module is required. Then it shows at least something, and fails on missing str.center(). And yeah, I believe I was morally ready to add it ;-).

dhylands commented 9 years ago

Ahhh. Yes commenting out the .menu import and I got it to work both ways. Cool.

pfalcon commented 8 years ago

This has been fixed, now picotui is a proper Python package, which works out of the box.