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
|
---|
9 | import mlx.config as config
|
---|
10 |
|
---|
11 | import urlparse
|
---|
12 |
|
---|
13 | #------------------------------------------------------------------------------
|
---|
14 |
|
---|
15 | class Hotkey(gtk.HBox):
|
---|
16 | """A widget to handle a hotkey."""
|
---|
17 |
|
---|
18 | # Constant to denote that the status of the Ctrl modifier is changed
|
---|
19 | CHANGED_CTRL = 1
|
---|
20 |
|
---|
21 | # Constant to denote that the status of the Shift modifier is changed
|
---|
22 | CHANGED_SHIFT = 2
|
---|
23 |
|
---|
24 | # Constant to denote that the value of the key is changed
|
---|
25 | CHANGED_KEY = 3
|
---|
26 |
|
---|
27 | def __init__(self, labelText, tooltips):
|
---|
28 | """Construct the hotkey widget.
|
---|
29 |
|
---|
30 | labelText is the text for the label before the hotkey.
|
---|
31 |
|
---|
32 | The tooltips parameter is an array of the tooltips for:
|
---|
33 | - the hotkey combo box,
|
---|
34 | - the control check box, and
|
---|
35 | - the shift check box."""
|
---|
36 | super(Hotkey, self).__init__()
|
---|
37 |
|
---|
38 | label = gtk.Label(labelText)
|
---|
39 | label.set_use_underline(True)
|
---|
40 | labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
41 | xscale = 0.0, yscale = 0.0)
|
---|
42 | labelAlignment.set_padding(padding_top = 0, padding_bottom = 0,
|
---|
43 | padding_left = 0, padding_right = 4)
|
---|
44 | labelAlignment.add(label)
|
---|
45 | self.pack_start(labelAlignment, False, False, 0)
|
---|
46 |
|
---|
47 | self._ctrl = gtk.CheckButton("Ctrl")
|
---|
48 | self._ctrl.set_tooltip_text(tooltips[1])
|
---|
49 | self._ctrl.connect("toggled", self._ctrlToggled)
|
---|
50 | self.pack_start(self._ctrl, False, False, 4)
|
---|
51 |
|
---|
52 | self._shift = gtk.CheckButton("Shift")
|
---|
53 | self._shift.set_tooltip_text(tooltips[2])
|
---|
54 | self._shift.connect("toggled", self._shiftToggled)
|
---|
55 | self.pack_start(self._shift, False, False, 4)
|
---|
56 |
|
---|
57 | self._hotkeyModel = gtk.ListStore(str)
|
---|
58 | for keyCode in range(ord("0"), ord("9")+1) + range(ord("A"), ord("Z")+1):
|
---|
59 | self._hotkeyModel.append([chr(keyCode)])
|
---|
60 |
|
---|
61 | self._hotkey = gtk.ComboBox(model = self._hotkeyModel)
|
---|
62 | cell = gtk.CellRendererText()
|
---|
63 | self._hotkey.pack_start(cell, True)
|
---|
64 | self._hotkey.add_attribute(cell, 'text', 0)
|
---|
65 | self._hotkey.set_tooltip_text(tooltips[0])
|
---|
66 | self._hotkey.connect("changed", self._keyChanged)
|
---|
67 | self.pack_start(self._hotkey, False, False, 4)
|
---|
68 |
|
---|
69 | label.set_mnemonic_widget(self._hotkey)
|
---|
70 |
|
---|
71 | self._setting = False
|
---|
72 |
|
---|
73 | @property
|
---|
74 | def ctrl(self):
|
---|
75 | """Get whether the Ctrl modifier is selected."""
|
---|
76 | return self._ctrl.get_active()
|
---|
77 |
|
---|
78 | @ctrl.setter
|
---|
79 | def ctrl(self, ctrl):
|
---|
80 | """Get whether the Ctrl modifier is selected."""
|
---|
81 | self._setting = True
|
---|
82 | self._ctrl.set_active(ctrl)
|
---|
83 | self._setting = False
|
---|
84 |
|
---|
85 | @property
|
---|
86 | def shift(self):
|
---|
87 | """Get whether the Shift modifier is selected."""
|
---|
88 | return self._shift.get_active()
|
---|
89 |
|
---|
90 | @shift.setter
|
---|
91 | def shift(self, shift):
|
---|
92 | """Get whether the Shift modifier is selected."""
|
---|
93 | self._setting = True
|
---|
94 | self._shift.set_active(shift)
|
---|
95 | self._setting = False
|
---|
96 |
|
---|
97 | @property
|
---|
98 | def key(self):
|
---|
99 | """Get the value of the key."""
|
---|
100 | return self._hotkeyModel.get_value(self._hotkey.get_active_iter(), 0)
|
---|
101 |
|
---|
102 | @key.setter
|
---|
103 | def key(self, key):
|
---|
104 | """Set the value of the key."""
|
---|
105 | self._setting = True
|
---|
106 |
|
---|
107 | hotkeyModel = self._hotkeyModel
|
---|
108 | iter = hotkeyModel.get_iter_first()
|
---|
109 | while iter is not None and \
|
---|
110 | hotkeyModel.get_value(iter, 0)!=key:
|
---|
111 | iter = hotkeyModel.iter_next(iter)
|
---|
112 |
|
---|
113 | if iter is None:
|
---|
114 | iter = hotkeyModel.get_iter_first()
|
---|
115 |
|
---|
116 | self._hotkey.set_active_iter(iter)
|
---|
117 |
|
---|
118 | self._setting = False
|
---|
119 |
|
---|
120 | def set(self, hotkey):
|
---|
121 | """Set the hotkey widget from the given hotkey."""
|
---|
122 | self.ctrl = hotkey.ctrl
|
---|
123 | self.shift = hotkey.shift
|
---|
124 | self.key = hotkey.key
|
---|
125 |
|
---|
126 | def get(self):
|
---|
127 | """Get a hotkey corresponding to the settings in the widghet."""
|
---|
128 |
|
---|
129 | key = self._hotkeyModel.get_value(self._hotkey.get_active_iter(), 0)
|
---|
130 |
|
---|
131 | return config.Hotkey(ctrl = self.ctrl, shift = self.shift,
|
---|
132 | key = self.key)
|
---|
133 |
|
---|
134 | def _ctrlToggled(self, checkButton):
|
---|
135 | """Called when the status of the Ctrl modifier has changed."""
|
---|
136 | if not self._setting:
|
---|
137 | self.emit("hotkey-changed", Hotkey.CHANGED_CTRL)
|
---|
138 |
|
---|
139 | def _shiftToggled(self, checkButton):
|
---|
140 | """Called when the status of the Shift modifier has changed."""
|
---|
141 | if not self._setting:
|
---|
142 | self.emit("hotkey-changed", Hotkey.CHANGED_SHIFT)
|
---|
143 |
|
---|
144 | def _keyChanged(self, comboBox):
|
---|
145 | """Called when the value of the key has changed."""
|
---|
146 | if not self._setting:
|
---|
147 | self.emit("hotkey-changed", Hotkey.CHANGED_KEY)
|
---|
148 |
|
---|
149 | def __eq__(self, other):
|
---|
150 | """Determine if the two hotkeys are equal."""
|
---|
151 | return self.ctrl==other.ctrl and self.shift==other.shift and \
|
---|
152 | self.key==other.key
|
---|
153 |
|
---|
154 | #------------------------------------------------------------------------------
|
---|
155 |
|
---|
156 | gobject.signal_new("hotkey-changed", Hotkey, gobject.SIGNAL_RUN_FIRST,
|
---|
157 | None, (int,))
|
---|
158 |
|
---|
159 | #------------------------------------------------------------------------------
|
---|
160 |
|
---|
161 | class Preferences(gtk.Dialog):
|
---|
162 | """The preferences dialog."""
|
---|
163 | def __init__(self, gui):
|
---|
164 | """Construct the dialog."""
|
---|
165 | super(Preferences, self).__init__(WINDOW_TITLE_BASE + " " +
|
---|
166 | xstr("prefs_title"),
|
---|
167 | gui.mainWindow,
|
---|
168 | DIALOG_MODAL)
|
---|
169 |
|
---|
170 | self.add_button(xstr("button_cancel"), RESPONSETYPE_REJECT)
|
---|
171 | self.add_button(xstr("button_ok"), RESPONSETYPE_ACCEPT)
|
---|
172 |
|
---|
173 | self._gui = gui
|
---|
174 | self._settingFromConfig = False
|
---|
175 |
|
---|
176 | contentArea = self.get_content_area()
|
---|
177 |
|
---|
178 | notebook = gtk.Notebook()
|
---|
179 | contentArea.pack_start(notebook, True, True, 4)
|
---|
180 |
|
---|
181 | general = self._buildGeneral()
|
---|
182 | label = gtk.Label(xstr("prefs_tab_general"))
|
---|
183 | label.set_use_underline(True)
|
---|
184 | label.set_tooltip_text(xstr("prefs_tab_general_tooltip"))
|
---|
185 | notebook.append_page(general, label)
|
---|
186 |
|
---|
187 | messages = self._buildMessages()
|
---|
188 | label = gtk.Label(xstr("prefs_tab_messages"))
|
---|
189 | label.set_use_underline(True)
|
---|
190 | label.set_tooltip_text(xstr("prefs_tab_message_tooltip"))
|
---|
191 | notebook.append_page(messages, label)
|
---|
192 |
|
---|
193 | sounds = self._buildSounds()
|
---|
194 | label = gtk.Label(xstr("prefs_tab_sounds"))
|
---|
195 | label.set_use_underline(True)
|
---|
196 | label.set_tooltip_text(xstr("prefs_tab_sounds_tooltip"))
|
---|
197 | notebook.append_page(sounds, label)
|
---|
198 |
|
---|
199 | advanced = self._buildAdvanced()
|
---|
200 | label = gtk.Label(xstr("prefs_tab_advanced"))
|
---|
201 | label.set_use_underline(True)
|
---|
202 | label.set_tooltip_text(xstr("prefs_tab_advanced_tooltip"))
|
---|
203 | notebook.append_page(advanced, label)
|
---|
204 |
|
---|
205 | def run(self, config):
|
---|
206 | """Run the preferences dialog.
|
---|
207 |
|
---|
208 | The dialog will be set up from data in the given configuration. If the
|
---|
209 | changes are accepted by the user, the configuration is updated and saved."""
|
---|
210 | self._fromConfig(config)
|
---|
211 |
|
---|
212 | self.show_all()
|
---|
213 | response = super(Preferences, self).run()
|
---|
214 | self.hide()
|
---|
215 |
|
---|
216 | if response==RESPONSETYPE_ACCEPT:
|
---|
217 | self._toConfig(config)
|
---|
218 | config.save()
|
---|
219 |
|
---|
220 | def _fromConfig(self, config):
|
---|
221 | """Setup the dialog from the given configuration."""
|
---|
222 | self._settingFromConfig = True
|
---|
223 |
|
---|
224 | self._setLanguage(config.language)
|
---|
225 | self._hideMinimizedWindow.set_active(config.hideMinimizedWindow)
|
---|
226 | self._onlineGateSystem.set_active(config.onlineGateSystem)
|
---|
227 | self._onlineACARS.set_active(config.onlineACARS)
|
---|
228 | self._flareTimeFromFS.set_active(config.flareTimeFromFS)
|
---|
229 | self._syncFSTime.set_active(config.syncFSTime)
|
---|
230 | self._usingFS2Crew.set_active(config.usingFS2Crew)
|
---|
231 |
|
---|
232 | pirepDirectory = config.pirepDirectory
|
---|
233 | self._pirepDirectory.set_text("" if pirepDirectory is None
|
---|
234 | else pirepDirectory)
|
---|
235 |
|
---|
236 | for messageType in const.messageTypes:
|
---|
237 | level = config.getMessageTypeLevel(messageType)
|
---|
238 | button = self._msgFSCheckButtons[messageType]
|
---|
239 | button.set_active(level == const.MESSAGELEVEL_FS or
|
---|
240 | level == const.MESSAGELEVEL_BOTH)
|
---|
241 | button = self._msgSoundCheckButtons[messageType]
|
---|
242 | button.set_active(level == const.MESSAGELEVEL_SOUND or
|
---|
243 | level == const.MESSAGELEVEL_BOTH)
|
---|
244 |
|
---|
245 | self._enableSounds.set_active(config.enableSounds)
|
---|
246 | self._pilotControlsSounds.set_active(config.pilotControlsSounds)
|
---|
247 | self._pilotHotkey.set(config.pilotHotkey)
|
---|
248 | #self._approachCallOuts.set_active(config.approachCallOuts)
|
---|
249 | self._speedbrakeAtTD.set_active(config.speedbrakeAtTD)
|
---|
250 |
|
---|
251 | self._enableChecklists.set_active(config.enableChecklists)
|
---|
252 | self._checklistHotkey.set(config.checklistHotkey)
|
---|
253 |
|
---|
254 | self._autoUpdate.set_active(config.autoUpdate)
|
---|
255 | if not config.autoUpdate:
|
---|
256 | self._warnedAutoUpdate = True
|
---|
257 |
|
---|
258 | self._updateURL.set_text(config.updateURL)
|
---|
259 |
|
---|
260 | self._settingFromConfig = False
|
---|
261 |
|
---|
262 | def _toConfig(self, config):
|
---|
263 | """Setup the given config from the settings in the dialog."""
|
---|
264 | config.language = self._getLanguage()
|
---|
265 | config.hideMinimizedWindow = self._hideMinimizedWindow.get_active()
|
---|
266 | config.onlineGateSystem = self._onlineGateSystem.get_active()
|
---|
267 | config.onlineACARS = self._onlineACARS.get_active()
|
---|
268 | config.flareTimeFromFS = self._flareTimeFromFS.get_active()
|
---|
269 | config.syncFSTime = self._syncFSTime.get_active()
|
---|
270 | config.usingFS2Crew = self._usingFS2Crew.get_active()
|
---|
271 | config.pirepDirectory = text2unicode(self._pirepDirectory.get_text())
|
---|
272 |
|
---|
273 | for messageType in const.messageTypes:
|
---|
274 | fsButtonActive = self._msgFSCheckButtons[messageType].get_active()
|
---|
275 | soundButtonActive = self._msgSoundCheckButtons[messageType].get_active()
|
---|
276 | if fsButtonActive:
|
---|
277 | level = const.MESSAGELEVEL_BOTH if soundButtonActive \
|
---|
278 | else const.MESSAGELEVEL_FS
|
---|
279 | elif soundButtonActive:
|
---|
280 | level = const.MESSAGELEVEL_SOUND
|
---|
281 | else:
|
---|
282 | level = const.MESSAGELEVEL_NONE
|
---|
283 | config.setMessageTypeLevel(messageType, level)
|
---|
284 |
|
---|
285 | config.enableSounds = self._enableSounds.get_active()
|
---|
286 | config.pilotControlsSounds = self._pilotControlsSounds.get_active()
|
---|
287 | config.pilotHotkey = self._pilotHotkey.get()
|
---|
288 | #config.approachCallOuts = self._approachCallOuts.get_active()
|
---|
289 | config.speedbrakeAtTD = self._speedbrakeAtTD.get_active()
|
---|
290 |
|
---|
291 | config.enableChecklists = self._enableChecklists.get_active()
|
---|
292 | config.checklistHotkey = self._checklistHotkey.get()
|
---|
293 |
|
---|
294 | config.autoUpdate = self._autoUpdate.get_active()
|
---|
295 | config.updateURL = self._updateURL.get_text()
|
---|
296 |
|
---|
297 | def _buildGeneral(self):
|
---|
298 | """Build the page for the general settings."""
|
---|
299 | mainAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
300 | xscale = 1.0, yscale = 0.0)
|
---|
301 | mainAlignment.set_padding(padding_top = 16, padding_bottom = 8,
|
---|
302 | padding_left = 4, padding_right = 4)
|
---|
303 | mainBox = gtk.VBox()
|
---|
304 | mainAlignment.add(mainBox)
|
---|
305 |
|
---|
306 | languageBox = gtk.HBox()
|
---|
307 | mainBox.pack_start(languageBox, False, False, 4)
|
---|
308 |
|
---|
309 | label = gtk.Label(xstr("prefs_language"))
|
---|
310 | label.set_use_underline(True)
|
---|
311 |
|
---|
312 | languageBox.pack_start(label, False, False, 4)
|
---|
313 |
|
---|
314 | self._languageList = gtk.ListStore(str, str)
|
---|
315 | for language in const.languages:
|
---|
316 | self._languageList.append([xstr("prefs_lang_" + language),
|
---|
317 | language])
|
---|
318 |
|
---|
319 | self._languageComboBox = languageComboBox = \
|
---|
320 | gtk.ComboBox(model = self._languageList)
|
---|
321 | cell = gtk.CellRendererText()
|
---|
322 | languageComboBox.pack_start(cell, True)
|
---|
323 | languageComboBox.add_attribute(cell, 'text', 0)
|
---|
324 | languageComboBox.set_tooltip_text(xstr("prefs_language_tooltip"))
|
---|
325 | languageComboBox.connect("changed", self._languageChanged)
|
---|
326 | languageBox.pack_start(languageComboBox, False, False, 4)
|
---|
327 |
|
---|
328 | label.set_mnemonic_widget(languageComboBox)
|
---|
329 |
|
---|
330 | self._changingLanguage = False
|
---|
331 | self._warnedRestartNeeded = False
|
---|
332 |
|
---|
333 | self._hideMinimizedWindow = gtk.CheckButton(xstr("prefs_hideMinimizedWindow"))
|
---|
334 | self._hideMinimizedWindow.set_use_underline(True)
|
---|
335 | self._hideMinimizedWindow.set_tooltip_text(xstr("prefs_hideMinimizedWindow_tooltip"))
|
---|
336 | mainBox.pack_start(self._hideMinimizedWindow, False, False, 4)
|
---|
337 |
|
---|
338 | self._onlineGateSystem = gtk.CheckButton(xstr("prefs_onlineGateSystem"))
|
---|
339 | self._onlineGateSystem.set_use_underline(True)
|
---|
340 | self._onlineGateSystem.set_tooltip_text(xstr("prefs_onlineGateSystem_tooltip"))
|
---|
341 | mainBox.pack_start(self._onlineGateSystem, False, False, 4)
|
---|
342 |
|
---|
343 | self._onlineACARS = gtk.CheckButton(xstr("prefs_onlineACARS"))
|
---|
344 | self._onlineACARS.set_use_underline(True)
|
---|
345 | self._onlineACARS.set_tooltip_text(xstr("prefs_onlineACARS_tooltip"))
|
---|
346 | mainBox.pack_start(self._onlineACARS, False, False, 4)
|
---|
347 |
|
---|
348 | self._flareTimeFromFS = gtk.CheckButton(xstr("prefs_flaretimeFromFS"))
|
---|
349 | self._flareTimeFromFS.set_use_underline(True)
|
---|
350 | self._flareTimeFromFS.set_tooltip_text(xstr("prefs_flaretimeFromFS_tooltip"))
|
---|
351 | mainBox.pack_start(self._flareTimeFromFS, False, False, 4)
|
---|
352 |
|
---|
353 | self._syncFSTime = gtk.CheckButton(xstr("prefs_syncFSTime"))
|
---|
354 | self._syncFSTime.set_use_underline(True)
|
---|
355 | self._syncFSTime.set_tooltip_text(xstr("prefs_syncFSTime_tooltip"))
|
---|
356 | mainBox.pack_start(self._syncFSTime, False, False, 4)
|
---|
357 |
|
---|
358 | self._usingFS2Crew = gtk.CheckButton(xstr("prefs_usingFS2Crew"))
|
---|
359 | self._usingFS2Crew.set_use_underline(True)
|
---|
360 | self._usingFS2Crew.set_tooltip_text(xstr("prefs_usingFS2Crew_tooltip"))
|
---|
361 | mainBox.pack_start(self._usingFS2Crew, False, False, 4)
|
---|
362 |
|
---|
363 | pirepBox = gtk.HBox()
|
---|
364 | mainBox.pack_start(pirepBox, False, False, 4)
|
---|
365 |
|
---|
366 | label = gtk.Label(xstr("prefs_pirepDirectory"))
|
---|
367 | label.set_use_underline(True)
|
---|
368 | pirepBox.pack_start(label, False, False, 4)
|
---|
369 |
|
---|
370 | self._pirepDirectory = gtk.Entry()
|
---|
371 | self._pirepDirectory.set_tooltip_text(xstr("prefs_pirepDirectory_tooltip"))
|
---|
372 | label.set_mnemonic_widget(self._pirepDirectory)
|
---|
373 | pirepBox.pack_start(self._pirepDirectory, True, True, 4)
|
---|
374 |
|
---|
375 | self._pirepDirectoryButton = gtk.Button(xstr("button_browse"))
|
---|
376 | self._pirepDirectoryButton.connect("clicked",
|
---|
377 | self._pirepDirectoryButtonClicked)
|
---|
378 | pirepBox.pack_start(self._pirepDirectoryButton, False, False, 4)
|
---|
379 |
|
---|
380 | return mainAlignment
|
---|
381 |
|
---|
382 | def _setLanguage(self, language):
|
---|
383 | """Set the language to the given one."""
|
---|
384 | iter = self._languageList.get_iter_first()
|
---|
385 | while iter is not None:
|
---|
386 | (lang,) = self._languageList.get(iter, 1)
|
---|
387 | if (not language and lang=="$system") or \
|
---|
388 | lang==language:
|
---|
389 | self._changingLanguage = True
|
---|
390 | self._languageComboBox.set_active_iter(iter)
|
---|
391 | self._changingLanguage = False
|
---|
392 | break
|
---|
393 | else:
|
---|
394 | iter = self._languageList.iter_next(iter)
|
---|
395 |
|
---|
396 | def _getLanguage(self):
|
---|
397 | """Get the language selected by the user."""
|
---|
398 | iter = self._languageComboBox.get_active_iter()
|
---|
399 | (lang,) = self._languageList.get(iter, 1)
|
---|
400 | return "" if lang=="$system" else lang
|
---|
401 |
|
---|
402 | def _languageChanged(self, comboBox):
|
---|
403 | """Called when the language has changed."""
|
---|
404 | if not self._changingLanguage and not self._warnedRestartNeeded:
|
---|
405 | dialog = gtk.MessageDialog(parent = self,
|
---|
406 | type = MESSAGETYPE_INFO,
|
---|
407 | message_format = xstr("prefs_restart"))
|
---|
408 | dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
|
---|
409 | dialog.set_title(self.get_title())
|
---|
410 | dialog.format_secondary_markup(xstr("prefs_language_restart_sec"))
|
---|
411 | dialog.run()
|
---|
412 | dialog.hide()
|
---|
413 | self._warnedRestartNeeded = True
|
---|
414 |
|
---|
415 | def _pirepDirectoryButtonClicked(self, button):
|
---|
416 | """Called when the PIREP directory button is clicked."""
|
---|
417 | dialog = gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " +
|
---|
418 | xstr("prefs_pirepDirectory_browser_title"),
|
---|
419 | action = FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
---|
420 | buttons = (gtk.STOCK_CANCEL, RESPONSETYPE_CANCEL,
|
---|
421 | gtk.STOCK_OK, RESPONSETYPE_OK),
|
---|
422 | parent = self)
|
---|
423 | dialog.set_modal(True)
|
---|
424 | dialog.set_transient_for(self)
|
---|
425 |
|
---|
426 | directory = self._pirepDirectory.get_text()
|
---|
427 | if directory:
|
---|
428 | dialog.select_filename(directory)
|
---|
429 |
|
---|
430 | result = dialog.run()
|
---|
431 | dialog.hide()
|
---|
432 |
|
---|
433 | if result==RESPONSETYPE_OK:
|
---|
434 | self._pirepDirectory.set_text(dialog.get_filename())
|
---|
435 |
|
---|
436 | def _buildMessages(self):
|
---|
437 | """Build the page for the message settings."""
|
---|
438 |
|
---|
439 | mainAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
440 | xscale = 0.0, yscale = 0.0)
|
---|
441 | mainAlignment.set_padding(padding_top = 16, padding_bottom = 8,
|
---|
442 | padding_left = 4, padding_right = 4)
|
---|
443 | mainBox = gtk.VBox()
|
---|
444 | mainAlignment.add(mainBox)
|
---|
445 |
|
---|
446 | table = gtk.Table(len(const.messageTypes) + 1, 3)
|
---|
447 | table.set_row_spacings(8)
|
---|
448 | table.set_col_spacings(32)
|
---|
449 | table.set_homogeneous(False)
|
---|
450 | mainBox.pack_start(table, False, False, 4)
|
---|
451 |
|
---|
452 | label = gtk.Label(xstr("prefs_msgs_fs"))
|
---|
453 | label.set_justify(JUSTIFY_CENTER)
|
---|
454 | label.set_alignment(0.5, 1.0)
|
---|
455 | table.attach(label, 1, 2, 0, 1)
|
---|
456 |
|
---|
457 | label = gtk.Label(xstr("prefs_msgs_sound"))
|
---|
458 | label.set_justify(JUSTIFY_CENTER)
|
---|
459 | label.set_alignment(0.5, 1.0)
|
---|
460 | table.attach(label, 2, 3, 0, 1)
|
---|
461 |
|
---|
462 | self._msgFSCheckButtons = {}
|
---|
463 | self._msgSoundCheckButtons = {}
|
---|
464 | row = 1
|
---|
465 | for messageType in const.messageTypes:
|
---|
466 | messageTypeStr = const.messageType2string(messageType)
|
---|
467 | label = gtk.Label(xstr("prefs_msgs_type_" + messageTypeStr))
|
---|
468 | label.set_justify(JUSTIFY_CENTER)
|
---|
469 | label.set_use_underline(True)
|
---|
470 | label.set_alignment(0.5, 0.5)
|
---|
471 | table.attach(label, 0, 1, row, row+1)
|
---|
472 |
|
---|
473 | fsCheckButton = gtk.CheckButton()
|
---|
474 | alignment = gtk.Alignment(xscale = 0.0, yscale = 0.0,
|
---|
475 | xalign = 0.5, yalign = 0.5)
|
---|
476 | alignment.add(fsCheckButton)
|
---|
477 | table.attach(alignment, 1, 2, row, row+1)
|
---|
478 | self._msgFSCheckButtons[messageType] = fsCheckButton
|
---|
479 |
|
---|
480 | soundCheckButton = gtk.CheckButton()
|
---|
481 | alignment = gtk.Alignment(xscale = 0.0, yscale = 0.0,
|
---|
482 | xalign = 0.5, yalign = 0.5)
|
---|
483 | alignment.add(soundCheckButton)
|
---|
484 | table.attach(alignment, 2, 3, row, row+1)
|
---|
485 | self._msgSoundCheckButtons[messageType] = soundCheckButton
|
---|
486 |
|
---|
487 | mnemonicWidget = gtk.Label("")
|
---|
488 | table.attach(mnemonicWidget, 3, 4, row, row+1)
|
---|
489 | label.set_mnemonic_widget(mnemonicWidget)
|
---|
490 | mnemonicWidget.connect("mnemonic-activate",
|
---|
491 | self._msgLabelActivated,
|
---|
492 | messageType)
|
---|
493 |
|
---|
494 | row += 1
|
---|
495 |
|
---|
496 | return mainAlignment
|
---|
497 |
|
---|
498 | def _msgLabelActivated(self, button, cycle_group, messageType):
|
---|
499 | """Called when the mnemonic of a label is activated.
|
---|
500 |
|
---|
501 | It cycles the corresponding options."""
|
---|
502 | fsCheckButton = self._msgFSCheckButtons[messageType]
|
---|
503 | soundCheckButton = self._msgSoundCheckButtons[messageType]
|
---|
504 |
|
---|
505 | num = 1 if fsCheckButton.get_active() else 0
|
---|
506 | num += 2 if soundCheckButton.get_active() else 0
|
---|
507 | num += 1
|
---|
508 |
|
---|
509 | fsCheckButton.set_active((num&0x01)==0x01)
|
---|
510 | soundCheckButton.set_active((num&0x02)==0x02)
|
---|
511 |
|
---|
512 | return True
|
---|
513 |
|
---|
514 | def _buildSounds(self):
|
---|
515 | """Build the page for the sounds."""
|
---|
516 | mainAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
517 | xscale = 1.0, yscale = 1.0)
|
---|
518 | mainAlignment.set_padding(padding_top = 8, padding_bottom = 8,
|
---|
519 | padding_left = 4, padding_right = 4)
|
---|
520 |
|
---|
521 | mainBox = gtk.VBox()
|
---|
522 | mainAlignment.add(mainBox)
|
---|
523 |
|
---|
524 | backgroundFrame = gtk.Frame(label = xstr("prefs_sounds_frame_bg"))
|
---|
525 | mainBox.pack_start(backgroundFrame, False, False, 4)
|
---|
526 |
|
---|
527 | backgroundAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
528 | xscale = 1.0, yscale = 0.0)
|
---|
529 | backgroundAlignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
530 | padding_left = 4, padding_right = 4)
|
---|
531 | backgroundFrame.add(backgroundAlignment)
|
---|
532 |
|
---|
533 | backgroundBox = gtk.VBox()
|
---|
534 | backgroundAlignment.add(backgroundBox)
|
---|
535 |
|
---|
536 | self._enableSounds = gtk.CheckButton(xstr("prefs_sounds_enable"))
|
---|
537 | self._enableSounds.set_use_underline(True)
|
---|
538 | self._enableSounds.set_tooltip_text(xstr("prefs_sounds_enable_tooltip"))
|
---|
539 | self._enableSounds.connect("toggled", self._enableSoundsToggled)
|
---|
540 | alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
541 | xscale = 1.0, yscale = 0.0)
|
---|
542 | alignment.add(self._enableSounds)
|
---|
543 | backgroundBox.pack_start(alignment, False, False, 4)
|
---|
544 |
|
---|
545 | self._pilotControlsSounds = gtk.CheckButton(xstr("prefs_sounds_pilotControls"))
|
---|
546 | self._pilotControlsSounds.set_use_underline(True)
|
---|
547 | self._pilotControlsSounds.set_tooltip_text(xstr("prefs_sounds_pilotControls_tooltip"))
|
---|
548 | self._pilotControlsSounds.connect("toggled", self._pilotControlsSoundsToggled)
|
---|
549 | backgroundBox.pack_start(self._pilotControlsSounds, False, False, 4)
|
---|
550 |
|
---|
551 | self._pilotHotkey = Hotkey(xstr("prefs_sounds_pilotHotkey"),
|
---|
552 | [xstr("prefs_sounds_pilotHotkey_tooltip"),
|
---|
553 | xstr("prefs_sounds_pilotHotkeyCtrl_tooltip"),
|
---|
554 | xstr("prefs_sounds_pilotHotkeyShift_tooltip")])
|
---|
555 |
|
---|
556 | backgroundBox.pack_start(self._pilotHotkey, False, False, 4)
|
---|
557 |
|
---|
558 | # self._approachCallOuts = gtk.CheckButton(xstr("prefs_sounds_approachCallOuts"))
|
---|
559 | # self._approachCallOuts.set_use_underline(True)
|
---|
560 | # self._approachCallOuts.set_tooltip_text(xstr("prefs_sounds_approachCallOuts_tooltip"))
|
---|
561 | # backgroundBox.pack_start(self._approachCallOuts, False, False, 4)
|
---|
562 |
|
---|
563 | self._speedbrakeAtTD = gtk.CheckButton(xstr("prefs_sounds_speedbrakeAtTD"))
|
---|
564 | self._speedbrakeAtTD.set_use_underline(True)
|
---|
565 | self._speedbrakeAtTD.set_tooltip_text(xstr("prefs_sounds_speedbrakeAtTD_tooltip"))
|
---|
566 | backgroundBox.pack_start(self._speedbrakeAtTD, False, False, 4)
|
---|
567 |
|
---|
568 | checklistFrame = gtk.Frame(label = xstr("prefs_sounds_frame_checklists"))
|
---|
569 | mainBox.pack_start(checklistFrame, False, False, 4)
|
---|
570 |
|
---|
571 | checklistAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
572 | xscale = 1.0, yscale = 0.0)
|
---|
573 | checklistAlignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
574 | padding_left = 4, padding_right = 4)
|
---|
575 | checklistFrame.add(checklistAlignment)
|
---|
576 |
|
---|
577 | checklistBox = gtk.VBox()
|
---|
578 | checklistAlignment.add(checklistBox)
|
---|
579 |
|
---|
580 | self._enableChecklists = gtk.CheckButton(xstr("prefs_sounds_enableChecklists"))
|
---|
581 | self._enableChecklists.set_use_underline(True)
|
---|
582 | self._enableChecklists.set_tooltip_text(xstr("prefs_sounds_enableChecklists_tooltip"))
|
---|
583 | self._enableChecklists.connect("toggled", self._enableChecklistsToggled)
|
---|
584 | checklistBox.pack_start(self._enableChecklists, False, False, 4)
|
---|
585 |
|
---|
586 | self._checklistHotkey = Hotkey(xstr("prefs_sounds_checklistHotkey"),
|
---|
587 | [xstr("prefs_sounds_checklistHotkey_tooltip"),
|
---|
588 | xstr("prefs_sounds_checklistHotkeyCtrl_tooltip"),
|
---|
589 | xstr("prefs_sounds_checklistHotkeyShift_tooltip")])
|
---|
590 |
|
---|
591 | checklistBox.pack_start(self._checklistHotkey, False, False, 4)
|
---|
592 |
|
---|
593 | self._enableSoundsToggled(self._enableSounds)
|
---|
594 | self._enableChecklistsToggled(self._enableChecklists)
|
---|
595 |
|
---|
596 | self._pilotHotkey.connect("hotkey-changed", self._reconcileHotkeys,
|
---|
597 | self._checklistHotkey)
|
---|
598 | self._checklistHotkey.connect("hotkey-changed", self._reconcileHotkeys,
|
---|
599 | self._pilotHotkey)
|
---|
600 |
|
---|
601 | return mainAlignment
|
---|
602 |
|
---|
603 | def _enableSoundsToggled(self, button):
|
---|
604 | """Called when the enable sounds button is toggled."""
|
---|
605 | active = button.get_active()
|
---|
606 | self._pilotControlsSounds.set_sensitive(active)
|
---|
607 | self._pilotControlsSoundsToggled(self._pilotControlsSounds)
|
---|
608 | #self._approachCallOuts.set_sensitive(active)
|
---|
609 | self._speedbrakeAtTD.set_sensitive(active)
|
---|
610 |
|
---|
611 | def _pilotControlsSoundsToggled(self, button):
|
---|
612 | """Called when the enable sounds button is toggled."""
|
---|
613 | active = button.get_active() and self._enableSounds.get_active()
|
---|
614 | self._pilotHotkey.set_sensitive(active)
|
---|
615 | if active and self._checklistHotkey.get_sensitive():
|
---|
616 | self._reconcileHotkeys(self._checklistHotkey, Hotkey.CHANGED_SHIFT,
|
---|
617 | self._pilotHotkey)
|
---|
618 |
|
---|
619 | def _enableChecklistsToggled(self, button):
|
---|
620 | """Called when the enable checklists button is toggled."""
|
---|
621 | active = button.get_active()
|
---|
622 | self._checklistHotkey.set_sensitive(active)
|
---|
623 | if active and self._pilotHotkey.get_sensitive():
|
---|
624 | self._reconcileHotkeys(self._pilotHotkey, Hotkey.CHANGED_SHIFT,
|
---|
625 | self._checklistHotkey)
|
---|
626 |
|
---|
627 | def _reconcileHotkeys(self, changedHotkey, what, otherHotkey):
|
---|
628 | """Reconcile the given hotkeys so that they are different.
|
---|
629 |
|
---|
630 | changedHotkey is the hotkey that has changed. what is one of the
|
---|
631 | Hotkey.CHANGED_XXX constants denoting what has changed. otherHotkey is
|
---|
632 | the other hotkey that must be reconciled.
|
---|
633 |
|
---|
634 | If the other hotkey is not sensitive or is not equal to the changed
|
---|
635 | one, nothing happens.
|
---|
636 |
|
---|
637 | Otherwise, if the status of the Ctrl modifier has changed, the status
|
---|
638 | of the Ctrl modifier on the other hotkey will be negated. Similarly, if
|
---|
639 | the Shift modifier has changed. If the key has changed, the Shift
|
---|
640 | modifier is negated in the other hotkey."""
|
---|
641 | if otherHotkey.get_sensitive() and changedHotkey==otherHotkey:
|
---|
642 | if what==Hotkey.CHANGED_CTRL:
|
---|
643 | otherHotkey.ctrl = not changedHotkey.ctrl
|
---|
644 | elif what==Hotkey.CHANGED_SHIFT or what==Hotkey.CHANGED_KEY:
|
---|
645 | otherHotkey.shift = not changedHotkey.shift
|
---|
646 |
|
---|
647 | def _buildAdvanced(self):
|
---|
648 | """Build the page for the advanced settings."""
|
---|
649 |
|
---|
650 | mainAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
651 | xscale = 1.0, yscale = 0.0)
|
---|
652 | mainAlignment.set_padding(padding_top = 16, padding_bottom = 8,
|
---|
653 | padding_left = 4, padding_right = 4)
|
---|
654 | mainBox = gtk.VBox()
|
---|
655 | mainAlignment.add(mainBox)
|
---|
656 |
|
---|
657 | self._autoUpdate = gtk.CheckButton(xstr("prefs_update_auto"))
|
---|
658 | mainBox.pack_start(self._autoUpdate, False, False, 4)
|
---|
659 |
|
---|
660 | self._autoUpdate.set_use_underline(True)
|
---|
661 | self._autoUpdate.connect("toggled", self._autoUpdateToggled)
|
---|
662 | self._autoUpdate.set_tooltip_text(xstr("prefs_update_auto_tooltip"))
|
---|
663 | self._warnedAutoUpdate = False
|
---|
664 |
|
---|
665 | updateURLBox = gtk.HBox()
|
---|
666 | mainBox.pack_start(updateURLBox, False, False, 4)
|
---|
667 | label = gtk.Label(xstr("prefs_update_url"))
|
---|
668 | label.set_use_underline(True)
|
---|
669 | updateURLBox.pack_start(label, False, False, 4)
|
---|
670 |
|
---|
671 | self._updateURL = gtk.Entry()
|
---|
672 | label.set_mnemonic_widget(self._updateURL)
|
---|
673 | self._updateURL.set_width_chars(40)
|
---|
674 | self._updateURL.set_tooltip_text(xstr("prefs_update_url_tooltip"))
|
---|
675 | self._updateURL.connect("changed", self._updateURLChanged)
|
---|
676 | updateURLBox.pack_start(self._updateURL, True, True, 4)
|
---|
677 |
|
---|
678 | return mainAlignment
|
---|
679 |
|
---|
680 | def _setOKButtonSensitivity(self):
|
---|
681 | """Set the sensitive state of the OK button."""
|
---|
682 | sensitive = False
|
---|
683 | try:
|
---|
684 | result = urlparse.urlparse(self._updateURL.get_text())
|
---|
685 | sensitive = result.scheme!="" and (result.netloc + result.path)!=""
|
---|
686 | except:
|
---|
687 | pass
|
---|
688 |
|
---|
689 | okButton = self.get_widget_for_response(RESPONSETYPE_ACCEPT)
|
---|
690 | okButton.set_sensitive(sensitive)
|
---|
691 |
|
---|
692 | def _autoUpdateToggled(self, button):
|
---|
693 | """Called when the auto update check button is toggled."""
|
---|
694 | if not self._settingFromConfig and not self._warnedAutoUpdate and \
|
---|
695 | not self._autoUpdate.get_active():
|
---|
696 | dialog = gtk.MessageDialog(parent = self,
|
---|
697 | type = MESSAGETYPE_INFO,
|
---|
698 | message_format = xstr("prefs_update_auto_warning"))
|
---|
699 | dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
|
---|
700 | dialog.set_title(self.get_title())
|
---|
701 | dialog.run()
|
---|
702 | dialog.hide()
|
---|
703 | self._warnedAutoUpdate = True
|
---|
704 |
|
---|
705 | def _updateURLChanged(self, entry):
|
---|
706 | """Called when the update URL is changed."""
|
---|
707 | self._setOKButtonSensitivity()
|
---|
708 |
|
---|