[113] | 1 | # -*- encoding: utf-8 -*-
|
---|
[36] | 2 |
|
---|
[919] | 3 | from . import const
|
---|
| 4 | from .util import secondaryInstallation, utf2unicode
|
---|
[132] | 5 |
|
---|
[40] | 6 | import os
|
---|
[43] | 7 | import sys
|
---|
[373] | 8 | import traceback
|
---|
[919] | 9 | import configparser
|
---|
[40] | 10 |
|
---|
[298] | 11 | ## @package mlx.config
|
---|
[373] | 12 | #
|
---|
[298] | 13 | # The handling of the configuration.
|
---|
| 14 | #
|
---|
| 15 | # The \ref Config class contains the main configuration and is capable of
|
---|
| 16 | # loading and saving the configuration. It contains getters and setters for the
|
---|
| 17 | # configuration options.
|
---|
| 18 | #
|
---|
| 19 | # Some parts of the configuration are not simple data items, like strings or
|
---|
| 20 | # booleans, but more complicated data. These have their own class, like \ref
|
---|
| 21 | # ApproachCallouts or \ref Checklist.
|
---|
| 22 |
|
---|
[40] | 23 | #-------------------------------------------------------------------------------
|
---|
| 24 |
|
---|
| 25 | configPath = os.path.join(os.path.expanduser("~"),
|
---|
[373] | 26 | "mlx.config" if os.name=="nt" else ".mlxrc") + \
|
---|
| 27 | ("-secondary" if secondaryInstallation else "")
|
---|
[40] | 28 |
|
---|
| 29 | #-------------------------------------------------------------------------------
|
---|
| 30 |
|
---|
[124] | 31 | if os.name=="nt":
|
---|
| 32 | _languageMap = { "en_GB" : "eng",
|
---|
| 33 | "hu_HU" : "hun" }
|
---|
| 34 |
|
---|
| 35 | #-------------------------------------------------------------------------------
|
---|
| 36 |
|
---|
[166] | 37 | class Hotkey(object):
|
---|
| 38 | """A hotkey."""
|
---|
| 39 | def __init__(self, ctrl = False, shift = False, key = "0"):
|
---|
| 40 | """Construct the hotkey."""
|
---|
| 41 | self.ctrl = ctrl
|
---|
| 42 | self.shift = shift
|
---|
| 43 | self.key = key
|
---|
| 44 |
|
---|
| 45 | def set(self, s):
|
---|
| 46 | """Set the hotkey from the given string."""
|
---|
| 47 | self.ctrl = "C" in s[:-1]
|
---|
| 48 | self.shift = "S" in s[:-1]
|
---|
| 49 | self.key = s[-1]
|
---|
| 50 |
|
---|
| 51 | def __eq__(self, other):
|
---|
| 52 | """Check if the given hotkey is equal to the other one."""
|
---|
| 53 | return self.ctrl == other.ctrl and self.shift == other.shift and \
|
---|
| 54 | self.key == other.key
|
---|
| 55 |
|
---|
[264] | 56 | def __ne__(self, other):
|
---|
| 57 | """Check if the given hotkey is not equal to the other one."""
|
---|
| 58 | return not self==other
|
---|
[373] | 59 |
|
---|
[166] | 60 | def __str__(self):
|
---|
| 61 | """Construct the hotkey to a string."""
|
---|
| 62 | s = ""
|
---|
| 63 | if self.ctrl: s += "C"
|
---|
| 64 | if self.shift: s += "S"
|
---|
| 65 | s += self.key
|
---|
| 66 | return s
|
---|
| 67 |
|
---|
| 68 | #-------------------------------------------------------------------------------
|
---|
| 69 |
|
---|
[175] | 70 | class Checklist(object):
|
---|
| 71 | """A checklist for a certain aircraft type."""
|
---|
| 72 | # The name of the section of the checklists
|
---|
| 73 | SECTION="checklists"
|
---|
[373] | 74 |
|
---|
[175] | 75 | @staticmethod
|
---|
| 76 | def fromConfig(config, aircraftType):
|
---|
| 77 | """Create a checklist for the given aircraft type from the given
|
---|
| 78 | config."""
|
---|
| 79 | baseName = "checklist." + const.icaoCodes[aircraftType] + "."
|
---|
| 80 | fileList = []
|
---|
| 81 | while True:
|
---|
| 82 | option = baseName + str(len(fileList))
|
---|
| 83 | if config.has_option(Checklist.SECTION, option):
|
---|
| 84 | fileList.append(config.get(Checklist.SECTION, option))
|
---|
| 85 | else:
|
---|
| 86 | break
|
---|
| 87 |
|
---|
| 88 | return Checklist(fileList)
|
---|
| 89 |
|
---|
| 90 | def __init__(self, fileList = None):
|
---|
| 91 | """Construct the check list with the given file list."""
|
---|
| 92 | self._fileList = [] if fileList is None else fileList[:]
|
---|
| 93 |
|
---|
| 94 | def clone(self):
|
---|
| 95 | """Clone the checklist."""
|
---|
| 96 | return Checklist(self._fileList)
|
---|
| 97 |
|
---|
| 98 | def toConfig(self, config, aircraftType):
|
---|
| 99 | """Add this checklist to the given config."""
|
---|
| 100 | baseName = "checklist." + const.icaoCodes[aircraftType] + "."
|
---|
| 101 | for index in range(0, len(self._fileList)):
|
---|
| 102 | option = baseName + str(index)
|
---|
| 103 | config.set(Checklist.SECTION, option,
|
---|
| 104 | self._fileList[index])
|
---|
| 105 |
|
---|
| 106 | def __eq__(self, other):
|
---|
| 107 | """Determine if the checklist is equal to the given other one."""
|
---|
| 108 | return self._fileList == other._fileList
|
---|
| 109 |
|
---|
[264] | 110 | def __ne__(self, other):
|
---|
| 111 | """Determine if the checklist is not equal to the given other one."""
|
---|
| 112 | return not self==other
|
---|
[373] | 113 |
|
---|
[175] | 114 | def __len__(self):
|
---|
| 115 | """Get the length of the file list."""
|
---|
| 116 | return len(self._fileList)
|
---|
| 117 |
|
---|
| 118 | def __getitem__(self, index):
|
---|
| 119 | """Get the file with the given index."""
|
---|
| 120 | return self._fileList[index]
|
---|
| 121 |
|
---|
| 122 | def __iter__(self):
|
---|
| 123 | """Iterate over the files."""
|
---|
| 124 | return iter(self._fileList)
|
---|
| 125 |
|
---|
| 126 | #-------------------------------------------------------------------------------
|
---|
| 127 |
|
---|
[264] | 128 | class ApproachCallouts(object):
|
---|
| 129 | """The approach callouts for a certain aircraft type."""
|
---|
| 130 | # The name of the section of the approach callouts
|
---|
| 131 | SECTION="callouts"
|
---|
[373] | 132 |
|
---|
[264] | 133 | @staticmethod
|
---|
| 134 | def fromConfig(config, aircraftType):
|
---|
| 135 | """Create a checklist for the given aircraft type from the given
|
---|
| 136 | config."""
|
---|
| 137 | baseName = "callouts." + const.icaoCodes[aircraftType] + "."
|
---|
| 138 | mapping = {}
|
---|
| 139 | while True:
|
---|
| 140 | option = baseName + str(len(mapping))
|
---|
| 141 | if config.has_option(ApproachCallouts.SECTION, option):
|
---|
| 142 | value = config.get(ApproachCallouts.SECTION, option)
|
---|
| 143 | (altitude, path) = value.split(",")
|
---|
| 144 | altitude = int(altitude.strip())
|
---|
| 145 | path = path.strip()
|
---|
| 146 | mapping[altitude] = path
|
---|
| 147 | else:
|
---|
| 148 | break
|
---|
| 149 |
|
---|
[373] | 150 | return ApproachCallouts(mapping)
|
---|
[264] | 151 |
|
---|
| 152 | def __init__(self, mapping = None):
|
---|
| 153 | """Construct the check list with the given mapping of altitudes to
|
---|
| 154 | files."""
|
---|
| 155 | self._mapping = {} if mapping is None else mapping.copy()
|
---|
| 156 |
|
---|
| 157 | def clone(self):
|
---|
| 158 | """Clone the callout information."""
|
---|
| 159 | return ApproachCallouts(self._mapping)
|
---|
| 160 |
|
---|
| 161 | def toConfig(self, config, aircraftType):
|
---|
| 162 | """Add this checklist to the given config."""
|
---|
| 163 | baseName = "callouts." + const.icaoCodes[aircraftType] + "."
|
---|
| 164 | index = 0
|
---|
[919] | 165 | for (altitude, path) in self._mapping.items():
|
---|
[264] | 166 | option = baseName + str(index)
|
---|
| 167 | config.set(ApproachCallouts.SECTION, option,
|
---|
| 168 | "%d, %s" % (altitude, path))
|
---|
| 169 | index += 1
|
---|
| 170 |
|
---|
[273] | 171 | def getAltitudes(self, descending = True):
|
---|
| 172 | """Get the altitudes in decreasing order by default."""
|
---|
[919] | 173 | altitudes = list(self._mapping.keys())
|
---|
[273] | 174 | altitudes.sort(reverse = descending)
|
---|
| 175 | return altitudes
|
---|
| 176 |
|
---|
[919] | 177 | def __bool__(self):
|
---|
[273] | 178 | """Return if there is anything in the mapping."""
|
---|
| 179 | return not not self._mapping
|
---|
| 180 |
|
---|
[264] | 181 | def __eq__(self, other):
|
---|
| 182 | """Determine if the approach callout mapping is equal to the given
|
---|
| 183 | other one."""
|
---|
| 184 | return self._mapping == other._mapping
|
---|
| 185 |
|
---|
| 186 | def __ne__(self, other):
|
---|
| 187 | """Determine if the approach callout mapping is not equal to the given
|
---|
| 188 | other one."""
|
---|
| 189 | return not self==other
|
---|
| 190 |
|
---|
| 191 | def __len__(self):
|
---|
| 192 | """Get the number of elements in the mapping."""
|
---|
| 193 | return len(self._mapping)
|
---|
| 194 |
|
---|
| 195 | def __getitem__(self, altitude):
|
---|
[273] | 196 | """Get the file that is associated with the given altitude.
|
---|
[264] | 197 |
|
---|
| 198 | If no such file found, return None."""
|
---|
[273] | 199 | return self._mapping[altitude] if altitude in self._mapping else None
|
---|
[264] | 200 |
|
---|
| 201 | def __iter__(self):
|
---|
| 202 | """Iterate over the pairs of altitudes and paths in decreasing order of
|
---|
| 203 | the altitude."""
|
---|
[273] | 204 | altitudes = self.getAltitudes()
|
---|
[264] | 205 |
|
---|
| 206 | for altitude in altitudes:
|
---|
| 207 | yield (altitude, self._mapping[altitude])
|
---|
| 208 |
|
---|
| 209 | #-------------------------------------------------------------------------------
|
---|
| 210 |
|
---|
[36] | 211 | class Config(object):
|
---|
| 212 | """Our configuration."""
|
---|
[1080] | 213 | DEFAULT_UPDATE_URL = "https://mlx.varadiistvan.hu/update"
|
---|
[132] | 214 |
|
---|
| 215 | _messageTypesSection = "messageTypes"
|
---|
[373] | 216 |
|
---|
[36] | 217 | def __init__(self):
|
---|
| 218 | """Construct the configuration with default values."""
|
---|
[40] | 219 |
|
---|
[42] | 220 | self._pilotID = ""
|
---|
| 221 | self._password = ""
|
---|
[45] | 222 | self._rememberPassword = False
|
---|
[42] | 223 |
|
---|
[1097] | 224 | self._clearBrowserCacheOnStart = False
|
---|
[132] | 225 | self._language = ""
|
---|
[1098] | 226 | self._mainWindowResizable = False
|
---|
[147] | 227 | self._hideMinimizedWindow = True
|
---|
[249] | 228 | self._quitOnClose = False
|
---|
[373] | 229 | self._onlineGateSystem = not secondaryInstallation
|
---|
| 230 | self._onlineACARS = not secondaryInstallation
|
---|
[132] | 231 | self._flareTimeFromFS = False
|
---|
[148] | 232 | self._syncFSTime = False
|
---|
[183] | 233 | self._usingFS2Crew = False
|
---|
[197] | 234 | self._iasSmoothingLength = -2
|
---|
| 235 | self._vsSmoothingLength = -2
|
---|
[149] | 236 |
|
---|
[684] | 237 | self._useSimBrief = False
|
---|
[1084] | 238 | self._useInternalBrowserForSimBrief = False
|
---|
[689] | 239 | self._simBriefUserName = ""
|
---|
| 240 | self._simBriefPassword = ""
|
---|
| 241 | self._rememberSimBriefPassword = False
|
---|
[684] | 242 |
|
---|
[149] | 243 | self._pirepDirectory = None
|
---|
[392] | 244 | self._pirepAutoSave = False
|
---|
[166] | 245 |
|
---|
[503] | 246 | self._defaultMSFS = os.name=="nt"
|
---|
| 247 |
|
---|
[373] | 248 | self._enableSounds = not secondaryInstallation
|
---|
[166] | 249 |
|
---|
| 250 | self._pilotControlsSounds = True
|
---|
| 251 | self._pilotHotkey = Hotkey(ctrl = True, shift = False, key = "0")
|
---|
| 252 |
|
---|
[1094] | 253 | self._taxiSoundOnPushback = False
|
---|
| 254 |
|
---|
[264] | 255 | self._enableApproachCallouts = False
|
---|
[166] | 256 | self._speedbrakeAtTD = True
|
---|
| 257 |
|
---|
| 258 | self._enableChecklists = False
|
---|
| 259 | self._checklistHotkey = Hotkey(ctrl = True, shift = True, key = "0")
|
---|
[373] | 260 |
|
---|
| 261 | self._autoUpdate = True
|
---|
[40] | 262 | self._updateURL = Config.DEFAULT_UPDATE_URL
|
---|
[132] | 263 |
|
---|
[1067] | 264 | self._xplaneRemote = False
|
---|
| 265 | self._xplaneAddress = ""
|
---|
| 266 |
|
---|
[132] | 267 | self._messageTypeLevels = {}
|
---|
[175] | 268 |
|
---|
| 269 | self._checklists = {}
|
---|
[264] | 270 | self._approachCallouts = {}
|
---|
[175] | 271 | for aircraftType in const.aircraftTypes:
|
---|
| 272 | self._checklists[aircraftType] = Checklist()
|
---|
[264] | 273 | self._approachCallouts[aircraftType] = ApproachCallouts()
|
---|
[373] | 274 |
|
---|
[123] | 275 | self._modified = False
|
---|
[107] | 276 |
|
---|
[40] | 277 | @property
|
---|
[42] | 278 | def pilotID(self):
|
---|
| 279 | """Get the pilot ID."""
|
---|
| 280 | return self._pilotID
|
---|
| 281 |
|
---|
| 282 | @pilotID.setter
|
---|
| 283 | def pilotID(self, pilotID):
|
---|
| 284 | """Set the pilot ID."""
|
---|
| 285 | if pilotID!=self._pilotID:
|
---|
| 286 | self._pilotID = pilotID
|
---|
| 287 | self._modified = True
|
---|
| 288 |
|
---|
| 289 | @property
|
---|
| 290 | def password(self):
|
---|
| 291 | """Get the password."""
|
---|
| 292 | return self._password
|
---|
| 293 |
|
---|
| 294 | @password.setter
|
---|
| 295 | def password(self, password):
|
---|
| 296 | """Set the password."""
|
---|
| 297 | if password!=self._password:
|
---|
| 298 | self._password = password
|
---|
| 299 | self._modified = True
|
---|
| 300 |
|
---|
| 301 | @property
|
---|
[45] | 302 | def rememberPassword(self):
|
---|
| 303 | """Get if we should remember the password."""
|
---|
| 304 | return self._rememberPassword
|
---|
| 305 |
|
---|
| 306 | @rememberPassword.setter
|
---|
| 307 | def rememberPassword(self, rememberPassword):
|
---|
| 308 | """Set if we should remember the password."""
|
---|
| 309 | if rememberPassword!=self._rememberPassword:
|
---|
| 310 | self._rememberPassword = rememberPassword
|
---|
| 311 | self._modified = True
|
---|
| 312 |
|
---|
| 313 | @property
|
---|
[1097] | 314 | def clearBrowseCacheOnStart(self):
|
---|
| 315 | """Get whether the browser cache should be cleared on start."""
|
---|
| 316 | return self._clearBrowserCacheOnStart
|
---|
| 317 |
|
---|
| 318 | @clearBrowseCacheOnStart.setter
|
---|
| 319 | def clearBrowseCacheOnStart(self, clearBrowseCacheOnStart):
|
---|
| 320 | """Set whether the browser cache should be cleared on start."""
|
---|
| 321 | if clearBrowseCacheOnStart!=self._clearBrowserCacheOnStart:
|
---|
| 322 | self._clearBrowserCacheOnStart = clearBrowseCacheOnStart
|
---|
| 323 | self._modified = True
|
---|
| 324 |
|
---|
| 325 | @property
|
---|
[123] | 326 | def language(self):
|
---|
| 327 | """Get the language to use."""
|
---|
| 328 | return self._language
|
---|
| 329 |
|
---|
| 330 | @language.setter
|
---|
| 331 | def language(self, language):
|
---|
| 332 | """Set the language to use."""
|
---|
| 333 | if language!=self._language:
|
---|
| 334 | self._language = language
|
---|
| 335 | self._modified = True
|
---|
| 336 |
|
---|
| 337 | @property
|
---|
[1098] | 338 | def mainWindowResizable(self):
|
---|
| 339 | """Get whether a the main window should be resizable."""
|
---|
| 340 | return self._mainWindowResizable
|
---|
| 341 |
|
---|
| 342 | @mainWindowResizable.setter
|
---|
| 343 | def mainWindowResizable(self, mainWindowResizable):
|
---|
| 344 | """Set whether a minimized window should be hidden."""
|
---|
| 345 | if mainWindowResizable!=self._mainWindowResizable:
|
---|
| 346 | self._mainWindowResizable = mainWindowResizable
|
---|
| 347 | self._modified = True
|
---|
| 348 |
|
---|
| 349 | @property
|
---|
[147] | 350 | def hideMinimizedWindow(self):
|
---|
| 351 | """Get whether a minimized window should be hidden."""
|
---|
| 352 | return self._hideMinimizedWindow
|
---|
| 353 |
|
---|
| 354 | @hideMinimizedWindow.setter
|
---|
| 355 | def hideMinimizedWindow(self, hideMinimizedWindow):
|
---|
| 356 | """Set whether a minimized window should be hidden."""
|
---|
| 357 | if hideMinimizedWindow!=self._hideMinimizedWindow:
|
---|
| 358 | self._hideMinimizedWindow = hideMinimizedWindow
|
---|
| 359 | self._modified = True
|
---|
[373] | 360 |
|
---|
[147] | 361 | @property
|
---|
[249] | 362 | def quitOnClose(self):
|
---|
| 363 | """Get whether the application should quit when the close button is
|
---|
| 364 | clicked."""
|
---|
| 365 | return self._quitOnClose
|
---|
| 366 |
|
---|
| 367 | @quitOnClose.setter
|
---|
| 368 | def quitOnClose(self, quitOnClose):
|
---|
| 369 | """Set whether the application should quit when the close button is
|
---|
| 370 | clicked."""
|
---|
| 371 | if quitOnClose!=self._quitOnClose:
|
---|
| 372 | self._quitOnClose = quitOnClose
|
---|
| 373 | self._modified = True
|
---|
[373] | 374 |
|
---|
[249] | 375 | @property
|
---|
[136] | 376 | def onlineGateSystem(self):
|
---|
| 377 | """Get whether the online gate system should be used."""
|
---|
| 378 | return self._onlineGateSystem
|
---|
| 379 |
|
---|
| 380 | @onlineGateSystem.setter
|
---|
| 381 | def onlineGateSystem(self, onlineGateSystem):
|
---|
| 382 | """Set whether the online gate system should be used."""
|
---|
| 383 | if onlineGateSystem!=self._onlineGateSystem:
|
---|
| 384 | self._onlineGateSystem = onlineGateSystem
|
---|
| 385 | self._modified = True
|
---|
| 386 |
|
---|
| 387 | @property
|
---|
[139] | 388 | def onlineACARS(self):
|
---|
| 389 | """Get whether the online ACARS system should be used."""
|
---|
| 390 | return self._onlineACARS
|
---|
| 391 |
|
---|
| 392 | @onlineACARS.setter
|
---|
| 393 | def onlineACARS(self, onlineACARS):
|
---|
| 394 | """Set whether the online ACARS system should be used."""
|
---|
| 395 | if onlineACARS!=self._onlineACARS:
|
---|
| 396 | self._onlineACARS = onlineACARS
|
---|
| 397 | self._modified = True
|
---|
| 398 |
|
---|
| 399 | @property
|
---|
[131] | 400 | def flareTimeFromFS(self):
|
---|
| 401 | """Get whether the flare time should be calculated from the time values
|
---|
| 402 | returned by the simulator."""
|
---|
| 403 | return self._flareTimeFromFS
|
---|
| 404 |
|
---|
| 405 | @flareTimeFromFS.setter
|
---|
| 406 | def flareTimeFromFS(self, flareTimeFromFS):
|
---|
| 407 | """Set whether the flare time should be calculated from the time values
|
---|
| 408 | returned by the simulator."""
|
---|
| 409 | if flareTimeFromFS!=self._flareTimeFromFS:
|
---|
| 410 | self._flareTimeFromFS = flareTimeFromFS
|
---|
| 411 | self._modified = True
|
---|
| 412 |
|
---|
[148] | 413 | @property
|
---|
| 414 | def syncFSTime(self):
|
---|
| 415 | """Get whether the simulator's time should be synchronized with the
|
---|
| 416 | machine's clock."""
|
---|
| 417 | return self._syncFSTime
|
---|
| 418 |
|
---|
| 419 | @syncFSTime.setter
|
---|
| 420 | def syncFSTime(self, syncFSTime):
|
---|
| 421 | """Set whether the simulator's time should be synchronized with the
|
---|
| 422 | machine's clock."""
|
---|
| 423 | if syncFSTime!=self._syncFSTime:
|
---|
| 424 | self._syncFSTime = syncFSTime
|
---|
| 425 | self._modified = True
|
---|
| 426 |
|
---|
[149] | 427 | @property
|
---|
[183] | 428 | def usingFS2Crew(self):
|
---|
| 429 | """Get whether the FS2Crew addon is being used."""
|
---|
| 430 | return self._usingFS2Crew
|
---|
| 431 |
|
---|
| 432 | @usingFS2Crew.setter
|
---|
| 433 | def usingFS2Crew(self, usingFS2Crew):
|
---|
| 434 | """Set whether the FS2Crew addon is being used."""
|
---|
| 435 | if usingFS2Crew!=self._usingFS2Crew:
|
---|
| 436 | self._usingFS2Crew = usingFS2Crew
|
---|
| 437 | self._modified = True
|
---|
| 438 |
|
---|
| 439 | @property
|
---|
[197] | 440 | def iasSmoothingLength(self):
|
---|
| 441 | """Get the number of samples over which the IAS is averaged for the
|
---|
| 442 | smoothed IAS calculation. It may be negative, in which case smoothing
|
---|
| 443 | is disabled, but we nevertheless store the number of seconds in case it
|
---|
| 444 | may become useful later."""
|
---|
| 445 | return self._iasSmoothingLength
|
---|
| 446 |
|
---|
| 447 | @property
|
---|
| 448 | def realIASSmoothingLength(self):
|
---|
| 449 | """Get the real smoothing length of IAS."""
|
---|
| 450 | return max(self._iasSmoothingLength, 1)
|
---|
| 451 |
|
---|
| 452 | @iasSmoothingLength.setter
|
---|
| 453 | def iasSmoothingLength(self, iasSmoothingLength):
|
---|
| 454 | """Set the number of samples over which the IAS is averaged for the
|
---|
| 455 | smoothed IAS calculation."""
|
---|
| 456 | if iasSmoothingLength!=self._iasSmoothingLength:
|
---|
| 457 | self._iasSmoothingLength = iasSmoothingLength
|
---|
| 458 | self._modified = True
|
---|
| 459 |
|
---|
| 460 | @property
|
---|
| 461 | def vsSmoothingLength(self):
|
---|
| 462 | """Get the number of samples over which the VS is averaged for the
|
---|
| 463 | smoothed VS calculation. It may be negative, in which case smoothing
|
---|
| 464 | is disabled, but we nevertheless store the number of seconds in case it
|
---|
| 465 | may become useful later."""
|
---|
| 466 | return self._vsSmoothingLength
|
---|
| 467 |
|
---|
| 468 | @property
|
---|
| 469 | def realVSSmoothingLength(self):
|
---|
| 470 | """Get the real smoothing length of VS."""
|
---|
| 471 | return max(self._vsSmoothingLength, 1)
|
---|
| 472 |
|
---|
| 473 | @vsSmoothingLength.setter
|
---|
| 474 | def vsSmoothingLength(self, vsSmoothingLength):
|
---|
| 475 | """Set the number of samples over which the VS is averaged for the
|
---|
| 476 | smoothed VS calculation."""
|
---|
| 477 | if vsSmoothingLength!=self._vsSmoothingLength:
|
---|
| 478 | self._vsSmoothingLength = vsSmoothingLength
|
---|
| 479 | self._modified = True
|
---|
| 480 |
|
---|
| 481 | @property
|
---|
[684] | 482 | def useSimBrief(self):
|
---|
| 483 | """Check if SimBrief should be used."""
|
---|
| 484 | return self._useSimBrief
|
---|
| 485 |
|
---|
| 486 | @useSimBrief.setter
|
---|
| 487 | def useSimBrief(self, useSimBrief):
|
---|
| 488 | """Check if SimBrief should be used."""
|
---|
| 489 | if self._useSimBrief != useSimBrief:
|
---|
| 490 | self._useSimBrief = useSimBrief
|
---|
| 491 | self._modified = True
|
---|
| 492 |
|
---|
| 493 | @property
|
---|
[1084] | 494 | def useInternalBrowserForSimBrief(self):
|
---|
| 495 | """Get if we should use the internal browser to handle SimBrief."""
|
---|
| 496 | return self._useInternalBrowserForSimBrief
|
---|
| 497 |
|
---|
| 498 | @useInternalBrowserForSimBrief.setter
|
---|
| 499 | def useInternalBrowserForSimBrief(self, useInternalBrowserForSimBrief):
|
---|
| 500 | """Set if we should use the internal browser to handle SimBrief."""
|
---|
| 501 | if useInternalBrowserForSimBrief!=self._useInternalBrowserForSimBrief:
|
---|
| 502 | self._useInternalBrowserForSimBrief = useInternalBrowserForSimBrief
|
---|
| 503 | self._modified = True
|
---|
| 504 |
|
---|
| 505 | @property
|
---|
[689] | 506 | def simBriefUserName(self):
|
---|
| 507 | """Get the SimBrief user name last used"""
|
---|
| 508 | return self._simBriefUserName
|
---|
| 509 |
|
---|
| 510 | @simBriefUserName.setter
|
---|
| 511 | def simBriefUserName(self, simBriefUserName):
|
---|
| 512 | """Set the SimBrief user name to be used next."""
|
---|
| 513 | if self._simBriefUserName != simBriefUserName:
|
---|
| 514 | self._simBriefUserName = simBriefUserName
|
---|
| 515 | self._modified = True
|
---|
| 516 |
|
---|
| 517 | @property
|
---|
| 518 | def simBriefPassword(self):
|
---|
| 519 | """Get the SimBrief password last used"""
|
---|
| 520 | return self._simBriefPassword
|
---|
| 521 |
|
---|
| 522 | @simBriefPassword.setter
|
---|
| 523 | def simBriefPassword(self, simBriefPassword):
|
---|
| 524 | """Set the SimBrief password to be used next."""
|
---|
| 525 | if self._simBriefPassword != simBriefPassword:
|
---|
| 526 | self._simBriefPassword = simBriefPassword
|
---|
| 527 | self._modified = True
|
---|
| 528 |
|
---|
| 529 | @property
|
---|
| 530 | def rememberSimBriefPassword(self):
|
---|
| 531 | """Get if we should remember the SimBrief password."""
|
---|
| 532 | return self._rememberSimBriefPassword
|
---|
| 533 |
|
---|
| 534 | @rememberSimBriefPassword.setter
|
---|
| 535 | def rememberSimBriefPassword(self, rememberSimBriefPassword):
|
---|
| 536 | """Set if we should remember the SimBrief password."""
|
---|
| 537 | if rememberSimBriefPassword!=self._rememberSimBriefPassword:
|
---|
| 538 | self._rememberSimBriefPassword = rememberSimBriefPassword
|
---|
| 539 | self._modified = True
|
---|
| 540 |
|
---|
| 541 | @property
|
---|
[149] | 542 | def pirepDirectory(self):
|
---|
| 543 | """Get the directory offered by default when saving a PIREP."""
|
---|
| 544 | return self._pirepDirectory
|
---|
| 545 |
|
---|
| 546 | @pirepDirectory.setter
|
---|
| 547 | def pirepDirectory(self, pirepDirectory):
|
---|
| 548 | """Get the directory offered by default when saving a PIREP."""
|
---|
| 549 | if pirepDirectory!=self._pirepDirectory and \
|
---|
| 550 | (pirepDirectory!="" or self._pirepDirectory is not None):
|
---|
| 551 | self._pirepDirectory = None if pirepDirectory=="" \
|
---|
| 552 | else pirepDirectory
|
---|
[392] | 553 | if self._pirepDirectory is None:
|
---|
| 554 | self._pirepAutoSave = False
|
---|
| 555 | self._modified = True
|
---|
| 556 |
|
---|
| 557 | @property
|
---|
| 558 | def pirepAutoSave(self):
|
---|
| 559 | """Get whether the PIREP should be saved automatically when it becomes
|
---|
| 560 | saveable."""
|
---|
| 561 | return self._pirepAutoSave
|
---|
| 562 |
|
---|
| 563 | @pirepAutoSave.setter
|
---|
| 564 | def pirepAutoSave(self, pirepAutoSave):
|
---|
| 565 | """Set whether the PIREP should be saved automatically when it becomes
|
---|
| 566 | saveable."""
|
---|
| 567 | pirepAutoSave = pirepAutoSave and self._pirepDirectory is not None
|
---|
| 568 | if pirepAutoSave!=self._pirepAutoSave:
|
---|
| 569 | self._pirepAutoSave = pirepAutoSave
|
---|
[149] | 570 | self._modified = True
|
---|
| 571 |
|
---|
[503] | 572 | @property
|
---|
| 573 | def defaultMSFS(self):
|
---|
| 574 | """Get if the default simulator type is MS FS."""
|
---|
| 575 | return self._defaultMSFS
|
---|
| 576 |
|
---|
| 577 | @defaultMSFS.setter
|
---|
| 578 | def defaultMSFS(self, defaultMSFS):
|
---|
| 579 | """Set if the default simulator type is MS FS."""
|
---|
| 580 | if defaultMSFS!=self._defaultMSFS:
|
---|
| 581 | self._defaultMSFS = defaultMSFS
|
---|
| 582 | self._modified = True
|
---|
| 583 |
|
---|
[132] | 584 | def getMessageTypeLevel(self, messageType):
|
---|
| 585 | """Get the level for the given message type."""
|
---|
| 586 | return self._messageTypeLevels[messageType] \
|
---|
| 587 | if messageType in self._messageTypeLevels \
|
---|
| 588 | else const.MESSAGELEVEL_NONE
|
---|
| 589 |
|
---|
[134] | 590 | def isMessageTypeFS(self, messageType):
|
---|
| 591 | """Determine if the given message type is displayed in the
|
---|
| 592 | simulator."""
|
---|
| 593 | level = self.getMessageTypeLevel(messageType)
|
---|
| 594 | return level==const.MESSAGELEVEL_FS or \
|
---|
| 595 | level==const.MESSAGELEVEL_BOTH
|
---|
[373] | 596 |
|
---|
[132] | 597 | def setMessageTypeLevel(self, messageType, level):
|
---|
| 598 | """Set the level of the given message type."""
|
---|
| 599 | if messageType not in self._messageTypeLevels or \
|
---|
| 600 | self._messageTypeLevels[messageType]!=level:
|
---|
| 601 | self._messageTypeLevels[messageType] = level
|
---|
| 602 | self._modified = True
|
---|
| 603 |
|
---|
[131] | 604 | @property
|
---|
[166] | 605 | def enableSounds(self):
|
---|
| 606 | """Get whether background sounds are enabled."""
|
---|
| 607 | return self._enableSounds
|
---|
| 608 |
|
---|
| 609 | @enableSounds.setter
|
---|
| 610 | def enableSounds(self, enableSounds):
|
---|
| 611 | """Set whether background sounds are enabled."""
|
---|
| 612 | if enableSounds!=self._enableSounds:
|
---|
| 613 | self._enableSounds = enableSounds
|
---|
| 614 | self._modified = True
|
---|
| 615 |
|
---|
[373] | 616 | @property
|
---|
[166] | 617 | def pilotControlsSounds(self):
|
---|
| 618 | """Get whether the pilot controls the background sounds."""
|
---|
| 619 | return self._pilotControlsSounds
|
---|
| 620 |
|
---|
| 621 | @pilotControlsSounds.setter
|
---|
| 622 | def pilotControlsSounds(self, pilotControlsSounds):
|
---|
| 623 | """Set whether the pilot controls the background sounds."""
|
---|
| 624 | if pilotControlsSounds!=self._pilotControlsSounds:
|
---|
| 625 | self._pilotControlsSounds = pilotControlsSounds
|
---|
| 626 | self._modified = True
|
---|
| 627 |
|
---|
| 628 | @property
|
---|
| 629 | def pilotHotkey(self):
|
---|
| 630 | """Get the pilot's hotkey."""
|
---|
| 631 | return self._pilotHotkey
|
---|
| 632 |
|
---|
| 633 | @pilotHotkey.setter
|
---|
| 634 | def pilotHotkey(self, pilotHotkey):
|
---|
| 635 | """Set the pilot's hotkey."""
|
---|
| 636 | if pilotHotkey!=self._pilotHotkey:
|
---|
| 637 | self._pilotHotkey = pilotHotkey
|
---|
| 638 | self._modified = True
|
---|
| 639 |
|
---|
[264] | 640 | @property
|
---|
[1094] | 641 | def taxiSoundOnPushback(self):
|
---|
| 642 | """Get whether the taxi sound should be played as soon as pushback starts."""
|
---|
| 643 | return self._taxiSoundOnPushback
|
---|
| 644 |
|
---|
| 645 | @taxiSoundOnPushback.setter
|
---|
| 646 | def taxiSoundOnPushback(self, taxiSoundOnPushback):
|
---|
| 647 | """Set whether the taxi sound should be played as soon as pushback starts."""
|
---|
| 648 | if taxiSoundOnPushback!=self._taxiSoundOnPushback:
|
---|
| 649 | self._taxiSoundOnPushback = taxiSoundOnPushback
|
---|
| 650 | self._modified = True
|
---|
| 651 |
|
---|
| 652 | @property
|
---|
[264] | 653 | def enableApproachCallouts(self):
|
---|
| 654 | """Get whether the approach callouts should be played."""
|
---|
| 655 | return self._enableApproachCallouts
|
---|
[166] | 656 |
|
---|
[264] | 657 | @enableApproachCallouts.setter
|
---|
| 658 | def enableApproachCallouts(self, enableApproachCallouts):
|
---|
| 659 | """Set whether the approach callouts should be played."""
|
---|
| 660 | if enableApproachCallouts!=self._enableApproachCallouts:
|
---|
| 661 | self._enableApproachCallouts = enableApproachCallouts
|
---|
| 662 | self._modified = True
|
---|
[166] | 663 |
|
---|
| 664 | @property
|
---|
| 665 | def speedbrakeAtTD(self):
|
---|
| 666 | """Get whether the speedbrake sounds should be played at touchdown."""
|
---|
| 667 | return self._speedbrakeAtTD
|
---|
| 668 |
|
---|
| 669 | @speedbrakeAtTD.setter
|
---|
| 670 | def speedbrakeAtTD(self, speedbrakeAtTD):
|
---|
| 671 | """Set whether the speedbrake sounds should be played at touchdown."""
|
---|
| 672 | if speedbrakeAtTD!=self._speedbrakeAtTD:
|
---|
| 673 | self._speedbrakeAtTD = speedbrakeAtTD
|
---|
| 674 | self._modified = True
|
---|
[373] | 675 |
|
---|
[166] | 676 | @property
|
---|
| 677 | def enableChecklists(self):
|
---|
| 678 | """Get whether aircraft-specific checklists should be played."""
|
---|
| 679 | return self._enableChecklists
|
---|
| 680 |
|
---|
| 681 | @enableChecklists.setter
|
---|
| 682 | def enableChecklists(self, enableChecklists):
|
---|
| 683 | """Get whether aircraft-specific checklists should be played."""
|
---|
| 684 | if enableChecklists!=self._enableChecklists:
|
---|
| 685 | self._enableChecklists = enableChecklists
|
---|
| 686 | self._modified = True
|
---|
| 687 |
|
---|
| 688 | @property
|
---|
| 689 | def checklistHotkey(self):
|
---|
| 690 | """Get the checklist hotkey."""
|
---|
| 691 | return self._checklistHotkey
|
---|
| 692 |
|
---|
| 693 | @checklistHotkey.setter
|
---|
| 694 | def checklistHotkey(self, checklistHotkey):
|
---|
| 695 | """Set the checklist hotkey."""
|
---|
| 696 | if checklistHotkey!=self._checklistHotkey:
|
---|
| 697 | self._checklistHotkey = checklistHotkey
|
---|
| 698 | self._modified = True
|
---|
| 699 |
|
---|
| 700 | @property
|
---|
[40] | 701 | def autoUpdate(self):
|
---|
| 702 | """Get if an automatic update is needed."""
|
---|
| 703 | return self._autoUpdate
|
---|
| 704 |
|
---|
| 705 | @autoUpdate.setter
|
---|
| 706 | def autoUpdate(self, autoUpdate):
|
---|
| 707 | """Set if an automatic update is needed."""
|
---|
| 708 | if autoUpdate!=self._autoUpdate:
|
---|
| 709 | self._autoUpdate = autoUpdate
|
---|
| 710 | self._modified = True
|
---|
| 711 |
|
---|
| 712 | @property
|
---|
| 713 | def updateURL(self):
|
---|
| 714 | """Get the update URL."""
|
---|
| 715 | return self._updateURL
|
---|
| 716 |
|
---|
| 717 | @updateURL.setter
|
---|
| 718 | def updateURL(self, updateURL):
|
---|
| 719 | """Set the update URL."""
|
---|
| 720 | if updateURL!=self._updateURL:
|
---|
| 721 | self._updateURL = updateURL
|
---|
| 722 | self._modified = True
|
---|
| 723 |
|
---|
[1067] | 724 | @property
|
---|
| 725 | def xplaneRemote(self):
|
---|
| 726 | """Indicate if X-Plane should be accessed remotely."""
|
---|
| 727 | return self._xplaneRemote
|
---|
| 728 |
|
---|
| 729 | @xplaneRemote.setter
|
---|
| 730 | def xplaneRemote(self, xplaneRemote):
|
---|
| 731 | """Set if X-Plane should be accessed remotely."""
|
---|
| 732 | if xplaneRemote!=self._xplaneRemote:
|
---|
| 733 | self._xplaneRemote = xplaneRemote
|
---|
| 734 | self._modified = True
|
---|
| 735 |
|
---|
| 736 | @property
|
---|
| 737 | def xplaneAddress(self):
|
---|
| 738 | """Get the address of the machine running X-Plane"""
|
---|
| 739 | return self._xplaneAddress
|
---|
| 740 |
|
---|
| 741 | @xplaneAddress.setter
|
---|
| 742 | def xplaneAddress(self, xplaneAddress):
|
---|
| 743 | """Set the address of the machine running X-Plane."""
|
---|
| 744 | if xplaneAddress!=self._xplaneAddress:
|
---|
| 745 | self._xplaneAddress = xplaneAddress
|
---|
| 746 | self._modified = True
|
---|
| 747 |
|
---|
[175] | 748 | def getChecklist(self, aircraftType):
|
---|
| 749 | """Get the checklist for the given aircraft type."""
|
---|
| 750 | return self._checklists[aircraftType]
|
---|
| 751 |
|
---|
| 752 | def setChecklist(self, aircraftType, checklist):
|
---|
| 753 | """Set the checklist for the given aircraft type."""
|
---|
| 754 | if checklist!=self._checklists[aircraftType]:
|
---|
| 755 | self._checklists[aircraftType] = checklist.clone()
|
---|
| 756 | self._modified = True
|
---|
| 757 |
|
---|
[264] | 758 | def getApproachCallouts(self, aircraftType):
|
---|
| 759 | """Get the approach callouts for the given aircraft type."""
|
---|
| 760 | return self._approachCallouts[aircraftType]
|
---|
| 761 |
|
---|
| 762 | def setApproachCallouts(self, aircraftType, approachCallouts):
|
---|
| 763 | """Set the approach callouts for the given aircraft type."""
|
---|
| 764 | if not approachCallouts==self._approachCallouts[aircraftType]:
|
---|
| 765 | self._approachCallouts[aircraftType] = approachCallouts.clone()
|
---|
| 766 | self._modified = True
|
---|
| 767 |
|
---|
[40] | 768 | def load(self):
|
---|
| 769 | """Load the configuration from its default location."""
|
---|
[373] | 770 | try:
|
---|
[919] | 771 | config = configparser.RawConfigParser()
|
---|
[373] | 772 | config.read(configPath)
|
---|
| 773 | except:
|
---|
| 774 | traceback.print_exc()
|
---|
| 775 | return
|
---|
[40] | 776 |
|
---|
[42] | 777 | self._pilotID = self._get(config, "login", "id", "")
|
---|
| 778 | self._password = self._get(config, "login", "password", "")
|
---|
[45] | 779 | self._rememberPassword = self._getBoolean(config, "login",
|
---|
| 780 | "rememberPassword", False)
|
---|
[42] | 781 |
|
---|
[1097] | 782 | self._clearBrowserCacheOnStart = \
|
---|
| 783 | self._getBoolean(config, "general",
|
---|
| 784 | "clearBrowseCacheOnStart", False)
|
---|
| 785 |
|
---|
[132] | 786 | self._language = self._get(config, "general", "language", "")
|
---|
[249] | 787 |
|
---|
[1098] | 788 | self._mainWindowResizable = self._getBoolean(config, "general",
|
---|
| 789 | "mainWindowResizable",
|
---|
| 790 | False)
|
---|
[147] | 791 | self._hideMinimizedWindow = self._getBoolean(config, "general",
|
---|
| 792 | "hideMinimizedWindow",
|
---|
| 793 | True)
|
---|
[249] | 794 | self._quitOnClose = self._getBoolean(config, "general",
|
---|
| 795 | "quitOnClose", False)
|
---|
[373] | 796 |
|
---|
[136] | 797 | self._onlineGateSystem = self._getBoolean(config, "general",
|
---|
| 798 | "onlineGateSystem",
|
---|
[373] | 799 | not secondaryInstallation)
|
---|
[139] | 800 | self._onlineACARS = self._getBoolean(config, "general",
|
---|
[373] | 801 | "onlineACARS",
|
---|
| 802 | not secondaryInstallation)
|
---|
[132] | 803 | self._flareTimeFromFS = self._getBoolean(config, "general",
|
---|
| 804 | "flareTimeFromFS",
|
---|
| 805 | False)
|
---|
[148] | 806 | self._syncFSTime = self._getBoolean(config, "general",
|
---|
| 807 | "syncFSTime",
|
---|
| 808 | False)
|
---|
[183] | 809 | self._usingFS2Crew = self._getBoolean(config, "general",
|
---|
| 810 | "usingFS2Crew",
|
---|
| 811 | False)
|
---|
[197] | 812 | self._iasSmoothingLength = int(self._get(config, "general",
|
---|
| 813 | "iasSmoothingLength",
|
---|
| 814 | -2))
|
---|
| 815 | self._vsSmoothingLength = int(self._get(config, "general",
|
---|
| 816 | "vsSmoothingLength",
|
---|
| 817 | -2))
|
---|
[684] | 818 |
|
---|
[688] | 819 | self._useSimBrief = self._getBoolean(config, "simbrief",
|
---|
| 820 | "use", False)
|
---|
[1084] | 821 | self._useInternalBrowserForSimBrief = self._getBoolean(config, "simbrief",
|
---|
| 822 | "useInternalBrowser",
|
---|
| 823 | False)
|
---|
[689] | 824 | self._simBriefUserName = self._get(config, "simbrief",
|
---|
| 825 | "username", "")
|
---|
| 826 | self._simBriefPassword = self._get(config, "simbrief",
|
---|
| 827 | "password", "")
|
---|
| 828 | self._rememberSimBriefPassword = self._getBoolean(config, "simbrief",
|
---|
| 829 | "rememberPassword",
|
---|
| 830 | False)
|
---|
[684] | 831 |
|
---|
[149] | 832 | self._pirepDirectory = self._get(config, "general",
|
---|
| 833 | "pirepDirectory", None)
|
---|
[132] | 834 |
|
---|
[485] | 835 | self._pirepAutoSave = self._getBoolean(config, "general",
|
---|
| 836 | "pirepAutoSave", False)
|
---|
[486] | 837 | if self._pirepDirectory is None:
|
---|
| 838 | self._pirepAutoSave = False
|
---|
[392] | 839 |
|
---|
[132] | 840 | self._messageTypeLevels = {}
|
---|
| 841 | for messageType in const.messageTypes:
|
---|
| 842 | self._messageTypeLevels[messageType] = \
|
---|
| 843 | self._getMessageTypeLevel(config, messageType)
|
---|
[166] | 844 |
|
---|
[373] | 845 | self._enableSounds = self._getBoolean(config, "sounds", "enable",
|
---|
| 846 | not secondaryInstallation)
|
---|
[166] | 847 | self._pilotControlsSounds = self._getBoolean(config, "sounds",
|
---|
| 848 | "pilotControls", True)
|
---|
| 849 | self._pilotHotkey.set(self._get(config, "sounds",
|
---|
| 850 | "pilotHotkey", "C0"))
|
---|
[1094] | 851 |
|
---|
| 852 | self._taxiSoundOnPushback = \
|
---|
| 853 | self._getBoolean(config, "sounds", "taxiSoundOnPushback", False)
|
---|
[270] | 854 | self._enableApproachCallouts = \
|
---|
| 855 | self._getBoolean(config, "sounds", "enableApproachCallouts", False)
|
---|
[166] | 856 | self._speedbrakeAtTD = self._getBoolean(config, "sounds",
|
---|
| 857 | "speedbrakeAtTD", True)
|
---|
| 858 |
|
---|
| 859 | self._enableChecklists = self._getBoolean(config, "sounds",
|
---|
| 860 | "enableChecklists", False)
|
---|
| 861 | self._checklistHotkey.set(self._get(config, "sounds",
|
---|
| 862 | "checklistHotkey", "CS0"))
|
---|
[373] | 863 |
|
---|
[40] | 864 | self._autoUpdate = self._getBoolean(config, "update", "auto", True)
|
---|
[1080] | 865 | self._updateURL = self._get(config, "update", "url",
|
---|
| 866 | Config.DEFAULT_UPDATE_URL)
|
---|
[1011] | 867 |
|
---|
[175] | 868 | for aircraftType in const.aircraftTypes:
|
---|
| 869 | self._checklists[aircraftType] = \
|
---|
| 870 | Checklist.fromConfig(config, aircraftType)
|
---|
[264] | 871 | self._approachCallouts[aircraftType] = \
|
---|
| 872 | ApproachCallouts.fromConfig(config, aircraftType)
|
---|
[175] | 873 |
|
---|
[503] | 874 | self._defaultMSFS = self._getBoolean(config, "general",
|
---|
| 875 | "defaultMSFS", os.name=="nt")
|
---|
| 876 |
|
---|
[1067] | 877 | self._xplaneRemote = self._getBoolean(config, "general",
|
---|
| 878 | "xplaneRemote", False)
|
---|
| 879 | self._xplaneAddress = self._get(config, "general",
|
---|
| 880 | "xplaneAddress", "")
|
---|
| 881 |
|
---|
[40] | 882 | self._modified = False
|
---|
| 883 |
|
---|
| 884 | def save(self):
|
---|
| 885 | """Save the configuration file if it has been modified."""
|
---|
| 886 | if not self._modified:
|
---|
| 887 | return
|
---|
| 888 |
|
---|
[919] | 889 | config = configparser.RawConfigParser()
|
---|
[40] | 890 |
|
---|
[42] | 891 | config.add_section("login")
|
---|
| 892 | config.set("login", "id", self._pilotID)
|
---|
| 893 | config.set("login", "password", self._password)
|
---|
[45] | 894 | config.set("login", "rememberPassword",
|
---|
| 895 | "yes" if self._rememberPassword else "no")
|
---|
[42] | 896 |
|
---|
[132] | 897 | config.add_section("general")
|
---|
[1097] | 898 | config.set("general", "clearBrowseCacheOnStart",
|
---|
| 899 | "yes" if self._clearBrowserCacheOnStart else "no")
|
---|
[132] | 900 | if self._language:
|
---|
| 901 | config.set("general", "language", self._language)
|
---|
[1098] | 902 | config.set("general", "mainWindowResizable",
|
---|
| 903 | "yes" if self._mainWindowResizable else "no")
|
---|
[147] | 904 | config.set("general", "hideMinimizedWindow",
|
---|
| 905 | "yes" if self._hideMinimizedWindow else "no")
|
---|
[249] | 906 | config.set("general", "quitOnClose",
|
---|
| 907 | "yes" if self._quitOnClose else "no")
|
---|
[136] | 908 | config.set("general", "onlineGateSystem",
|
---|
| 909 | "yes" if self._onlineGateSystem else "no")
|
---|
[139] | 910 | config.set("general", "onlineACARS",
|
---|
| 911 | "yes" if self._onlineACARS else "no")
|
---|
[132] | 912 | config.set("general", "flareTimeFromFS",
|
---|
| 913 | "yes" if self._flareTimeFromFS else "no")
|
---|
[148] | 914 | config.set("general", "syncFSTime",
|
---|
| 915 | "yes" if self._syncFSTime else "no")
|
---|
[183] | 916 | config.set("general", "usingFS2Crew",
|
---|
| 917 | "yes" if self._usingFS2Crew else "no")
|
---|
[197] | 918 | config.set("general", "iasSmoothingLength",
|
---|
| 919 | str(self._iasSmoothingLength))
|
---|
| 920 | config.set("general", "vsSmoothingLength",
|
---|
| 921 | str(self._vsSmoothingLength))
|
---|
[132] | 922 |
|
---|
[688] | 923 | config.add_section("simbrief")
|
---|
| 924 | config.set("simbrief", "use",
|
---|
[684] | 925 | "yes" if self._useSimBrief else "no")
|
---|
[1084] | 926 | config.set("simbrief", "useInternalBrowser",
|
---|
| 927 | "yes" if self._useInternalBrowserForSimBrief else "no")
|
---|
[689] | 928 | config.set("simbrief", "username", self._simBriefUserName)
|
---|
| 929 | config.set("simbrief", "password", self._simBriefPassword)
|
---|
| 930 | config.set("simbrief", "rememberPassword",
|
---|
| 931 | "yes" if self._rememberSimBriefPassword else "no")
|
---|
[684] | 932 |
|
---|
[149] | 933 | if self._pirepDirectory is not None:
|
---|
| 934 | config.set("general", "pirepDirectory", self._pirepDirectory)
|
---|
[392] | 935 | config.set("general", "pirepAutoSave",
|
---|
| 936 | "yes" if self._pirepAutoSave else "no")
|
---|
[149] | 937 |
|
---|
[503] | 938 | config.set("general", "defaultMSFS",
|
---|
| 939 | "yes" if self._defaultMSFS else "no")
|
---|
| 940 |
|
---|
[1067] | 941 | config.set("general", "xplaneRemote",
|
---|
| 942 | "yes" if self._xplaneRemote else "no")
|
---|
| 943 | config.set("general", "xplaneAddress", self._xplaneAddress)
|
---|
| 944 |
|
---|
[132] | 945 | config.add_section(Config._messageTypesSection)
|
---|
| 946 | for messageType in const.messageTypes:
|
---|
| 947 | if messageType in self._messageTypeLevels:
|
---|
| 948 | option = self._getMessageTypeLevelOptionName(messageType)
|
---|
[373] | 949 | level = self._messageTypeLevels[messageType]
|
---|
[132] | 950 | config.set(Config._messageTypesSection, option,
|
---|
| 951 | const.messageLevel2string(level))
|
---|
[166] | 952 |
|
---|
| 953 | config.add_section("sounds")
|
---|
| 954 | config.set("sounds", "enable",
|
---|
| 955 | "yes" if self._enableSounds else "no")
|
---|
| 956 | config.set("sounds", "pilotControls",
|
---|
| 957 | "yes" if self._pilotControlsSounds else "no")
|
---|
| 958 | config.set("sounds", "pilotHotkey", str(self._pilotHotkey))
|
---|
[1094] | 959 | config.set("sounds", "taxiSoundOnPushback",
|
---|
| 960 | "yes" if self._taxiSoundOnPushback else "no")
|
---|
[270] | 961 | config.set("sounds", "enableApproachCallouts",
|
---|
| 962 | "yes" if self._enableApproachCallouts else "no")
|
---|
[166] | 963 | config.set("sounds", "speedbrakeAtTD",
|
---|
| 964 | "yes" if self._speedbrakeAtTD else "no")
|
---|
| 965 |
|
---|
| 966 | config.set("sounds", "enableChecklists",
|
---|
| 967 | "yes" if self._enableChecklists else "no")
|
---|
| 968 | config.set("sounds", "checklistHotkey",
|
---|
| 969 | str(self._checklistHotkey))
|
---|
[373] | 970 |
|
---|
[40] | 971 | config.add_section("update")
|
---|
[45] | 972 | config.set("update", "auto",
|
---|
| 973 | "yes" if self._autoUpdate else "no")
|
---|
[40] | 974 | config.set("update", "url", self._updateURL)
|
---|
| 975 |
|
---|
[175] | 976 | config.add_section(Checklist.SECTION)
|
---|
[264] | 977 | config.add_section(ApproachCallouts.SECTION)
|
---|
[175] | 978 | for aircraftType in const.aircraftTypes:
|
---|
| 979 | self._checklists[aircraftType].toConfig(config, aircraftType)
|
---|
[264] | 980 | self._approachCallouts[aircraftType].toConfig(config, aircraftType)
|
---|
[175] | 981 |
|
---|
[40] | 982 | try:
|
---|
[43] | 983 | fd = os.open(configPath, os.O_CREAT|os.O_TRUNC|os.O_WRONLY,
|
---|
[919] | 984 | 0o600)
|
---|
[43] | 985 | with os.fdopen(fd, "wt") as f:
|
---|
[40] | 986 | config.write(f)
|
---|
| 987 | self._modified = False
|
---|
[402] | 988 |
|
---|
[919] | 989 | print("Configuration saved:")
|
---|
[402] | 990 | self.log()
|
---|
| 991 |
|
---|
[919] | 992 | except Exception as e:
|
---|
| 993 | print("Failed to update config: " + \
|
---|
| 994 | utf2unicode(str(e)), file=sys.stderr)
|
---|
[40] | 995 |
|
---|
| 996 | def _getBoolean(self, config, section, option, default):
|
---|
| 997 | """Get the given option as a boolean, if found in the given config,
|
---|
| 998 | otherwise the default."""
|
---|
| 999 | return config.getboolean(section, option) \
|
---|
| 1000 | if config.has_option(section, option) \
|
---|
| 1001 | else default
|
---|
[373] | 1002 |
|
---|
[40] | 1003 | def _get(self, config, section, option, default):
|
---|
| 1004 | """Get the given option as a string, if found in the given config,
|
---|
| 1005 | otherwise the default."""
|
---|
| 1006 | return config.get(section, option) \
|
---|
| 1007 | if config.has_option(section, option) \
|
---|
| 1008 | else default
|
---|
[36] | 1009 |
|
---|
[132] | 1010 | def _getMessageTypeLevel(self, config, messageType):
|
---|
| 1011 | """Get the message type level for the given message type."""
|
---|
| 1012 | option = self._getMessageTypeLevelOptionName(messageType)
|
---|
| 1013 | if config.has_option(Config._messageTypesSection, option):
|
---|
| 1014 | value = config.get(Config._messageTypesSection, option)
|
---|
| 1015 | return const.string2messageLevel(value)
|
---|
[373] | 1016 | elif secondaryInstallation:
|
---|
| 1017 | return const.MESSAGELEVEL_NONE
|
---|
[133] | 1018 | elif messageType in [const.MESSAGETYPE_LOGGER_ERROR,
|
---|
| 1019 | const.MESSAGETYPE_FAULT,
|
---|
| 1020 | const.MESSAGETYPE_NOGO,
|
---|
| 1021 | const.MESSAGETYPE_GATE_SYSTEM,
|
---|
[373] | 1022 | const.MESSAGETYPE_HELP]:
|
---|
[133] | 1023 | return const.MESSAGELEVEL_BOTH
|
---|
[132] | 1024 | else:
|
---|
[133] | 1025 | return const.MESSAGELEVEL_FS
|
---|
[132] | 1026 |
|
---|
| 1027 | def _getMessageTypeLevelOptionName(self, messageType):
|
---|
| 1028 | """Get the option name for the given message type level."""
|
---|
| 1029 | return const.messageType2string(messageType)
|
---|
[155] | 1030 |
|
---|
| 1031 | def setupLocale(self):
|
---|
| 1032 | """Setup the locale based on the language set.
|
---|
| 1033 |
|
---|
| 1034 | Return True if a specific language was set, False otherwise."""
|
---|
| 1035 | import locale
|
---|
| 1036 | if self._language:
|
---|
[919] | 1037 | print("Setting up locale for", self._language)
|
---|
[155] | 1038 | os.environ["LANGUAGE"] = self._language
|
---|
| 1039 | langAndEncoding = self._language + "." + locale.getpreferredencoding()
|
---|
| 1040 | os.environ["LANG"] = langAndEncoding
|
---|
| 1041 | os.environ["LC_MESSAGES"] = langAndEncoding
|
---|
| 1042 | os.environ["LC_COLLATE"] = langAndEncoding
|
---|
| 1043 | os.environ["LC_CTYPE"] = langAndEncoding
|
---|
[156] | 1044 | os.environ["LC_MONETARY"] = langAndEncoding
|
---|
| 1045 | os.environ["LC_NUMERIC"] = langAndEncoding
|
---|
| 1046 | os.environ["LC_TIME"] = langAndEncoding
|
---|
[155] | 1047 | return True
|
---|
| 1048 | else:
|
---|
| 1049 | return False
|
---|
| 1050 |
|
---|
[107] | 1051 | def getLanguage(self):
|
---|
| 1052 | """Get the language to be used."""
|
---|
[113] | 1053 | import locale
|
---|
[107] | 1054 | if self._language:
|
---|
[124] | 1055 | if os.name=="nt":
|
---|
| 1056 | if self._language in _languageMap:
|
---|
| 1057 | locale.setlocale(locale.LC_ALL, _languageMap[self._language])
|
---|
| 1058 | else:
|
---|
| 1059 | locale.setlocale(locale.LC_ALL, "")
|
---|
| 1060 | else:
|
---|
| 1061 | locale.setlocale(locale.LC_ALL, (self._language,
|
---|
| 1062 | locale.getpreferredencoding()))
|
---|
[107] | 1063 | return self._language
|
---|
| 1064 | else:
|
---|
[113] | 1065 | locale.setlocale(locale.LC_ALL, "")
|
---|
[107] | 1066 | return locale.getdefaultlocale()[0]
|
---|
| 1067 |
|
---|
[402] | 1068 | def log(self):
|
---|
| 1069 | """Log the configuration by printing the values"""
|
---|
[919] | 1070 | print(" pilot ID:", self._pilotID)
|
---|
| 1071 | print(" rememberPassword:", self._rememberPassword)
|
---|
[402] | 1072 |
|
---|
[1097] | 1073 | print(" clearBrowseCacheOnStart:", self._clearBrowserCacheOnStart)
|
---|
[919] | 1074 | print(" language:", self._language)
|
---|
[402] | 1075 |
|
---|
[1098] | 1076 | print(" mainWindowResizable:", self._mainWindowResizable)
|
---|
[919] | 1077 | print(" hideMinimizedWindow:", self._hideMinimizedWindow)
|
---|
| 1078 | print(" quitOnClose:", self._quitOnClose)
|
---|
[402] | 1079 |
|
---|
[919] | 1080 | print(" onlineGateSystem:", self._onlineGateSystem)
|
---|
| 1081 | print(" onlineACARS:", self._onlineACARS)
|
---|
[402] | 1082 |
|
---|
[919] | 1083 | print(" flareTimeFromFS:", self._flareTimeFromFS)
|
---|
| 1084 | print(" syncFSTime:", self._syncFSTime)
|
---|
| 1085 | print(" usingFS2Crew:", self._usingFS2Crew)
|
---|
[402] | 1086 |
|
---|
[919] | 1087 | print(" iasSmoothingLength:", self._iasSmoothingLength)
|
---|
| 1088 | print(" vsSmoothingLength:", self._vsSmoothingLength)
|
---|
[402] | 1089 |
|
---|
[919] | 1090 | print(" useSimBrief:", self._useSimBrief)
|
---|
[1084] | 1091 | print(" useInternalBrowserForSimBrief:", self._useInternalBrowserForSimBrief)
|
---|
[919] | 1092 | print(" simBriefUserName:", self._simBriefUserName)
|
---|
| 1093 | print(" rememberSimBriefPassword:", self._rememberSimBriefPassword)
|
---|
[684] | 1094 |
|
---|
[919] | 1095 | print(" pirepDirectory:", self._pirepDirectory)
|
---|
| 1096 | print(" pirepAutoSave:", self._pirepAutoSave)
|
---|
[402] | 1097 |
|
---|
[919] | 1098 | print(" defaultMSFS:", self._defaultMSFS)
|
---|
[1067] | 1099 | print(" xplaneRemote:", self._xplaneRemote)
|
---|
| 1100 | print(" xplaneAddress:", self._xplaneAddress)
|
---|
[503] | 1101 |
|
---|
[919] | 1102 | print(" enableSounds:", self._enableSounds)
|
---|
[402] | 1103 |
|
---|
[919] | 1104 | print(" pilotControlsSounds:", self._pilotControlsSounds)
|
---|
| 1105 | print(" pilotHotkey:", str(self._pilotHotkey))
|
---|
[402] | 1106 |
|
---|
[1094] | 1107 | print(" taxiSoundOnPushback:", self._taxiSoundOnPushback)
|
---|
| 1108 |
|
---|
[919] | 1109 | print(" enableApproachCallouts:", self._enableApproachCallouts)
|
---|
| 1110 | print(" speedbrakeAtTD:", self._speedbrakeAtTD)
|
---|
[402] | 1111 |
|
---|
[919] | 1112 | print(" enableChecklists:", self._enableChecklists)
|
---|
| 1113 | print(" checklistHotkey:", str(self._checklistHotkey))
|
---|
[402] | 1114 |
|
---|
[919] | 1115 | print(" autoUpdate:", self._autoUpdate)
|
---|
| 1116 | print(" updateURL:", self._updateURL)
|
---|
[402] | 1117 |
|
---|
[919] | 1118 | print(" messageTypeLevels:")
|
---|
| 1119 | for (type, level) in self._messageTypeLevels.items():
|
---|
| 1120 | print(" %s: %s" % (const.messageType2string(type),
|
---|
| 1121 | const.messageLevel2string(level)))
|
---|
[402] | 1122 |
|
---|
[919] | 1123 | print(" checklists:")
|
---|
| 1124 | for (type, checklist) in self._checklists.items():
|
---|
| 1125 | print(" %s:" % (const.icaoCodes[type],))
|
---|
[402] | 1126 | for path in checklist:
|
---|
[919] | 1127 | print(" " + path)
|
---|
[402] | 1128 |
|
---|
[919] | 1129 | print(" approachCallouts:")
|
---|
| 1130 | for (type, approachCallouts) in self._approachCallouts.items():
|
---|
| 1131 | print(" %s:" % (const.icaoCodes[type],))
|
---|
[402] | 1132 | for (altitude, path) in approachCallouts:
|
---|
[919] | 1133 | print(" %d: %s" % (altitude, path))
|
---|
[402] | 1134 |
|
---|
[36] | 1135 | #-------------------------------------------------------------------------------
|
---|