Package elisa :: Package plugins :: Package base :: Package controllers :: Module slideshow_controller
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.base.controllers.slideshow_controller

  1  # -*- coding: utf-8 -*- 
  2  # Elisa - Home multimedia server 
  3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  4  # All rights reserved. 
  5  # 
  6  # This file is available under one of two license agreements. 
  7  # 
  8  # This file is licensed under the GPL version 3. 
  9  # See "LICENSE.GPL" in the root of this distribution including a special 
 10  # exception to use Elisa with Fluendo's plugins. 
 11  # 
 12  # The GPL part of Elisa is also available under a commercial licensing 
 13  # agreement from Fluendo. 
 14  # See "LICENSE.Elisa" in the root directory of this distribution package 
 15  # for details on that license. 
 16   
 17   
 18  __maintainer__ = 'Lionel Martin <lionel@fluendo.com>' 
 19  __maintainer2__ = 'Florian Boucault <florian@fluendo.com>' 
 20   
 21   
 22  from elisa.base_components.controller import Controller 
 23  from twisted.internet import reactor 
 24  from elisa.core.input_event import * 
 25   
 26   
27 -class SlideshowController(Controller):
28 29 supported_models = ('base:slideshow_model',) 30 bindings = {'current_index': 'current_index', 31 'playing': 'playing', 32 'preview_mode': 'preview_mode', 33 'duration': 'duration'} 34
35 - def __init__(self):
36 Controller.__init__(self) 37 self._call_later = None
38
39 - def handle_input(self, input_event):
40 if input_event.action == EventAction.GO_LEFT: 41 if len(self.model.playlist) > 0: 42 self.previous_image() 43 return True 44 45 elif input_event.action == EventAction.GO_RIGHT: 46 if len(self.model.playlist) > 0: 47 self.next_image() 48 return True 49 50 elif input_event.action == EventAction.OK: 51 self.model.playing = not self.model.playing 52 return True 53 54 elif input_event.action == EventAction.PLAY: 55 self.model.playing = True 56 return True 57 58 elif input_event.action == EventAction.PAUSE: 59 self.model.playing = False 60 return True 61 62 elif input_event.action == EventAction.STOP: 63 self.model.playing = False 64 self.model.current_index = 0 65 return True 66 67 return False
68
69 - def attribute_set(self, origin, key, old_value, new_value):
70 Controller.attribute_set(self, origin, key, old_value, new_value) 71 72 if key == 'playing': 73 if self.model.playing: 74 self._call_later = reactor.callLater(self.model.duration, 75 self.next_image) 76 else: 77 self._cancel_last_call_later() 78 elif key == 'preview_mode': 79 if not new_value: 80 self.focus()
81
82 - def _cancel_last_call_later(self):
83 if self._call_later != None and self._call_later.active(): 84 self._call_later.cancel()
85
86 - def focused_changed(self, old_focused, new_focused):
87 if new_focused == False and self.model.playing == True: 88 self._cancel_last_call_later() 89 self.model.playing = False
90
91 - def next_image(self):
92 self._cancel_last_call_later() 93 94 index = self.model.current_index + 1 95 if index < len(self.model.playlist): 96 self.info("Loading image at index %r", index) 97 self.model.current_index = index 98 if self.model.playing == True: 99 self._call_later = reactor.callLater(self.model.duration, 100 self.next_image) 101 return True 102 else: 103 self.info("Reached end of slideshow") 104 return False
105
106 - def previous_image(self):
107 self._cancel_last_call_later() 108 109 index = self.model.current_index - 1 110 if index < len(self.model.playlist) and index >= 0: 111 self.info("Loading image at index %r", index) 112 self.model.current_index = index 113 if self.model.playing == True: 114 self._call_later = reactor.callLater(self.model.duration, 115 self.previous_image) 116 return True 117 else: 118 self.info("Reached beginning of slideshow") 119 return False
120