ソースを参照

Merge pull request #25 from jezek/keyboard_control

ESC exits program, if keyboard control is enabled
pull/37/merge
Brennen Bearnes 6年前
committed by GitHub
コミット
9a17034b68
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: 4AEE18F83AFDEB23
2個のファイルの変更24行の追加2行の削除
  1. +19
    -2
      Adafruit_Video_Looper/video_looper.py
  2. +5
    -0
      video_looper.ini

+ 19
- 2
Adafruit_Video_Looper/video_looper.py ファイルの表示

@@ -54,6 +54,7 @@ class VideoLooper(object):
# Load other configuration values.
self._osd = self._config.getboolean('video_looper', 'osd')
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
# list of ints for colors.
self._bgcolor = map(int, self._config.get('video_looper', 'bgcolor') \
@@ -190,6 +191,11 @@ class VideoLooper(object):
sw, sh = self._screen.get_size()
self._screen.fill(self._bgcolor)
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()

def _prepare_to_run_playlist(self, playlist):
@@ -224,16 +230,27 @@ class VideoLooper(object):
# Rebuild playlist and show countdown again (if OSD enabled).
playlist = self._build_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.
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
if self._player is not None:
self._player.stop()
pygame.quit()

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


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


+ 5
- 0
video_looper.ini ファイルの表示

@@ -36,6 +36,11 @@ osd = true
# To play random playlist.
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
# 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.


読み込み中…
キャンセル
保存