Thank you bosco. That fix works for me on iPhone12.
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.
Posts made by frankL
-
RE: Problems with ios15
I copied the above code and ran it as is. It did not return the selected author. What was printed in the console was:
after wait: None
list dialog returned: None
items: ['Baldacci,David', 'Barr,Nevada', 'Bartol,Amy', 'Bernt,Eric', 'Brandt,Kylie', 'Bruni,Riccardo', 'Bryndza,Robert', 'Burke,James Lee', 'Burton,Mary', 'Butcher,Jim', 'Carlson,Tucker', 'Carrol,Sean', 'Case,Andrew', 'Chernov,Ron', 'Clayton,MegWaite', 'Coben,Harlan', 'Cole,Bobby', 'Connelly,Michael', 'Cornwell,Bernard', 'Cornwell,Patricia', 'Cowie,Amber', 'Crombie,Deborah', 'Crosby,Ellen', 'Cross,Katie', 'Cussler,Clive', 'Delaney,Matthew B.J.', 'Dilts,Tyler', 'Dorsey,Tim'] section, row: 0 4
in delegate: my_sel Brandt,Kylie -
RE: Problems with ios15
I did have it as return tbl.data_source.items[tbl.selected_row[1]] but I changed it to return tbl.data_source.items[tbl.selected_row[0]] and it still just returns the first list item ''Baldacci,David'. This is baffling.
-
RE: Problems with ios15
I did that and now it returns the first item in the list (''Baldacci,David') regardless of which item is selected. Where is "selected_row" defined?
-
RE: Problems with ios15
I get that same thing in the console but it doesn't populate the TextView field. It doesn't appear to be passing the value of my_sel['value'] so I put the assignment line into the def tableview_did_select function and it works. This seems like a real kluge! Beware ios15.1.1
def show_list_dialog(items=None, *args, **kwargs): items = items or [] tbl = ui.TableView(**kwargs) tbl.data_source = ui.ListDataSource(items) my_sel = {'value': None} class MyTableViewDelegate (object): def tableview_did_select(self, tableview, section, row): my_sel['value'] = tableview.data_source.items[row] tableview.close() print('my_sel',my_sel['value']) author_result.text = my_sel['value'] tbl.delegate = MyTableViewDelegate() tbl.present(style='sheet') tbl.wait_modal() return my_sel['value']
-
RE: Problems with ios15
I added those three lines and now it prints the correct selection from within def tableview_did_select but it apparently returns 'none' which is what gets populated into the TextView field. Here is the exact script:
import ui # def show_list_dialog(items=None, *args, **kwargs): items = items or [] tbl = ui.TableView(**kwargs) tbl.data_source = ui.ListDataSource(items) my_sel = {'value': None} class MyTableViewDelegate (object): def tableview_did_select(self, tableview, section, row): my_sel['value'] = tableview.data_source.items[row] tableview.close() print('my_sel',my_sel['value']) tbl.delegate = MyTableViewDelegate() tbl.present(style='sheet') tbl.wait_modal() return my_sel['value'] # w, h = ui.get_screen_size() view = ui.View(name="Frank's Library", bg_color='lightblue', frame=(0, 0, w, h)) def select_author(sender): author_unique = ['Baldacci,David', 'Barr,Nevada', 'Bartol,Amy', 'Bernt,Eric', 'Brandt,Kylie', 'Bruni,Riccardo', 'Bryndza,Robert', 'Burke,James Lee', 'Burton,Mary', 'Butcher,Jim', 'Carlson,Tucker', 'Carrol,Sean', 'Case,Andrew', 'Chernov,Ron', 'Clayton,MegWaite', 'Coben,Harlan', 'Cole,Bobby', 'Connelly,Michael', 'Cornwell,Bernard', 'Cornwell,Patricia', 'Cowie,Amber', 'Crombie,Deborah', 'Crosby,Ellen', 'Cross,Katie', 'Cussler,Clive', 'Delaney,Matthew B.J.', 'Dilts,Tyler', 'Dorsey,Tim'] f = (0, 0, 400, 300) selected_author = show_list_dialog(author_unique, frame=f, name='Select an Author') author_result.text = str(selected_author) return author_button = ui.Button(title='Author', frame=(10,5,350,100), border_color='black', border_width=2, background_color='#EAECEE', action=select_author, font=('Arial Rounded MT Bold',18)) author_button.width=70 author_button.height=40 view.add_subview(author_button) # global author_result author_entry='' author_result = ui.TextView(name='author',frame=(100,5,250,40), border_color='black', border_width=3, text=author_entry, font=('Arial Rounded MT Bold',16)) view.add_subview(author_result) nav_view = ui.NavigationView(view) nav_view.present('sheet')
-
RE: Problems with ios15
I don't get an error. It appears that the delegate just doesn't run. I removed those lines and it still doesn't work. I put a print statement into the def tableview_did_select functionn and it doesn't get executed.
What is strange is that this same function in several other scripts also stopped working. I checked them after this script stopped working and none of them work now. That's why I thought it might have something to do with ios15. I had just upgraded to ios15 the previous night. -
RE: Problems with ios15
This is a simple version of what I'm trying to run:
import ui # def show_list_dialog(items=None, *args, **kwargs): items = items or [] tbl = ui.TableView(**kwargs) tbl.data_source = ui.ListDataSource(items) my_sel = {'value': None} class MyTableViewDelegate (object): def tableview_did_select(self, tableview, section, row): my_sel['value'] = tableview.data_source.items[row] tableview.close() tbl.delegate = MyTableViewDelegate() tbl.present(style='sheet') tbl.wait_modal() return my_sel['value'] # w, h = ui.get_screen_size() view = ui.View(name="Frank's Library", bg_color='lightblue', frame=(0, 0, w, h)) def select_author(sender): author_unique = ['Baldacci,David', 'Barr,Nevada', 'Bartol,Amy', 'Bernt,Eric', 'Brandt,Kylie', 'Bruni,Riccardo', 'Bryndza,Robert', 'Burke,James Lee', 'Burton,Mary', 'Butcher,Jim', 'Carlson,Tucker', 'Carrol,Sean', 'Case,Andrew', 'Chernov,Ron', 'Clayton,MegWaite', 'Coben,Harlan', 'Cole,Bobby', 'Connelly,Michael', 'Cornwell,Bernard', 'Cornwell,Patricia', 'Cowie,Amber', 'Crombie,Deborah', 'Crosby,Ellen', 'Cross,Katie', 'Cussler,Clive', 'Delaney,Matthew B.J.', 'Dilts,Tyler', 'Dorsey,Tim'] f = (0, 0, 400, 300) selected_author = show_list_dialog(author_unique, frame=f, name='Select an Author') author_result.text = str(selected_author) return author_button = ui.Button(title='Author', frame=(10,5,350,100), border_color='black', border_width=2, background_color='#EAECEE', action=select_author, font=('Arial Rounded MT Bold',18)) author_button.width=70 author_button.height=40 view.add_subview(author_button) # global author_result author_entry='' author_result = ui.TextView(name='author',frame=(100,5,250,40), border_color='black', border_width=3, text=author_entry, font=('Arial Rounded MT Bold',16)) view.add_subview(author_result) nav_view = ui.NavigationView(view) nav_view.present('sheet')```
-
RE: Problems with ios15
Specifically, it appear that the tableview delegate is not working.
-
Problems with ios15
Is anyone having problems with previously working pythonista scripts after upgrading iPhone to ios15?
-
RE: Interaction between classes
That works perfectly! Thank you. As always, I really appreciate your help.
-
RE: Interaction between classes
I thought I was just updating the tableview each time. If I'm creating a new one each time then that could explain why it's not hidding. It is hiding but is creating a new one. How do I just create the one and then just update it each time textview changes?
-
Interaction between classes
I have a strange situation that I would like to get some help with. I have written a script with a class that contains a set of widgets that are common to several views so I want the common widgets to appear in the same place in any of the views. For the example code below, I have just one widget, a textview. When I type into the textview, I want a tableview dropdown to appear with a selection from a list that matches the text in the textview. When I select a row from the textview, I want the tableview delegate action to populate the textview with the selected row from the tableview and then have the tableview be hidden. The code below almost does this. With line 7 (#main.author_result.text = self.items[row]) commented out, once the row is selected from the tableview the tableview is hidden but the textview isn't populated with the tableview row. If I uncomment line 7, when I select a row from the tableview, the textview is populated properly but the tableview isn't hidden. This seems like very strange behavior. Can someone advise me how to correct the code to work as described above? Thanks.
import ui class MyTableViewDelegate(object): def __init__(self,items): self.items = items def tableview_did_select(self, tableview, section, row): #main.author_result.text = self.items[row] tableview.hidden = True pass class MyAuthorDelegate (object): def textview_did_change_selection(self, textview): author_unique = ['Aaaa', 'Aabb', 'Bbbb', 'Bccc'] length = len(textview.text) options = [] for author in author_unique: if author[:length] == textview.text: options.append(author) datasource = ui.ListDataSource(options) dropDown = ui.TableView() dropDown.data_source = datasource dropDown.delegate = MyTableViewDelegate(options) dropDown.x = 100 dropDown.y = 55 dropDown.width = 250 dropDown.row_height = 25 view.add_subview(dropDown) pass class Common_View (object): def __init__(self,*args,**kwargs): # pass self.author_result = ui.TextView(name='author',frame=(100,5,250,40), border_color='black', border_width=3, text= '', font=('Arial Rounded MT Bold',20)) # w, h = ui.get_screen_size() view = ui.View(name='Test', bg_color='lightblue', frame=(0, 0, w, h)) main = Common_View() view.add_subview(main.author_result) main.author_result.delegate = MyAuthorDelegate() nav_view = ui.NavigationView(view) nav_view.present('sheet')```
-
RE: search for phrase within script
No need to respond, I figured out the problem.
-
RE: search for phrase within script
Thank you. The first suggestion works and I like the idea of subclassing ui.View, but after I moved the white space around, I'm still getting an error message:
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/99B62839-B39E-4ADF-9308-D5D986E28E91/Pythonista3/Documents/Frank/CommonView2.py", line 19, in <module>
view = Common_View()
File "/private/var/mobile/Containers/Shared/AppGroup/99B62839-B39E-4ADF-9308-D5D986E28E91/Pythonista3/Documents/Frank/CommonView2.py", line 15, in init
self.add_subview(main_author)
NameError: name 'main_author' is not definedimport ui class Common_View(ui.View): def select_author(self, sender): print(self.author_result.text) self.author_result.text = "selected author" print(self.author_result.text) return def __init__(self, *args, **kwargs): self.author_button = ui.Button(title="Author", frame=(10, 5, 350, 100), border_color="black", border_width=2, background_color="#EAECEE", action=self.select_author, font=("Arial Rounded MT Bold", 18)) self.author_button.width = 70 self.author_button.height = 40 self.author_result = ui.TextField(name="author", frame=(100, 5, 250, 40), border_color="black", border_width=3, text="empty") w, h = ui.get_screen_size() ui.View.__init__(self, name="Test View", bg_color="lightblue", frame=(0, 0, w, h), **kwargs) self.add_subview(main_author) self.add_subview(main_author_button) view = Common_View() nav_view = ui.NavigationView(view) nav_view.present("sheet")```
-
RE: search for phrase within script
I have yet another question...over the past few months I have written a number of scripts in which I use a number of TextFields and Buttons in multiple views within the script. I have been creating duplicate versions of the TextFields and Buttons to use in each of the various views. I have been having some small success lately creating classes so I thought I could create a class to contain a set of fields and buttons that I could instantiate for each view. I tried writing a simple class and I can instantiate a button and field in a view but I have so far been unable to populate the field as a result of the button push. If I change the value of the TextField text in the button press function, it prints correctly to the console but does not update the contents of the field in the view. What am I doing wrong? Thanks.
import ui # class Common_View (object): def __init__(self): pass def select_author(sender): print(self.author_result.text) self.author_result.text = 'selected author' print(self.author_result.text) return self.author_button = ui.Button(title='Author', frame=(10,5,350,100), border_color='black', border_width=2, background_color='#EAECEE', action=select_author, font=('Arial Rounded MT Bold',18)) self.author_button.width=70 self.author_button.height=40 self.author_result = ui.TextField(name='author',frame=(100,5,250,40), border_color='black', border_width=3, text= 'empty') # w, h = ui.get_screen_size() view = ui.View(name= 'Test View', bg_color='lightblue', frame=(0, 0, w, h)) main_author = Common_View().author_result view.add_subview(main_author) main_author_button = Common_View().author_button view.add_subview(main_author_button) nav_view = ui.NavigationView(view) nav_view.present('sheet')
-
search for phrase within script
Is there a search function in the pythonista editor? How can I find a specific word or phrase in a script on iphone without reading through the entire script looking for it?
-
RE: how to set the font size of segmented control titles
@cvp said:
UIFont = ObjCClass('UIFont').fontWithName_size_('Arial Rounded MT Bold',22)
attributes = {'NSFont': UIFont}
vo= ObjCInstance(v).segmentedControl()
vo.setTitleTextAttributes_forState_(attributes, 0)That's perfect, thank you.