Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
UI module on desktop that bridges kivy
-
Hi, all.
As the title suggests, I started to write ui module on desktop which bridges between ui.py on Pythonista and kivy on desktop.To give you an idea, here's a sample python script that's working on both Pythonista and desktop.
(I will omit .pyui since it's too long and unimportant here)import ui def button_tapped(sender): '@type sender: ui.Button' # Get the button's title for the following logic: t = sender.title global shows_result # Get the labels: label_sentence = sender.superview['label_sentence'] input_sentence = sender.superview['input_sentence'] label_answer = sender.superview['label_answer'] if t == 'Check': label_answer.text = input_sentence.text v = ui.load_view() label_sentence = v['label_sentence'] input_sentence = v['input_sentence'] label_answer = v['label_answer'] label_sentence.text = 'test' v.present('sheet')
I can't run this script on desktop because there is no ui module.
So, I wrote ui.py that internally calls kivy.
it's working with Button(along with its action function), Label, TextField classes so far.Q) My code is based on ui.py from Pythonista. Can I upload my code to a public repository such as github?
I'm aware of the fact that there are similar topics on this forum.
https://forum.omz-software.com/topic/1869/ui-on-desktop
https://forum.omz-software.com/topic/3964/unipage-as-a-bridge-between-kivy-and-pythonistaHowever, I couldn't find the way to meet my goal: run scripts with .pyui on desktop without ANY modification
UniPAGe has a great advantage that it can run on five major platforms with almost identical visuals, but with no disrespect, it has a disadvantage that one has to write the script with it from the start. Also, I think it deprives Pythonista of its great UI editing ability since a variety of attributes including the position and size have to be hard-coded inside the script.
-> UniPAGe now has a visual interface designer. Check it out hereOne might think what I'm trying to achieve is a little bit odd because ui module is not universal--it could be only used in Pythonista.
I am a software engineer and python is not my main language.
If I use python, that would be mainly on Pythonista.
Occasionally, I would like to run it on desktop too.
My work will minimize inconvenience to such a job.I can say I am almost new to python.
So, things I understood and mentioned above could be wrong.
I would appreciate if you correct me. -
I like this approach. This allows me to write simple scripts with UI in Pythonista and give them to business people in our company (simple stats, tables, ...). Nothing fancy, but I'm just trying to solve the same thing.
EDIT: Not actually trying, but just thinking how to do it :)
-
@hylo, I assume this is limited to standard UI components that are editable with Pythonista UI editor? This means that if I have a ui.View with a custom draw method, I would be out of luck.
-
@zrzka Thank you for your supporting reply. This could benefit lots of people like you and me in the future, though it is in a nascent stage right now. I only checked Labels, TextField, Button, and the Button's action that just copies the TextField's content into Label object's text when it is clicked. If the module code goes public, we all can develop together in a faster way. However, I guess that needs @omz's permission because, as far as I know, ui.py in Pythonista belongs to them.
@mikael Hello. I've never used custom view before. But while I was working on this module, I saw several lines of code regarding custom view and custom attributes in the very function I modified. After I created a custom view on Pythonista UI editing interface and glanced its attributes, I am optimistic about it. You might want to look at ui.py in Pythonista.
(Standard Library -> site-packages -> ui.py) -
@hylo you no longer have to hard code GUI elements into UniPAGe. A visual Interface Designer based on UniPAGe allows the user to create interface components a the click/touch of a button. They can be dragged and positioned anywhere on the screen. In the latest version their sizes can also be modified by stretching them with a mouse or finger. You may also save a fully functional UniPAGe script comprising the created interface. That script is located here in this forum.
-
@Ti-Leyon I saw the title, GAP, but I didn't know it is the visual interface designer! I have tried it. Although it currently lacks the graphical way of editing attributes, it is a great work. I would definitely use UniPAGe and GAP if my code needs to run on several platforms. Thanks for your hard work.