Browse Source

Merge pull request #25 from jezek/keyboard_control

ESC exits program, if keyboard control is enabled
pull/37/merge
Brennen Bearnes 6 years ago
committed by GitHub
parent
commit
9a17034b68
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions
  1. +19
    -2
      Adafruit_Video_Looper/video_looper.py
  2. +5
    -0
      video_looper.ini

+ 19
- 2
Adafruit_Video_Looper/video_looper.py View File

@@ -54,6 +54,7 @@ class VideoLooper(object):
# Load other configuration values. # Load other configuration values.
self._osd = self._config.getboolean('video_looper', 'osd') self._osd = self._config.getboolean('video_looper', 'osd')
self._is_random = self._config.getboolean('video_looper', 'is_random') self._is_random = self._config.getboolean('video_looper', 'is_random')
self._keyboard_control = self._config.getboolean('video_looper', 'keyboard_control')
# Parse string of 3 comma separated values like "255, 255, 255" into # Parse string of 3 comma separated values like "255, 255, 255" into
# list of ints for colors. # list of ints for colors.
self._bgcolor = map(int, self._config.get('video_looper', 'bgcolor') \ self._bgcolor = map(int, self._config.get('video_looper', 'bgcolor') \
@@ -190,6 +191,11 @@ class VideoLooper(object):
sw, sh = self._screen.get_size() sw, sh = self._screen.get_size()
self._screen.fill(self._bgcolor) self._screen.fill(self._bgcolor)
self._screen.blit(label, (sw/2-lw/2, sh/2-lh/2)) self._screen.blit(label, (sw/2-lw/2, sh/2-lh/2))
# If keyboard control is enabled, display message about it
if self._keyboard_control:
label2 = self._render_text('press ESC to quit')
l2w, l2h = label2.get_size()
self._screen.blit(label2, (sw/2-l2w/2, sh/2-l2h/2+lh))
pygame.display.update() pygame.display.update()


def _prepare_to_run_playlist(self, playlist): def _prepare_to_run_playlist(self, playlist):
@@ -224,16 +230,27 @@ class VideoLooper(object):
# Rebuild playlist and show countdown again (if OSD enabled). # Rebuild playlist and show countdown again (if OSD enabled).
playlist = self._build_playlist() playlist = self._build_playlist()
self._prepare_to_run_playlist(playlist) self._prepare_to_run_playlist(playlist)
# Event handling for key press, if keyboard control is enabled
if self._keyboard_control:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
# If pressed key is ESC quit program
if event.key == pygame.K_ESCAPE:
self.quit()
# Give the CPU some time to do other tasks. # Give the CPU some time to do other tasks.
time.sleep(0.002) time.sleep(0.002)


def signal_quit(self, signal, frame):
"""Shut down the program, meant to by called by signal handler."""
def quit(self):
"""Shut down the program"""
self._running = False self._running = False
if self._player is not None: if self._player is not None:
self._player.stop() self._player.stop()
pygame.quit() pygame.quit()


def signal_quit(self, signal, frame):
"""Shut down the program, meant to by called by signal handler."""
self.quit()



# Main entry point. # Main entry point.
if __name__ == '__main__': if __name__ == '__main__':


+ 5
- 0
video_looper.ini View File

@@ -36,6 +36,11 @@ osd = true
# To play random playlist. # To play random playlist.
is_random = false is_random = false


# Control the program via keyboard
# If enabled, hit ESC key to quit the program anytime (except countdown).
keyboard_control = false
#keyboard_control = true

# Change the color of the background that is displayed behind movies (only works # Change the color of the background that is displayed behind movies (only works
# with omxplayer). Provide 3 numeric values from 0 to 255 separated by a commma # with omxplayer). Provide 3 numeric values from 0 to 255 separated by a commma
# for the red, green, and blue color value. Default is 0, 0, 0 or black. # for the red, green, and blue color value. Default is 0, 0, 0 or black.


Loading…
Cancel
Save