Forum Archive

How to hide status bar in scene?

Tey

How can I keep the status bar (giving time, date, .... battery level) from appearing at the top of my scene?

import scene
import ui

class Loop(scene.Scene):

    def setup(self):
        self.background_color = 'white'

    def update(self):
        time = self.t 

v = ui.View(frame=(0, 0, 1366, 1024))
v.present('full_screen', hide_title_bar = True) 
  • list item
JonB
import objc_util
objc_util.UIApplication.sharedApplication().statusBar().hidden = True

Add that after you present your script.

Tey

That causes my screen to appear briefly, then the program terminates.

cvp

@Tey That's because Pythonista crashes, this function needs to run in main thread
See file _objc_exception.txt

The app was terminated due to an Objective-C exception. Details below:

2020-02-19 10:39:50.178902
threading violation: expected the main thread 

Try so

@on_main_thread
def x():
    objc_util.UIApplication.sharedApplication().statusBar().hidden = True
x() 

No more crash but does not work, perhaps due to ios13

mikael

@Tey, it does not make a lot of sense, but include title_bar_color='black' in present.

mikael

@Tey, just checking the question. If I run the below, I get a full red screen with no extras except the ”X” to close. What happens on your device, and which device is it?

import scene

class Loop(scene.Scene):

    def setup(self):
        self.background_color = 'red'

scene.run(Loop()) 
cvp

@mikael said:

include title_bar_color='black' in present.

It works but I don't understand why.

The status bar either disappears, either has its characters white???

cvp

@mikael said:

I get a full red screen with no extras except the ”X” to close.

I too, but why?

mikael

@cvp, because scene is not ui, and this is how it is supposed to work?

ui has issues not really supporting removing the extras with present *), but if OP had the issue with scene as the title suggests, I do not see the problem.

*) Workaround: run a scene, then use its view attribute as you would any other ui root view.

cvp

@mikael Already understood in the past and forgotten. 70 years old today, thus perhaps too old for this kind of stuff 😢 If you say "yes", I kill you 😂

mikael

@cvp, congratulations!

cvp

@mikael Thanks

mikael

@cvp, Grand Old Man of Pythonista? :-P

cvp

@mikael Ho no, believe me. I've just enough free time to test/try a lot.

ccc

@cvp said:

70 years old today

How would you use Python to determine how many days old you are? Hint: use actual birthdate and 70 year birthday date to avoid any off-by-one errors for leap years.

Extra credit: How many leap seconds have you live through so far?!?

cvp

@ccc said:

How would you use Python to determine how many days old you are?

Sure you will have shorter

from datetime import date
d0 = date(1950,2,19)    # birthdate
d1 = date.today()
delta = d1 - d0
print(delta.days) 
Tey

My ... we do wander off topic don’t we?

I’m running 13.3.1 on an iPad Pro (12.9 inch) (2nd generation)

My problem is with the status bar, not the title bar. The title bar is the one with the X used to terminate the program. It can be made to completely disappear using hide_title_bar = True, as in my original post.

The status bar is an Apple thing. It contains time and date at the left and battery indicator among other things at the left. You see it at the top of your main screen.

So, to summarize:

@JonB your suggestion of
import objc_util
objc_util.UIApplication.sharedApplication().statusBar().hidden = True

for reasons unknown to me no longer causes the screen to appear for a split second before Pythonista terminates. The program no longer terminates but the status bar is still present.

@cvp your suggestion of
“@on_main_thread
def x():
objc_util.UIApplication.sharedApplication().statusBar().hidden = True
x() “

causes a NameError, name on_main_thread is not defined. And the status bar is still there.

@cvp I have you beat by a decade. My first computer was an IBM 1620, used paper tape, took 180 microseconds to execute a NOOP and had a 40K digital memory. None of this newfangled octal or hexadecimal. Seventy may be the new fifty but eighty is still the same old eighty!

cvp

@Tey The suggestion of @JonB is correct but, since iOS 13 needs to run in main thread.
You can have the reason of the error in the _objc_exception.txt file after the crash
Thus, you need to do

from objc_util import *
.
.
.
@on_main_thread # comes from objc_util
def x():
.
.

Thus, so no more crash but status bar still there because jonb suggestion is no more valid in iOS 13

cvp

@Tey said:

@on_main_thread
def x():
objc_util.UIApplication.sharedApplication().statusBar().hidden = True
x() “
causes a NameError, name on_main_thread is not defined.

