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.
Programmable keys in Pythonista for quickly wrench actions execution
-
Flex tells you what happens when the containing view is resized. The way to envision things are springs or bars connecting the top, left, right and bottom of the view to the corrrsponding edge of the parent, and also a bar across (width) and vertical (height) of your view.
By "flexing" one of these, it becomes a spring.
So, for example, 'W' will allo the width to be flexible -- so keeps the same margin to the parent view by adjusting your view's size.
L means that the left side can float (anchors to the right)
LW means it is anchored to the right side, and the width is resized as the parent is resized. -
Hi @JonB, thank you for explanation, but in general where can I find documentation about flex and other similar advanced things in order to customize Pythonista IDE?
Thanks
Regards -
Flex is somewhat documented in the you docs. The native version is called autoresizing masks, which you can do Google searches for.
The other approach that might work better for you is a custom view class that implements a layout method. Then, you can relayout the entire view when orientation changes, such as doing one long bar in landscape and two bars in portrait...
-
@JonB Thank you for your answer, and yes, it is interesting to know that user could have a view "A" when in portrait and a view "B" when in landscape. I like your idea about having two short bars in portrait and a single long bar in landscape, obviously it makes sense for little idevices, no problem with ipads.
The only problem about having a single long bar in landscape mode is how to show the triangle key at up-right corner in landscape in order to hide/show the bar based on user choice.
My curiosity: in Pythonista how can user write some python code that executes an external script when in portrait and an other external script when in landscape (I mean, immediately after rotating the device in portrait or landscape mode?)
Thank you very much,
Regards -
The original code ensured the right corner was aligned to the right side of the screen, then flex='L' kept it there.
Another option is a custom
layout
method, which would run code as you describe.It is possible to write a notification handler to register for rotation events. in objc that looks like
[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)name:UIDeviceOrientationDidChangeNotification object:nil];
but in this case, the StatusBarOverlay would already get these events, so a method named layout would get called automatically, so i wouldnt go that complexity (have to create an objclass, objcinstance, and manage its lifetime)
-
@JonB Hi, thank you, I will try to write a script that executes script A when idevice is in portrait and script B when in landscape. But first of all I will need to study something about what you posted ;-)
I just finished to add a key action to the user buttons bars that executes any python script with the remote server provided by SageMathCell: now I have the 12th user key (last one of second bar, that is over the built-in Run key) that executes the opened script in editor with remote Sage interpreter, without need to open the big wrench window that freezes the entire editor (with it I can't scroll up/down, swipe, add new values in the script, etc...).
Question: how can I force Pythonista to switch automatically to Console window after the execution of any script? Purpose: I'd like to see always the output in Console of a script without manually swiping with finger from right to left. I noticed that the very first execution switches to Console and the next executions of the same script/action work well but can't switch automatically to Console.
Thank you
Regards -
okay, here is a working version of a multiline toolbar, that adjusts as needed for orientation. If the buttons don't fit on one line, a second line is added. Not the cleanest code, but works.
I also showed some examples of using draw_string to add text within an existing icon, or custom icons.
def show_console(sender):
app.keyWindow().rootViewController().showAccessoryWithAnimationDuration_(1)is an action you can use to show the console.
-
Hi @JonB, thank you so much for your scripts!
The code:
app.keyWindow().rootViewController().showAccessoryWithAnimationDuration_(0.5)
works well in any user button created with original StatusBarOverlay by you and with the modified version for two bars in portrait mode.
About your new script I will try to inspect it and do some tests in order to create one long bar with 12 keys in landscape mode (with the right up corner key to show/hide the long bar).
An other idea in my mind about user keys is the creation of a key that executes the current script opened in editor but with a pre and post processing, that is: when touching that key, 1) it executes a script "pre.py" , 2) then executes the current main script opened in editor, and 3) finally executes a script "post.py". An usage example is : I want to execute only some parts of the opened script by preprocessing it and then creates automatically an animation of several images in a folder or creates a well formatted pdf of all variables of the main current script after its execution.
I will try to write a generic "recipe" to execute pre, main and post script, maybe next weekend, in order to have a second RUN button similar to the built-in one but with pre-post proc.Thank you
Regards