Esempio n. 1
0
    def display(self, x, y, timeout = None):
        "Start it up"

        x, y, width, height = self.window.keep_on_screen(x, y, self.width, self.height)
        self.window.configure(x = x, y = y, width = width, height = height)
        self.window.map()

        self.timeout = timeout or self.seconds * len(self.lines)

        if self.timeout:
            timer_id = event.new_event_type()
            self.timer = event.TimerEvent(timer_id, after = self.timeout)
            self.wm.events.add_timer(self.timer)
            self.wm.dispatch.add_handler(timer_id, self.close, handlerid = self)
Esempio n. 2
0
    def _internal_timeout(self, ev):
        """Called when the timer event times out.
        Don't override this, override _timeout instead.
        """

        # Call _timeout if it has been at least self.timeout
        # seconds since the last keypress
        if self.last_key_time is None \
           or ev.time - self.last_key_time >= self.timeout:
            wmanager.debug('keys', 'timeout, last_key = %s, now = %s',
                           self.last_key_time, ev.time)
            self._timeout(ev)

        # If not: reschedule a timeout
        else:
            wmanager.debug('keys', 'rescheduling timeout at %s',
                           self.last_key_time + self.timeout)
            self.timer = event.TimerEvent(self.timer_id,
                                          at=self.last_key_time + self.timeout)
            self.wm.events.add_timer(self.timer)
Esempio n. 3
0
    def __init__(self, obj):

        # The object can be a window manager, a screen or a window ... just
        # like keys.  What happens depends on that.
        # The vast majority of my testing has been on passing a WindowManager
        # so  ... your mileage may vary on the others.  Please, go ahead
        # and try it and let me know if it needs work.

        if isinstance(obj, wmanager.WindowManager):
            wm = obj
            grabmgrs = []
            for s in obj.screens:
                if not hasattr(s, 'mousegrab_mgr'):
                    s.mousegrab_mgr = MousegrabManager(obj, s.root)
                grabmgrs.append(s.mousegrab_mgr)

        elif isinstance(obj, wmanager.Screen):
            wm = obj.wm
            if not hasattr(obj, 'mousegrab_mgr'):
                obj.mousegrab_mgr = MousegrabManager(obj.wm, obj.root)
            grabmgrs = [obj.mousegrab_mgr]

        elif isinstance(obj, wmanager.Window):
            wm = obj.wm
            if not hasattr(obj, 'keygrab_mgr'):
                obj.mousegrab_mgr = MousegrabManager(obj.wm, obj.window)
            grabmgrs = [obj.mousegrab_mgr]

        else:
            raise TypeError('expected WindowManager, Screen or Client object')

        # Dig through all names in this object, ignoring those beginning with
        # an underscore.

        # First collect all method names in this and it's base classes
        names = {}
        c = [self.__class__]
        while len(c):
            names.update(c[0].__dict__)
            c = c + list(c[0].__bases__)
            del c[0]

        # And now parse the names
        rawbinds = []
        for name in names.keys():
            if name[0] != '_':

                # Find modifiers in name
                mask = 0
                parts = string.split(name, '_')
                while len(parts) >= 2 and modifiers.has_key(parts[0]):
                    mask = mask | modifiers[parts[0]]
                    del parts[0]

                    if len(parts) == 1:
                        buttonsym = string_to_buttonsym(parts[0])
                        if buttonsym != None:
                            rawbinds.append(
                                (buttonsym, mask, getattr(self, name)))

        self.wm = wm
        self.dispatch = obj.dispatch
        self.grabmgrs = grabmgrs
        self.rawbindings = rawbinds
        self.grabs = []

        # Add handlers
        if self.propagate_mouse:
            # This is where you want to be ... it will result in only
            # those mouse events you care about triggering the _mouseevent
            # method, everything else will fall through to the apps.
            self.dispatch.add_handler(X.ButtonPress,
                                      self._mouseevent,
                                      handlerid=self)
            self.dispatch.add_handler(X.ButtonRelease,
                                      self._mouseevent,
                                      handlerid=self)
            self.dispatch.add_handler(X.MotionNotify,
                                      self._mouseevent,
                                      handlerid=self)
        else:
            # I left this part in from the keys module, but I think it's
            # a really bad idea.  I wouldn't use this at all.  Bout the
            # only time I could think of using it is if you're writing a
            # system for just one program ... maybe dedicating a laptop
            # to a single purpose ... like mp3 player or something.
            self.dispatch.add_grab_handler(X.ButtonPress,
                                           self._mouseevent,
                                           handlerid=self)
            self.dispatch.add_grab_handler(X.ButtonRelease,
                                           self._mouseevent,
                                           handlerid=self)
            self.dispatch.add_grab_handler(X.MotionNotify,
                                           self._mouseevent,
                                           handlerid=self)

        if self.timeout:
            self.last_mouse_time = None
            self.timer_id = event.new_event_type()
            self.timer = event.TimerEvent(self.timer_id, after=self.timeout)
            self.wm.events.add_timer(self.timer)
            self.dispatch.add_handler(self.timer_id,
                                      self._internal_timeout,
                                      handlerid=self)

        self._buildmap()
