~forsslundsystems/forssim/statistics

« back to all changes in this revision

Viewing changes to python/KeyDispatcher.py

  • Committer: par.hellstrom at hiq
  • Date: 2009-01-14 12:29:11 UTC
  • Revision ID: par.hellstrom@hiq.se-20090114122911-1l0tbujn4ftfugfn
added python directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from Route import * 
 
3
 
 
4
class InputDispatcher:
 
5
  di = dict()
 
6
  def __init__(self, arg):
 
7
    if InputDispatcher.di.has_key(arg):
 
8
      raise Exception("Duplicated argument:"+arg)
 
9
    else:
 
10
      self.tmparg = arg
 
11
  
 
12
  def __call__(self, func):
 
13
    if hasattr(self, 'tmparg'):
 
14
      InputDispatcher.di[self.tmparg] = func
 
15
 
 
16
  @classmethod
 
17
  def dispatch(cls, inpu):
 
18
    if inpu=='':
 
19
      return
 
20
    if InputDispatcher.di.has_key(inpu):
 
21
      return InputDispatcher.di[inpu]()
 
22
    else:
 
23
      raise Exception("No registred reciver for:"+inpu)
 
24
 
 
25
@InputDispatcher(' ')
 
26
def doUpdatePrint():
 
27
  #highlightTypeField.setValue("highlightTypeUserVersusExpert")
 
28
  sys.stdout.write('\a')
 
29
 
 
30
@InputDispatcher('r')
 
31
def doRenderMethod():
 
32
  renderMethod = renderMethodField.getValue()
 
33
  renderMethod += 1
 
34
  if renderMethod > 3:
 
35
    renderMethod=0
 
36
  renderMethodField.setValue(renderMethod)
 
37
 
 
38
@InputDispatcher('u')
 
39
def doShiftWindowLeft():
 
40
  windowCenter = windowCenterField.getValue()
 
41
  windowWidth = windowWidthField.getValue()
 
42
  if (windowCenter - (windowWidth/2)) > 0:
 
43
    windowCenter = windowCenter - 1
 
44
    windowCenterField.setValue(windowCenter)
 
45
 
 
46
@InputDispatcher('i')
 
47
def doShiftWindowRight():
 
48
  windowCenter = windowCenterField.getValue()
 
49
  windowWidth = windowWidthField.getValue()
 
50
  if (windowCenter + (windowWidth/2)) < 255:
 
51
    windowCenter = windowCenter + 1 
 
52
    windowCenterField.setValue(windowCenter)
 
53
 
 
54
@InputDispatcher('j')
 
55
def doDecreaseWindowWidth():
 
56
  windowCenter = windowCenterField.getValue()
 
57
  windowWidth = windowWidthField.getValue()
 
58
  if (windowCenter - (windowWidth/2)) > 0 and windowWidth > 2:
 
59
    windowWidthField.setValue(windowWidth - 1)
 
60
 
 
61
@InputDispatcher('k')
 
62
def doIncreaseWindowWidth():
 
63
  windowCenter = windowCenterField.getValue()
 
64
  windowWidth = windowWidthField.getValue()
 
65
  if (windowCenter + (windowWidth/2)) < 255 and windowWidth < 255 and windowCenter - (windowWidth/2) > 1:
 
66
    windowWidthField.setValue(windowWidth + 1)
 
67
 
 
68
@InputDispatcher('t')
 
69
def doDecreaseCutRadius():
 
70
  cutRadiusField.setValue(cutRadiusField.getValue() / 1.1)
 
71
 
 
72
@InputDispatcher('y')
 
73
def doIncreaseCutRadius():
 
74
  cutRadiusField.setValue(cutRadiusField.getValue() * 1.1)
 
75
 
 
76
@InputDispatcher('g')
 
77
def doDecreaseDrillSpeed():
 
78
  drillSpeedField.setValue(drillSpeedField.getValue() / 1.1)
 
79
 
 
80
@InputDispatcher('h')
 
81
def doIncreaseDrillSpeed():
 
82
  drillSpeedField.setValue(drillSpeedField.getValue() * 1.1)
 
83
 
 
84
@InputDispatcher('!')
 
85
def doToggleSegment():
 
86
  segment = segmentField.getValue()
 
87
  if (segment == 64):
 
88
    segmentField.setValue(128)
 
89
  elif (segment == 128):
 
90
    segmentField.setValue(192)
 
91
  elif (segment == 192):  
 
92
    segmentField.setValue(255)
 
93
  elif (segment == 255):  
 
94
    segmentField.setValue(64)
 
