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.
tableview_did_select
-
Iβm launching a standard dialog from tableview_did_select
def tableview_did_select(self, tableview, section, row): self.selected_row = row self.selected_section = section print(dialogs.list_dialog('list dialog', items=['happy', 'days', 'are', 'here', 'again']))
This always returns None!
However, if itβs launched from a ui.ButtonItem on the same view it works properly and returns the selected item.
def cancel_action(sender): print(dialogs.list_dialog('list dialog', items=['happy', 'days', 'are', 'here', 'again'])) ui.end_editing() ds.container_view.close()
This always returns the selected item
Any suggestions on making tableview_did_select work?
-
@Appletrain, please use the friendly code button
</>
to surround code with backticks and make it much more readable.So the dialog comes up, you make the selection normally, but the return value is None?
Very curious: if you put the dialog call in another function that you call from
did_select
withui.delay
(very small delay), it works. -
@Appletrain put @ui.in_background just before the def
@ui.in_background def tableview_did_select(self, tableview, section, row):
-
@cvp, cool!
But then I do not really understand why ui.delay and the button action handler worked, as they are both run on the main UI thread, as is
tableview_did_select
. -
@mikael I don't understand too but I often (not always) meet this problem.
The problem comes from the wait_modal in the dialog, it doesn't wait sometimes -
-
@stephen I think it is something like that..
-
This post is deleted! -
@mikael @cvp @Appletrain sorry about post miss-hap.. i found this to work. but it bypasses dialogs module..
import ui class DataSource(object): def __init__(self, items): self.items=items def tableview_cell_for_row(self, tableview, section, row): # Create and return a cell for the given section/row cell = ui.TableViewCell() cell.text_label.text = self.items[row] return cell def tableview_number_of_sections(self, tableview): # Return the number of sections (defaults to 1) return 1 def tableview_number_of_rows(self, tableview, section): # Return the number of rows in the section return len(self.items) class TV: def __init__(self): self.menu_one_options = ['Banana', 'Orenge', 'Grape'] self.menu_two_options = ['happy', 'days', 'are', 'here', 'again'] frame=(0, 0, 200, 600) self.selected='' self.tv1 = ui.TableView(frame=frame) self.tv1.name='menu-one' self.tv1.delegate = self self.tv1.hidden=False self.tv1.data_source = DataSource(self.menu_one_options) self.tv1.present('sheets') self.tv2 = ui.TableView(frame=frame) self.tv2.name='menu-two' self.tv2.delegate = self self.tv2.hidden=True self.tv2.data_source = DataSource(self.menu_two_options) def tableview_did_select(self, tableview, section, row): if not self.tv1.hidden: self.selected += tableview.data_source.items[row] + ' ' self.tv1.hidden=True self.tv2.present('sheets') self.tv2.hidden=False elif not self.tv2.hidden: self.selected += tableview.data_source.items[row] print (self.selected) self.tv2.hidden=True self.tv1.close() self.tv2.close()
-
-
@cvp π π oops
-
Thank you all. @ui.in_backround solved it.
-
@Appletrain youpee