youey - intro to the concept
mikael last edited by
What is it?
What does it look like?
Here is a picture of the same piece code running on an iPhone, iPad and a Mac:
And here is the code:
from youey import * from faker import Faker fake = Faker() class DemoApp(App): def setup(self): container = NavigationView(self, title='Demo', flow_direction=VERTICAL ).container for _ in range(10): card = StyledCardView(container, size=(225,125)) card_title = LabelView(card, text=fake.sentence( nb_words=3, variable_nb_words=True)[:-1], font=card.theme.headline, text_color=card.theme.primary, text_align=LEFT, padding=(5, 10) ).dock_top() card_text = LabelView(card, text=fake.text(), text_align=LEFT, padding=(0, 10), top=Bottom(card_title) ).dock_bottom() app = DemoApp()
The iPad version includes an additional line, to adjust the theme:
View.default_theme = Theme(Grey1, Dark)
What am I seeing here?
Early days, but there's already several things going on:
- Running same code on Pythonista and pywebview WebViews.
- No servers involved.
- "Layout for humans", defining element placement with dynamic constraints rather than pixels ("set the top of this view to be where the bottom of another view is").
- Influenced but not limited by Pythonista UI.
- Coding follows desktop/mobile UI coding conventions, not web coding conventions.
- ... but, where applicable, we take advantage of web capabilities, like views flowing freely in a container view.
- Responding to events like resizing.
Where is it?
Why are you re-inventing the UI wheel?
Even though there are a number of platform-independent UI projects out there, I am opinionated about how I want to write UIs, and did not find this exact approach used elsewhere.
I found pywebview, a very useful project focused on providing a consistent Python API to WebView implementations on different platforms. At about the same I accidentally implemented a convenient JS wrapper for web scraping, and then realized it could be used for more.
What are the limitations?
- I have only tried this on Apple devices. Trials on Linux and Windows - and Android? - would probably also be in order.
- Python 3.6.
- Limited documentation and testing, for a while.
Images and other basic views, events, animation, data models etc.
Even though youey is purposefully platform-independent, I develop primarily on my phone, and would like to discuss new features here.