Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pythonista hangs on opening Photo Library #729

Open
kami83 opened this issue Jan 15, 2024 · 9 comments
Open

Pythonista hangs on opening Photo Library #729

kami83 opened this issue Jan 15, 2024 · 9 comments

Comments

@kami83
Copy link

kami83 commented Jan 15, 2024

Hi,

i am using Pytonista on an Iphone 15 Pro (iOS 17.2.1) and Pythonista 3.4.

On a older Iphone XS (iOS 17.2.1) everything works fine. But on the new Iphone if i just press the Button form the UI. The Iphone App hangs a lot.

I i just run the "photos.pick_asset". It works fine. Could it be a problem with the Popup Function?

In the UI Script there is just a button which start the launchimg() function.

BR kami

import ui
import photos

def launchimg(sender):
assets = photos.pick_asset(assets=photos.get_assets(media_type='image'),title='Select Image2', multi=True)
print (assets)

assets = photos.pick_asset(assets=photos.get_assets(media_type='image'),title='Select Image1', multi=True)
print (assets)

v= ui.load_view('image')
v.present()

@cclauss
Copy link
Contributor

cclauss commented Jan 15, 2024

How long does assets=photos.get_assets(media_type='image') take to run?

@kami83
Copy link
Author

kami83 commented Jan 15, 2024

30sec - 60secs and more. But it is also the same problem if i run "assets = photos.capture_image()"

@cclauss
Copy link
Contributor

cclauss commented Jan 15, 2024

Does the following work if you leave out all of the ui code?

import photos

def launch_img(sender):
    print("Calling photos.get_assets(media_type='image')...")
    assets = photos.get_assets(media_type='image')
    print(f"{len(assets)} images found. -- Calling photos.pick_asset()")
    assets = photos.pick_asset(assets, title='Select images', multi=True)
    print(f"{len(assets)} images selected.")

if __name__ == "__main__":
    launch_img(None)

If not, does multi=False change things?

@kami83
Copy link
Author

kami83 commented Jan 15, 2024

Hi, works fine with both True and False. The hanging just starts if i use a Button.

@cclauss
Copy link
Contributor

cclauss commented Jan 15, 2024

Cool... So first get the images from the user and then once that is finished you can do the ui work.

import photos
import ui

def launch_img(sender):
    print("Calling photos.get_assets(media_type='image')...")
    assets = photos.get_assets(media_type='image')
    print(f"{len(assets)} images found. -- Calling photos.pick_asset()")
    assets = photos.pick_asset(assets, title='Select images', multi=True)
    print(f"{len(assets)} images selected.")
    return assets

if __name__ == "__main__":
    assets = launch_img(None)
    if assets:
        view = ui.load_view('image')
        view.present()
    

@kami83
Copy link
Author

kami83 commented Jan 15, 2024

No, sorry that is just a small example for the problem. The main app is much bigger and in this app i need to use a button.
So the problem should be somewhere else. Because on my older iphone it is no Problem.

BR kami

@cclauss
Copy link
Contributor

cclauss commented Jan 15, 2024

You probably need the @ui.in_background function decorator somewhere in your code as discussed at:

@kami83
Copy link
Author

kami83 commented Jan 15, 2024

Hi,
if i put @ui.in_background before every function it works fine. But why do i need this now and not in the past?
Can i fix it any way else. Maybe globally?

BR kami

@kami83
Copy link
Author

kami83 commented Jan 16, 2024

You probably need the @ui.in_background function decorator somewhere in your code as discussed at:

* https://omz-software.com/pythonista/docs-3.4/py3/ios/ui.html#about-actions-and-delegates

Hi, any more infos? Can i use it globally? BR kami

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants