~sjdv1982/hivesystem/trunk

« back to all changes in this revision

Viewing changes to sparta/sensors/mouse.py

  • Committer: Sjoerd de Vries
  • Date: 2014-06-09 10:19:38 UTC
  • mfrom: (182.1.43 hive-view)
  • Revision ID: sjdv1982@gmail.com-20140609101938-7ji5g0buo09r0se6
merged with hive-view branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import libcontext, bee
 
2
from bee.segments import *
 
3
from libcontext.socketclasses import *
 
4
from libcontext.pluginclasses import *
 
5
 
 
6
class mouse(bee.worker):
 
7
    """
 
8
    The mouse sensor reports any mouse input during the last tick
 
9
    """
 
10
        
 
11
    #What kind of mouse click events are we listening for?
 
12
    mode = variable("str")
 
13
    parameter(mode, "LClick")
 
14
    
 
15
    #Has a mouse event happened during the last tick?
 
16
    is_active = variable("bool")
 
17
    startvalue(is_active, False)
 
18
    active = output("pull", "bool")    
 
19
    connect(is_active, active)
 
20
    
 
21
    #What are the X and Y positions? 
 
22
    vx = variable("int")
 
23
    startvalue(vx, 0)
 
24
    x = output("pull", "int")
 
25
    connect(vx, x)
 
26
    vy = variable("int")
 
27
    startvalue(vy, 0)
 
28
    y = output("pull", "int")
 
29
    connect(vy, y)
 
30
        
 
31
    # Mark "x" and "y" as an advanced output segment, and capitalize the I/O names
 
32
    guiparams = {
 
33
      "identifier" : {"name": "Identifier", "fold" : True},
 
34
      "x" : {"name": "X Position", "advanced" : True},
 
35
      "y" : {"name": "Y Position", "advanced" : True},
 
36
      "active" : {"name": "Active"},
 
37
      "_memberorder" : ["identifier", "x", "y", "active"],
 
38
    }
 
39
    
 
40
    # Method to manipulate the parameter form as it appears in the GUI
 
41
    @staticmethod
 
42
    def form(f):
 
43
        f.mode.name = "Detection mode"
 
44
        f.mode.type = "option"
 
45
        f.mode.options = "Move", "LClick", "RClick", "LDoubleClick", "MiddleClick", "LDrag", "RDrag"
 
46
        f.mode.optiontitles = "Move", "Left Click", "Right Click", "Double Click", "Middle Click", "Left Button Drag", "Right Button Drag"
 
47
            
 
48
    # Finally, declare our sockets and plugins, to communicate with the rest of the hive
 
49
    def place(self):    
 
50
        raise NotImplementedError("sparta.sensors.mouse has not been implemented yet") 
 
51
        
 
52
      
 
53