[123] | 1 | # Module for the preferences dialog
|
---|
| 2 |
|
---|
| 3 | #------------------------------------------------------------------------------
|
---|
| 4 |
|
---|
| 5 | from common import *
|
---|
| 6 |
|
---|
| 7 | from mlx.i18n import xstr
|
---|
| 8 | import mlx.const as const
|
---|
[166] | 9 | import mlx.config as config
|
---|
[123] | 10 |
|
---|
| 11 | import urlparse
|
---|
| 12 |
|
---|
| 13 | #------------------------------------------------------------------------------
|
---|
| 14 |
|
---|
[166] | 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)
|
---|
| 84 |
|
---|
| 85 | #------------------------------------------------------------------------------
|
---|
| 86 |
|
---|
[123] | 87 | class Preferences(gtk.Dialog):
|
---|
| 88 | """The preferences dialog."""
|
---|
| 89 | def __init__(self, gui):
|
---|
| 90 | """Construct the dialog."""
|
---|
| 91 | super(Preferences, self).__init__(WINDOW_TITLE_BASE + " " +
|
---|
| 92 | xstr("prefs_title"),
|
---|
| 93 | gui.mainWindow,
|
---|
[124] | 94 | DIALOG_MODAL)
|
---|
| 95 |
|
---|
| 96 | self.add_button(xstr("button_cancel"), RESPONSETYPE_REJECT)
|
---|
| 97 | self.add_button(xstr("button_ok"), RESPONSETYPE_ACCEPT)
|
---|
| 98 |
|
---|
[123] | 99 | self._gui = gui
|
---|
[166] | 100 | self._settingFromConfig = False
|
---|
[123] | 101 |
|
---|
| 102 | contentArea = self.get_content_area()
|
---|
| 103 |
|
---|
| 104 | notebook = gtk.Notebook()
|
---|
| 105 | contentArea.pack_start(notebook, True, True, 4)
|
---|
| 106 |
|
---|
| 107 | general = self._buildGeneral()
|
---|
| 108 | label = gtk.Label(xstr("prefs_tab_general"))
|
---|
| 109 | label.set_use_underline(True)
|
---|
| 110 | label.set_tooltip_text(xstr("prefs_tab_general_tooltip"))
|
---|
| 111 | notebook.append_page(general, label)
|
---|
| 112 |
|
---|
[132] | 113 | messages = self._buildMessages()
|
---|
| 114 | label = gtk.Label(xstr("prefs_tab_messages"))
|
---|
| 115 | label.set_use_underline(True)
|
---|
| 116 | label.set_tooltip_text(xstr("prefs_tab_message_tooltip"))
|
---|
| 117 | notebook.append_page(messages, label)
|
---|
| 118 |
|
---|
[166] | 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)
|
---|
| 124 |
|
---|
[123] | 125 | advanced = self._buildAdvanced()
|
---|
| 126 | label = gtk.Label(xstr("prefs_tab_advanced"))
|
---|
| 127 | label.set_use_underline(True)
|
---|
| 128 | label.set_tooltip_text(xstr("prefs_tab_advanced_tooltip"))
|
---|
| 129 | notebook.append_page(advanced, label)
|
---|
| 130 |
|
---|
| 131 | def run(self, config):
|
---|
| 132 | """Run the preferences dialog.
|
---|
| 133 |
|
---|
| 134 | The dialog will be set up from data in the given configuration. If the
|
---|
| 135 | changes are accepted by the user, the configuration is updated and saved."""
|
---|
| 136 | self._fromConfig(config)
|
---|
| 137 |
|
---|
| 138 | self.show_all()
|
---|
| 139 | response = super(Preferences, self).run()
|
---|
| 140 | self.hide()
|
---|
| 141 |
|
---|
| 142 | if response==RESPONSETYPE_ACCEPT:
|
---|
| 143 | self._toConfig(config)
|
---|
| 144 | config.save()
|
---|
| 145 |
|
---|
| 146 | def _fromConfig(self, config):
|
---|
| 147 | """Setup the dialog from the given configuration."""
|
---|
[166] | 148 | self._settingFromConfig = True
|
---|
| 149 |
|
---|
[123] | 150 | self._setLanguage(config.language)
|
---|
[147] | 151 | self._hideMinimizedWindow.set_active(config.hideMinimizedWindow)
|
---|
[136] | 152 | self._onlineGateSystem.set_active(config.onlineGateSystem)
|
---|
[139] | 153 | self._onlineACARS.set_active(config.onlineACARS)
|
---|
[131] | 154 | self._flareTimeFromFS.set_active(config.flareTimeFromFS)
|
---|
[148] | 155 | self._syncFSTime.set_active(config.syncFSTime)
|
---|
[123] | 156 |
|
---|
[149] | 157 | pirepDirectory = config.pirepDirectory
|
---|
| 158 | self._pirepDirectory.set_text("" if pirepDirectory is None
|
---|
| 159 | else pirepDirectory)
|
---|
| 160 |
|
---|
[132] | 161 | for messageType in const.messageTypes:
|
---|
| 162 | level = config.getMessageTypeLevel(messageType)
|
---|
| 163 | button = self._msgFSCheckButtons[messageType]
|
---|
| 164 | button.set_active(level == const.MESSAGELEVEL_FS or
|
---|
| 165 | level == const.MESSAGELEVEL_BOTH)
|
---|
| 166 | button = self._msgSoundCheckButtons[messageType]
|
---|
| 167 | button.set_active(level == const.MESSAGELEVEL_SOUND or
|
---|
| 168 | level == const.MESSAGELEVEL_BOTH)
|
---|
| 169 |
|
---|
[166] | 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 |
|
---|
[123] | 179 | self._autoUpdate.set_active(config.autoUpdate)
|
---|
| 180 | if not config.autoUpdate:
|
---|
| 181 | self._warnedAutoUpdate = True
|
---|
| 182 |
|
---|
| 183 | self._updateURL.set_text(config.updateURL)
|
---|
| 184 |
|
---|
[166] | 185 | self._settingFromConfig = False
|
---|
| 186 |
|
---|
[123] | 187 | def _toConfig(self, config):
|
---|
| 188 | """Setup the given config from the settings in the dialog."""
|
---|
| 189 | config.language = self._getLanguage()
|
---|
[147] | 190 | config.hideMinimizedWindow = self._hideMinimizedWindow.get_active()
|
---|
[136] | 191 | config.onlineGateSystem = self._onlineGateSystem.get_active()
|
---|
[139] | 192 | config.onlineACARS = self._onlineACARS.get_active()
|
---|
[131] | 193 | config.flareTimeFromFS = self._flareTimeFromFS.get_active()
|
---|
[148] | 194 | config.syncFSTime = self._syncFSTime.get_active()
|
---|
[164] | 195 | config.pirepDirectory = text2unicode(self._pirepDirectory.get_text())
|
---|
[132] | 196 |
|
---|
| 197 | for messageType in const.messageTypes:
|
---|
| 198 | fsButtonActive = self._msgFSCheckButtons[messageType].get_active()
|
---|
| 199 | soundButtonActive = self._msgSoundCheckButtons[messageType].get_active()
|
---|
| 200 | if fsButtonActive:
|
---|
| 201 | level = const.MESSAGELEVEL_BOTH if soundButtonActive \
|
---|
| 202 | else const.MESSAGELEVEL_FS
|
---|
| 203 | elif soundButtonActive:
|
---|
| 204 | level = const.MESSAGELEVEL_SOUND
|
---|
| 205 | else:
|
---|
| 206 | level = const.MESSAGELEVEL_NONE
|
---|
| 207 | config.setMessageTypeLevel(messageType, level)
|
---|
| 208 |
|
---|
[166] | 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()
|
---|
| 217 |
|
---|
[123] | 218 | config.autoUpdate = self._autoUpdate.get_active()
|
---|
| 219 | config.updateURL = self._updateURL.get_text()
|
---|
| 220 |
|
---|
| 221 | def _buildGeneral(self):
|
---|
| 222 | """Build the page for the general settings."""
|
---|
| 223 | mainAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
[149] | 224 | xscale = 1.0, yscale = 0.0)
|
---|
| 225 | mainAlignment.set_padding(padding_top = 16, padding_bottom = 8,
|
---|
| 226 | padding_left = 4, padding_right = 4)
|
---|
[123] | 227 | mainBox = gtk.VBox()
|
---|
| 228 | mainAlignment.add(mainBox)
|
---|
| 229 |
|
---|
| 230 | languageBox = gtk.HBox()
|
---|
| 231 | mainBox.pack_start(languageBox, False, False, 4)
|
---|
| 232 |
|
---|
| 233 | label = gtk.Label(xstr("prefs_language"))
|
---|
| 234 | label.set_use_underline(True)
|
---|
| 235 |
|
---|
| 236 | languageBox.pack_start(label, False, False, 4)
|
---|
| 237 |
|
---|
| 238 | self._languageList = gtk.ListStore(str, str)
|
---|
| 239 | for language in const.languages:
|
---|
| 240 | self._languageList.append([xstr("prefs_lang_" + language),
|
---|
| 241 | language])
|
---|
| 242 |
|
---|
| 243 | self._languageComboBox = languageComboBox = \
|
---|
| 244 | gtk.ComboBox(model = self._languageList)
|
---|
| 245 | cell = gtk.CellRendererText()
|
---|
| 246 | languageComboBox.pack_start(cell, True)
|
---|
| 247 | languageComboBox.add_attribute(cell, 'text', 0)
|
---|
| 248 | languageComboBox.set_tooltip_text(xstr("prefs_language_tooltip"))
|
---|
| 249 | languageComboBox.connect("changed", self._languageChanged)
|
---|
| 250 | languageBox.pack_start(languageComboBox, False, False, 4)
|
---|
| 251 |
|
---|
[131] | 252 | label.set_mnemonic_widget(languageComboBox)
|
---|
| 253 |
|
---|
[123] | 254 | self._changingLanguage = False
|
---|
| 255 | self._warnedRestartNeeded = False
|
---|
| 256 |
|
---|
[147] | 257 | self._hideMinimizedWindow = gtk.CheckButton(xstr("prefs_hideMinimizedWindow"))
|
---|
| 258 | self._hideMinimizedWindow.set_use_underline(True)
|
---|
| 259 | self._hideMinimizedWindow.set_tooltip_text(xstr("prefs_hideMinimizedWindow_tooltip"))
|
---|
| 260 | mainBox.pack_start(self._hideMinimizedWindow, False, False, 4)
|
---|
| 261 |
|
---|
[136] | 262 | self._onlineGateSystem = gtk.CheckButton(xstr("prefs_onlineGateSystem"))
|
---|
| 263 | self._onlineGateSystem.set_use_underline(True)
|
---|
| 264 | self._onlineGateSystem.set_tooltip_text(xstr("prefs_onlineGateSystem_tooltip"))
|
---|
| 265 | mainBox.pack_start(self._onlineGateSystem, False, False, 4)
|
---|
| 266 |
|
---|
[139] | 267 | self._onlineACARS = gtk.CheckButton(xstr("prefs_onlineACARS"))
|
---|
| 268 | self._onlineACARS.set_use_underline(True)
|
---|
| 269 | self._onlineACARS.set_tooltip_text(xstr("prefs_onlineACARS_tooltip"))
|
---|
| 270 | mainBox.pack_start(self._onlineACARS, False, False, 4)
|
---|
| 271 |
|
---|
[131] | 272 | self._flareTimeFromFS = gtk.CheckButton(xstr("prefs_flaretimeFromFS"))
|
---|
| 273 | self._flareTimeFromFS.set_use_underline(True)
|
---|
| 274 | self._flareTimeFromFS.set_tooltip_text(xstr("prefs_flaretimeFromFS_tooltip"))
|
---|
| 275 | mainBox.pack_start(self._flareTimeFromFS, False, False, 4)
|
---|
[123] | 276 |
|
---|
[148] | 277 | self._syncFSTime = gtk.CheckButton(xstr("prefs_syncFSTime"))
|
---|
| 278 | self._syncFSTime.set_use_underline(True)
|
---|
| 279 | self._syncFSTime.set_tooltip_text(xstr("prefs_syncFSTime_tooltip"))
|
---|
| 280 | mainBox.pack_start(self._syncFSTime, False, False, 4)
|
---|
[149] | 281 |
|
---|
| 282 | pirepBox = gtk.HBox()
|
---|
| 283 | mainBox.pack_start(pirepBox, False, False, 4)
|
---|
| 284 |
|
---|
| 285 | label = gtk.Label(xstr("prefs_pirepDirectory"))
|
---|
| 286 | label.set_use_underline(True)
|
---|
| 287 | pirepBox.pack_start(label, False, False, 4)
|
---|
| 288 |
|
---|
| 289 | self._pirepDirectory = gtk.Entry()
|
---|
| 290 | self._pirepDirectory.set_tooltip_text(xstr("prefs_pirepDirectory_tooltip"))
|
---|
| 291 | label.set_mnemonic_widget(self._pirepDirectory)
|
---|
| 292 | pirepBox.pack_start(self._pirepDirectory, True, True, 4)
|
---|
| 293 |
|
---|
| 294 | self._pirepDirectoryButton = gtk.Button(xstr("button_browse"))
|
---|
| 295 | self._pirepDirectoryButton.connect("clicked",
|
---|
| 296 | self._pirepDirectoryButtonClicked)
|
---|
| 297 | pirepBox.pack_start(self._pirepDirectoryButton, False, False, 4)
|
---|
| 298 |
|
---|
[123] | 299 | return mainAlignment
|
---|
| 300 |
|
---|
| 301 | def _setLanguage(self, language):
|
---|
| 302 | """Set the language to the given one."""
|
---|
| 303 | iter = self._languageList.get_iter_first()
|
---|
| 304 | while iter is not None:
|
---|
| 305 | (lang,) = self._languageList.get(iter, 1)
|
---|
| 306 | if (not language and lang=="$system") or \
|
---|
| 307 | lang==language:
|
---|
| 308 | self._changingLanguage = True
|
---|
| 309 | self._languageComboBox.set_active_iter(iter)
|
---|
| 310 | self._changingLanguage = False
|
---|
| 311 | break
|
---|
| 312 | else:
|
---|
| 313 | iter = self._languageList.iter_next(iter)
|
---|
| 314 |
|
---|
| 315 | def _getLanguage(self):
|
---|
| 316 | """Get the language selected by the user."""
|
---|
| 317 | iter = self._languageComboBox.get_active_iter()
|
---|
| 318 | (lang,) = self._languageList.get(iter, 1)
|
---|
| 319 | return "" if lang=="$system" else lang
|
---|
| 320 |
|
---|
| 321 | def _languageChanged(self, comboBox):
|
---|
| 322 | """Called when the language has changed."""
|
---|
| 323 | if not self._changingLanguage and not self._warnedRestartNeeded:
|
---|
| 324 | dialog = gtk.MessageDialog(parent = self,
|
---|
| 325 | type = MESSAGETYPE_INFO,
|
---|
| 326 | message_format = xstr("prefs_restart"))
|
---|
[124] | 327 | dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
|
---|
[123] | 328 | dialog.set_title(self.get_title())
|
---|
| 329 | dialog.format_secondary_markup(xstr("prefs_language_restart_sec"))
|
---|
| 330 | dialog.run()
|
---|
| 331 | dialog.hide()
|
---|
| 332 | self._warnedRestartNeeded = True
|
---|
[149] | 333 |
|
---|
| 334 | def _pirepDirectoryButtonClicked(self, button):
|
---|
| 335 | """Called when the PIREP directory button is clicked."""
|
---|
| 336 | dialog = gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " +
|
---|
| 337 | xstr("prefs_pirepDirectory_browser_title"),
|
---|
| 338 | action = FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
---|
| 339 | buttons = (gtk.STOCK_CANCEL, RESPONSETYPE_CANCEL,
|
---|
[151] | 340 | gtk.STOCK_OK, RESPONSETYPE_OK),
|
---|
| 341 | parent = self)
|
---|
| 342 | dialog.set_modal(True)
|
---|
| 343 | dialog.set_transient_for(self)
|
---|
[123] | 344 |
|
---|
[149] | 345 | directory = self._pirepDirectory.get_text()
|
---|
| 346 | if directory:
|
---|
| 347 | dialog.select_filename(directory)
|
---|
| 348 |
|
---|
| 349 | result = dialog.run()
|
---|
| 350 | dialog.hide()
|
---|
| 351 |
|
---|
| 352 | if result==RESPONSETYPE_OK:
|
---|
| 353 | self._pirepDirectory.set_text(dialog.get_filename())
|
---|
| 354 |
|
---|
[132] | 355 | def _buildMessages(self):
|
---|
| 356 | """Build the page for the message settings."""
|
---|
| 357 |
|
---|
| 358 | mainAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
| 359 | xscale = 0.0, yscale = 0.0)
|
---|
| 360 | mainAlignment.set_padding(padding_top = 16, padding_bottom = 8,
|
---|
| 361 | padding_left = 4, padding_right = 4)
|
---|
| 362 | mainBox = gtk.VBox()
|
---|
| 363 | mainAlignment.add(mainBox)
|
---|
| 364 |
|
---|
| 365 | table = gtk.Table(len(const.messageTypes) + 1, 3)
|
---|
| 366 | table.set_row_spacings(8)
|
---|
| 367 | table.set_col_spacings(32)
|
---|
| 368 | table.set_homogeneous(False)
|
---|
| 369 | mainBox.pack_start(table, False, False, 4)
|
---|
| 370 |
|
---|
| 371 | label = gtk.Label(xstr("prefs_msgs_fs"))
|
---|
| 372 | label.set_justify(JUSTIFY_CENTER)
|
---|
| 373 | label.set_alignment(0.5, 1.0)
|
---|
| 374 | table.attach(label, 1, 2, 0, 1)
|
---|
| 375 |
|
---|
| 376 | label = gtk.Label(xstr("prefs_msgs_sound"))
|
---|
| 377 | label.set_justify(JUSTIFY_CENTER)
|
---|
| 378 | label.set_alignment(0.5, 1.0)
|
---|
| 379 | table.attach(label, 2, 3, 0, 1)
|
---|
| 380 |
|
---|
| 381 | self._msgFSCheckButtons = {}
|
---|
| 382 | self._msgSoundCheckButtons = {}
|
---|
| 383 | row = 1
|
---|
| 384 | for messageType in const.messageTypes:
|
---|
| 385 | messageTypeStr = const.messageType2string(messageType)
|
---|
| 386 | label = gtk.Label(xstr("prefs_msgs_type_" + messageTypeStr))
|
---|
| 387 | label.set_justify(JUSTIFY_CENTER)
|
---|
| 388 | label.set_use_underline(True)
|
---|
| 389 | label.set_alignment(0.5, 0.5)
|
---|
| 390 | table.attach(label, 0, 1, row, row+1)
|
---|
| 391 |
|
---|
| 392 | fsCheckButton = gtk.CheckButton()
|
---|
| 393 | alignment = gtk.Alignment(xscale = 0.0, yscale = 0.0,
|
---|
| 394 | xalign = 0.5, yalign = 0.5)
|
---|
| 395 | alignment.add(fsCheckButton)
|
---|
| 396 | table.attach(alignment, 1, 2, row, row+1)
|
---|
| 397 | self._msgFSCheckButtons[messageType] = fsCheckButton
|
---|
| 398 |
|
---|
| 399 | soundCheckButton = gtk.CheckButton()
|
---|
| 400 | alignment = gtk.Alignment(xscale = 0.0, yscale = 0.0,
|
---|
| 401 | xalign = 0.5, yalign = 0.5)
|
---|
| 402 | alignment.add(soundCheckButton)
|
---|
| 403 | table.attach(alignment, 2, 3, row, row+1)
|
---|
| 404 | self._msgSoundCheckButtons[messageType] = soundCheckButton
|
---|
| 405 |
|
---|
| 406 | mnemonicWidget = gtk.Label("")
|
---|
| 407 | table.attach(mnemonicWidget, 3, 4, row, row+1)
|
---|
| 408 | label.set_mnemonic_widget(mnemonicWidget)
|
---|
| 409 | mnemonicWidget.connect("mnemonic-activate",
|
---|
| 410 | self._msgLabelActivated,
|
---|
| 411 | messageType)
|
---|
| 412 |
|
---|
| 413 | row += 1
|
---|
| 414 |
|
---|
| 415 | return mainAlignment
|
---|
| 416 |
|
---|
| 417 | def _msgLabelActivated(self, button, cycle_group, messageType):
|
---|
| 418 | """Called when the mnemonic of a label is activated.
|
---|
| 419 |
|
---|
| 420 | It cycles the corresponding options."""
|
---|
| 421 | fsCheckButton = self._msgFSCheckButtons[messageType]
|
---|
| 422 | soundCheckButton = self._msgSoundCheckButtons[messageType]
|
---|
| 423 |
|
---|
| 424 | num = 1 if fsCheckButton.get_active() else 0
|
---|
| 425 | num += 2 if soundCheckButton.get_active() else 0
|
---|
| 426 | num += 1
|
---|
| 427 |
|
---|
| 428 | fsCheckButton.set_active((num&0x01)==0x01)
|
---|
| 429 | soundCheckButton.set_active((num&0x02)==0x02)
|
---|
| 430 |
|
---|
| 431 | return True
|
---|
[166] | 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 |
|
---|
[123] | 529 | def _buildAdvanced(self):
|
---|
| 530 | """Build the page for the advanced settings."""
|
---|
| 531 |
|
---|
| 532 | mainAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
[149] | 533 | xscale = 1.0, yscale = 0.0)
|
---|
| 534 | mainAlignment.set_padding(padding_top = 16, padding_bottom = 8,
|
---|
| 535 | padding_left = 4, padding_right = 4)
|
---|
[123] | 536 | mainBox = gtk.VBox()
|
---|
| 537 | mainAlignment.add(mainBox)
|
---|
| 538 |
|
---|
| 539 | self._autoUpdate = gtk.CheckButton(xstr("prefs_update_auto"))
|
---|
| 540 | mainBox.pack_start(self._autoUpdate, False, False, 4)
|
---|
| 541 |
|
---|
| 542 | self._autoUpdate.set_use_underline(True)
|
---|
| 543 | self._autoUpdate.connect("toggled", self._autoUpdateToggled)
|
---|
| 544 | self._autoUpdate.set_tooltip_text(xstr("prefs_update_auto_tooltip"))
|
---|
| 545 | self._warnedAutoUpdate = False
|
---|
| 546 |
|
---|
| 547 | updateURLBox = gtk.HBox()
|
---|
| 548 | mainBox.pack_start(updateURLBox, False, False, 4)
|
---|
| 549 | label = gtk.Label(xstr("prefs_update_url"))
|
---|
| 550 | label.set_use_underline(True)
|
---|
| 551 | updateURLBox.pack_start(label, False, False, 4)
|
---|
| 552 |
|
---|
| 553 | self._updateURL = gtk.Entry()
|
---|
| 554 | label.set_mnemonic_widget(self._updateURL)
|
---|
| 555 | self._updateURL.set_width_chars(40)
|
---|
| 556 | self._updateURL.set_tooltip_text(xstr("prefs_update_url_tooltip"))
|
---|
| 557 | self._updateURL.connect("changed", self._updateURLChanged)
|
---|
[149] | 558 | updateURLBox.pack_start(self._updateURL, True, True, 4)
|
---|
[123] | 559 |
|
---|
| 560 | return mainAlignment
|
---|
| 561 |
|
---|
| 562 | def _setOKButtonSensitivity(self):
|
---|
| 563 | """Set the sensitive state of the OK button."""
|
---|
| 564 | sensitive = False
|
---|
| 565 | try:
|
---|
| 566 | result = urlparse.urlparse(self._updateURL.get_text())
|
---|
| 567 | sensitive = result.scheme!="" and (result.netloc + result.path)!=""
|
---|
| 568 | except:
|
---|
| 569 | pass
|
---|
| 570 |
|
---|
| 571 | okButton = self.get_widget_for_response(RESPONSETYPE_ACCEPT)
|
---|
| 572 | okButton.set_sensitive(sensitive)
|
---|
| 573 |
|
---|
| 574 | def _autoUpdateToggled(self, button):
|
---|
| 575 | """Called when the auto update check button is toggled."""
|
---|
[166] | 576 | if not self._settingFromConfig and not self._warnedAutoUpdate and \
|
---|
[123] | 577 | not self._autoUpdate.get_active():
|
---|
| 578 | dialog = gtk.MessageDialog(parent = self,
|
---|
| 579 | type = MESSAGETYPE_INFO,
|
---|
| 580 | message_format = xstr("prefs_update_auto_warning"))
|
---|
[124] | 581 | dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
|
---|
[123] | 582 | dialog.set_title(self.get_title())
|
---|
| 583 | dialog.run()
|
---|
| 584 | dialog.hide()
|
---|
| 585 | self._warnedAutoUpdate = True
|
---|
| 586 |
|
---|
| 587 | def _updateURLChanged(self, entry):
|
---|
| 588 | """Called when the update URL is changed."""
|
---|
| 589 | self._setOKButtonSensitivity()
|
---|