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.
A compact text based alternative to pyui
-
Here is a compact text based alternative to pyui.
https://github.com/balachandrana/textlayoutI have used the existing examples calculator and colormixer for illustrating layout specification . A compact representation of attribute initialization is getting implemented. The implementation is in early stage. Since there is a discussion related to positioning ui element, I thought this may be useful in getting some comments on this layout specification.
https://forum.omz-software.com/topic/3402/share-position-a-ui-control-in-a-viewThe layout text specifies position and size of each ui element in the application. The lines in the text represent rows in the grid and each character in a line represents a grid cell. Each ui element is represented by a single letter (b - represents button, s - represents slider l - label etc.) A blank cell is represented '*'.If an element spans more than a cell, the characters '-' and '|' can be used to specify horizontal and vertical spanning. Overlaps are not allowed currently.
Currently attributes are represented by a dictionary. A compact representation is getting implemented.
Here is a sample layout specification for counter application with one label (counter value) and one button (tapping the button increments the counter). The label element is a single row with four horizontal cells and the button element is a rectangular box of 3*4 cells.
import ui, textlayout cnt = 0 def button_action(sender): global cnt cnt += 1 sender.superview['label1'].text = 'Counter:' + str(cnt) layout_text = '''\ ******** **l---** ******** ******** **b---** **|--|** **|--|** ******** ******** ''' attributes = { 'b':[ {'action':button_action, 'font' :('Helvetica', 20), 'title':'Tap to increment counter' }], 'l':[ { 'text': 'Counter:0', 'alignment': ui.ALIGN_CENTER, 'font':('Helvetica', 20) } ] } v = textlayout.BuildView(layout_text, width=600, height=600, view_name='Counter', attributes=attributes).build_view() v.present('popover')
-
@abcabc , this is nice. Certainly a different approach.
But I think to be a full alternative to pyui would be really difficult. I am not sure what you are aiming for as far as being a replacement. But things like Custom View Classes, Custom Attributes, Subviews etc is were a lot of the power of the pyui/designer is.
But I still really like your idea.
Look I think you can see I am far from good at this stuff. But it does strike me a solution as you have done would me more suited to creating custom views. I know you are creating a view now to display. But if your emphasis was on creating a custom view, that is either used by a pyui object or inserted into existing views, the focus would be more sharp. Not focused on trying to be alternative to pyui. Huge job, I think.Anyway, that's just my idea. I have been wrong about many things before.
My head is spinning though, I really like the text layout
-
I have created a new repository that supports compact attribute specification
and it also includes some more examples.https://github.com/balachandrana/pythonista_textlayout
Attributes could be compactly specified as follows for the above counter example.
attributes_text = ''' b background_color title font_name font_size action whitesmoke Tap_to_increment_counter Helvetica 20 button_action l background_color text alignment font_name font_size whitesmoke Counter:_0 center Helvetica 20 '''
The full code is given below:
import ui, textlayout def button_action(sender): label = sender.superview['label1'] label.text = 'Counter: ' + str(int(label.text.split()[-1]) + 1) layout_text = ''' ******** **l---** ******** ******** **b---** **|--|** **|--|** ******** ******** ''' # attributes specification attributes_text = ''' b background_color title font_name font_size action whitesmoke Tap_to_increment_counter Helvetica 20 button_action l background_color text alignment font_name font_size whitesmoke Counter:_0 center Helvetica 20 ''' # attributes transformation specification attr_transform_map = { 'action': lambda x:globals()[x] if x in globals() else None, 'title': lambda x:x.replace('_', ' '), 'text': lambda x:x.replace('_', ' ') } v = textlayout.BuildView(layout_text, width=600, height=600, view_name='Counter', attributes_text=attributes_text, attr_transform_map=attr_transform_map).build_view() v.present('popover')
-
@Phuket2 thanks for your comments. It is not a replacement for pyui, though it aims to cover all the features of pyui. Text based system has some advantages like:
(a) you can cut-and-paste from other projects
(b) you can easily edit it
(c) programatically you can generate layout and attribute specifications. For example it is easy to generate large number of buttons as in the scientific calculator example.
(d) various themes can be represented by text based style sheets
(e) we can even generate pyui file from this specification ( I have not included this in current release). Other way (i.e. from pyui to text based specification) is also possible but I have done any work on that.It is not just limited to pyui. We could use it in custom views for placement of various shapes and images. May be I will post an example later.
Furthermore I have borrowed a lot of ideas from you, JonB, ccc, omz and many others. So the community can use some of these ideas and can come up with better tools. (Anyway I am just a bored, retired, old man and wasting time is not an issue.)
-
@abcabc , sorry I didn't mean to intimate you were wasting your time. I was just commenting from how I could see it. But I know I don't see everything clearly 😬
Anyway, appears we are both the same. Old and retired. Nothing is urgent anymore.My comments come partly from I am really becoming a big fan of the Designer. In the past I was not, mostly for the wrong reasons. But some reasons were valid some time ago. But a lot of things have changed since then. Not really important, just I really like what you can do now with it.
-
Looks like a fun little project, but it doesn't address the biggest obstacle to Pythonista users -- the fact that there's no common GUI for Pythonista and other Python implementations.
Do you reckon some of the basic UI elements could be abstracted to map onto both Pythonista's
ui
module and something else for other Python implementations? -
@Niall Thanks for your interest and comments. I think that this UI tool (A compact text based alternative to pyui) could be modified to support kivy. Actually this tool is somewhat inspired by kivy language (KV lang or kvlang). Initially I tried specifying
attributes like in kvlang and later used a more compact form.I have also written a tool that could run pythonista-scene based programs including shader in mac and pc.
https://github.com/balachandrana/pythonista_pyglet_simulation
The forum post related to this is here.
https://forum.omz-software.com/topic/3196/running-pythonista-scene-based-programs-including-shader-in-mac-and-pcScene is not just for games and it can do many functions of UI. Scene may be better if your application is animation and
graphic intensive. The above tool could be easily modified to support pygame.Do you reckon some of the basic UI elements could be abstracted to map onto both Pythonista's ui module and something else for other Python implementations?
If you look at the following forum post, I have given an example that uses this layout function for placement of various shapes and images in custom views.
https://forum.omz-software.com/topic/3402/share-position-a-ui-control-in-a-viewPlease let me know if you have any specific needs.