Changeset 166:e4ba22b7a13b for src
- Timestamp:
- 05/10/12 18:17:18 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/config.py
r156 r166 20 20 _languageMap = { "en_GB" : "eng", 21 21 "hu_HU" : "hun" } 22 23 #------------------------------------------------------------------------------- 24 25 class Hotkey(object): 26 """A hotkey.""" 27 def __init__(self, ctrl = False, shift = False, key = "0"): 28 """Construct the hotkey.""" 29 self.ctrl = ctrl 30 self.shift = shift 31 self.key = key 32 33 def set(self, s): 34 """Set the hotkey from the given string.""" 35 self.ctrl = "C" in s[:-1] 36 self.shift = "S" in s[:-1] 37 self.key = s[-1] 38 39 def __eq__(self, other): 40 """Check if the given hotkey is equal to the other one.""" 41 return self.ctrl == other.ctrl and self.shift == other.shift and \ 42 self.key == other.key 43 44 def __str__(self): 45 """Construct the hotkey to a string.""" 46 s = "" 47 if self.ctrl: s += "C" 48 if self.shift: s += "S" 49 s += self.key 50 return s 22 51 23 52 #------------------------------------------------------------------------------- … … 44 73 45 74 self._pirepDirectory = None 46 75 76 self._enableSounds = True 77 78 self._pilotControlsSounds = True 79 self._pilotHotkey = Hotkey(ctrl = True, shift = False, key = "0") 80 81 #self._approachCallOuts = False 82 self._speedbrakeAtTD = True 83 84 self._enableChecklists = False 85 self._checklistHotkey = Hotkey(ctrl = True, shift = True, key = "0") 86 47 87 self._autoUpdate = True 48 88 self._updateURL = Config.DEFAULT_UPDATE_URL … … 196 236 self._messageTypeLevels[messageType]!=level: 197 237 self._messageTypeLevels[messageType] = level 238 self._modified = True 239 240 @property 241 def enableSounds(self): 242 """Get whether background sounds are enabled.""" 243 return self._enableSounds 244 245 @enableSounds.setter 246 def enableSounds(self, enableSounds): 247 """Set whether background sounds are enabled.""" 248 if enableSounds!=self._enableSounds: 249 self._enableSounds = enableSounds 250 self._modified = True 251 252 @property 253 def pilotControlsSounds(self): 254 """Get whether the pilot controls the background sounds.""" 255 return self._pilotControlsSounds 256 257 @pilotControlsSounds.setter 258 def pilotControlsSounds(self, pilotControlsSounds): 259 """Set whether the pilot controls the background sounds.""" 260 if pilotControlsSounds!=self._pilotControlsSounds: 261 self._pilotControlsSounds = pilotControlsSounds 262 self._modified = True 263 264 @property 265 def pilotHotkey(self): 266 """Get the pilot's hotkey.""" 267 return self._pilotHotkey 268 269 @pilotHotkey.setter 270 def pilotHotkey(self, pilotHotkey): 271 """Set the pilot's hotkey.""" 272 if pilotHotkey!=self._pilotHotkey: 273 self._pilotHotkey = pilotHotkey 274 self._modified = True 275 276 # @property 277 # def approachCallOuts(self): 278 # """Get whether the approach callouts should be played.""" 279 # return self._approachCallOuts 280 281 # @approachCallOuts.setter 282 # def approachCallOuts(self, approachCallOuts): 283 # """Set whether the approach callouts should be played.""" 284 # if approachCallOuts!=self._approachCallOuts: 285 # self._approachCallOuts = approachCallOuts 286 # self._modified = True 287 288 @property 289 def speedbrakeAtTD(self): 290 """Get whether the speedbrake sounds should be played at touchdown.""" 291 return self._speedbrakeAtTD 292 293 @speedbrakeAtTD.setter 294 def speedbrakeAtTD(self, speedbrakeAtTD): 295 """Set whether the speedbrake sounds should be played at touchdown.""" 296 if speedbrakeAtTD!=self._speedbrakeAtTD: 297 self._speedbrakeAtTD = speedbrakeAtTD 298 self._modified = True 299 300 @property 301 def enableChecklists(self): 302 """Get whether aircraft-specific checklists should be played.""" 303 return self._enableChecklists 304 305 @enableChecklists.setter 306 def enableChecklists(self, enableChecklists): 307 """Get whether aircraft-specific checklists should be played.""" 308 if enableChecklists!=self._enableChecklists: 309 self._enableChecklists = enableChecklists 310 self._modified = True 311 312 @property 313 def checklistHotkey(self): 314 """Get the checklist hotkey.""" 315 return self._checklistHotkey 316 317 @checklistHotkey.setter 318 def checklistHotkey(self, checklistHotkey): 319 """Set the checklist hotkey.""" 320 if checklistHotkey!=self._checklistHotkey: 321 self._checklistHotkey = checklistHotkey 198 322 self._modified = True 199 323 … … 254 378 self._messageTypeLevels[messageType] = \ 255 379 self._getMessageTypeLevel(config, messageType) 380 381 self._enableSounds = self._getBoolean(config, "sounds", 382 "enable", True) 383 self._pilotControlsSounds = self._getBoolean(config, "sounds", 384 "pilotControls", True) 385 self._pilotHotkey.set(self._get(config, "sounds", 386 "pilotHotkey", "C0")) 387 #self._approachCallOuts = self._getBoolean(config, "sounds", 388 # "approachCallOuts", False) 389 self._speedbrakeAtTD = self._getBoolean(config, "sounds", 390 "speedbrakeAtTD", True) 391 392 self._enableChecklists = self._getBoolean(config, "sounds", 393 "enableChecklists", False) 394 self._checklistHotkey.set(self._get(config, "sounds", 395 "checklistHotkey", "CS0")) 256 396 257 397 self._autoUpdate = self._getBoolean(config, "update", "auto", True) … … 298 438 config.set(Config._messageTypesSection, option, 299 439 const.messageLevel2string(level)) 440 441 config.add_section("sounds") 442 config.set("sounds", "enable", 443 "yes" if self._enableSounds else "no") 444 config.set("sounds", "pilotControls", 445 "yes" if self._pilotControlsSounds else "no") 446 config.set("sounds", "pilotHotkey", str(self._pilotHotkey)) 447 #config.set("sounds", "approachCallOuts", 448 # "yes" if self._approachCallOuts else "no") 449 config.set("sounds", "speedbrakeAtTD", 450 "yes" if self._speedbrakeAtTD else "no") 451 452 config.set("sounds", "enableChecklists", 453 "yes" if self._enableChecklists else "no") 454 config.set("sounds", "checklistHotkey", 455 str(self._checklistHotkey)) 300 456 301 457 config.add_section("update") -
src/mlx/gui/prefs.py
r164 r166 7 7 from mlx.i18n import xstr 8 8 import mlx.const as const 9 import mlx.config as config 9 10 10 11 import urlparse 12 13 #------------------------------------------------------------------------------ 14 15 class Hotkey(gtk.HBox): 16 """A widget to handle a hotkey.""" 17 def __init__(self, labelText, tooltips): 18 """Construct the hotkey widget. 19 20 labelText is the text for the label before the hotkey. 21 22 The tooltips parameter is an array of the tooltips for: 23 - the hotkey combo box, 24 - the control check box, and 25 - the shift check box.""" 26 super(Hotkey, self).__init__() 27 28 label = gtk.Label(labelText) 29 label.set_use_underline(True) 30 labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5, 31 xscale = 0.0, yscale = 0.0) 32 labelAlignment.add(label) 33 self.pack_start(labelAlignment, False, False, 8) 34 35 self._ctrl = gtk.CheckButton("Ctrl") 36 self._ctrl.set_tooltip_text(tooltips[1]) 37 self.pack_start(self._ctrl, False, False, 4) 38 39 self._shift = gtk.CheckButton("Shift") 40 self._shift.set_tooltip_text(tooltips[2]) 41 self.pack_start(self._shift, False, False, 4) 42 43 self._hotkeyModel = gtk.ListStore(str) 44 for keyCode in range(ord("0"), ord("9")) + range(ord("A"), ord("Z")): 45 self._hotkeyModel.append([chr(keyCode)]) 46 47 self._hotkey = gtk.ComboBox(model = self._hotkeyModel) 48 cell = gtk.CellRendererText() 49 self._hotkey.pack_start(cell, True) 50 self._hotkey.add_attribute(cell, 'text', 0) 51 self._hotkey.set_tooltip_text(tooltips[0]) 52 self.pack_start(self._hotkey, False, False, 4) 53 54 self._setting = False 55 56 def set(self, hotkey): 57 """Set the hotkey widget from the given hotkey.""" 58 self._setting = True 59 60 self._ctrl.set_active(hotkey.ctrl) 61 self._shift.set_active(hotkey.shift) 62 63 hotkeyModel = self._hotkeyModel 64 iter = hotkeyModel.get_iter_first() 65 while iter is not None and \ 66 hotkeyModel.get_value(iter, 0)!=hotkey.key: 67 iter = hotkeyModel.iter_next(iter) 68 69 if iter is None: 70 iter = hotkeyModel.get_iter_first() 71 72 self._hotkey.set_active_iter(iter) 73 74 self._setting = False 75 76 def get(self): 77 """Get a hotkey corresponding to the settings in the widghet.""" 78 79 key = self._hotkeyModel.get_value(self._hotkey.get_active_iter(), 0) 80 81 return config.Hotkey(ctrl = self._ctrl.get_active(), 82 shift = self._shift.get_active(), 83 key = key) 11 84 12 85 #------------------------------------------------------------------------------ … … 25 98 26 99 self._gui = gui 100 self._settingFromConfig = False 27 101 28 102 contentArea = self.get_content_area() … … 42 116 label.set_tooltip_text(xstr("prefs_tab_message_tooltip")) 43 117 notebook.append_page(messages, label) 118 119 sounds = self._buildSounds() 120 label = gtk.Label(xstr("prefs_tab_sounds")) 121 label.set_use_underline(True) 122 label.set_tooltip_text(xstr("prefs_tab_sounds_tooltip")) 123 notebook.append_page(sounds, label) 44 124 45 125 advanced = self._buildAdvanced() … … 66 146 def _fromConfig(self, config): 67 147 """Setup the dialog from the given configuration.""" 148 self._settingFromConfig = True 149 68 150 self._setLanguage(config.language) 69 151 self._hideMinimizedWindow.set_active(config.hideMinimizedWindow) … … 86 168 level == const.MESSAGELEVEL_BOTH) 87 169 88 self._togglingAutoUpdate = True 170 self._enableSounds.set_active(config.enableSounds) 171 self._pilotControlsSounds.set_active(config.pilotControlsSounds) 172 self._pilotHotkey.set(config.pilotHotkey) 173 #self._approachCallOuts.set_active(config.approachCallOuts) 174 self._speedbrakeAtTD.set_active(config.speedbrakeAtTD) 175 176 self._enableChecklists.set_active(config.enableChecklists) 177 self._checklistHotkey.set(config.checklistHotkey) 178 89 179 self._autoUpdate.set_active(config.autoUpdate) 90 self._togglingAutoUpdate = False91 180 if not config.autoUpdate: 92 181 self._warnedAutoUpdate = True 93 182 94 183 self._updateURL.set_text(config.updateURL) 184 185 self._settingFromConfig = False 95 186 96 187 def _toConfig(self, config): … … 115 206 level = const.MESSAGELEVEL_NONE 116 207 config.setMessageTypeLevel(messageType, level) 208 209 config.enableSounds = self._enableSounds.get_active() 210 config.pilotControlsSounds = self._pilotControlsSounds.get_active() 211 config.pilotHotkey = self._pilotHotkey.get() 212 #config.approachCallOuts = self._approachCallOuts.get_active() 213 config.speedbrakeAtTD = self._speedbrakeAtTD.get_active() 214 215 config.enableChecklists = self._enableChecklists.get_active() 216 config.checklistHotkey = self._checklistHotkey.get() 117 217 118 218 config.autoUpdate = self._autoUpdate.get_active() … … 330 430 331 431 return True 332 432 433 def _buildSounds(self): 434 """Build the page for the sounds.""" 435 mainAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0, 436 xscale = 1.0, yscale = 1.0) 437 mainAlignment.set_padding(padding_top = 8, padding_bottom = 8, 438 padding_left = 4, padding_right = 4) 439 440 mainBox = gtk.VBox() 441 mainAlignment.add(mainBox) 442 443 backgroundFrame = gtk.Frame(label = xstr("prefs_sounds_frame_bg")) 444 mainBox.pack_start(backgroundFrame, False, False, 4) 445 446 backgroundAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0, 447 xscale = 1.0, yscale = 0.0) 448 backgroundAlignment.set_padding(padding_top = 4, padding_bottom = 4, 449 padding_left = 4, padding_right = 4) 450 backgroundFrame.add(backgroundAlignment) 451 452 backgroundBox = gtk.VBox() 453 backgroundAlignment.add(backgroundBox) 454 455 self._enableSounds = gtk.CheckButton(xstr("prefs_sounds_enable")) 456 self._enableSounds.set_use_underline(True) 457 self._enableSounds.set_tooltip_text(xstr("prefs_sounds_enable_tooltip")) 458 self._enableSounds.connect("toggled", self._enableSoundsToggled) 459 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5, 460 xscale = 1.0, yscale = 0.0) 461 alignment.add(self._enableSounds) 462 backgroundBox.pack_start(alignment, False, False, 4) 463 464 self._pilotControlsSounds = gtk.CheckButton(xstr("prefs_sounds_pilotControls")) 465 self._pilotControlsSounds.set_use_underline(True) 466 self._pilotControlsSounds.set_tooltip_text(xstr("prefs_sounds_pilotControls_tooltip")) 467 backgroundBox.pack_start(self._pilotControlsSounds, False, False, 4) 468 469 self._pilotHotkey = Hotkey(xstr("prefs_sounds_pilotHotkey"), 470 [xstr("prefs_sounds_pilotHotkey_tooltip"), 471 xstr("prefs_sounds_pilotHotkeyCtrl_tooltip"), 472 xstr("prefs_sounds_pilotHotkeyShift_tooltip")]) 473 474 backgroundBox.pack_start(self._pilotHotkey, False, False, 4) 475 476 # self._approachCallOuts = gtk.CheckButton(xstr("prefs_sounds_approachCallOuts")) 477 # self._approachCallOuts.set_use_underline(True) 478 # self._approachCallOuts.set_tooltip_text(xstr("prefs_sounds_approachCallOuts_tooltip")) 479 # backgroundBox.pack_start(self._approachCallOuts, False, False, 4) 480 481 self._speedbrakeAtTD = gtk.CheckButton(xstr("prefs_sounds_speedbrakeAtTD")) 482 self._speedbrakeAtTD.set_use_underline(True) 483 self._speedbrakeAtTD.set_tooltip_text(xstr("prefs_sounds_speedbrakeAtTD_tooltip")) 484 backgroundBox.pack_start(self._speedbrakeAtTD, False, False, 4) 485 486 checklistFrame = gtk.Frame(label = xstr("prefs_sounds_frame_checklists")) 487 mainBox.pack_start(checklistFrame, False, False, 4) 488 489 checklistAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0, 490 xscale = 1.0, yscale = 0.0) 491 checklistAlignment.set_padding(padding_top = 4, padding_bottom = 4, 492 padding_left = 4, padding_right = 4) 493 checklistFrame.add(checklistAlignment) 494 495 checklistBox = gtk.VBox() 496 checklistAlignment.add(checklistBox) 497 498 self._enableChecklists = gtk.CheckButton(xstr("prefs_sounds_enableChecklists")) 499 self._enableChecklists.set_use_underline(True) 500 self._enableChecklists.set_tooltip_text(xstr("prefs_sounds_enableChecklists_tooltip")) 501 self._enableChecklists.connect("toggled", self._enableChecklistsToggled) 502 checklistBox.pack_start(self._enableChecklists, False, False, 4) 503 504 self._checklistHotkey = Hotkey(xstr("prefs_sounds_checklistHotkey"), 505 [xstr("prefs_sounds_checklistHotkey_tooltip"), 506 xstr("prefs_sounds_checklistHotkeyCtrl_tooltip"), 507 xstr("prefs_sounds_checklistHotkeyShift_tooltip")]) 508 509 checklistBox.pack_start(self._checklistHotkey, False, False, 4) 510 511 self._enableSoundsToggled(self._enableSounds) 512 self._enableChecklistsToggled(self._enableChecklists) 513 514 return mainAlignment 515 516 def _enableSoundsToggled(self, button): 517 """Called when the enable sounds button is toggled.""" 518 active = button.get_active() 519 self._pilotControlsSounds.set_sensitive(active) 520 self._pilotHotkey.set_sensitive(active) 521 #self._approachCallOuts.set_sensitive(active) 522 self._speedbrakeAtTD.set_sensitive(active) 523 524 def _enableChecklistsToggled(self, button): 525 """Called when the enable checklists button is toggled.""" 526 active = button.get_active() 527 self._checklistHotkey.set_sensitive(active) 528 333 529 def _buildAdvanced(self): 334 530 """Build the page for the advanced settings.""" … … 348 544 self._autoUpdate.set_tooltip_text(xstr("prefs_update_auto_tooltip")) 349 545 self._warnedAutoUpdate = False 350 self._togglingAutoUpdate = False351 546 352 547 updateURLBox = gtk.HBox() … … 379 574 def _autoUpdateToggled(self, button): 380 575 """Called when the auto update check button is toggled.""" 381 if not self._ togglingAutoUpdateand not self._warnedAutoUpdate and \576 if not self._settingFromConfig and not self._warnedAutoUpdate and \ 382 577 not self._autoUpdate.get_active(): 383 578 dialog = gtk.MessageDialog(parent = self, -
src/mlx/i18n.py
r155 r166 568 568 self.add("prefs_tab_message_tooltip", 569 569 "Enable/disable message notifications in FS and/or by sound") 570 self.add("prefs_tab_sounds", "_Sounds") 571 self.add("prefs_tab_sounds_tooltip", 572 "Preferences regarding what sounds should be played during the various flight stages") 570 573 self.add("prefs_tab_advanced", "_Advanced") 571 574 self.add("prefs_tab_advanced_tooltip", … … 604 607 "from timestamps returned by the simulator.") 605 608 self.add("prefs_syncFSTime", 606 " _Synchronize the time in FS with the computer's clock")609 "S_ynchronize the time in FS with the computer's clock") 607 610 self.add("prefs_syncFSTime_tooltip", 608 611 "If this is checked the flight simulator's internal clock " … … 615 618 self.add("prefs_pirepDirectory_browser_title", 616 619 "Select PIREP directory") 620 621 self.add("prefs_sounds_frame_bg", "Background") 622 self.add("prefs_sounds_enable", 623 "_Enable background sounds") 624 self.add("prefs_sounds_enable_tooltip", 625 "If the background sounds are enabled, the logger " 626 "can play different pre-recorded sounds during the " 627 "various stages of the flight.") 628 self.add("prefs_sounds_pilotControls", 629 "_Pilot controls the sounds") 630 self.add("prefs_sounds_pilotControls_tooltip", 631 "If checked, the background sounds can be started by the " 632 "pilot by pressing the hotkey specified below. Otherwise " 633 "the sounds will start automatically when certain " 634 "conditions hold.") 635 self.add("prefs_sounds_pilotHotkey", 636 "_Hotkey:") 637 self.add("prefs_sounds_pilotHotkey_tooltip", 638 "The key to press possibly together with modifiers to play " 639 "the sound relevant to the current flight status.") 640 self.add("prefs_sounds_pilotHotkeyCtrl_tooltip", 641 "If checked, the Ctrl key should be pressed together with the " 642 "main key.") 643 self.add("prefs_sounds_pilotHotkeyShift_tooltip", 644 "If checked, the Shift key should be pressed together with the " 645 "main key.") 646 self.add("prefs_sounds_approachCallOuts", 647 "Enable approach callouts") 648 self.add("prefs_sounds_approachCallOuts_tooltip", 649 "If checked, the approach callouts will be played at " 650 "certain altitudes.") 651 self.add("prefs_sounds_speedbrakeAtTD", 652 "Enable speed_brake sound at touchdown") 653 self.add("prefs_sounds_speedbrakeAtTD_tooltip", 654 "If checked, a speedbrake sound will be played after " 655 "touchdown, when the speedbrakes deploy.") 656 self.add("prefs_sounds_frame_checklists", "Checklists") 657 self.add("prefs_sounds_enableChecklists", 658 "E_nable aircraft-specific checklists") 659 self.add("prefs_sounds_enableChecklists_tooltip", 660 "If checked, the program will play back pre-recorded " 661 "aircraft-specific checklists at the pilot's discretion.") 662 self.add("prefs_sounds_checklistHotkey", 663 "Checklist hot_key:") 664 self.add("prefs_sounds_checklistHotkey_tooltip", 665 "The key to press possibly together with modifiers to play the next " 666 "checklist item.") 667 self.add("prefs_sounds_checklistHotkeyCtrl_tooltip", 668 "If checked, the Ctrl key should be pressed together with the " 669 "main key.") 670 self.add("prefs_sounds_checklistHotkeyShift_tooltip", 671 "If checked, the Shift key should be pressed together with the " 672 "main key.") 673 617 674 self.add("prefs_update_auto", "Update the program auto_matically") 618 675 self.add("prefs_update_auto_tooltip",
Note:
See TracChangeset
for help on using the changeset viewer.