/[gzz]/gzz/gfx/util/demokeys.py
ViewVC logotype

Diff of /gzz/gfx/util/demokeys.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by tjl, Thu Dec 19 15:02:33 2002 UTC revision 1.2 by tjl, Thu Dec 19 15:31:00 2002 UTC
# Line 1  Line 1 
1  # Demo keystroke handling  # Demo keystroke handling
2    
3  from __future__ import nested_scopes  from __future__ import nested_scopes
4    from gzz.client import AbstractUpdateManager
5    
6    
7  class KeyPresses:  class KeyPresses:
# Line 22  class KeyPresses: Line 23  class KeyPresses:
23              return self.keymap[key](self.scene,key)              return self.keymap[key](self.scene,key)
24          print "No such key known: ",key,"Here:",self.keymap          print "No such key known: ",key,"Here:",self.keymap
25            
26    class _NoAnimation:
27        def __init__(self, func): self.func = func
28        def __call__(self, *args):
29            print "NOANIMATION CALL"
30            AbstractUpdateManager.setNoAnimation()
31            self.func(*args)
32    
33  class _Presses:  class _Presses:
34      def __init__(self, opts, *keys):      def __init__(self, opts, *keys):
35          print "PRESSES: ",keys          print "PRESSES: ",keys
36          self.keys = keys          self.keys = keys
37            if opts.get("noAnimation", 0):
38                self.keys = [
39                    (k[0], _NoAnimation(k[1])) for k in self.keys]
40      def getKeys(self):      def getKeys(self):
41          return self.keys          return self.keys
42                            
# Line 36  class _Presses: Line 46  class _Presses:
46          """          """
47          pass          pass
48    
49    class Action(_Presses):
50        """A key used to fire an action.
51        """
52        def __init__(self, description, key, func, **opts):
53            _Presses.__init__(self, opts,
54               (key, self.act),
55                )
56            self.func = func
57            self.descline = key + ": " + description
58    
59        def prepare(self, scene):
60            pass
61    
62        def act(self, scene, key):
63            self.func()
64    
65    
66  class Toggle(_Presses):  class Toggle(_Presses):
67      """A key used to toggle a feature on or off.      """A key used to toggle a feature on or off.
68      """      """
# Line 52  class Toggle(_Presses): Line 79  class Toggle(_Presses):
79          setattr(scene, self.attr, 1 - getattr(scene, self.attr))          setattr(scene, self.attr, 1 - getattr(scene, self.attr))
80    
81  class SlideLog(_Presses):  class SlideLog(_Presses):
82      """A key used to toggle a feature on or off.      """A pair of keys used to move a log slider up&down.
83      """      """
84      def __init__(self, attr, default, description, keydown, keyup, **opts):      def __init__(self, attr, default, description, keydown, keyup, **opts):
85          _Presses.__init__(self, opts,          _Presses.__init__(self, opts,
# Line 69  class SlideLog(_Presses): Line 96  class SlideLog(_Presses):
96      def move(self, dir, scene, key):      def move(self, dir, scene, key):
97          v = getattr(scene, self.attr)          v = getattr(scene, self.attr)
98          if dir > 0:          if dir > 0:
99              v *= 1.05              v *= 1.1
100          else:          else:
101              v /= 1.05              v /= 1.1
102          setattr(scene, self.attr, v)          setattr(scene, self.attr, v)

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26