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
-
I load a view when the user presses the âFindâ button as shown below.
I have a TextField delegate and I want to be able to close the view from âtextfield_did_end_editingâ
Is there a internal way that allows the delegate to call close() for the view itâs in. I know I can define a variable in the delegate that contains a reference to the view and a function to set it, but I was hoping for something more elegant.
-
@BGKirkham did you try
textfield.superview.close()
-
Well, that was so obvious it didnât occur to me. In my defense, Iâm only on my second cup of coffee.
Thanks
-
@BGKirkham thanks to remind me to take my last cup đ
-
-
@crazyfox I suppose the arrow is a button and it's action shows a TableView with the list of allowed values, and when you select one, it is copied in the TextField at left of the arrow.
It is something like that I do for this kind of process
-
@crazyfox very quick and dirty
import ui v = ui.View() v.background_color = 'white' v.frame = (0,0,400,400) tf = ui.TextField(name='tf') tf.enabled = False tf.frame = (10,10,200,32) tf.border_width= 1 tf.corner_radius = 5 v.add_subview(tf) b = ui.Button() b.frame = (210,10,32,32) b.image = ui.Image.named('iob:arrow_down_b_32') b.border_width = 1 b.corner_radius = 5 def b_action(sender): sender.superview['tv'].hidden = False b.action = b_action v.add_subview(b) class MyTableViewDelegate (object): def tableview_did_select(self,tableview, section, row): # Called when a row was selected data = tableview.data_source.items[row] tableview.superview['tf'].text = data tableview.hidden = True tv = ui.TableView(name='tv') tv.frame = (10,42,200,300) tv.border_width = 1 tv.corner_radius = 5 bands = ['10m','12m','15m','17m'] tv.data_source = ui.ListDataSource(items=bands) tv.delegate = MyTableViewDelegate() tv.hidden = True v.add_subview(tv) v.present('sheet')
-
@cvp Thanks.
I will go through your code - just starting with Python.
Would I need to put this code in a class in order to call it multiple times -multiple drop downs on ui sheet (and passing different parameters)?-KP
-
@crazyfox you could but TableView is already a class...
-
@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')
-
-
@BGKirkham
Thank you. Sorry didnât mean to hijack your thread.@cvp
It works. Thanks again for pointing me in the right direction. -
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.
-
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.
-
@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 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)
-
@BGKirkham other detail
-
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?
-
I found this post that you did.
-
@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.