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 to populate designer tableview sections with a dictionary

    Pythonista
    2
    4
    1680
    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.
    • nvedwards
      nvedwards last edited by ccc

      I’m trying to populate a tableview with the contents of a dictionary. i want the tableview data to be grouped by sections following the rows belonging to each section. Below is the code that i put together so far. The keys show up in the tableview but not the values. How do you populate the rows/cells of each section with the key values?

      Thanks!

      import ui
      
      
      def load_table(view):
      	#data = ['spam', 'ham', 'egg']
      	# Sections and section rows
      	data = {'meat': ['spam', 'ham'], 'fruit': ['apple', 'orange']}
      	
      	datasource = ui.ListDataSource(data)
      	view['tv_food'].data_source=datasource
      	view['tv_food'].delegate=datasource
      
      
      def main():
      	view = ui.load_view('tableview_test') # tableview from designer
      	load_table(view)
      	nav = ui.NavigationView(view)
      	nav.present()
      
      
      if __name__ == '__main__':
      	main()
      
      cvp 2 Replies Last reply Reply Quote 0
      • cvp
        cvp @nvedwards last edited by cvp

        @nvedwards see an example here or here

        1 Reply Last reply Reply Quote 0
        • cvp
          cvp @nvedwards last edited by

          @nvedwards quick and dirty script only to show that it could be easier with dialogs

          import dialogs
          
          def main():
          	# Sections and section rows
          	data = {'meat': ['spam', 'ham'], 'fruit': ['apple', 'orange']}
          
          	sections = []
          	for k in data.keys():
          		fields = []
          		for val in data[k]:
          			fields.append({'title':val})
          		sections.append((k,fields))
          	f = dialogs.form_dialog('test via dialogs',sections=sections)
          
          if __name__ == '__main__':
          	main() 
          
          1 Reply Last reply Reply Quote 0
          • nvedwards
            nvedwards last edited by

            Very helpful. Thanks much!

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