Need help about ui function
using load_view('myui'), how can I get the quit event ?
how to show the pick music view?
import ui def mediaPicker_didPickMediaItems_(_self,_cmd,mediaPicker,mediaItemCollection): print '!!!',ObjCInstance(mediaPicker),ObjCInstance(mediaItemCollection) mediaPickerDelegate = create_objc_class('mediaPickerDelegate',methods=[mediaPicker_didPickMediaItems_],protocols=['mediaPickerDelegate']) mpDelegate = mediaPickerDelegate.alloc().init() def pick_music(): mp1 = MPicker.alloc().initWithMediaTypes_(1) mp1.setDelegate_(mpDelegate) mp1.allowsPickingMultipleItems = False v = ui.load_view('myui') v.present('sheet')
@jmv38 It works on iOS 9 too. For some reason,
MPMediaPickerControlleris from) is loaded by default on iOS 10, but on iOS 9 you first need to load it manually:
NSBundle.bundleWithPath_("/System/Library/Frameworks/MediaPlayer.framework").load() MPicker = ObjCClass("MPMediaPickerController")
By the way, it is possible to copy error messages. When you open the traceback navigator (the red window that pops up when an exception happens) there is a "Print Traceback" option at the top of the traceback list. This prints a normal Python traceback to the console, which you can copy and paste like normal.
thank you @dgelessus .
I dont have the print option, it must be a pythonista3 feature.
@omz doesn't iOS 10 require a
NSAppleMusicUsageDescriptionentry in the
Info.plistto access the
@lukaskollmer Only if the app is linked against the iOS 10 SDK. The current App Store versions are linked against the iOS 9 SDK, and the betas do have that Info.plist key.
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/A393CF34-1371-47E1-B49E-D9AF34A644DC/Pythonista3/Documents/Test/test1.py", line 41, in <module>
mc = MYUIClass(ui_file, frame=f, bg_color='white')
File "/private/var/mobile/Containers/Shared/AppGroup/A393CF34-1371-47E1-B49E-D9AF34A644DC/Pythonista3/Documents/Test/test1.py", line 20, in init
TypeError: super() takes at least 1 argument (0 given)
@wolf71 , are you using Pythonista 2?
@wolf71 , well I guess you are. If you replace the super().xxx line as the below it will work.
class MYUIClass(ui.View): def __init__(self, ui_file, *args, **kwargs): ui.load_view(ui_file, pyui_bindings(self)) #super().__init__(*args, **kwargs) ui.View.__init__(self, *args, **kwargs)
ui.View.init(self, *args, **kwargs)
- Python 2.7
- ui.View.init(self, *args, **kwargs) work.
- Thank you very much. :-)
@wolf71 , great. The call to super is a Python 3 construct. But it's nice, because it's generic. It just calls the base class without having to refer to it absolutely. In the Python 2 version, you can see calling ui.View.init() by name. It may seem like a small difference, but it really can make life a lot easier if you chop,and change your code object model. I am just thinking about small things here. But on a medium to large project I am sure it can have a profound impact. I can only speculate as I have never done a large project in Python.
My comments above are about when you are inheriting from just one base class. You have to think a little harder(aka, have more understanding) if your are inheriting from multiple base classes (multiple inheritance).