Author: dmeyer
Date: Sat Jan 20 20:20:15 2007
New Revision: 9015

Added:
   trunk/ui/src/application/handler.py
      - copied, changed from r8908, /trunk/ui/src/application/eventhandler.py
   trunk/ui/src/application/window.py
Removed:
   trunk/ui/src/application/childapp.py
   trunk/ui/src/application/eventhandler.py
   trunk/ui/src/application/mplayer.py
Modified:
   trunk/ui/src/application/__init__.py
   trunk/ui/src/application/base.py
   trunk/ui/src/application/menuw.py

Log:
Major update
o remove childapp and mplayer application templates
o rework stack handling to make it possible to toggle
  between different running applications. (Alt-Tab)
o rename eventhandler to handler
o add properties to application if the application is
  fullscreen, can be toggled, etc.
o window (popup) support is now in application
o application and window call the gui code, other parts
  should not need to access this


Modified: trunk/ui/src/application/__init__.py
==============================================================================
--- trunk/ui/src/application/__init__.py        (original)
+++ trunk/ui/src/application/__init__.py        Sat Jan 20 20:20:15 2007
@@ -1,8 +1,46 @@
-from base import Application
-from menuapp import MenuApplication
-from childapp import Application as ChildApp
-from eventhandler import add_window, remove_window, get_active, \
-     app_change_signal
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# application - Application Submodule
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2006 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
+# Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------------
+
+from base import Application, STATUS_RUNNING, STATUS_STOPPING, \
+     STATUS_STOPPED, STATUS_IDLE, CAPABILITY_TOGGLE, CAPABILITY_PAUSE, \
+     CAPABILITY_FULLSCREEN
+
+from handler import handler as _handler
+from window import *
+
+def get_active():
+    """
+    Get active application.
+    """
+    return _handler.get_active()
 
 # signals defined by the application base code
-signals = { 'application change': app_change_signal }
+signals = _handler.signals

Modified: trunk/ui/src/application/base.py
==============================================================================
--- trunk/ui/src/application/base.py    (original)
+++ trunk/ui/src/application/base.py    Sat Jan 20 20:20:15 2007
@@ -6,12 +6,12 @@
 #
 # -----------------------------------------------------------------------------
 # Freevo - A Home Theater PC framework
-# Copyright (C) 2002-2005 Krister Lagerstrom, Dirk Meyer, et al.
+# Copyright (C) 2002-2006 Krister Lagerstrom, Dirk Meyer, et al.
 #
 # First Edition: Dirk Meyer <[EMAIL PROTECTED]>
 # Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
 #
-# Please see the file doc/CREDITS for a complete list of authors.
+# Please see the file AUTHORS for a complete list of authors.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -34,37 +34,103 @@
 # python imports
 import logging
 
+# kaa imports
+from kaa.notifier import Signal
+
 # freevo imports
-import input
-import eventhandler
 import gui
-import gui.animation 
+
+# application imports
+from handler import handler
 
 # get logging object
 log = logging.getLogger()
 
+STATUS_IDLE     = 'idle'
+STATUS_RUNNING  = 'running'
+STATUS_STOPPING = 'stopping'
+STATUS_STOPPED  = 'stopped'
+
+CAPABILITY_TOGGLE     = 1
+CAPABILITY_PAUSE      = 2
+CAPABILITY_FULLSCREEN = 4
 
 class Application(object):
     """
     A basic application
     """
-    def __init__(self, name, eventmap, fullscreen, animated=False):
+
+    _global_resources = {}
+
+    def __init__(self, name, eventmap, capabilities=[]):
         """
         Init the Application object.
+        """
+        self.__name    = name
+        self._eventmap = eventmap
+
+        self._visible  = False
+        self.engine    = gui.Application(name)
+        self.signals   = { 'show' : Signal(), 'hide': Signal(),
+                           'start': Signal(), 'stop': Signal() }
+
+        self._status   = STATUS_IDLE
+        self._capabilities = 0
+        for cap in capabilities:
+            self._capabilities |= cap
+
+
+    def has_capability(self, capability):
+        """
+        Return True if the application has the given capability.
+        """
+        return self._capabilities & capability
+
+
+    def get_status(self):
+        """
+        Return the current application status.
+        """
+        return self._status
+
+
+    def set_status(self, status):
+        """
+        Set application status and react on some changes.
+        """
+        if status in (STATUS_STOPPED, STATUS_IDLE):
+            self.free_resources()
+        if status == STATUS_RUNNING and self._status == STATUS_IDLE:
+            handler.show_application(self)
+            self._status = status
+            self.signals['start'].emit()
+        elif status == STATUS_IDLE:
+            handler.hide_application(self)
+            self._status = status
+            self.signals['stop'].emit()
+        else:
+            self._status = status
+
+    status = property(get_status, set_status, None, "application status")
 
