Update of /cvsroot/freevo/freevo/src/input/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12699/src/input/plugins
Modified Files:
sdl.py
Log Message:
use new sdl kaa.display signals
Index: sdl.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/input/plugins/sdl.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** sdl.py 9 Jul 2005 09:08:39 -0000 1.7
--- sdl.py 13 Jul 2005 20:17:32 -0000 1.8
***************
*** 1,40 ****
! #if 0 /*
! # -----------------------------------------------------------------------
# sdl.py - SDL input support using pygame.
! # -----------------------------------------------------------------------
# $Id$
#
! # This file handles pygame events and handles the keycode -> event
! # mapping. You don't have to activate this plugin, it will be auto
! # activated when the sdl display engine is used.
! #
! # -----------------------------------------------------------------------
! # $Log$
! # Revision 1.7 2005/07/09 09:08:39 dischi
! # update mouse support
! #
! # Revision 1.6 2005/07/08 14:46:06 dischi
! # add basic mouse support
! #
! # Revision 1.5 2005/05/07 18:09:41 dischi
! # move InputPlugin definition to input.interface
! #
! # Revision 1.4 2004/11/20 18:23:03 dischi
! # use python logger module for debug
! #
! # Revision 1.3 2004/10/06 18:52:27 dischi
! # use KEYBOARD_MAP now and switch to new notifier code
! #
! # Revision 1.2 2004/09/27 18:40:35 dischi
! # reworked input handling again
#
! # Revision 1.1 2004/09/25 04:42:22 rshortt
! # An SDL input handler using pygame. This may work already but is still a
! # work in progress. Freevo still gets its input using src/gui/displays/sdl.py
! # for the time being. We need to work on universal user defined keymaps.
#
- # -----------------------------------------------------------------------
- # Freevo - A Home Theater PC framework
- # Copyright (C) 2003 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
--- 1,15 ----
! # -*- coding: iso-8859-1 -*-
! #
-----------------------------------------------------------------------------
# sdl.py - SDL input support using pygame.
! #
-----------------------------------------------------------------------------
# $Id$
#
! #
-----------------------------------------------------------------------------
! # Freevo - A Home Theater PC framework
! # Copyright (C) 2002-2005 Krister Lagerstrom, Dirk Meyer, et al.
#
! # First Edition: Dirk Meyer <[EMAIL PROTECTED]>
! # Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
#
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
***************
*** 53,76 ****
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
! # ----------------------------------------------------------------------- */
! #endif
- # external imports
- import notifier
- import weakref
! # python imports
! import time
import pygame
! from pygame import locals
# Freevo imports
import config
import gui
from menu import Item
from event import *
from input.interface import InputPlugin
! import logging
log = logging.getLogger('input')
--- 28,48 ----
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
! #
-----------------------------------------------------------------------------
! # Python imports
! import weakref
import pygame
! import logging
# Freevo imports
import config
import gui
+
from menu import Item
from event import *
from input.interface import InputPlugin
! # get logging object
log = logging.getLogger('input')
***************
*** 81,191 ****
def __init__(self):
InputPlugin.__init__(self)
!
self.keymap = {}
for key in config.KEYBOARD_MAP:
! if hasattr(locals, 'K_%s' % key):
! code = getattr(locals, 'K_%s' % key)
self.keymap[code] = config.KEYBOARD_MAP[key]
! elif hasattr(locals, 'K_%s' % key.lower()):
! code = getattr(locals, 'K_%s' % key.lower())
self.keymap[code] = config.KEYBOARD_MAP[key]
else:
log.error('unable to find key code for %s' % key)
- if not config.INPUT_MOUSE_SUPPORT:
- self.mousehidetime = time.time()
- pygame.key.set_repeat(500, 30)
- notifier.addTimer( 20, self.handle )
! def handle(self):
"""
! Callback to handle the pygame events.
"""
! if not pygame.display.get_init():
! return True
- if not config.INPUT_MOUSE_SUPPORT:
- # Check if mouse should be visible or hidden
- mouserel = pygame.mouse.get_rel()
- mousedist = (mouserel[0]**2 + mouserel[1]**2) ** 0.5
! if mousedist > 4.0:
! pygame.mouse.set_visible(1)
! # Hide the mouse in 2s
! self.mousehidetime = time.time() + 1.0
! else:
! if time.time() > self.mousehidetime:
! pygame.mouse.set_visible(0)
- # Return the next key event, or None if the queue is empty.
- # Everything else (mouse etc) is discarded.
- while 1:
- event = pygame.event.poll()
! if event.type == locals.NOEVENT:
! return True
! if event.type == locals.KEYDOWN:
! if event.key in self.keymap:
! self.post_key(self.keymap[event.key])
- if not config.INPUT_MOUSE_SUPPORT:
- continue
-
- if event.type in (locals.MOUSEBUTTONDOWN, locals.MOUSEBUTTONUP):
- # Mouse button event handling.
- # This code is in an very early stage and may fail. It also
- # only works with the menu right now, going back one menu
- # is not working, there is a visible button the the screen
- # missing to do that.
- # A bigger eventmap should be created somewhere to make this
- # work for the player as well.
- action = None
- for widget in gui.display.get_childs_at(event.pos):
- if hasattr(widget, 'action'):
- action = widget.action
- break
- else:
- # no widget with an action found
- continue
-
- if isinstance(action, weakref.ReferenceType):
- # follow the weakref
- action = action()
! # event to be posted to the eventhandler
! post_event = None
!
! if event.type == locals.MOUSEBUTTONDOWN:
! # Handle mouse button down
! if isinstance(action, Item):
! # Action is an item, do some menu code here.
! post_event = Event(MENU_CHANGE_SELECTION, action)
! if event.type == locals.MOUSEBUTTONUP:
! # Handle mouse button up
! if isinstance(action, str):
! if action == 'PAGE_UP':
! # Action 'UP' is defined in the listing_area
! post_event = MENU_PAGEUP
! elif action == 'PAGE_DOWN':
! # Action 'DOWN' is defined in the listing_area
! post_event = MENU_PAGEDOWN
! elif isinstance(action, Item):
! if action.menu and action.menu.selected == action:
! # Action is an item, do some menu code here.
! if event.button == 1:
! post_event = MENU_SELECT
! elif event.button == 3:
! post_event = MENU_SUBMENU
! else:
! # mouse moved to much
! pass
! elif callable(action):
! # Action can be called
! action()
!
! if post_event:
! self.post_event(post_event)
! return True
--- 53,155 ----
def __init__(self):
InputPlugin.__init__(self)
!
! # define the keymap
self.keymap = {}
for key in config.KEYBOARD_MAP:
! if hasattr(pygame.locals, 'K_%s' % key):
! code = getattr(pygame.locals, 'K_%s' % key)
self.keymap[code] = config.KEYBOARD_MAP[key]
! elif hasattr(pygame.locals, 'K_%s' % key.lower()):
! code = getattr(pygame.locals, 'K_%s' % key.lower())
self.keymap[code] = config.KEYBOARD_MAP[key]
else:
log.error('unable to find key code for %s' % key)
+ # set mouse hiding on/off
+ gui.display._window.hide_mouse = not config.INPUT_MOUSE_SUPPORT
! # connect to signals
! signals = gui.display._window.signals
! signals['key_press_event'].connect(self.key_press_event)
! if config.INPUT_MOUSE_SUPPORT:
! signals['mouse_down_event'].connect(self.mouse_down_event)
! signals['mouse_up_event'].connect(self.mouse_up_event)
!
!
! def key_press_event(self, key):
"""
! Callback when a key is pressed.
"""
! if key in self.keymap:
! self.post_key(self.keymap[key])
! def get_widget_at(self, point):
! """
! Return action at the given point.
! """
! for widget in gui.display.get_childs_at(point):
! if hasattr(widget, 'action'):
! if isinstance(widget.action, weakref.ReferenceType):
! # follow the weakref
! return widget.action()
! return widget.action
! return None
! def mouse_down_event(self, button, pos):
! """
! Mouse button event handling.
! This code is in an very early stage and may fail. It also
! only works with the menu right now, going back one menu
! is not working, there is a visible button the the screen
! missing to do that.
! A bigger eventmap should be created somewhere to make this
! work for the player as well.
! """
! action = self.get_widget_at(pos)
! if not action:
! return True
! if isinstance(action, Item):
! # Action is an item, do some menu code here.
! self.post_event(Event(MENU_CHANGE_SELECTION, action))
! return True
! def mouse_up_event(self, button, pos):
! """
! Mouse button event handling.
! This code is in an very early stage and may fail. It also
! only works with the menu right now, going back one menu
! is not working, there is a visible button the the screen
! missing to do that.
! A bigger eventmap should be created somewhere to make this
! work for the player as well.
! """
! action = self.get_widget_at(pos)
! if not action:
! return True
! if isinstance(action, str):
! if action == 'PAGE_UP':
! # Action 'UP' is defined in the listing_area
! self.post_event(MENU_PAGEUP)
! elif action == 'PAGE_DOWN':
! # Action 'DOWN' is defined in the listing_area
! self.post_event(MENU_PAGEDOWN)
! elif isinstance(action, Item):
! if action.menu and action.menu.selected == action:
! # Action is an item, do some menu code here.
! if button == 1:
! self.post_event(MENU_SELECT)
! elif button == 3:
! self.post_event(MENU_SUBMENU)
! else:
! # mouse moved to much
! pass
!
! elif callable(action):
! # Action can be called
! action()
-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA. To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog