@mcriley821 I have a quick question. I have implemented the function you gave me in a “utility” module and it works fine when calling it from the “main” view. If I call it after loading another “sheet” view, from within that view’s code, the function returns without detecting the theme as it is set in iOS.
Any ideas why the same function would work correctly from the main view and not from other views?
Thanks
From the main view calling the check periodically:
class ThemeThread(threading.Thread):
def __init__(self, event, views=()):
threading.Thread.__init__(self)
self.stopped = event
self.views = views
def run(self):
while not self.stopped.wait(2.0):
mode = utility.get_device_mode()
print('mode for main screen: {}'.format(mode))
if mode == 'dark':
self.change_bg_color('black')
else:
self.change_bg_color('white')
From the other module after loading the “sheet” view:
class AppConfiguration(object):
def __init__(self):
self.utility = Utility()
self.config_file = 'app_configuration.json'
self.screen = ui.load_view("screens_configuration")
mode = self.utility.get_device_mode()
print('mode returns: {}'.format(mode))
My utility module code:
def get_device_mode(self):
traits=objc_util.ObjCClass('UITraitCollection').currentTraitCollection()
mode=traits.userInterfaceStyle()
print('utility mode: {}'.format(mode))
if mode==2:
return 'dark'
else:
return 'light'
Console output:
utility mode: 2
utility mode: 2
mode for main screen: dark
utility mode: 2
mode for main screen: dark
utility mode: 1
mode returns: light
utility mode: 2
mode for main screen: dark
utility mode: 2
mode for main screen: dark
utility mode: 2
mode for main screen: dark
main view will close...