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.
Change cell background upon double taps
-
Hello,
I am stuck at the following point and wondering if someone could shed some light:def tableview_cell_for_row(self, tableview, section, row): person = self.items[row][0] act = self.items[row][1] cell = ui.TableViewCell('subtitle') cell.text_label.text = person.name cell.detail_text_label.text = act.name cell.text_label.font = ('Courier', 16) cell.detail_text_label.font = ('Courier', 11) cell.selectable = False g= Gestures() def popup(data): console.hud_alert("this is a test") data.view.background_color = 'gray' g.add_tap(cell, popup, numbers_of_taps_required = 2, number_of_touches_required = None) return cell
When I generate the cell for this tableview, I assign it a function upon double tapping the cell using the Gestures module. This all works well, the popup shows up properly.
I have disabled the "cell.selectable" because I do not want the cell to be selected with a single tap. Instead I would like the cell to give visual feedback of being selected upon double tapping, so I change the color to gray in the popup(data) function. And this works as expected as well. However I would like to get the cell's background colour to revert to white after 2 seconds. How do I go about that? I tried the time.sleep() function but that does not work. I tried threading Timer but again no success.
Any idea would be appreciated -
ui.delay is probably your best bet.
you do need to think through what should happen if the user double taps more than once -- maybe you want to ui.cancel_delays, or else you need to keep some sort of tap count, and when the delay expires, the tap clunt is decremented, and set to white if zero.
-
Great thank you that is exactly it.
And I'll look into ui.cancel_delays for corner cases