@JonB Wonderful, it works! I used the code:
Really, @JonB how can you know these things? However, now I have a code that creates, every time I launch Pythonista, two buttons, at left and at right of upper bar. The left one, if touched, shows six little squares buttons (one button for one action). The right one, if touched, hides the six buttons.
Maybe you will find this a little easy, but for me it is a great thing ;-)
How can I program the left button in order to use it both for showing and hiding of the six user buttons? I mean, when the six buttons are showed, touching the left button should hide them; when the six buttons are hidden, touching the left button should show them.
Can Pythonista execute automatically a script every time user changes iphone screen from portrait to landscape and viceversa? Inside 'pythonista_startup.py'?
@cvp thank you for info about buttons size. But the last two values in:
are a bit strange for me: what do they mean (40 and 40)?
And I can't show any text inside my buttons. Can you kindly show me what and where I must add some code for button text? Let's imagine the user button must show the text "Copy": what should I do in the following code (JonB's apphack.py) to add text inside the button?
# coding: utf-8
''' 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 __ '''
from objc_util import *
from functools import partial
#get main editor toolbar, by recursively walking the view
for v in sv:
'''create a button on main toolbar, with action, imagename, index location, and string tagname. button and action are stored in __persistent_views[index]. tag allows finding view using tb.viewFromTag_(hash(tag)) (old idea)'''
#check for existing button in this index and delete if needed
#add new button to the left of the rightbuttons. index 0 is next to left buttons, index 1 is further left, etc
#store so it is not cleared.
'''run a script without clearing glbals'''
Thank you so much!