omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. donLaden

    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.


    • Profile
    • Following 3
    • Followers 0
    • Topics 0
    • Posts 4
    • Best 1
    • Controversial 0
    • Groups 0

    donLaden

    @donLaden

    1
    Reputation
    412
    Profile views
    4
    Posts
    0
    Followers
    3
    Following
    Joined Last Online

    donLaden Unfollow Follow

    Best posts made by donLaden

    • RE: Getting touch-ended/touch-cancelled in a scrollview?

      @mikael Thanks for the pull to refresh example. I really appreciate the help. I had a couple issues. The biggest issue was only being able to refresh once after the view is loaded. The second Issue was when pulled too far down, the refresh function was called multiple times. I think I solved these issues. I attached the solution I came up with below.

      import ui, sound
      
      
      class scrollViewDelegate:
      	maxPull = -100
      
      	def __init__(self):
      		self.refresh = False
      
      	def scrollview_did_scroll(self, scrollview):
      		x, y = scrollview.content_offset
      		
      		if y <= 0:
      			delta = max(y, self.maxPull) / self.maxPull
      
      			if (y <= self.maxPull and not scrollview.tracking and
      							scrollview.decelerating and not self.refresh):
      				scrollview['refresh_bg'][
      					'refresh_label'].text_color = 0.50, 0.50, 0.50, delta
      				self.contentRefresh()
      			elif (y <= self.maxPull - 10 and scrollview.tracking and
      									not scrollview.decelerating and not self.refresh):
      				scrollview['refresh_bg']['refresh_label'].text = 'Release to refresh'
      				scrollview['refresh_bg'][
      					'refresh_label'].text_color = 0.50, 0.50, 0.50, delta
      			elif (y >= self.maxPull - 10 and scrollview.tracking and
      									not scrollview.decelerating and not self.refresh):
      				scrollview['refresh_bg']['refresh_label'].text = 'Pull to refresh'
      				scrollview['refresh_bg'][
      					'refresh_label'].text_color = 0.60, 0.60, 0.60, delta
      
      	def contentRefresh(self):
      		self.refresh = True
      		sound.play_effect('ui:click3')
      		#print('refreshing')
      		ui.delay(self.contentDidRefresh, 0)
      
      	def contentDidRefresh(self):
      		self.__init__()
      
      	
      
      w, h = ui.get_screen_size()
      
      sv = ui.ScrollView()
      sv.name = 'Scrollview'
      sv.always_bounce_horizontal = False
      sv.always_bounce_vertical = True
      sv.directional_lock_enabled = True
      sv.scroll_indicator_insets = (10, 0, 10, 0)
      sv.bounces = True
      sv.paging_enabled = False
      sv.indicator_style = 'black'
      sv.scroll_enabled = True
      sv.background_color = 1.0, 1.0, 1.0
      sv.content_inset = (0, 0, 0, 0)
      sv.content_size = (w - 10, h*2)
      sv.delegate = scrollViewDelegate()
      
      
      rb = ui.View()
      rb.name = 'refresh_bg'
      rb.alpha = 1.0
      rb.background_color = 0.90, 0.90, 0.90
      
      rl = ui.Label()
      rl.name = 'refresh_label'
      rl.alpha = 1.0
      rl.alignment = ui.ALIGN_CENTER
      #rl.background_color = 'white'
      rl.text = 'Pull to Refresh'
      rl.text_color = None
      rl.font = ('<system>', 14)
      
      rb.add_subview(rl)
      
      sv.frame = (0, 0, w, 0.5)
      rb.frame = (0, -600, sv.width, 600)
      rl.frame = (0, rb.height - 32, sv.width, 32)
      sv.add_subview(rb)
      
      sv.present('fullscreen') 
      
      posted in Pythonista
      donLaden
      donLaden

    Latest posts made by donLaden

    • RE: Getting touch-ended/touch-cancelled in a scrollview?

      @mikael Thanks for the pull to refresh example. I really appreciate the help. I had a couple issues. The biggest issue was only being able to refresh once after the view is loaded. The second Issue was when pulled too far down, the refresh function was called multiple times. I think I solved these issues. I attached the solution I came up with below.

      import ui, sound
      
      
      class scrollViewDelegate:
      	maxPull = -100
      
      	def __init__(self):
      		self.refresh = False
      
      	def scrollview_did_scroll(self, scrollview):
      		x, y = scrollview.content_offset
      		
      		if y <= 0:
      			delta = max(y, self.maxPull) / self.maxPull
      
      			if (y <= self.maxPull and not scrollview.tracking and
      							scrollview.decelerating and not self.refresh):
      				scrollview['refresh_bg'][
      					'refresh_label'].text_color = 0.50, 0.50, 0.50, delta
      				self.contentRefresh()
      			elif (y <= self.maxPull - 10 and scrollview.tracking and
      									not scrollview.decelerating and not self.refresh):
      				scrollview['refresh_bg']['refresh_label'].text = 'Release to refresh'
      				scrollview['refresh_bg'][
      					'refresh_label'].text_color = 0.50, 0.50, 0.50, delta
      			elif (y >= self.maxPull - 10 and scrollview.tracking and
      									not scrollview.decelerating and not self.refresh):
      				scrollview['refresh_bg']['refresh_label'].text = 'Pull to refresh'
      				scrollview['refresh_bg'][
      					'refresh_label'].text_color = 0.60, 0.60, 0.60, delta
      
      	def contentRefresh(self):
      		self.refresh = True
      		sound.play_effect('ui:click3')
      		#print('refreshing')
      		ui.delay(self.contentDidRefresh, 0)
      
      	def contentDidRefresh(self):
      		self.__init__()
      
      	
      
      w, h = ui.get_screen_size()
      
      sv = ui.ScrollView()
      sv.name = 'Scrollview'
      sv.always_bounce_horizontal = False
      sv.always_bounce_vertical = True
      sv.directional_lock_enabled = True
      sv.scroll_indicator_insets = (10, 0, 10, 0)
      sv.bounces = True
      sv.paging_enabled = False
      sv.indicator_style = 'black'
      sv.scroll_enabled = True
      sv.background_color = 1.0, 1.0, 1.0
      sv.content_inset = (0, 0, 0, 0)
      sv.content_size = (w - 10, h*2)
      sv.delegate = scrollViewDelegate()
      
      
      rb = ui.View()
      rb.name = 'refresh_bg'
      rb.alpha = 1.0
      rb.background_color = 0.90, 0.90, 0.90
      
      rl = ui.Label()
      rl.name = 'refresh_label'
      rl.alpha = 1.0
      rl.alignment = ui.ALIGN_CENTER
      #rl.background_color = 'white'
      rl.text = 'Pull to Refresh'
      rl.text_color = None
      rl.font = ('<system>', 14)
      
      rb.add_subview(rl)
      
      sv.frame = (0, 0, w, 0.5)
      rb.frame = (0, -600, sv.width, 600)
      rl.frame = (0, rb.height - 32, sv.width, 32)
      sv.add_subview(rb)
      
      sv.present('fullscreen') 
      
      posted in Pythonista
      donLaden
      donLaden
    • RE: Getting touch-ended/touch-cancelled in a scrollview?

      @mikael @Stephen Thanks for the quick responses.
      I’ve never really dabbled in Python, I’ve just started to really try and teach myself so I could build an app to help manage my shop at work. I was trying to build a pull to refresh function into my scroll view. I’m just working on trying to make sense of all this and make something useful I can add to my app later. I’ll give it a go this weekend and see what I can accomplish.

      posted in Pythonista
      donLaden
      donLaden
    • RE: Getting touch-ended/touch-cancelled in a scrollview?

      is there an example of how you get a scroll view to recognize touch events?

      posted in Pythonista
      donLaden
      donLaden