-        @param name       : internal name of the application
-        @param eventmap   : name of the event handler mapping
-        @param fullscreen : if the application uses the whole screen
-        @param animated   : use fade in/out animation
-        """
-        self.__name     = name
-        self.__eventmap = eventmap
-        self.__handler  = eventhandler.get_singleton()
-
-        self.animated   = animated
-        self.visible    = False
-        self._stopped   = True
-        self.fullscreen = fullscreen
+
+    def show_app(self):
+        """
+        Show the application on the screen. This function should only be called
+        from the application handler.
+        """
+        self._visible = True
+        self.signals['show'].emit()
+        self.engine.show()
+
+
+    def hide_app(self):
+        """
+        Hide the application. This function should only be called from
+        the application handler.
+        """
+        self._visible = False
+        self.signals['hide'].emit()
 
 
     def eventhandler(self, event):
@@ -75,97 +141,76 @@
         raise AttributeError(error)
 
 
-    def show(self):
-        """
-        Show this application. This function will return False if the
-        application is already visible in case this function is overloaded.
-        In case it is not overloaded, this function will also update the
-        display.
-        """
-        if self.visible:
-            # Already visible. But maybe stopped, correct that
-            self._stopped = False
-            return False
-        # Set visible and append to the eventhandler
-        self.visible = True
-        self._stopped = False
-        if not self in self.__handler:
-            self.__handler.append(self)
-        # Check if the new app uses animation to show itself
-        if not self.animated:
-            # This application has no animation for showing. But the old one
-            # may have. So we need to wait until the renderer is done.
-            # FIXME: what happens if a 'normal' animation is running?
-            log.info('no show animation for %s -- waiting' % self.__name)
-            gui.animation.render().wait()
-        if self.__class__.show == Application.show:
-            # show() is not changed in the inherting class. Update the display.
-            gui.display.update()
-        return True
-
-
-    def hide(self):
-        """
-        Hide this application. This can be either because a different
-        application has started or that the application was stopped and is no
-        longer needed.
-        """
-        if not self.visible:
-            # already hidden
-            return
-        # Wait until all application change animations are done. There
-        # should be none, but just in case to avoid fading in and out the
-        # same object.
-        # FIXME: what happens if a 'normal' animation is running?
-        gui.animation.render().wait()
-        self.visible = False
-
-
     def stop(self):
         """
         Stop the application. If it is not shown again in the same cycle, the
         hide() function will be called. If the app isn't really stopped now
         (e.g. a child needs to be stopped), do not call this function.
         """
-        self.stopped()
+        self._status = STATUS_STOPPED
 
 
-    def stopped(self):
+    def is_visible(self):
         """
-        Set the application to status stopped. If it is not shown again in the 
same
-        cycle, the hide() function will be called.
+        Return if the application is visible right now.
         """
-        self._stopped = True
+        return self._visible
+
 
-        
     def set_eventmap(self, eventmap):
         """
         Set a new eventmap for the event handler
         """
-        self.__eventmap = eventmap
-        if self.__handler.get_active() == self:
-            # We are the current application with the focus,
-            # so set eventmap of the eventhandler to the new eventmap
-            input.set_mapping(eventmap)
+        self._eventmap = eventmap
+        handler.set_focus()
 
 
     def get_eventmap(self):
         """
         Return the eventmap for the application.
         """
-        return self.__eventmap
+        return self._eventmap
 
+    eventmap = property(get_eventmap, set_eventmap, None, "eventmap")
 
     def get_name(self):
         """
         Get the name of the application.
         """
         return self.__name
-    
 
-    def __str__(self):
+
+    def get_resources(self, *resources):
+        """
+        Reserve a list of resources. If one or more resources can not be
+        reserved, the whole operation fails. The function will return the
+        list of failed resources with the application having this resource.
+        """
+        blocked = {}
+        for r in resources:
+            if r in self._global_resources:
+                blocked[r] = self._global_resources[r]
+        if blocked:
+            # failed to reserve
+            return blocked
+        # reserve all resources
+        for r in resources:
+            self._global_resources[r] = self
+        return {}
+
+
+    def free_resources(self, *resources):
+        """
+        Free all resources blocked by this application. If not resources are
+        provided, free all resources.
+        """
+        for res, app in self._global_resources.items()[:]:
+            if app == self and (not resources or res in resources):
+                del self._global_resources[res]
+
+
+    def __repr__(self):
         """
         String for debugging.
         """
         return self.__name
-        

Copied: trunk/ui/src/application/handler.py (from r8908, 
/trunk/ui/src/application/eventhandler.py)
==============================================================================
--- /trunk/ui/src/application/eventhandler.py   (original)
+++ trunk/ui/src/application/handler.py Sat Jan 20 20:20:15 2007
@@ -1,31 +1,23 @@
 # -*- coding: iso-8859-1 -*-
 # -----------------------------------------------------------------------------
-# eventhandler.py - Event handling
+# handler.py - Handle active applications and windows
 # -----------------------------------------------------------------------------
 # $Id$
 #
-# FIXME: add documentation about this module
+# This file defines the application handler. The handler will manage the
+# current active applications and windows, show/hide them and send events to
+# the application or window with the focus.
 #
-# Note on eventhandler functions:
-#
-# Many different objects can have an eventhandler function and the parameters
-# differs based on the object itself. There are three different kinds of
-# eventhandlers:
-#
-# The basic idea is that the event is passed to an application or window by
-# this module. It doesn't know about a menuw or item. The application may pass
-# the event to an item, menuw will add itself to it, other applications don't
-# do this. The item itself will call the plugins and add itself to the list
-# of parameters.
+# The handler should not be accessed from outside the application module.
 #
 # -----------------------------------------------------------------------------
 # Freevo - A Home Theater PC framework
-# Copyright (C) 2002-2005 Krister Lagerstrom, Dirk Meyer, et al.
+# Copyright (C) 2002-2006 Krister Lagerstrom, Dirk Meyer, et al.
 #
 # First Edition: Dirk Meyer <[EMAIL PROTECTED]>
 # Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
 #
-# Please see the file doc/CREDITS for a complete list of authors.
+# Please see the file AUTHORS for a complete list of authors.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -43,6 +35,8 @@
 #
 # -----------------------------------------------------------------------------
 
+__all__ = [ 'handler' ]
+
 # python imports
 import sys
 import time
@@ -53,9 +47,7 @@
 
 # freevo imports
 import config
-import plugin
 import input
-from gui.windows import ConfirmBox
 
 from event import *
 
@@ -65,143 +57,123 @@
 # debug stuff
 _TIME_DEBUG = False
 
-_singleton = None
-
-def get_singleton():
-    """
-    get the global application object
-    """
-    global _singleton
-
-    # One-time init
-    if _singleton == None:
-        _singleton = Eventhandler()
-
-    return _singleton
-
-
-def add_window(window):
-    """
-    Add a window above all applications (WaitBox)
-    """
-    return get_singleton().add_window(window)
-
-
-def remove_window(window):
-    """
-    Remove window from window list and reset the focus
-    """
-    return get_singleton().remove_window(window)
-
-
-def get_active():
-    """
-    Return the application which has the focus or the
-    WaitBox that is active
-    """
-    return get_singleton().get_active()
+# the global object
+handler = None
 
+# -----------------------------------------------------------------------------
 
-# Signals
-app_change_signal = kaa.notifier.Signal()
+STATUS_IDLE     = 'idle'
+STATUS_RUNNING  = 'running'
+STATUS_STOPPING = 'stopping'
+STATUS_STOPPED  = 'stopped'
 
-# -----------------------------------------------------------------------------
+CAPABILITY_TOGGLE = 1
 
-class Eventhandler(object):
+class Handler(object):
     """
     This is the main application for Freevo, handling applications
     with an event handler and the event mapping.
     """
     def __init__(self):
-        self.popups       = []
         self.applications = []
+        self.current = None
+        self.windows = []
         # callback for events
         kaa.notifier.EventHandler(self.handle).register()
 
-
-    def __iter__(self):
-        """
-        Iterate through applications.
-        """
-        return self.applications.__iter__()
+        # Signals
+        self.signals = { 'changed': kaa.notifier.Signal() }
 
 
-    def set_focus(self, previous, app):
+    def set_focus(self):
         """
-        change the focus
+        Set new focus (input mapping, application show/hide)
         """
-        log.info('set focus from %s to %s' % (previous, app))
-        if not self.popups:
-            input.set_mapping(app.get_eventmap())
-        else:
-            input.set_mapping(self.popups[-1].get_eventmap())
+        app = self.applications[-1]
 
-        fade = app.animated
-        if previous:
-            if previous.visible:
-                log.info('hide previous app')
-                previous.hide()
-            fade = fade or previous.animated
+        # set input mapping
+        focus = app
+        if self.windows:
+            focus = self.windows[-1]
+        log.info('set focus to %s' % focus)
+        input.set_mapping(focus.eventmap)
 
-        log.info('signal screen content change')
-        app_change_signal.emit(app, app.fullscreen, fade)
+        if app == self.current:
+            # same app as before
+            return
 
-        if not app.visible:
-            log.info('make current app visible')
-            app.show()
+        log.info('switch application from %s to %s' % (self.current, app))
+        self.signals['changed'].emit(app)
+        app.show_app()
+        if self.current:
+            self.current.hide_app()
+        self.current = app
 
 
-    def append(self, app):
+    def show_application(self, app):
         """
-        Add app the list of applications and set the focus
+        Show application and set the focus
         """
-        log.info('new application %s' % app)
-        # make sure the app is not stopped
-        app._stopped = False
+        log.info('show application %s' % app)
         # do will have a stack or is this the first application?
         if len(self.applications) == 0:
             # just add the application
             self.applications.append(app)
-            self.set_focus(None, app)
+            self.set_focus()
             return True
         # check about the old app if it is marked as removed
         # or if it is the same application as before
         previous = self.applications[-1]
         if previous == app:
-            # It is the same app, just remove the stopped flag
-            previous._stopped = False
+            # It is the same app, nothing to do
+            return True
+        if app in self.applications:
+            # already in list, remove it before appending
+            self.applications.remove(app)
+        # check if an application is in status stopped and replace it.
+        for pos, a in enumerate(self.applications):
+            if a.status == STATUS_STOPPED:
+                self.applications[pos] = app
+                break
         else:
-            # hide the application and mark the application change
-            previous.hide()
-            if previous._stopped:
-                # the previous application is stopped, remove it
-                self.applications.remove(previous)
+            # no stopped application, just append to the list
             self.applications.append(app)
-            self.set_focus(previous, app)
+        self.set_focus()
+
+
+    def hide_application(self, app):
+        """
+        Remove application from stack.
+        """
+        log.info('hide application %s' % app)
+        if not app in self.applications:
+            # already gone (maybe by show_application of a new one)
+            return
+        if not app == self.applications[-1]:
+            # not visible, just remove
+            self.applications.remove(app)
+            return
+        # remove from list and set new focus
+        self.applications.pop()
+        self.set_focus()
 
 
     def add_window(self, window):
         """
-        Add a window above all applications (WaitBox)
+        Add a window above all applications
         """
-        self.popups.append(window)
-        input.set_mapping(window.get_eventmap())
+        self.windows.append(window)
+        self.set_focus()
 
 
     def remove_window(self, window):
         """
         Remove window from window list and reset the focus
         """
-        if not window in self.popups:
-            return
-        if not self.popups[-1] == window:
-            self.popups.remove(window)
+        if not window in self.windows:
             return
-        self.popups.remove(window)
-        if self.popups:
-            input.set_mapping(self.popups[-1].get_eventmap())
-        else:
-            input.set_mapping(self.applications[-1].get_eventmap())
+        self.windows.remove(window)
+        self.set_focus()
 
 
     def get_active(self):
@@ -215,15 +187,20 @@
 
     def handle(self, event):
         """
