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.
getting columns into a TableView, or otherwise presenting tabular data
-
I’ve been looking for a way to present some basic table data, much like a scoresheet/score card. ie, the left column being what’s being tracked, and a second or third column with the relevant peoples scores.
Something akin to:
Info P#1 P#2 Jump 15 25 Score 123 200
I’m not readily seeing any way to present that data.
I thought tableview may have been appropriate given its name, but it’s really just a listbox.
I’m open to any ideas.
-
@madivad very quick and very dirty, as usual, and sorry, not the good orange 😂
import ui lst = [['Info','P#1','P#2'], ['Jump',15,25],['Score',123,200]] def tableview_cell_for_row(tableview, section, row): data = tableview.data_source.items[row] cell = ui.TableViewCell() #cell.text_label.text = data[0] w = (cell.content_view.width-4)/3 h = cell.content_view.height col1 = ui.Label(frame=(4,0,w,h)) col1.text = data[0] cell.content_view.add_subview(col1) col2 = ui.Label(frame=(4+w,0,w,h)) col2.alignment = ui.ALIGN_RIGHT col2.text = str(data[1]) cell.content_view.add_subview(col2) col3 = ui.Label(frame=(4+2*w,0,w,h)) col3.alignment = ui.ALIGN_RIGHT col3.text = str(data[2]) cell.content_view.add_subview(col3) if row == 0: col1.text_color = 'gray' col2.text_color = 'gray' col3.text_color = 'gray' else: col2.text_color = 'orange' col3.text_color = 'orange' return cell tv = ui.TableView() tv.data_source = ui.ListDataSource(items=lst) tv.data_source.tableview_cell_for_row = tableview_cell_for_row tv.frame = (0,0,400,400) tv.name = 'for @madivad' tv.present('sheet')
-
That’s perfectly workable. Thanks very much!