Skip to content

Commit

Permalink
changes to match alterations in pi3d Keyboard and Mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
paddywwoof committed Feb 22, 2025
1 parent 94386ee commit 2e2c598
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
24 changes: 19 additions & 5 deletions src/picframe/interface_peripherals.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(
self.__clock_is_suspended = False
self.__pointer_position = (0, 0)
self.__timestamp = 0
self.__last_check_display_on = 0.0

def check_input(self) -> None:
"""Checks for any input from the selected peripheral device and handles it."""
Expand Down Expand Up @@ -135,6 +136,7 @@ def __get_gui(self) -> "pi3d.Gui":
def __get_mouse(self) -> typing.Optional["pi3d.Mouse"]:
if self.__input_type in ["touch", "mouse"]:
mouse = pi3d.Mouse(
use_x=True,
restrict=self.__input_type == "mouse",
width=self.__viewer.display_width,
height=self.__viewer.display_height,
Expand Down Expand Up @@ -253,6 +255,12 @@ def __handle_keyboard_input(self) -> None:
self.controller.display_is_on = True
else:
self.__gui.checkkey(code)
if code == "RIGHT":
self.controller.next()
elif code == "LEFT":
self.controller.back()
elif code == "ESCAPE":
self.controller.stop()

def __handle_touch_input(self) -> None:
"""Due to pi3d not reliably detecting touch as Mouse.LEFT_BUTTON event
Expand All @@ -275,28 +283,34 @@ def __handle_touch_input(self) -> None:
self.menu_is_on = True # Reset clock for autohide

def __handle_mouse_input(self) -> None:
if self.__pointer_moved() and not self.controller.display_is_on:
self.controller.display_is_on = True
if self.__pointer_moved():
if self.__timestamp > self.__last_check_display_on + 2.0: # this @getter is potentially expensive to run so will slow the mouse
self.__last_check_display_on = self.__timestamp
if self.controller.display_is_on:
self.controller.display_is_on = True

# Show or hide menu
self.menu_is_on = self.__pointer_position[1] > self.__viewer.display_height // 2 - self.__menu_height

# Detect click
if self.__mouse.button_status() == self.__mouse.LEFT_BUTTON and not self.__mouse_is_down:
button = self.__mouse.button_status()
if button == self.__mouse.LEFT_BUTTON and not self.__mouse_is_down:
self.__mouse_is_down = True
self.__handle_click()
elif self.__mouse.button_status() != self.__mouse.LEFT_BUTTON and self.__mouse_is_down:
self.__mouse_is_down = False

def __update_pointer_position(self) -> None:
position_x, position_y = self.__mouse.position()
""" # the mouse location should be generated correctly by X11 or SDL2 in the Mouse class now
if self.__input_type == "mouse":
position_x -= self.__viewer.display_width // 2
position_y -= self.__viewer.display_height // 2
elif self.__input_type == "touch":
# Workaround, pi3d seems to always assume screen ratio 4:3 so touch is incorrectly translated
# to x, y on screens with a different ratio
position_y *= self.__viewer.display_height / (self.__viewer.display_width * 3 / 4)
"""
self.__pointer_position = (position_x, position_y)

def __pointer_moved(self) -> bool:
Expand Down Expand Up @@ -390,7 +404,7 @@ class ExitMenuItem(IPMenuItem):
config_name = "exit"

def action(self):
self.ip.controller.keep_looping = False
self.ip.controller.stop()


class PowerDownMenuItem(IPMenuItem):
Expand All @@ -399,5 +413,5 @@ class PowerDownMenuItem(IPMenuItem):
config_name = "power_down"

def action(self):
self.ip.controller.keep_looping = False
self.ip.controller.stop()
subprocess.check_call(["sudo", "poweroff"])
4 changes: 2 additions & 2 deletions src/picframe/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import locale
import sys
from distutils.dir_util import copy_tree
from shutil import copytree

from picframe import model, viewer_display, controller, __version__

Expand All @@ -15,7 +15,7 @@ def copy_files(pkgdir, dest, target):
fullpath = os.path.join(pkgdir, target)
destination = os.path.join(dest, PICFRAME_DATA_DIR)
destination = os.path.join(destination, target)
copy_tree(fullpath, destination)
copytree(fullpath, destination)
except Exception:
raise

Expand Down
5 changes: 4 additions & 1 deletion src/picframe/viewer_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def display_is_on(self):
self.__logger.debug("Display ON/OFF is X with dpms enabled, but an error occurred")
self.__logger.debug("Cause: %s", e)
return True
elif self.__display_power == 2:
return True # TODO this needs proper test
else:
self.__logger.warning("Unsupported setting for display_power=%d.", self.__display_power)
return True
Expand Down Expand Up @@ -287,6 +289,7 @@ def __get_aspect_diff(self, screen_size, image_size):

def __tex_load(self, pics, size=None): # noqa: C901
try:
self.__logger.debug(f"loading images: {pics[0].fname} {pics[1].fname if pics[1] else ''}") #<<<<<<
if self.__mat_images and self.__matter is None:
self.__matter = mat_image.MatImage(display_size=(self.__display.width, self.__display.height),
resource_folder=self.__mat_resource_folder,
Expand Down Expand Up @@ -492,7 +495,7 @@ def is_in_transition(self):
def slideshow_start(self):
self.__display = pi3d.Display.create(x=self.__display_x, y=self.__display_y,
w=self.__display_w, h=self.__display_h, frames_per_second=self.__fps,
display_config=pi3d.DISPLAY_CONFIG_HIDE_CURSOR,
display_config=pi3d.DISPLAY_CONFIG_HIDE_CURSOR | pi3d.DISPLAY_CONFIG_NO_FRAME,
background=self.__background, use_glx=self.__use_glx,
use_sdl2=self.__use_sdl2)
camera = pi3d.Camera(is_3d=False)
Expand Down

0 comments on commit 2e2c598

Please sign in to comment.