-        event handling function
+        Event handling function.
         """
         log.debug('handling event %s' % str(event))
-
         if _TIME_DEBUG:
             t1 = time.clock()
 
         try:
-            if event == FUNCTION_CALL:
+            if event == TOGGLE_APPLICATION and len(self.applications) > 1 and \
+                   self.applications[-1].has_capability(CAPABILITY_TOGGLE):
+                log.info('Toggle application')
+                self.applications.insert(0, self.applications.pop())
+                self.set_focus()
+
+            elif event == FUNCTION_CALL:
                 # event is a direct function call, call it and do not
                 # pass it on the the normal handling
                 event.arg()
@@ -231,33 +208,22 @@
             elif event.handler:
                 # event has it's own handler function, call this
                 # function and do not pass it on the the normal
-                # handling
+                # handling.
                 event.handler(event=event)
 
-            elif len(self.popups) and \
-                     self.popups[-1].eventhandler(event=event):
+            elif len(self.windows) and 
self.windows[-1].eventhandler(event=event):
                 # handled by the current popup
                 pass
 
             else:
+                # handle by the current appliaction
                 self.applications[-1].eventhandler(event=event)
 
-            # now do some checking if the focus needs to be changed
-            if self.applications[-1]._stopped or \
-                   not self.applications[-1].visible:
-                log.info('current application is stopped')
-                # the current application wants to be removed, either
-                # because stop() is called or the hide() function was
-                # called from the event handling
-                previous, current = self.applications[-2:]
-                self.applications.remove(current)
-                self.set_focus(current, previous)
-
             if _TIME_DEBUG:
                 print time.clock() - t1
             return True
 
-        except SystemExit, e:
+        except (SystemExit, KeyboardInterrupt):
             sys.exit(0)
 
         except Exception, e:
@@ -270,8 +236,12 @@
                       'could cause more errors until you restart '\
                       'Freevo.') % event
                 handler = kaa.notifier.Callback(sys.exit, 0)
-                pop = ConfirmBox(msg, (_('Shutdown'), _('Continue')))
-                pop.connect(0, sys.exit, 0)
+                from window import ConfirmWindow
+                pop = ConfirmWindow(msg, (_('Shutdown'), _('Continue')))
+                pop.buttons[0].connect(sys.exit, 0)
                 pop.show()
             else:
                 sys.exit(1)
+
+# create the global object
+handler = Handler()

Modified: trunk/ui/src/application/menuw.py
==============================================================================
--- trunk/ui/src/application/menuw.py   (original)
+++ trunk/ui/src/application/menuw.py   Sat Jan 20 20:20:15 2007
@@ -32,14 +32,10 @@
 __all__ = [ 'MenuWidget' ]
 
 # freevo imports
-import config
-import gui
-
-from event import *
 from menu import MenuStack
 
 # application imports
-from base import Application
+from base import Application, STATUS_RUNNING, CAPABILITY_TOGGLE
 
 
 class MenuWidget(Application, MenuStack):
@@ -47,61 +43,29 @@
     The MenuWidget is an Application for GUI and event handling and also
     an instance of MenuStack defined in menu.stack.
     """
-    def __init__(self):
-        Application.__init__(self, 'menu', 'menu', False, True)
+    def __init__(self, menu):
+        Application.__init__(self, 'menu', 'menu', (CAPABILITY_TOGGLE,))
         MenuStack.__init__(self)
-
-        # define areas
-        areas = ('screen', 'title', 'subtitle', 'view', 'listing', 'info')
-        # create engine
-        self.engine = gui.areas.Handler('menu', areas)
+        self.pushmenu(menu)
+        self.status = STATUS_RUNNING
 
 
-    def show(self):
+    def show_app(self):
         """
         Show the menu on the screen
         """
-        Application.show(self)
-        MenuStack.show(self)
         self.refresh(True)
-        if self.inside_menu:
-            self.engine.show(0)
-            self.inside_menu = False
-        else:
-            self.engine.show(config.GUI_FADE_STEPS)
-
-
-    def hide(self):
-        """
-        Hide the menu
-        """
-        Application.hide(self)
-        MenuStack.hide(self)
-        if self.inside_menu:
-            self.engine.hide(0)
-            self.inside_menu = False
-        else:
-            self.engine.hide(config.GUI_FADE_STEPS)
+        Application.show_app(self)
+        self.engine.update(self.menustack[-1])
 
 
-    def redraw(self):
-        """
-        Redraw the menu.
-        """
-        self.engine.draw(self.menustack[-1])
+    def refresh(self, reload=False):
+        MenuStack.refresh(self, reload)
+        self.engine.update(self.menustack[-1])
 
 
     def eventhandler(self, event):
         """
-        Eventhandler for menu controll
+        Eventhandler for menu control
         """
