Skip to content

Commit

Permalink
Only auto-reload the active screen
Browse files Browse the repository at this point in the history
  • Loading branch information
tsbarnes committed Sep 19, 2021
1 parent ca911ea commit 549f5d3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
43 changes: 30 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,26 @@ def current_screen(self):
def current_screen_module(self):
return self.screen_modules[self.current_screen_index]

def previous_screen(self):
if self.current_screen_index > 0:
self.current_screen_index -= 1
else:
self.current_screen_index = len(self.screens) - 1
logging.debug("Current screen: {0}".format(self.current_screen().__module__))
self.current_screen().reload()
self.current_screen().show()

def next_screen(self):
self.current_screen_index += 1
if self.current_screen_index >= len(self.screens):
self.current_screen_index = 0
logging.debug("Current screen: {0}".format(self.current_screen().__module__))
self.current_screen().reload()
self.current_screen().show()

def handle_btn0_press(self):
if settings.PAGE_BUTTONS:
if self.current_screen_index > 0:
self.current_screen_index -= 1
else:
self.current_screen_index = len(self.screens) - 1
logging.debug("Current screen: {0}".format(self.current_screen().__module__))
self.current_screen().show()
self.previous_screen()
else:
logging.debug("Screen '{0}' handling button 0".format(self.current_screen().__module__))
self.current_screen().handle_btn_press(button_number=0)
Expand All @@ -68,11 +80,7 @@ def handle_btn2_press(self):

def handle_btn3_press(self):
if settings.PAGE_BUTTONS:
self.current_screen_index += 1
if self.current_screen_index >= len(self.screens):
self.current_screen_index = 0
logging.debug("Current screen: {0}".format(self.current_screen().__module__))
self.current_screen().show()
self.next_screen()
else:
logging.debug("Screen '{0}' handling button 3".format(self.current_screen().__module__))
self.current_screen().handle_btn_press(button_number=3)
Expand Down Expand Up @@ -153,14 +161,18 @@ def process_message(self):

command = parts[0]
logging.debug("Received IPC command: " + command)
if command == "previous" or command == "button0":
if command == "button0":
self.handle_btn0_press()
elif command == "next" or command == "button3":
elif command == "button3":
self.handle_btn3_press()
elif command == "button1":
self.handle_btn1_press()
elif command == "button2":
self.handle_btn2_press()
elif command == "previous":
self.previous_screen()
elif command == "next":
self.next_screen()
elif command == "reload":
self.current_screen().reload()
self.current_screen().show()
Expand Down Expand Up @@ -211,6 +223,11 @@ def loop(self):
if self.weather.refresh_interval < 0:
self.update_weather()

self.current_screen().reload_wait += 1
if self.current_screen().reload_wait >= self.current_screen().reload_interval:
self.current_screen().reload_wait = 0
self.current_screen().reload()

time.sleep(1)

if self.loop_time == TIME:
Expand Down
7 changes: 2 additions & 5 deletions screens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,10 @@ def handle_btn_press(self, button_number=1):
def iterate_loop(self):
"""
Called once per cycle (roughly every one second). If you need to do something in the main loop,
do it here. Make sure to call super().iterate_loop() if you override this.
do it here.
:return: None
"""
self.reload_wait += 1
if self.reload_wait >= self.reload_interval:
self.reload_wait = 0
self.reload()
pass

def paste(self, image: Image, position: tuple = (0, 0)):
"""
Expand Down

0 comments on commit 549f5d3

Please sign in to comment.