Ideas for Dropdown
-
Hey, ..
I have a question in connection with the picture:
https://imgur.com/Q5vFkpGIs it possible to create a list as Dropdown... to show my QR-Codes with the beginning Numbers and in the best way to select them too ?
like the example in the Picture:
--> 25
--> 2587
--> 2549
--> 2566
--> ...
--> ..
--> .
--> 25/00001
--> 25/00008
--> 25/00017
--> 25/000198
--> ...
--> ..
--> .
only the numbers which are available.. (all QR-Codes stored in a MySQL database)I hope you can understand my question and have suggestions :D
-
@DavinE not sure that I correctly understand. Guess you have a TextField where you type your "25" initials and under, a TableView to show codes beginning with this 25.
In the TextField delegate textfield_did_change, you scan all your available codes and build a list with the codes beginning with the TextField text, here 25, and reload your TableView with this list.
Now, not sure I'm clear enough.
-
@cvp
I think from the consideration it is exactly what I'm looking for and meant 😊Will try to implement in the near future once when I have questions I'll get back to you here (but may take a while at the moment a lot of stress)
-
@DavinE please try this quick and dirty example
import ui class MyView(ui.View): def __init__(self,w,h): self.width = w self.height = h # init existing codes self.codes = ['1','2','25','2587','2549','256625/10000','3','33','4','44/45'] # TextField for search search_width = self.width - 100 search_text = ui.TextField(name='search_text') search_text.text = '' search_text.width = search_width - 100 search_text.height = 32 search_text.x = (self.width - search_width)/2 search_text.y = 10 search_text.border_color = 'blue' search_text.border_width = 3 search_text.text_color = 'blue' search_text.keyboard_type = ui.KEYBOARD_DEFAULT search_text.autocorrection_type = False search_text.alignment = ui.ALIGN_LEFT search_text.clear_button_mode = 'while_editing' search_text.font= ('Helvetica',20) search_text.delegate = self self.add_subview(search_text) # ListDataSource for search TableView found_codes = ui.TableView(name='found_codes') found_codes.allows_multiple_selection = False found_codes.text_color = 'black' found_codes.font= ('Courier',12) found_codes.row_height = 50 found_codes.x = search_text.x found_codes.y = search_text.y + search_text.height + 10 found_codes.width = search_width found_codes.height = self.height - 130 found_codes.border_color = 'blue' found_codes.border_width = 3 found_codes.data_source = ui.ListDataSource(items=[]) self.add_subview(found_codes) def textfield_did_change(self, field): txt = field.text lst = [] for code in self.codes: if txt and code.startswith(txt): lst.append(code) self['found_codes'].data_source.items = lst def main(): w, h = ui.get_screen_size() my_back = MyView(w,h) my_back.background_color='white' my_back.name = 'for @DavinE' my_back.present('fullscreen',hide_title_bar=False) # Protect against import if __name__ == '__main__': main()
-
@cvp you might consider a search controller, which behaves the way one expects in iOS
https://github.com/tdamdouni/Pythonista/blob/master/_2017/SearchableTable.py
-
@JonB I did not even know about this controller, or perhaps and probably I did forget it.
But, it is for @DavinE , not for me.Anyway, what is
from objc_classes import objcmethod, objcclass
Edit : ok, found here https://github.com/tdamdouni/Pythonista/blob/master/_2017/objc_classes.py
-
This post is deleted!last edited by
-
This post is deleted!last edited by
-
This post is deleted!last edited by
-
This post is deleted!last edited by
-
@cvp said:
@DavinE please try this quick and dirty example
import ui class MyView(ui.View): def __init__(self,w,h): self.width = w self.height = h # init existing codes self.codes = ['1','2','25','2587','2549','256625/10000','3','33','4','44/45'] # TextField for search search_width = self.width - 100 search_text = ui.TextField(name='search_text') search_text.text = '' search_text.width = search_width - 100 search_text.height = 32 search_text.x = (self.width - search_width)/2 search_text.y = 10 search_text.border_color = 'blue' search_text.border_width = 3 search_text.text_color = 'blue' search_text.keyboard_type = ui.KEYBOARD_DEFAULT search_text.autocorrection_type = False search_text.alignment = ui.ALIGN_LEFT search_text.clear_button_mode = 'while_editing' search_text.font= ('Helvetica',20) search_text.delegate = self self.add_subview(search_text) # ListDataSource for search TableView found_codes = ui.TableView(name='found_codes') found_codes.allows_multiple_selection = False found_codes.text_color = 'black' found_codes.font= ('Courier',12) found_codes.row_height = 50 found_codes.x = search_text.x found_codes.y = search_text.y + search_text.height + 10 found_codes.width = search_width found_codes.height = self.height - 130 found_codes.border_color = 'blue' found_codes.border_width = 3 found_codes.data_source = ui.ListDataSource(items=[]) self.add_subview(found_codes) def textfield_did_change(self, field): txt = field.text lst = [] for code in self.codes: if txt and code.startswith(txt): lst.append(code) self['found_codes'].data_source.items = lst def main(): w, h = ui.get_screen_size() my_back = MyView(w,h) my_back.background_color='white' my_back.name = 'for @DavinE' my_back.present('fullscreen',hide_title_bar=False) # Protect against import if __name__ == '__main__': main()
Yes, that's exactly what I meant.
With it I can try the days once around 👍
-
@JonB said:
@cvp you might consider a search controller, which behaves the way one expects in iOS
https://github.com/tdamdouni/Pythonista/blob/master/_2017/SearchableTable.py
Yes that is of course nicer...
But the whole thing is displayed in the Console... and I can not really understand the whole thing 🙈
So that a customization would be modest for me....
Will test it with @cvp's example and try.
-
@DavinE said
But the whole thing is displayed in the Console
You only have to replace 'panel' by 'fullscreen' and display will be done in normal ui.View
-
@cvp said:
@DavinE said
But the whole thing is displayed in the Console
You only have to replace 'panel' by 'fullscreen' and display will be done in normal ui.View
oh, okay if that's all it is, I'll take a look.
-
I have two other Questions for it.
- Is it possible to sort the Numbers correctly ? Image: 30/00001 then 30/00070 ?
- Can i set the TableView Height to my Keyboard ?
-
Are you pulling the data from MySQL from your datasource ? Why not set up your query so you get a sorted list.
Or, are you passing in a list? In that case, just use sort or sorted instead before assigning to your datasource items.
If the issue is that you have
1
10
2And you want these sorted as numbers, rather than as alphabetical strings, then you need to sort on a key that converts to int first.
-
@JonB said:
Are you pulling the data from MySQL from your datasource ? Why not set up your query so you get a sorted list.
Or, are you passing in a list? In that case, just use sort or sorted instead before assigning to your datasource items.
If the issue is that you have
1
10
2And you want these sorted as numbers, rather than as alphabetical strings, then you need to sort on a key that converts to int first.
i missed:
ORDER BY barcode ASC
lol....this works now.