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.
@mestela said
-the album has videos in there too, can pythonista display videos via the ui module?
Yes it you should need ObjectiveC, try this quick and dirty script
import photos
import time
import ui
import random
import threading
from objc_util import *
class my_thread(threading.Thread):
def __init__(self,asset, vo):
threading.Thread.__init__(self)
self.asset = asset
self.vo = vo
def run(self):
asseturl = ObjCClass('AVURLAsset').alloc().initWithURL_options_(self.asset.ALAssetURL(),None)
i=AVPlayerItem.playerItemWithAsset_(asseturl)
p=AVPlayer.playerWithPlayerItem_(i)
videolayer=AVPlayerLayer.playerLayerWithPlayer_(p)
videolayer.frame=self.vo.bounds()
self.vo.layer().addSublayer_(videolayer)
p.play()
AVPlayerItem=ObjCClass('AVPlayerItem')
AVPlayer=ObjCClass('AVPlayer')
AVPlayerLayer=ObjCClass('AVPlayerLayer')
albums = photos.get_albums()
album = [x for x in albums if x.title=='Pastels'][0]
photos = album.assets
random.shuffle(photos)
iv = ui.ImageView()
iv.content_mode=ui.CONTENT_SCALE_ASPECT_FIT
iv.present('fullscreen', hide_title_bar=True)
v = ui.View()
v.frame = iv.frame
v.hidden = True
iv.add_subview(v)
vo = ObjCInstance(v)
dt = 0
for photo in photos:
#print(photo)
if photo.media_type == 'image':
iv.image = photo.get_ui_image()
time.sleep(0.2)
elif photo.media_type == 'video':
phasset = ObjCInstance(photo)
v.hidden = False
mythread = my_thread(phasset, vo)
mythread.start()
time.sleep(photo.duration)
v.hidden = True
@mestela said
-the fullscreen view has a large white bar at the top with a x on it. Can that be reduced in size, or even removed entirely? Assuming I then provide my own code to bring up a menu on tap to end the slideshow, skip to next image etc
Yes, via
iv.present('fullscreen', hide_title_bar=True)
As the close button is absent, To close, swipe down with two fingers
@rami this little script does not list show as an asset method
import photos
asset = photos.pick_asset()
print(dir(asset))
If you extract an ui.Image from the asset, this one has a show method.
@ihf If you use "my" old FloorPlanArea.py and if you did not change it 😉, be sure you also use the Gestures.py of @jonB in the same folder, to avoid using another Gestures module, for example, of @mikael, they could have different parameters.
@ihf Weird. I don't have any problem. Perhaps due it uses also an old Gestures module, in the same folder.
Gestures checked, same as in old Gestures
Did you restart Pythonista ?
@ihf It was floorplanarea.py , not RoomAreaFinder, and yes, it uses a fixed image, no picking
@xgm in iOS 16.3.1, error is Segmentation fault
as often in the beta...
Fatal Python error: Segmentation fault
Thread 0x000000016d81b000 (most recent call first):
File "/var/containers/Bundle/Application/F73D86DB-15E8-4BD5-8791-9D84A82746C3/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/threading.py", line 321 in wait
File "/var/containers/Bundle/Application/F73D86DB-15E8-4BD5-8791-9D84A82746C3/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/threading.py", line 461 in acquire
File "/var/containers/Bundle/Application/F73D86DB-15E8-4BD5-8791-9D84A82746C3/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/pythonista/notification.py", line 110 in get_scheduled
File "/private/var/mobile/Containers/Shared/AppGroup/94C45A26-1F47-4486-9539-896F8F44AA91/Pythonista3/Documents/MesApps/Notifications_List.py", line 3 in <module>
Extension modules: pykit_io, _ui, _appex, _frameworksimporter, console, _pythonista, _debugger_ui, _notification (total: 8)
@bosco I run on iPad Air 5 (M1) with beta 340007. I have opened an issue in Github and @mikael will check it. No urgence, but perhaps he would be interested by your workaround. Wait and see. Thanks for helping.