Esempio n. 4
0
    def __init__(self, obj, deprecated_arg=None):
        """Instantiate a KeyHandler object.
        """

        # Warn if the deprecated and unused former "dispatch" argument
        # is used.
        if deprecated_arg is not None:
            sys.stderr.write(
                "%s: warning: using deprecated KeyHandler __init__ interface\n"
                % sys.argv[0])

        wmanager.debug('mem', 'Initing keyhandler %s for %s', self, obj)

        # Figure out if we have been added to a WindowManager, Screen
        # or Client object.  Set up KeygrabManager objects if not
        # already done on screens or clients.

        if isinstance(obj, wmanager.WindowManager):
            wm = obj
            grabmgrs = []
            for s in obj.screens:
                if not hasattr(s, 'keygrab_mgr'):
                    s.keygrab_mgr = KeygrabManager(obj, s.root)
                grabmgrs.append(s.keygrab_mgr)

        elif isinstance(obj, wmanager.Screen):
            wm = obj.wm
            if not hasattr(obj, 'keygrab_mgr'):
                obj.keygrab_mgr = KeygrabManager(obj.wm, obj.root)
            grabmgrs = [obj.keygrab_mgr]

        elif isinstance(obj, wmanager.Window):
            wm = obj.wm
            if not hasattr(obj, 'keygrab_mgr'):
                obj.keygrab_mgr = KeygrabManager(obj.wm, obj.window)
            grabmgrs = [obj.keygrab_mgr]

        else:
            raise TypeError('expected WindowManager, Screen or Client object')

        # Dig through all names in this object, ignoring those beginning with
        # an underscore.

        # First collect all method names in this and it's base classes
        names = {}
        c = [self.__class__]
        while len(c):
            names.update(c[0].__dict__)
            c = c + list(c[0].__bases__)
            del c[0]

        names.update(self.__dict__)

        # And now parse the names
        rawbinds = []
        for name in names.keys():
            if name[0] != '_':

                # Find modifiers in name
                mask = 0
                parts = string.split(name, '_')
                while len(parts) >= 2 and modifiers.has_key(parts[0]):
                    mask = mask | modifiers[parts[0]]
                    del parts[0]

                # Find name keysym
                rest = string.join(parts, '_')
                keysym = XK.string_to_keysym(rest)
                if keysym != X.NoSymbol:
                    rawbinds.append((keysym, mask, getattr(self, name)))

        self.wm = wm
        self.dispatch = obj.dispatch
        self.grabmgrs = grabmgrs
        self.rawbindings = rawbinds
        self.grabs = []

        # Add handlers
        if self.propagate_keys:
            self.dispatch.add_handler(X.KeyPress,
                                      self._keyevent,
                                      handlerid=self)
            self.dispatch.add_handler(X.KeyRelease,
                                      self._keyevent,
                                      handlerid=self)
        else:
            self.dispatch.add_grab_handler(X.KeyPress,
                                           self._keyevent,
                                           handlerid=self)
            self.dispatch.add_grab_handler(X.KeyRelease,
                                           self._keyevent,
                                           handlerid=self)

        # Okay, so we will remap and regrab once for every
        # screen, but I'm not worried.  xmodmap isn't the most
        # frequently used command...
        self.dispatch.add_handler(X.MappingNotify,
                                  self._mappingnotify,
                                  handlerid=self)

        if self.timeout:
            self.last_key_time = None
            self.timer_id = event.new_event_type()
            self.timer = event.TimerEvent(self.timer_id, after=self.timeout)
            self.wm.events.add_timer(self.timer)
            self.dispatch.add_handler(self.timer_id,
                                      self._internal_timeout,
                                      handlerid=self)

        self._buildmap()