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.
Tableview font type
-
Is there an easy quick way to set a different text font to tableview contents?
-
If I correctly understand the question:
elements_txt = ui.TableView() elements_txt.text_color = 'black' elements_txt.font= ('Courier',12)
-
Thanks for the tip. I managed to change the font by passing my ListDataSource object instead of the tableview name. Is that ok?
-
No idea, sorry
I also use the delegate tableview_cell_for_row to change the content of the cell
cell = ui.TableViewCell() cell.text_label.text_color = 'green' cell.accessory_type = 'detail_button' selected_cell = ui.View() selected_cell.border_color = 'black' selected_cell.border_width = 2 selected_cell.corner_radius = 10 selected_cell.bg_color = 'cornflowerblue' cell.selected_background_view = selected_cell
-
Now that's interesting. Where should we put that code?
So, I assume we are able to define a custom formatting to individual cells. I am particularly interested at this point in changing cell background color and maybe text color or font, according to certain criteria, while creating the tableview or adding cells.
At this point I have a tableview named 'mutable' made with the designer and I am calling it with this simple code:
mydatasource = ui.ListDataSource(DADOS) v = ui.load_view('my-GUI-app') v['mytable'].data_source = mydatasource v['mytable'].delegate = mydatasource mydatasource.font = ('Helvetica Neue', 14) v.present('sheet')
Is my usage of ListDataSource preventing me from adding that kind of formatting to cells? Should I use other way?
-
I don't use pyui file, I build the ui.view in my script, but perhaps you could use the same feature of delegate with a pyui file.
class my_list(ui.View): def __init__(self): ... elements_txt.delegate = self def tableview_cell_for_row(self, tableview, section, row): cell = ui.TableViewCell() v = my_list() v.present(...)
-
I really got to try Pythonista ui by coding directly in the script, instead of using the graphical designer. I am trying to find some seasy step-by-step tutorials. I have recently had a similar struggle with tkinter :-)
-
I build my UI using the UI designer and then I copy the JSON into a string inside of the code. Then I load the view using
ui.load_view_str()
. Another way you could do it.
Example: https://github.com/TutorialDoctor/The-Bible-App/blob/master/the_bible.py -
Nice!
I didn't know that
I learn each day -
I am right now dissecting a sample tableview in order to better understand how it works. It's starting to make some sense in my head, but I am still figuring things out.