omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    How do I pass arguments from Pythonista to Workflow?

    Pythonista
    4
    9
    6571
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Oak
      Oak last edited by

      Hey guys, I can't figure out how to do this. Basically I have several sets of coordinates in Pythonista (a list for all the latitudes and a list for all the longitudes, as well as a list containing the feature names). I want to be able to choose from a list of these points in Workflow then have it show that point (or route to that point) in Maps.

      The problem is, I don't know how to pass data like this from Pythonista to Workflow. Also, the number of point data will be variable, so that complicates things; I may need to pass anywhere from 1 feature to 20+ features to choose from in Workflow. But then again, I also suppose I could script the "choose" part in Pythonista so that only one latitude and one longitude would need to be passed to Workflow. That might be easier.

      In a perfect world I would like all of this to be done in two presses.. One to start the chain reaction, and one to choose which point to access.

      Anybody have any idea how to do this??

      1 Reply Last reply Reply Quote 0
      • Oak
        Oak last edited by

        UPDATE I figured it out

        I used <code>webbrowser.open('workflow://x-callback-url/run-workflow?name=CoordsMap')</code> to open the workflow and <code>clipboard.set(Coordinates)</code> to pass the variable. In Workflow I'm literally just going to have two actions: Get Clipboard and Show In Maps.

        Now I need to figure out a way to be able to choose from a varying list in Python...

        1 Reply Last reply Reply Quote 0
        • JonB
          JonB last edited by

          If you are using the beta, the dialogs module is for this sort of thing. If not... Well dialogs is actually pure Python wrapper to the ui module, basically you want a ListDataSource as delegate and datasource for a TableView, then have the did select method run your script.

          1 Reply Last reply Reply Quote 0
          • Oak
            Oak last edited by

            Thanks Jon! I'll for sure check it out. I didn't know there was a beta.

            And another UPDATE: Got my script finished. In order to do the list I ended up using a loop to print all the options, then a simple raw_input to define a variable which assembles the coordinates to be copied to the clipboard. Then I used the above URL callback code to open the Workflow app that instantly draws from the clipboard to open the point up in Maps.

            1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by

              Here's an extract from dialogs.py that will present a list and return the selected entry.

              # coding: utf-8
              import ui, collections
              class _ListDialogController (object):
              	def __init__(self, title, items, multiple=False, done_button_title='Done'):
              		self.items = items
              		self.selected_item = None
              		self.view = ui.TableView()
              		self.view.name = title
              		self.view.allows_multiple_selection = multiple
              		if multiple:
              			done_button = ui.ButtonItem(title=done_button_title)
              			done_button.action = self.done_action
              			self.view.right_button_items = [done_button]
              		ds = ui.ListDataSource(items)
              		ds.action = self.row_selected
              		self.view.data_source = ds
              		self.view.delegate = ds
              		self.view.frame = (0, 0, 500, 500)
              	
              	def done_action(self, sender):
              		selected = []
              		for row in self.view.selected_rows:
              			selected.append(self.items[row[1]])
              		self.selected_item = selected
              		self.view.close()
              		
              	def row_selected(self, ds):
              		if not self.view.allows_multiple_selection:
              			self.selected_item = self.items[ds.selected_row]
              			self.view.close()
              		
              
              def list_dialog(title='', items=None, multiple=False, done_button_title='Done'):
              	if not items:
              		items = []
              	if not isinstance(title, str) and not isinstance(title, unicode):
              		raise TypeError('title must be a string')
              	if not isinstance(items, collections.Sequence):
              		raise TypeError('items must be a sequence')
              
              	c = _ListDialogController(title, items, multiple, done_button_title=done_button_title)
              	c.view.present('sheet')
              	c.view.wait_modal()
              	return c.selected_item
              
              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by

                Also, fyi, pythonista can launch the maps app directly.
                https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html

                1 Reply Last reply Reply Quote 0
                • brumm
                  brumm last edited by

                  Workflow

                  1 Reply Last reply Reply Quote 0
                  • Tizzy
                    Tizzy last edited by

                    @JonB with regards to the apple maps documentation...when trying those maps.apple.com formatted urls from webbrowser.open("https://maps.apple.com........") it opens a web view with ... Google maps? So confused... I found using map:// opens apple maps, but can't get any of the URL parameters to work there... Basically I want to open apple maps set to an address I provide.

                    UPDATE: okay so the actual URL form is a combination of the two: webbrowser.open("maps://http://maps.apple.com/q=")

                    1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB last edited by

                      I think you may be able to omit the http:// if you use maps://

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      Powered by NodeBB Forums | Contributors