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.


    Change cell background upon double taps

    Pythonista
    2
    3
    2080
    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.
    • Grun6
      Grun6 last edited by Grun6

      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

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

        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.

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

          Great thank you that is exactly it.
          And I'll look into ui.cancel_delays for corner cases

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