Changeset 264:6fbadb22b2c3 for src/mlx/config.py
- Timestamp:
- 07/01/12 07:58:44 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/config.py
r249 r264 42 42 self.key == other.key 43 43 44 def __ne__(self, other): 45 """Check if the given hotkey is not equal to the other one.""" 46 return not self==other 47 44 48 def __str__(self): 45 49 """Construct the hotkey to a string.""" … … 92 96 return self._fileList == other._fileList 93 97 98 def __ne__(self, other): 99 """Determine if the checklist is not equal to the given other one.""" 100 return not self==other 101 94 102 def __len__(self): 95 103 """Get the length of the file list.""" … … 103 111 """Iterate over the files.""" 104 112 return iter(self._fileList) 113 114 #------------------------------------------------------------------------------- 115 116 class ApproachCallouts(object): 117 """The approach callouts for a certain aircraft type.""" 118 # The name of the section of the approach callouts 119 SECTION="callouts" 120 121 @staticmethod 122 def fromConfig(config, aircraftType): 123 """Create a checklist for the given aircraft type from the given 124 config.""" 125 baseName = "callouts." + const.icaoCodes[aircraftType] + "." 126 mapping = {} 127 while True: 128 option = baseName + str(len(mapping)) 129 if config.has_option(ApproachCallouts.SECTION, option): 130 value = config.get(ApproachCallouts.SECTION, option) 131 (altitude, path) = value.split(",") 132 altitude = int(altitude.strip()) 133 path = path.strip() 134 mapping[altitude] = path 135 else: 136 break 137 138 return ApproachCallouts(mapping) 139 140 def __init__(self, mapping = None): 141 """Construct the check list with the given mapping of altitudes to 142 files.""" 143 self._mapping = {} if mapping is None else mapping.copy() 144 145 def clone(self): 146 """Clone the callout information.""" 147 return ApproachCallouts(self._mapping) 148 149 def toConfig(self, config, aircraftType): 150 """Add this checklist to the given config.""" 151 baseName = "callouts." + const.icaoCodes[aircraftType] + "." 152 index = 0 153 for (altitude, path) in self._mapping.iteritems(): 154 option = baseName + str(index) 155 config.set(ApproachCallouts.SECTION, option, 156 "%d, %s" % (altitude, path)) 157 index += 1 158 159 def __eq__(self, other): 160 """Determine if the approach callout mapping is equal to the given 161 other one.""" 162 return self._mapping == other._mapping 163 164 def __ne__(self, other): 165 """Determine if the approach callout mapping is not equal to the given 166 other one.""" 167 return not self==other 168 169 def __len__(self): 170 """Get the number of elements in the mapping.""" 171 return len(self._mapping) 172 173 def __getitem__(self, altitude): 174 """Get the file that is associated with the highest altitude not higher 175 than the given one. 176 177 If no such file found, return None.""" 178 candidate = None 179 for (alt, path) in self._mapping.iteritems(): 180 if alt<=altitude: 181 if candidate is None or alt>candidate[0]: 182 candidate = (alt, path) 183 184 return candidate 185 186 def __iter__(self): 187 """Iterate over the pairs of altitudes and paths in decreasing order of 188 the altitude.""" 189 altitudes = self._mapping.keys() 190 altitudes.sort(reverse = True) 191 192 for altitude in altitudes: 193 yield (altitude, self._mapping[altitude]) 105 194 106 195 #------------------------------------------------------------------------------- … … 137 226 self._pilotHotkey = Hotkey(ctrl = True, shift = False, key = "0") 138 227 139 #self._approachCallOuts = False228 self._enableApproachCallouts = False 140 229 self._speedbrakeAtTD = True 141 230 … … 149 238 150 239 self._checklists = {} 240 self._approachCallouts = {} 151 241 for aircraftType in const.aircraftTypes: 152 242 self._checklists[aircraftType] = Checklist() 153 243 self._approachCallouts[aircraftType] = ApproachCallouts() 244 154 245 self._modified = False 155 246 … … 404 495 self._modified = True 405 496 406 #@property407 # def approachCallOuts(self):408 #"""Get whether the approach callouts should be played."""409 # return self._approachCallOuts410 411 # @approachCallOuts.setter412 # def approachCallOuts(self, approachCallOuts):413 #"""Set whether the approach callouts should be played."""414 # if approachCallOuts!=self._approachCallOuts:415 # self._approachCallOuts = approachCallOuts416 #self._modified = True497 @property 498 def enableApproachCallouts(self): 499 """Get whether the approach callouts should be played.""" 500 return self._enableApproachCallouts 501 502 @enableApproachCallouts.setter 503 def enableApproachCallouts(self, enableApproachCallouts): 504 """Set whether the approach callouts should be played.""" 505 if enableApproachCallouts!=self._enableApproachCallouts: 506 self._enableApproachCallouts = enableApproachCallouts 507 self._modified = True 417 508 418 509 @property … … 484 575 if checklist!=self._checklists[aircraftType]: 485 576 self._checklists[aircraftType] = checklist.clone() 577 self._modified = True 578 579 def getApproachCallouts(self, aircraftType): 580 """Get the approach callouts for the given aircraft type.""" 581 return self._approachCallouts[aircraftType] 582 583 def setApproachCallouts(self, aircraftType, approachCallouts): 584 """Set the approach callouts for the given aircraft type.""" 585 if not approachCallouts==self._approachCallouts[aircraftType]: 586 print "Updating approach callouts" 587 self._approachCallouts[aircraftType] = approachCallouts.clone() 486 588 self._modified = True 487 589 … … 538 640 self._pilotHotkey.set(self._get(config, "sounds", 539 641 "pilotHotkey", "C0")) 540 #self._approachCallOuts = self._getBoolean(config, "sounds",541 # "approachCallOuts", False)642 self._enableApproachCallOuts = \ 643 self._getBoolean(config, "sounds", "enableApproachCallOuts", False) 542 644 self._speedbrakeAtTD = self._getBoolean(config, "sounds", 543 645 "speedbrakeAtTD", True) … … 555 657 self._checklists[aircraftType] = \ 556 658 Checklist.fromConfig(config, aircraftType) 659 self._approachCallouts[aircraftType] = \ 660 ApproachCallouts.fromConfig(config, aircraftType) 557 661 558 662 self._modified = False … … 626 730 627 731 config.add_section(Checklist.SECTION) 732 config.add_section(ApproachCallouts.SECTION) 628 733 for aircraftType in const.aircraftTypes: 629 734 self._checklists[aircraftType].toConfig(config, aircraftType) 735 self._approachCallouts[aircraftType].toConfig(config, aircraftType) 630 736 631 737 try:
Note:
See TracChangeset
for help on using the changeset viewer.