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.
Possible to change menubar/header color and font for ui.view?
-
-
Hello guys.
Is there a way to havemain_view.present('test_1')
And
nav_view = ui.NavigationView(main_view) nav_view.present()``` Both at the sametime Somehow? As of now it will crash and the only way is to remove one of them. The reason I would like both of them is that using frame = x,x,x,x for main_view makes it somehow not possible to use the header for text and icons. Using a pyui file I can use 768x1024 format and have my title and icons on the header
-
It is a bit unclear to me what you are trying to do.
- An
ui.NavigationView
is just a (weirdly named) StackPanel - You cannot present an instance of a view twice. If you do present your
main_view
you cannot add it to thenav_view
and present it again. - You can however present as many views as you want alongside (views are always modal though).
edit: You can present an instance of a view multiple times as a popover (popovers behave it a bit weirdly). Also nothing should crash if you try to present a view twice. You should just get an exception informing you that the view is already being presented. So if your code is crashing for you, you should probably provide a more extensive code example.
Your code should look something like this:
import ui some_view = ui.View() nav_view = ui.NavigationView(some_view) nav_view.present('popover')
- An
-
@zipit Views aren't always modal - if you present a view as
"panel"
, it appears as an extra tab in the console panel. You can do this for as many views as you want, without blocking the rest of Pythonista.PS: I think Pythonista still has some crashing issues if you present a
NavigationView
and then close it. As a workaround, you can put theNavigationView
inside a normalView
and present that. -
This is a great discussion because these choices can be confusing. Perhaps someone could create a repo showing several various possibilities. This could be added to the UI tutorial or could be a standalone repo. https://github.com/Pythonista-Tools/Pythonista-Tools/blob/master/UI.md
-
@zipit thanks for the answer, I will try using pop-over and see how it looks. I just like how the NavigationView covers the whole ui.view this way
-
Is there a way to load a pyui file for the main view without using
Main_view.present('pyui file)
this crash is really bugging me tried different options like "popover" and "panel" for NavigationView but in the end it always crashes -
This should look something like:
ui.load_view('My UI').present('sheet')
...You could also leave the
ui.load_view()
parameter blank and then make sure thatmy_script.py
andmy_script.pyui
have matching names or could post a minimal example that actually crashes so that we can debug it together.It is easier to debug Python code than it is to debug English prose.
-
@ccc thx. Gonna try your example first if it does not work. I will try to post it in a short version
-
@ccc it's not crashing anymore now thanks to you!
I also found an other issue that I could fix thanks to this
Really greatful for your help -
Is it possible to dynamically change the title bar color?
I have a ui.View derived class, where initially set the title_bar_color when I present the view. Based on user input, I would like to change the color of the title bar. Is this possible?
-
Are you presentng full screen, sheet, or panel?
-
Bjucha, I am presenting a sheet.
The code is:
if __name__ == "__main__": v = FSButtonView() v.present('sheet', title_bar_color='#334444', hide_close_button=True, orientation=['portrait'])
The FSButtonView class derives from the ui.View class.
In the code, I add an ImageView instance as a subview of the main view to show an image that covers all the screen except the title bar. I want the title bar so the cell signal strength, the time, etc. are visible at the top of my iPhone screen. I also want the background of the title bar to match the background of the image. The image background is approximately the color '#334444'.
By tapping the screen (using Morse code) I can control various functions, including removing the subview (image) from the view, and later adding it back. When it's removed, the screen becomes black (minimum battery power), and I want the title bar to become black too. When I add the image back, I want the title bar to return to the image background color, not to the view background color).
The problem now is that the title bar is always the image background color. It do not know how to change the title bar to be black, and then how to change it back to the image color if the image (sub-view) is added back to the view.
If I hide the title bar by using a key argument (I think it was "hide_title_bar") in the "present" methods, then the image covers the entire screen, and then the cell signal strength, time, etc.., are not visible. I want those to remain visible.
I'm not sure what would happen if I hid the title bar when the image was removed, and showed the title bar when the image was put back. I also don't know how to hide/show the title bar dynamically, or if that's even possible.
-
So, this is not at all robust, and could change in any pythonista version.... but here is a way to get access to the title bar, to change its color, hide it, etc.
v=ui.View() v.present('sheet') V=ObjCInstance(v) titlebarbkg= V.superview().superview().superview().subviews()[1].subviews()[0] #a more robust way might be to keep traversing up until one of subviews is a UINavigationBar, then follow that down to the UINavigationBarBackground titlebarbkg.backgroundColor=UIColor.redColor() #titlebarbkg.backgroundColor=UIColor.UIColor.colorWithHexString_('ffee22') #titlebarbkg.hidden=True
-
JonB, thank you very much! That worked. I had tried to write some code that iterated over Obective C UI items, trying to find the item that mattered and changing it's color, but I never got it to work.
Eventually, I'll try to figure out the hierarchy using your code as a guide, and match to the right names so that the code is somewhat more robust to version changes. For now, I added the following method to my ui.View-derived class, that allows me to change the title bar color dynamically.
def change_title_bar_color(self, hex_color): """ Change the title bar color to the passed color. """ vv = ObjCInstance(self) bar_bckgnd = vv.superview().superview().superview().subviews()[1].subviews()[0] bar_bckgnd.backgroundColor = UIColor.colorWithHexString_(hex_color)
-
This post is deleted!