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
-
- .....,40,40) = width and height of the button
Edit: if you add a text like 'copy' you could need to set a bigger width and no image - as explained in one of my previous posts, you can set the text, its color, etc...
btn.image = ... btn.title = 'copy' btn.action = ...
- .....,40,40) = width and height of the button
-
@Matteo If your actual
left button doesbtn1.hidden = True
right button does
btn1.hidden = False
Your future unique button could do
btn1.hidden = not btn1.hidden
-
@Matteo We would have to experiment, but a custom view class
layout
method, would get called upon rotation, assuming flex=`w'. -
https://gist.github.com/37e5115840bef9b898dba36ba3df5802
Here is an experiment, where I add a half-button at the top right corner of the screen (at battery icon), in the status bar. Tapping there pops down a menu. Tapping again makes it dissappear. You could adjust the size of this as desired. This seems somewhat cleaner, visually. At 32 height, buttons are tappable, and also could stay displayed without interfering with normal ui buttons. Things stay anchored correctly even with rotation.
This lives in the statusbar window, so is over top of everything, which might not be desirable... it might make more sense to keep the button in the statusbar, but keep the overlay in the editor, though this way, it is available even in console. You also have the whole screen to work with, if you want, so are not confined to the toolbar.
-
@JonB Whaaaaaaa, as usual
-
@JonB Impressive, really! Thank you! I still find hard to believe that you can do certain things with Pythonista.
I tried your script in my iPhone 4'' screen and works very well.
I've seen that the user buttons remain in the three Pythonista windows: file editor, text editor and python console. It is a wonderful thing in my opinion: in this way user can have quickly access to favourite actions in file editor window (for actions an files and folders) and in text editor window (for actions on text and strings).Your code is a little incomprehensible to me but I will try to adapt your work in order to use it with my frequent actions.
Thank you @JonB and @cvp for all help!
Regards -
@JonB Hi! Sorry but I can't solve a little problem with your code.
The procedure I follow to reproduce the issue is:
- full restart of Pythonista,
- run your script in order to show the half button in right up corner,
- write a simple python script like
print('hello')
, - execute the script with |> button (it automatically goes to console window),
- return to text editor windows and touch the half button,
- it return
NameError: global name 'ui' is not defined
.
Note that the user buttons in action bar work well: if I touch for example the button 'Blah' it print in console the number 50.0. The problem is that I can't anymore hide the full action bar.
When you have time, can you kindly test the issue? Thank you very much,
Regards
PS: I use Pythonista 3.1 (301016).
-
@Matteo put the import ui in the action def...
-
Right, your actions have to stand alone, and cannot rely on globals, or external imports. All imports must happen in the def itself. That's because globals and modules get cleared.
-
@JonB Why did __persistent_views not disappear?
-
-
@Matteo Really, @JonB did all the work, it was described in his comment at begin of script
''' A set of tools to add or delete custom buttons from the toolbar. This may not be super robust, but seems to work ok. Button objects and actions are saved so they survive global clearing, but thid has not been tested extensively. If a function relies on imports that occured outside of the function, these might dissappear -- user must make sure those modules are added to a module that is kept by pythonista, such as anything in site-packages, or name starting with __ '''```
-
@cvp variables with double underscores don't get cleared when running a script. Nor do modules in site-packages, modules starting with dunders, and a few other rules which I can never remember (you can look at pythonista_preflight.py)
-
@JonB Ok, understood, thanks. But, in this case, why to set this variable as global?
-
@cvp Yes you are right, I've tried to read JonB string at the beginning, but I don't have great programming knowledge so, when I read, lets say, 100 words about programming, I understand, the first time, about 20-30 %.
Anyway I will try to work with JonB script, that in my opinion gives to Pythonista much power for little screens (I repeat that Wrench action window of Pythonista is a wonderful feature, but in my little screen its window hides all my screen preventing me to see my code in text editor window).Regards
Bye -
-
@JonB Sorry, I feel very very little/bad/novice/zero (delete eventual useless adjectives, if any) but even that I can't 😢: I don't find this Pythonista_preflight?py
-
@cvp It's an internal script used by Pythonista, you can't find it anywhere in Pythonista's file browser. You can open it using the
editor
module though:import editor import os py3kit_dir = os.path.dirname(os.path.dirname(os.__file__)) editor.open_file(os.path.join(py3kit_dir, "pykit_preflight.py"))
-
@dgelessus Thanks, but I searched for pythonista_preflight.py 😢
-
@dgelessus & @JonB Thanks to both to help me to learn each day something's new.