Home | Trees | Indices | Help |
---|
|
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 Input events data structures 19 """ 20 21 22 __maintainer__ = 'Philippe Normand <philippe@fluendo.com>' 23 __maintainer2__ = 'Florian Boucault <florian@fluendo.com>' 24 25 26 # FIXME: many questions are left unanswered such as: 27 # - do we need more information than that ? 28 # : mouse position x/y 29 # - how do we handle events from multiple Pigment's viewports ? 30 31 from elisa.extern import enum 32 import string 33 34 EventSource = enum.Enum('KEYBOARD', 'MOUSE', 'REMOTE', 'OTHER') 35 EventType = enum.Enum('MOUSE_DOWN', 'MOUSE_UP', 'MOUSE_MOVE', 'KEY_DOWN', 36 'KEY_UP', 'OTHER') 37 38 39 key_values = ['KEY_%s' % k for k in string.ascii_letters] + ['KEY_RETURN'] 40 num_values = ['KEY_%s' % k for k in string.digits] 41 42 mouse_values = ['MOUSE_LEFT', 'MOUSE_MIDDLE', 'MOUSE_RIGHT',] 43 values = key_values + num_values + mouse_values + ['NONE'] 44 EventValue = enum.Enum(*values) 45 46 EventAction = enum.Enum('NONE', 'GO_UP', 'GO_DOWN', 'GO_LEFT', 47 'GO_RIGHT', 'OK', 'MENU','DVD_MENU', 48 'EXIT', 'PLAY', 'PAUSE', 49 'STOP', 'INC_PLAYBACK_SPEED', 50 'DEC_PLAYBACK_SPEED', 'SEEK_FORWARD', 51 'SEEK_BACKWARD', 'TOGGLE_FULLSCREEN', 52 'MUTE', 'VOL_UP', 'VOL_DOWN', 53 'NEXT','PREVIOUS') 54 EventModifier = enum.Enum('NONE', 'CTRL', 'SHIFT', 'ALT') 55 5658 """ 59 InputEvent base class 60 61 Each InputProvider component is able to build them and feed the 62 InputManager with them. This class should allow us to abstract any 63 kind of input event that can be injected in Elisa. 64 65 @ivar source: source device of the event (keyboard, mouse, ...) 66 @ivar type: type of event (KEY_UP, KEY_DOWN, ...) 67 @ivar action: event's high level action (EXIT, PLAY, ...) 68 @ivar value: event's value (KEY_a, MOUSE_LEFT, ...) 69 @ivar modifier: event's modifier, especially useful for keyboards 70 @ivar source_id: source device id, 0 by default 71 """ 72 7313174 - def __init__(self, source_type, event_type, action=EventAction.NONE, 75 value=EventValue.NONE, source_id=None, modifier=EventModifier.NONE, origin=None):76 """ 77 Create an InputEvent of a given type 78 79 @param source_type: source device of the event (keyboard, mouse, ...) 80 @type source_type: L{EventSource} 81 @param event_type: type of event (key_up, key_down, ...) 82 @type event_type: L{EventType} 83 @param value: event's value (KEY_a, MOUSE_LEFT, ...) 84 @type value: L{EventValue} 85 @param action: event's high level action 86 @type action: L{EventAction} 87 @param source_id: source device id, 0 by default 88 @type source_id: int 89 @param modifier: event's modifier, especially useful for keyboards 90 @type modifier: L{EventModifier} 91 @param origin: origin of the event 92 @type origin: L{elisa.core.backend.Backend} or L{elisa.core.frontend.Frontend} or None 93 94 95 @raise ValueError: raised when either source, event_type 96 or value is None 97 """ 98 if not source_type: 99 raise ValueError("Event with no source") 100 if not event_type: 101 raise ValueError("Event with no type") 102 if not value: 103 raise ValueError("Event with no value") 104 105 self.source = source_type 106 self.type = event_type 107 self.value = value 108 self.action = action 109 self.modifier = modifier 110 self.source_id = source_id 111 self.origin = origin112114 return "InputEvent from a %s (id=%s) with: type=%s, action=%s, value=%s, modifier=%s, origin=%s" \ 115 % (self.source, self.source_id, self.type, \ 116 self.action, self.value, self.modifier, self.origin)117119 if not isinstance(other, InputEvent): 120 return False 121 return self.source == other.source and \ 122 self.type == other.type and \ 123 self.action == other.action and \ 124 self.value == other.value and \ 125 self.modifier == other.modifier and \ 126 self.source_id == other.source_id and \ 127 self.origin == other.origin128130 return not self.__eq__(other)
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Wed Jan 16 19:10:30 2008 | http://epydoc.sourceforge.net |