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.
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
present
method, 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
present
method 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 thepresent
method, I'm lacking the close button. As far as I can tell it is not possible either to add aButtonItem
to 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!
-
-
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 topresent
to do that) and add my own close button manually to the titlebar of the view in theNavigationView
. Using theNavigationView
as the top-level view was not an option, becausepresent
ing it sometimes crashed, depending on the mode. -
@dgelessus Did you use a
ButtonItem
or a full-fledgeButtonView
? 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! -
Filenav
is 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)
-
What @ccc said. Thank you for looking up the relevant bits of code.
:)
FYI, theclose_proxy
is a tiny one-liner that calls the main view'sclose
method (though this does not work properly with "panel" mode views). Also the*_button_items
have to be tuples, singleButtonItem
s 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
ButtonItem
s were pretty much the same as you suggested. After a lot of trying I think it's due to theNavigationView
generated 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 createdNavigationView
. 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 theNavigationView
that 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
NavigationView
generated by the UI editor has some flaw in it making it "misbehave"?