95
 
 
96
@InputDispatcher(']')
 
97
def doIncreaseHardness():
 
98
  segment = segmentField.getValue()
 
99
  if (segment == 64):
 
100
   hardness64Field.setValue(hardness64Field.getValue() + 0.01)   
 
101
  elif (segment == 128):
 
102
   hardness128Field.setValue(hardness128Field.getValue() + 0.01)   
 
103
  elif (segment == 192):  
 
104
   hardness192Field.setValue(hardness192Field.getValue() + 0.01)   
 
105
  elif (segment == 255):  
 
106
   hardness255Field.setValue(hardness255Field.getValue() + 0.01)   
 
107
 
 
108
@InputDispatcher('[')
 
109
def doDecreaseHardness():
 
110
  segment = segmentField.getValue()
 
111
  if (segment == 64):
 
112
   hardness64Field.setValue(hardness64Field.getValue() - 0.01)   
 
113
  elif (segment == 128):
 
114
   hardness128Field.setValue(hardness128Field.getValue() - 0.01)   
 
115
  elif (segment == 192):  
 
116
   hardness192Field.setValue(hardness192Field.getValue() - 0.01)   
 
117
  elif (segment == 255):  
 
118
   hardness255Field.setValue(hardness255Field.getValue() - 0.01)   
 
119
 
 
120
@InputDispatcher('@')
 
121
def doToggleSetHardness():
 
122
 hardnessSetEnabledField.setValue(not hardnessSetEnabledField.getValue())   #Toggle between true/false
 
123
 
 
124
@InputDispatcher('-')
 
125
def doResetTimePlayback():
 
126
  resetTimePlaybackField.setValue(True) 
 
127
  playbackDirectionField.setValue(0)
 
128
 
 
129
@InputDispatcher('n')
 
130
def doDecreaseTimePlayback():
 
131
  playbackDirectionField.setValue(-1)
 
132
  runPlaybackField.setValue(False)
 
133
 
 
134
@InputDispatcher('m')
 
135
def doIncreaseTimePlayback():
 
136
  playbackDirectionField.setValue(1)
 
137
  runPlaybackField.setValue(False)
 
138
 
 
139
@InputDispatcher('p')
 
140
def doIncreaseTimePlayback():
 
141
  runPlaybackField.setValue(not runPlaybackField.getValue())
 
142
 
 
143
@InputDispatcher('P')
 
144
def doPlayHaptic():
 
145
  playHapticField.setValue(True)
 
146
 
 
147
@InputDispatcher('S')
 
148
def doSaveVolume():
 
149
  global tempPos
 
150
  saveVolumeField.setValue(True)
 
151
  if saveHapticField.getValue() == True:
 
152
    done = True;
 
153
    length = len(tempPos)   
 
154
    FILE = open("positionTest.txt",'w')
 
155
    for pos in tempPos:
 
156
      FILE.write(str(pos))
 
157
      FILE.write('\n')
 
158
    FILE.close()
 
159
    print 'Haptic saved to file'
 
160
    saveHapticField.setValue(False)
 
161
    
 
162
@InputDispatcher('A')
 
163
def doToggleSaveHaptic():
 
164
  saveHapticField.setValue(not saveHapticField.getValue()) #Toggle between true/false
 
165
 
 
166
@InputDispatcher('5')
 
167
def doSaveStatisitcsToFile():
 
168
  saveStatisticsToFileField.setValue(True) 
 
169
  sys.stdout.write('\a')
 
170
 
 
171
@InputDispatcher('6')
 
172
def doSaveExpertToFile():
 
173
  saveExpertToFileField.setValue(True) 
 
174
  sys.stdout.write('\a')
 
175
 
 
176
@InputDispatcher('7')
 
177
def doHighlightTypeNormal():
 
178
  highlightTypeField.setValue("highlightTypeNormal")
 
179
  sys.stdout.write('\a')
 
180
 
 
181
@InputDispatcher('8')
 
182
def doHighlightTypeExpert():
 
183
  highlightTypeField.setValue("highlightTypeExpert")
 
184
  sys.stdout.write('\a')
 
185
 
 
186
@InputDispatcher('9')
 
187
def doHighlightTypeSegment():
 
188
  highlightTypeField.setValue("highlightTypeSegment")
 
189
  sys.stdout.write('\a')
 
190
 
 
191
@InputDispatcher('0')
 
192
def doHighlightTypeUserVsExpert():
 
193
  highlightTypeField.setValue("highlightTypeUserVersusExpert")
 
194
  sys.stdout.write('\a')
 
195