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.


    Closing a view from a TextField Delegate

    Pythonista
    3
    22
    9119
    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.
    • cvp
      cvp @crazyfox last edited by

      @crazyfox you could but TableView is already a class...

      1 Reply Last reply Reply Quote 0
      • cvp
        cvp @crazyfox last edited by

        @crazyfox try this, not sure it is full ok

        import ui
        
        v = ui.View()
        v.background_color = 'white'
        v.frame = (0,0,400,500)
        
        class MyDropDown(ui.View):
        	def __init__(self, items=[], *args, **kwargs):
        		ui.View.__init__(self, *args, **kwargs)
        		self.h = self.height
        		#self.border_width = 2
        		#self.border_color = 'red'
        		tf = ui.TextField(name='tf')
        		tf.enabled = False
        		tf.frame = (0,0,self.width-32,32)
        		tf.border_width= 1
        		tf.corner_radius = 5
        		self.add_subview(tf)
        		self.tf = tf
        		b = ui.Button()
        		b.frame = (tf.x+tf.width,0,32,32)
        		b.image = ui.Image.named('iob:arrow_down_b_32')
        		b.border_width = 1
        		b.corner_radius = 5
        		b.action = self.b_action
        		self.add_subview(b)
        		tv = ui.TableView()
        		tv.frame = (0,tf.height,tf.width,self.height-32)
        		tv.border_width = 1
        		tv.corner_radius = 5
        		tv.data_source = ui.ListDataSource(items=items)
        		tv.height = min(tv.height,32*len(items))
        		tv.delegate = self
        		tv.hidden = True
        		self.add_subview(tv)
        		self.tv = tv
        	def b_action(self,sender):
        		self.tv.hidden = False		
        		self.height = self.h
        		self.bring_to_front()
        	def tableview_did_select(self,tableview, section, row):
        		# Called when a row was selected
        		data = tableview.data_source.items[row]
        		self.tf.text = data
        		tableview.hidden = True
        		self.height = 32
        
        dd1 = MyDropDown(items=['10m','12m','15m','17m'],frame=(10,10,242,300))
        v.add_subview(dd1)
        
        dd2 = MyDropDown(items=['aaa','bbb','ccc'],frame=(10,50,242,300))
        v.add_subview(dd2)
        
        v.present('sheet') 
        
        1 Reply Last reply Reply Quote 0
        • BGKirkham
          BGKirkham @crazyfox last edited by BGKirkham

          @crazyfox

          @cvp nailed it. It’s a button that shows a TableView when it is clicked. The selected item in the TableView is extracted and placed in the TextField. Then the TableView is hidden again. Here is a pic of mine dropped down

          crazyfox 1 Reply Last reply Reply Quote 0
          • crazyfox
            crazyfox @BGKirkham last edited by

            @BGKirkham
            Thank you. Sorry didn’t mean to hijack your thread.

            @cvp
            It works. Thanks again for pointing me in the right direction.

            BGKirkham 1 Reply Last reply Reply Quote 0
            • BGKirkham
              BGKirkham @crazyfox last edited by

              @crazyfox

              Not a problem. I’m still learning Pythonista myself although I have a ton of experience with other languages. It’s always good to ask questions as it helps you and others with the same question.

              1 Reply Last reply Reply Quote 0
              • BGKirkham
                BGKirkham @cvp last edited by

                @cvp

                Is this something you wrote? When I saw it I thought it would be cool to show that type of view for people I talk to.

                cvp 3 Replies Last reply Reply Quote 0
                • cvp
                  cvp @BGKirkham last edited by

                  @BGKirkham Yes, I wrote it for for a neighbor who is a radio amateur.
                  But, it is a big (for me) script (7600 lines) with a lot of parameters files and I would need to ask him if he agree I share the source code. And the script would never be finished because it has still some bugs and my friend has always new ideas or requests 😀

                  BGKirkham 1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @BGKirkham last edited by

                    @BGKirkham for instance, if you tap on a pin, you get infos of the multiple contacts he has had with this call (I take a sample of a common call he and you have had)

                    1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp @BGKirkham last edited by

                      @BGKirkham other detail

                      1 Reply Last reply Reply Quote 0
                      • BGKirkham
                        BGKirkham @cvp last edited by

                        @cvp

                        It looks like you did a great job. I wouldn’t necessarily want to get the code, but can you tell me how you handled the maps? Is it an imported image or are you using something like google maps interactively?

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

                          I found this post that you did.

                          cvp 2 Replies Last reply Reply Quote 0
                          • cvp
                            cvp @BGKirkham last edited by

                            @BGKirkham yes, same kind of process. The big script uses more complex objects as pin's.
                            Always in the mapView_viewForAnnotation_ delegate of the MKMapView, where you can use MKAnnotationView for you own view as pin, MKPinAnnotationView for the standard pin, MKMarkerAnnotationView for the standard marker as pin.
                            If you want, I can post my mapView_viewForAnnotation_ alone but it uses a lot of user variables.

                            I also use a mapView_annotationView_calloutAccessoryControlTapped_ delegate when you tap on the view showed when you tap on a pin. I could also post it if you want, only as example.

                            BGKirkham 1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @BGKirkham last edited by cvp

                              @BGKirkham A last example before I bore you too much 😀
                              The user wanted an aura/halo around the pin's of recent (delay is a parameter) contacts.
                              Thus, you can't use standard pin and I build an image with a standard pin and a circle around (color is function of band) and I use MKAnnotationView.
                              If you zoom, you can see the difference between both pins, mine (top left) is not so nice

                              1 Reply Last reply Reply Quote 0
                              • BGKirkham
                                BGKirkham @cvp last edited by

                                @cvp

                                Thank you for the info. I'll look into it when I have time. I've moved on to another project, but I will likely come back to this one soon. I also need to extract my scrolling tableview from this project and post the code.

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