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.
Automatic .py-script from .pyui?
-
Hello coder community,
I am new to Python and I haven't written code for some while.
I specifically want to write gui with python.
At home I have managed to install Pyqt5 and run some test variants in Visual Studio Code.
My biggest problem was that all video tutorials are dated.
They refere to Python 2.7 or some Python 3 variants before Python 3.5.
Nevertheless now I know how and what to import.On the go I want to learn and use python as well.
That is why I want to ask:
Is there a way that placed modules in the .pyui file are implemented
in the .py file as code automatically?That would drastically help me.
Right now I don't even know what to write to talk to the .pyui file, nor to the
modules in it. Like to a button.Thank you in advance.
-
I found und this topic:
https://forum.omz-software.com/topic/3931/beginner-custom-ui-how-to-get-the-python-script
The given code doesn't work, because there is no module "workflow"
that I can import.
Do I have to install this module "workflow" first? -
The
workflow
module only exists in Editorial, which is another app from the developer of Pythonista (it's a text editor for languages like Markdown, and allows automation via "workflows" and Python scripts). The code from the thread you linked only makes sense within an Editorial workflow, it does some work with a view loaded from the workflow. In Pythonista you can do basically the same usingui.load_view
.That doesn't do what you're looking for though - while
ui.load_view
makes the contents of a .pyui file available as aui.View
object in the Python script, there's no built-in way to convert that back to Python code. It's possible that someone has written a script to convert a .pyui to Python code, but if so I don't remember. Maybe someone else knows. -
https://github.com/humberry/ui-tutorial Is a good place to start.
-
I want to thank you both for helping me.
It would be helpful if Pythonista would allow to copy an existing script / file and be able to rename this file.
Than I could rename the .pyui file to an .py file and just read what Pythonista does in the background.Nevertheless I will look up the examples / tutorials on GitHub.
The .pyui scripts are exactly what I wanted to see.
Right now I can´t do anything with them, but it´s good to know how I could look them up.Thank you :)
-
OK. Got it.
I have to import the hello_world_v2.pyui script first and copy it into a script file. Can be hello_world_v2.py as well and then change .py to .pyui. When I have imported the .py text into the hello_world_v2.py file I have to rename the .pyui file to hello_world_v2_1.py to read the script.Great. That´s how I can learn.
-
.pyui
files are not Python files. Instead,.pyui
files contain json. The Python interpreter can not execute a.pyui
file but Pythonista's ui module can load them and render their ui.Normally when you open a
.pyui
file in the Pythonista editor, it opens them in the ui builder so that you can view and modify the ui elements. If you want to view the json code in a.pyui
file then you need to change the file extension of that file.json
. You do this by clicking on the title of the file in the editor and then clicking the box with three dots [...] just to the right of the title. MyFile.pyui will open in the ui builder and MyFile.json will be viewable/editable as json text. -
I wrote a script that converts the pyui attributes into text for copying into a py file as code. I will take a bit of manipulation to convert over some of the attributes, but it should help get you started. The code is available here.