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.
Invoking the share sheet
-
Hi, apologies if this is easy and I've just missed it, but is it possible to include a "Share Sheet" button on a scene or ui built in pythonista. I have looked at the use of Appex and I don't see an option to invoke the share sheet. Many thanks
-
@rhythmart not sure I understand the request.
If you want to open a share sheet to share a file, tryconsole.open_in(file path)
-
Or, do you mean you want to export a script from the editor to another app?
You share entire scripts from the script library view (swipe left from editor) -
cvp, JonB - thanks for coming back to me. I can see how much support you both provide everyone - thank you. For my own enjoyment, i have written my own version of Wordle. When you complete Wordle on an iphone, the resulting "share" button invokes the share sheet for you to copy the clipboard to, for example, WhatsApp for sharing. I can see the share button is available in pythonista as you can get to it under the Editor Wrench option. What I'd like to be able to do is bring up the share sheet in exactly the same way Wordle, Nerdle, Quordle etc do. Many thanks again.
-
@rhythmart please, try this little script and tap the share button
import ui from objc_util import * class MyView(ui.View): def __init__(self): super().__init__(self) self.background_color = 'white' b = ui.ButtonItem() b.title = 'share' b.action = self.share self.right_button_items = (b,) @on_main_thread def share(self, sender): vo = ObjCInstance(self) SUIViewController = ObjCClass('SUIViewController') root_vc = SUIViewController.viewControllerForView_(vo) main_view=root_vc.view() url_array = ['@rhythmart text'] UIActivityViewController = ObjCClass('UIActivityViewController').alloc().initWithActivityItems_applicationActivities_(url_array,None) UIActivityViewController.setCompletionHandler_(None) r = root_vc.presentViewController_animated_completion_(UIActivityViewController, True, None) UIActivityViewController.popoverPresentationController().sourceView = main_view UIActivityViewController.popoverPresentationController().sourceRect = CGRect(CGPoint(0,0), CGSize(300,500)) if __name__ == '__main__': v = MyView() v.present('fullscreen')
-
Many thanks cvp. That does exactly what I want. Thank you. Now I just need to understand it! My app is scene based. How easy is it to convert it to a touch of a scene ‘button’? Thanks.
-
@rhythmart try and see I use
scene.view
as superview for button in vo = ObjCInstance(self.view) and self.view.add_subview(btn)
Thé script has 2 different 'buttons': an ui.Button and a SpriteNode, only to show both waysfrom objc_util import * import scene import ui class MyScene (scene.Scene): def setup(self): self.ship = scene.SpriteNode('spc:PlayerShip1Orange') self.ship.position = self.size / 2 self.add_child(self.ship) self.share_node = scene.SpriteNode('iow:share_32', position=(self.size[0]-32, 100), parent=self) btn = ui.Button(title='share', tint_color='white', background_color='blue', action=self.share) frm = btn.frame bnds = self.view.bounds btn.frame = frm.inset(-8,-8) btn.frame = (bnds.width - btn.width - 8, bnds.height - btn.height - 8, btn.width, btn.height) btn.flex = 'RTBL' self.view.add_subview(btn) def touch_began(self, touch): if touch.location in self.share_node.frame: self.share('unused sender') @on_main_thread def share(self, sender): vo = ObjCInstance(self.view) SUIViewController = ObjCClass('SUIViewController') root_vc = SUIViewController.viewControllerForView_(vo) main_view=root_vc.view() url_array = ['@rhythmart text'] UIActivityViewController = ObjCClass('UIActivityViewController').alloc().initWithActivityItems_applicationActivities_(url_array,None) UIActivityViewController.setCompletionHandler_(None) r = root_vc.presentViewController_animated_completion_(UIActivityViewController, True, None) UIActivityViewController.popoverPresentationController().sourceView = main_view UIActivityViewController.popoverPresentationController().sourceRect = CGRect(CGPoint(0,0), CGSize(300,500)) scene.run(MyScene()) if __name__ == '__main__': scene.run(MyScene())
-
Many thanks cvp. Works perfectly on my iPad. Just what I was looking for. Thank you. On my iPhone the popover lines provide an AttributeError, I presume because popover is not supported on an iPhone. What alternative can I use? Thanks again.
-
@rhythmart too late for today, sorry, I'LL try tomorrow
-
Thanks cvp. Got it. Omitting the popover lines for iPhone works perfectly. Thank you.