NameError because we

import objc_util

Instead of

from objc_util import *
Tey

Still get the NameError. Just to be clear, below is what ran. I’ve also run it with @JonB lines after v.present but of course still get the name error.

I’ll give up on this for now because in actual practice my screen is black not white and the status info only shows up when something light colored passes behind the status bar.

Thanks everyone for trying.

import scene
import ui
from objc_util import *

class Loop(scene.Scene):

    def setup(self):
        self.background_color = 'white'

    def update(self):
        time = self.t 

v = ui.View(frame=(0, 0, 1366, 1024))

@on_main_thread # comes from objc_util
def x():
    objc_util.UIApplication.sharedApplication().statusBar().hidden = True
x() 

v.present('full_screen', hide_title_bar = True)
mikael

@Tey, this seems solvable. Could you first clarify whether you are developing with the ui or scene? I would expect scene if this is some type of a game, and ui otherwise.

Your code snippet imports both, but only uses ui, as the scene class seems not to be used.

If you are really using scene only, you should not be using present, only scene.run.

If you are using ui, you can use the workaround I mentioned above to hide the Apple stuff at the top.

JonB

If you import * from objc_util, then erase the objc_util before UIApplication.

But yes, there is a different solution for scenes inside sceneview, versus scenes using Scene.run

Tey

@mikael
I am new to all this, so I’m not sure what you mean by “developing with”. I am using both scene and ui. I create menus by calls to ui, not with the UI builder.The program begins with menu buttons appearing to float on top of the initially black scene (because the menu itself has alpha 0.) Pressing a button causes the buttons to disappear and an animation to begin. Pressing a navicon icon in the upper left of the scene causes the animation to stop and the buttons to return. Menus of buttons and controls will be dynamically created allowing the user to adjust animation parameters.

mikael

@Tey, thank you for explaining. Since you are mostly building on scene with minor ui embellishments, and do not like the Apple stuff at the top, start with running the scene and then add ui elements as needed. Please see a minimal example below.

With the mixed use, remember that for scene, y=0 is at the bottom, while for the ui views it is at the top.

import ui
import scene

class Loop(scene.Scene):

    def setup(self):
        self.background_color = 'black'

        btn1 = self.button1 = ui.Button(
            title='Animation 1',
            background_color='grey',
            tint_color='black',
            action=self.animation1,
        )
        btn1.size_to_fit()
        btn1.width += 16
        btn1.center = self.view.bounds.center()
        self.view.add_subview(btn1)

        btne = self.end_button = ui.Button(
            title='Stop',
            background_color='transparent',
            tint_color='grey',
            action=self.show_menu,
            hidden=True,
        )
        btne.size_to_fit()
        btne.width += 16
        btne.x = btne.y = 8
        self.view.add_subview(btne)

    def hide_menu(self):
        self.button1.hidden = True
        self.end_button.hidden = False

    def show_menu(self, sender):
        for node in self.children:
            node.remove_all_actions()
            node.remove_from_parent()
        self.button1.hidden = False
        self.end_button.hidden = True

    def animation1(self, sender):
        self.hide_menu()
        ship = scene.SpriteNode('spc:PlayerShip1Orange')
        ship.position = self.size / 2
        self.add_child(ship)
        ship.run_action(
            scene.Action.repeat_forever(
                scene.Action.rotate_by(1)
        ))

scene.run(Loop())

cvp

@JonB said:

If you import * from objc_util, then erase the objc_util before UIApplication.

Of course, this is how my script does but I forgot to mention it, sorry.

Tey

@mikael
Thank you so much! It looks like it will do the trick. I won’t have time to apply it to my project for the next week or so but will get back to you.

Carme7n

We need to hide the status bar, navigation bar, and other things and only show the content we want to display!

omz

I'm not sure if I understand the problem correctly, and I think a solution has already have been suggested.

However, I would recommend using scene.run() for presenting, and then adding UI elements e.g. in setup(), like this:

from scene import *
A = Action

class MyScene (Scene):
    def setup(self):
        button = ui.Button(title='Tap me')
        self.view.add_subview(button)

    def did_change_size(self):
        pass
        # You may want to do layout here...

    # ...

if __name__ == '__main__':
    run(MyScene(), show_fps=False)

(Modified just slightly from the standard Game/Animation template)