-        if MenuStack.eventhandler(self, event):
-            return True
-
-        if event == MENU_CHANGE_STYLE and len(self.menustack) > 1:
-            # change the menu style
-            self.engine.toggle_display_style(self.menustack[-1])
-            self.refresh()
-            return True
-
-        return False
+        return MenuStack.eventhandler(self, event)

Added: trunk/ui/src/application/window.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/application/window.py  Sat Jan 20 20:20:15 2007
@@ -0,0 +1,203 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# window.py - Popup Windows known by Freevo
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2006 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
+# Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------------
+
+__all__ = [ 'TextWindow', 'MessageWindow', 'ConfirmWindow']
+
+# kaa imports
+from kaa.notifier import Signal
+
+# freevo imports
+import gui
+from event import *
+import math
+
+# application imports
+from handler import handler
+
+class Window(object):
+    """
+    A basic empty window, not very usefull on its own.
+    """
+    type = None
+
+    def __init__(self):
+        self.engine = gui.Window(self.type)
+        self._eventmap = 'input'
+        self._visible = False
+
+
+    def show(self):
+        """
+        Show the window on the screen.
+        """   
+        if self._visible:
+            return False
+        self._visible = True
+        handler.add_window(self)
+        self.engine.show(self)
+        return True
+
+
+    def hide(self):
+        """
+        Hide the window.
+        """
+        if not self._visible:
+            return False
+        self._visible = False
+        handler.remove_window(self)
+        self.engine.hide()
+        return True
+
+
+    def is_visible(self):
+        """
+        Return if the window is visible right now.
+        """
+        return self._visible
+
+
+    def eventhandler(self, event):
+        """
+        Eventhandler for the window, this raw window has nothing to do
+        """
+        return False
+
+
+    def set_eventmap(self):
+        """
+        Set the eventmap for the window
+        """
+        self._eventmap = eventmap
+        handler.set_focus()
+
+
+    def get_eventmap(self):
+        """
+        Return the eventmap for the window
+        """
+        return self._eventmap
+
+    eventmap = property(get_eventmap, set_eventmap, None, "eventmap")
+
+
+class TextWindow(Window):
+    """
+    A simple window without eventhandler showing a text.
+    """
+
+    type = 'text'
+
+    def __init__(self, text):
+        Window.__init__(self)
+        self.text = text
+
+
+class Button(Signal):
+    """
+    A button used in some windows.
+    """
+
+    def __init__(self, name, selected=True):
+        self.name = name
+        self.selected = selected
+        Signal.__init__(self)
+
+
+class MessageWindow(Window):
+    """
+    A simple window showing a text. The window will hide on input
+    events.
+    """
+
+    type = 'message'
+
+    def __init__(self, text, button=_('OK')):
+        Window.__init__(self)
+        self.text = text
+        self.button = Button(button)
+
+
+    def eventhandler(self, event):
+        """
+        Eventhandler to close the box on INPUT_ENTER or INPUT_EXIT
+        """
+        if event in (INPUT_ENTER, INPUT_EXIT):
+            self.hide()
+            if event == INPUT_ENTER:
+                self.button.emit()
+            return True
+        return False
+
+
+class ConfirmWindow(Window):
+    """
+    A simple window showing a text and two buttons for the user to choose
+    from. In most cases this window is used to ask the user if an action
+    should really be performed.
+    """
+
+    type = 'confirm'
+
+    def __init__(self, text, buttons=(_('Yes'), _('No')), default_choice=0):
+        Window.__init__(self)
+        self.text = text
+        self.buttons = []
+        for text in buttons:
+            self.buttons.append(Button(text, len(self.buttons) == 
default_choice))
+        self.selected = self.buttons[default_choice]
+
+
+    def eventhandler(self, event):
+        """
+        Eventhandler to toggle the selection or press the button
+        """
+        if event in (INPUT_LEFT, INPUT_RIGHT):
+            # Toggle selection
+            self.selected.selected = False
+            index = self.buttons.index(self.selected)
+            if event == INPUT_LEFT:
+                index = (index + 1) % len(self.buttons)
+            elif index == 0:
+                index = len(self.buttons) - 1
+            else:
+                index = index - 1
+            self.selected = self.buttons[index]
+            self.selected.selected = True
+            self.engine.update()
+            return True
+
+        elif event == INPUT_ENTER:
+            self.selected.emit()
+            self.hide()
+            return True
+
+        return False

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to