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.


    Simple n00b question: Populating TableView from a list

    Pythonista
    3
    5
    4305
    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.
    • heliophagus
      heliophagus last edited by

      Greetings. I need to allow the users of my app to choose one item from a list of about 50 text items (column names in an np matrix, loaded into a list). It seems that the best UI tool for this is the TableView, but after a few hours of frustration and playing with various sample code snippets I haven't managed to make this happen. The more I read, the more confused I get. I simply need to populate the TableView from the list, allow the user to choose an item, and then see what item was chosen.

      I'd be most grateful for some practical help targeted at someone who isn't (yet) a master of OOP. Thanks in advance!

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

        I'd really appreciate some help with this, folks. I'm a scientist with lots of experience with other languages, faced with serious data handling challenges with a critical time limit, having real issues adapting to Python and Pythonista. Your help and support would be enormously appreciated.

        Phuket2 1 Reply Last reply Reply Quote 0
        • Cethric
          Cethric last edited by

          I assume that you have your data already in a list form and that you have some understanding of how pythonista UI's work, if not let me know and I will try and explain it as best I can.
          The following is a brief outline of what needs to be done:

          import ui
          data = [x for x in range(0, 50)]
          datasource = ui.ListDataSource(data)
          tv = ui.TableView()
          tv.data_source = datasource
          tv.delegate = datasource
          
          def selectitem(*args):
              view = ui.View(title='{}'.format(args[1]))
              label = ui.Label()
              label.text = "{}, {}, {}".format(*args)
              label.size_to_fit()
              view.add_subview(label)
              view.background_color = 'white'
              nav.push_view(view)
          datasource.tableview_did_select = selectitem
          
          nav = ui.NavigationView(tv)
          
          nav.present()
          

          Hope this helps.

          1 Reply Last reply Reply Quote 1
          • Phuket2
            Phuket2 @heliophagus last edited by Phuket2

            @heliophagus , below is probably the easiest to do what you want. It uses the Pythonista dialogs module. It's worth reading. There are a number of different types of dialogs you can create. The dialogs module is just a wrapper around ui.TableView so you can make quick lists etc...
            Hope this helps. It's not difficult to do with a ui.TableView, but seems like you could use a quick rest from them 😬

            Edit: if dialogs is not flexible enough for your list data, let me know. Will try to help further.

            import dialogs
            
            def show_dlg(the_list):
            	return dialogs.list_dialog('Please select', the_list)
            
            
            lst = range(100)
            res=show_dlg(lst)
            print(res)
            
            1 Reply Last reply Reply Quote 1
            • heliophagus
              heliophagus last edited by

              Super helpful- Thank you both! I woke up at 3 a.m. to check the forum, and found two very different answers, and both would work. The shorter, 'wrapper' approach is particularly appealing because it uses less real estate and (to me, at my present basic level of Python and Pythonista understanding) is more intuitive.

              Picking an item from a scrollable pop-up list seems like a really basic action that shouldn't take more than a couple of lines of code, but then again I'm not a trained programmer, just someone who needs to get something relatively complex done on an iPad platform within a tight time-frame.

              Again, thanks to both of you!

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