Beta expired
Let us pray
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.
Ole is back on Twitter and there is a new version of Editorial
And the new version of Pythonista will come soon.
@ihf said
This a (low priority) idea for the wish list: I sometimes want to read my outlines on the Mac. What I do now is save them in pdf or some other format that the Mac understands. This works fine but I have to remember to do it after any change so that the outline will be up-to-date. A reader script in python would permit me to view an outline on the Mac or on anything that runs python and has access to the iCloud files.
Written in my todo list, but when you say "view an outline", that will say use an UI...or print it in the console of this Python interpreter.
I have never used Python on a Mac, which free app do I need?
Little (not quick but still dirty) script to be executed once by Pythonista restart (fi in your pythonista_startup.py).
When you tap help in the popup menu of a selected text
After some seconds (function of your iDevice, the number and size of your scripts), you get a list of scripts containing the selected text (case insensitive)
If you select a script, you'll get, like for Pythonista help, a small (webview) window displaying the script as an html with Python syntax highlighting, where occurrences of selected text are also highlighted (in yellow)
If you search has also results in Pythonista help, you'll see both results in the list
The script imports @jonB's swizzle module
You can find this script here
@omz Welcome back and thanks for the future version. I'm sincerely more than happy that you feel better.
@Matteo Please could you try this code as a Pythonista tool.
First, you run the tool,
then you run a script with a console output,
then, in console mode, you type the text fo search and tap the 🔍 icon, and you will watch the miracle 😀
Sure that the code is not bug free, but it is good to start, if interested
The OMTextView does not allow to set text attributes as an UITextView but you can draw on it
from objc_util import *
import clipboard
import ui
@on_main_thread
def test(sender):
import console
import re
import ui
txt = str(sender.console.text())
if txt[-1] == '\n':
txt = txt[:-1]
win = ObjCClass('UIApplication').sharedApplication().keyWindow()
main_view = win.rootViewController().view()
ret = ''
def analyze(v):
for tv in v.subviews():
if 'OMTextView' in str(tv._get_objc_classname()):
su = tv.superview()
if 'OMTextEditorView' in str(su._get_objc_classname()):
continue
for sv in tv.subviews():
if 'SUIButton_PY3' in str(sv._get_objc_classname()):
sv.removeFromSuperview()
if txt == '':
return
t = str(tv.text())
#print('search',txt,'in',t)
for m in re.finditer(txt, t):
st,end=m.span()
p1 = tv.positionFromPosition_offset_(tv.beginningOfDocument(), st)
p2 = tv.positionFromPosition_offset_(tv.beginningOfDocument(), st+len(txt))
rge = tv.textRangeFromPosition_toPosition_(p1,p2)
rect = tv.firstRectForRange_(rge) # CGRect
x,y = rect.origin.x,rect.origin.y
w,h = rect.size.width,rect.size.height
#print(x,y,w,h)
l = ui.Button()
l.frame = (x,y,w,h)
l.background_color = (1,0,0,0.2)
l.corner_radius = 4
l.border_width = 1
tv.addSubview_(l)
ret = analyze(tv)
if ret:
return ret
ret = analyze(main_view)
@on_main_thread
def FindTextInConsole():
global console_tv
win = ObjCClass('UIApplication').sharedApplication().keyWindow()
main_view = win.rootViewController().view()
ret = ''
next_is_console = False
def analyze(v,indent):
global next_is_console
ret = None
for sv in v.subviews():
#print(indent,sv._get_objc_classname())
if 'UILabel' in str(sv._get_objc_classname()):
#print(indent,sv.text())
if str(sv.text()) == '>':
next_is_console = sv
else:
next_is_console = False
elif 'OMTextView' in str(sv._get_objc_classname()):
if next_is_console:
su = next_is_console.superview()
for ssv in su.subviews():
if 'SUIButton_PY3'in str(ssv._get_objc_classname()):
# rerun of this script, remove previous button
ssv.removeFromSuperview()
b = ui.Button(name='clipboard')
b.tint_color ='red'
b.image = ui.Image.named('iob:ios7_search_32')
b.background_color = 'white'
h = su.frame().size.height
b.frame = (2,2,h-4,h-4)
b.action = test
b.console = sv
#print(dir(sv))
retain_global(b)
su.addSubview(ObjCInstance(b))
ret = analyze(sv,indent+' ')
if ret:
return ret
ret = analyze(main_view,'')
return ret
if __name__ == '__main__':
r = FindTextInConsole()
You can also put a line with 3 quotes above and under these lines
'''
these
lines
are
commented
'''
@TableForGlasses In the console. Swipe from right to left to get it.
@kami For me, my little script here-under still works under iOS 16.3 and Pythonista beta
import ui
from objc_util import *
tv = ui.TextView()
tv.frame = (0,0,500,500)
tv.text = 'a'*12000
b = ui.ButtonItem()
b.title = 'bottom'
def b_action(sender):
tvo = ObjCInstance(tv)
tvo.scrollRangeToVisible_(NSRange(len(tv.text),0))
tvo.setScrollingEnabled_(False)
tvo.setScrollingEnabled_(True)
pass
b.action = b_action
tv.right_button_items = (b,)
tv.present('sheet')
@Enez-Houad did you read this topic, it speaks about stash
@Enez-Houad If, in the files explorer of Pythonista, you search "site-", you will see that site-packages-3 is still present, but, perhaps, hidden
@Enez-Houad Sure it is not yet done by installation ?
@Enez-Houad As it supports only one version of Python, only one site-packages is sufficient
Sorry, seems to be due to a pkg_resources folder in my site-packages, I don't know which package has imported it in the past.
Thus forget this false bug.
Code
import matplotlib.pyplot as plt
Gives
import matplotlib.pyplot as plt
File "/var/containers/Bundle/Application/FF9F9C4D-CB37-49D1-8111-7450226E1EA3/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/matplotlib/pyplot.py", line 44, in <module>
from matplotlib.figure import Figure, figaspect
File "/var/containers/Bundle/Application/FF9F9C4D-CB37-49D1-8111-7450226E1EA3/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/matplotlib/figure.py", line 19, in <module>
from matplotlib import docstring, projections
File "/var/containers/Bundle/Application/FF9F9C4D-CB37-49D1-8111-7450226E1EA3/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/matplotlib/projections/__init__.py", line 5, in <module>
from mpl_toolkits.mplot3d import Axes3D
File "/var/containers/Bundle/Application/FF9F9C4D-CB37-49D1-8111-7450226E1EA3/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/mpl_toolkits/__init__.py", line 3, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "/private/var/mobile/Containers/Shared/AppGroup/1B829014-77B3-4446-9B65-034BDDC46F49/Pythonista3/Documents/site-packages/pkg_resources/__init__.py", line 71, in <module>
__import__('pkg_resources.extern.packaging.requirements')
File "/private/var/mobile/Containers/Shared/AppGroup/1B829014-77B3-4446-9B65-034BDDC46F49/Pythonista3/Documents/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 672, in _load_unlocked
File "<frozen importlib._bootstrap>", line 632, in _load_backward_compatible
File "/private/var/mobile/Containers/Shared/AppGroup/1B829014-77B3-4446-9B65-034BDDC46F49/Pythonista3/Documents/site-packages/pkg_resources/extern/__init__.py", line 42, in load_module
__import__(extant)
File "/private/var/mobile/Containers/Shared/AppGroup/1B829014-77B3-4446-9B65-034BDDC46F49/Pythonista3/Documents/site-packages/pkg_resources/_vendor/pyparsing.py", line 696, in <module>
collections.MutableMapping.register(ParseResults)
AttributeError: module 'collections' has no attribute 'MutableMapping'
Code
font = ImageFont.truetype('Courier-Bold',24)
Gives
font = ImageFont.truetype('Courier-Bold',24)
File "/var/containers/Bundle/Application/FF9F9C4D-CB37-49D1-8111-7450226E1EA3/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/PIL/ImageFont.py", line 845, in truetype
return freetype(font)
File "/var/containers/Bundle/Application/FF9F9C4D-CB37-49D1-8111-7450226E1EA3/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/PIL/ImageFont.py", line 842, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/var/containers/Bundle/Application/FF9F9C4D-CB37-49D1-8111-7450226E1EA3/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/PIL/ImageFont.py", line 194, in __init__
self.font = core.getfont(
OSError: cannot open resource