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
-
@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.
-
@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 -
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.