That strange little thing called NavigationView...
For my app I'm using a NavigationView to offer a second layer of configuration dialogs. It's configured using the built-in UI editor. The pyui is available here. There are three issues:
The button labels of the navigation are centered but the axis is shifted to the right. This effect is not visible in the GUI editor but only when the view is actually displayed. See the following screen shots. The first one shows the view in the GUI editor, the second one shows the view as presented by the
presentmethod, the third one shows the view as child of another larger view. Note the in the latter two cases the labels are centered around an axis which is shifted right from the horizontal center of the view.
The second issue is regarding the manner in which the subviews of the NavigationView are shown in the parent view. Although the parent view has a default title row, the subviews are located as though the title row were not active. Hence, the top subviews are overlayed by the title row. Since the rendering of the view in the app is actually correct this is only a little disturbing but not essential. On the other hand it's interesting to me to know if I'm making a systematic mistake by using NavigationViews in such a way.
The third issue also relates to the title row. As can be seen in this screenshot, using the
presentmethod to show the view results in two title rows: the top one containing the view name and a close button and the second one showing the active view of the navigation hierarchy. Actually, I would like to have the lower one only, but if I deactivate the upper one using a parameter of the
presentmethod, I'm lacking the close button. As far as I can tell it is not possible either to add a
ButtonItemto the left button items of the NavigationView. It is silently ignored. Is there better way to use the NavigationView as a top level view?
Thanks a lot for your help!
dgelessus last edited by
About the double titlebar issue - I encountered that issue back when I wrote filenav (which is basically one big
NavigationView). My solution was to hide the default title bar (I think there's an argument that you can pass to
presentto do that) and add my own close button manually to the titlebar of the view in the
NavigationView. Using the
NavigationViewas the top-level view was not an option, because
presenting it sometimes crashed, depending on the mode.
@dgelessus Did you use a
ButtonItemor a full-fledge
ButtonView? The former did not work for me and as for the latter I have no clue how to add it since the title bar does not seem to be a public attribute. Could you give me hint, please? Thanks!
ccc last edited by ccc
Filenavis in Pythonista-Tools Utilities and contains the lines:
lst.left_button_items = ui.ButtonItem(image=ui.Image.named("ionicons-close-24"), action=close_proxy()), # [ ... ] nav.present("popover", hide_title_bar=True)
dgelessus last edited by
What @ccc said. Thank you for looking up the relevant bits of code.
close_proxyis a tiny one-liner that calls the main view's
closemethod (though this does not work properly with "panel" mode views). Also the
*_button_itemshave to be tuples, single
ButtonItems are not allowed, that's what the comma at the end does (pointing it out because it's easy to overlook).
The first issue with the incorrectly centered buttons is really bugging me. Last night I tried to find a wrong setting somewhere in my code and/or view but everything seems to be alright. That's why I created two small gists reproducing the phenomenon. Find the python script to open the view here and the pyui script here. I would really appreciate some help. Thanks a lot!
@dgelessus @ccc The code that I tried for the
ButtonItems were pretty much the same as you suggested. After a lot of trying I think it's due to the
NavigationViewgenerated by the UI editor. If I create the view programmatically it works. I changed the code in my app to use a pyui file for the general frame. In the frame there is a placeholder where I insert the manually created
NavigationView. As subview I insert another view loaded from another pyui file. It's definitely not straight forward anymore but at least I made some progress after being stuck for two days with the
NavigationViewthat didn't work. By the way: this also fixes the trouble with the wrongly centered buttons.
@omz Could this be a general problem that the
NavigationViewgenerated by the UI editor has some flaw in it making it "misbehave"?