def changeFplOnlineStatus(self, new_status): t = now() if new_status == FPL.OPEN: text = 'Do you want also to update departure time with the current date & time below?\n%s, %s' % ( datestr(t), timestr(t)) text += '\n\nWARNING: Answering "yes" or "no" will open the flight plan online.' button = QMessageBox.question( self, 'Open FPL', text, buttons=(QMessageBox.Cancel | QMessageBox.No | QMessageBox.Yes)) if button == QMessageBox.Yes: self.depTime_edit.setDateTime( QDateTime(t.year, t.month, t.day, t.hour, t.minute)) ok = button != QMessageBox.Cancel elif new_status == FPL.CLOSED: ok = yesNo_question(self, 'Close FPL', 'Time is %s.' % timestr(t), 'This will close the flight plan online. OK?') if ok: try: settings.session_manager.changeFplStatus(self.fpl, new_status) except FplError as err: QMessageBox.critical(self, 'FPL open/close error', str(err)) self.updateOnlineStatusBox()
def savePreset(self): icao_pair = self.data_DEP.code, self.data_ARR.code route_txt = ' '.join(self.getRouteText().split()) got_routes = settings.route_presets.get(icao_pair, []) if route_txt == '' or route_txt in got_routes: QMessageBox.critical(self, 'Route preset rejected', 'This route entry is already saved!') return msg = 'Saving a route preset between %s and %s.' % icao_pair if got_routes != []: msg += '\n(%d route%s already saved for these end airports)' % ( len(got_routes), ('s' if len(got_routes) != 1 else '')) if yesNo_question(self, 'Saving route preset', msg, 'Confirm?'): try: settings.route_presets[icao_pair].append(route_txt) except KeyError: settings.route_presets[icao_pair] = [route_txt] self.recall_button.setEnabled(True) try: with open(route_presets_file, mode='a', encoding='utf8') as f: f.write('\n# Saved on %s at %s UTC:\n' % (datestr(), timestr())) f.write( '%s %s\t%s\n\n' % (self.data_DEP.code, self.data_ARR.code, route_txt)) QMessageBox.information( self, 'Route preset saved', 'Check file %s to remove or edit.' % route_presets_file) except OSError: QMessageBox.critical( self, 'Error', 'There was an error writing to "%s".\nYour preset will be lost at the end of the session.' )
def setTimer(self): timeout, ok = QInputDialog.getInt(self, \ 'Alarm clock %s' % self.name, 'Timeout in minutes:', value=self.prev_timeout, min=1, max=60) if ok: self.setToolTip('Timer %s started at %s for %d min' % (self.name, timestr(seconds=True), timeout)) self.timer.start(timeout * 60 * 1000) self.prev_timeout = timeout self.setChecked(True) elif not self.timerIsRunning(): self.resetButton()
def text_alias_replacement(text_alias, current_selection): alias = text_alias.lower() weather = env.primaryWeather() ## Check for general alias if alias == 'ad': noNone(env.airport_data) return env.locationName() elif alias == 'atis': return noNone(settings.last_ATIS_recorded) elif alias == 'decl': return noNone(env.readDeclination()) elif alias == 'elev': return '%d ft' % noNone(env.airport_data).field_elevation elif alias == 'frq': return str(noNone(settings.publicised_frequency)) elif alias == 'icao': return settings.location_code elif alias == 'me': return settings.session_manager.myCallsign() elif alias == 'metar': return noNone(weather).METAR() elif alias == 'qfe': noNone(env.airport_data) return '%d' % env.QFE(noNone(env.QNH(noneSafe=False))) elif alias == 'qnh': return '%d' % noNone(env.QNH(noneSafe=False)) elif alias == 'qnhg': return '%.2f' % (hPa2inHg * noNone(env.QNH(noneSafe=False))) elif alias == 'runways': noNone(env.airport_data) return env.readRunwaysInUse() elif alias == 'rwyarr': rwys = [ rwy.name for rwy in noNone(env.airport_data).allRunways() if rwy.use_for_arrivals ] if rwys == []: raise ValueError('No RWY marked for arrival') return ', '.join(rwys) elif alias == 'rwydep': rwys = [ rwy.name for rwy in noNone(env.airport_data).allRunways() if rwy.use_for_departures ] if rwys == []: raise ValueError('No RWY marked for departure') return ', '.join(rwys) elif alias == 'ta': return '%d ft' % env.transitionAltitude() elif alias == 'tl': noNone(env.QNH(noneSafe=False)) return 'FL%03d' % env.transitionLevel() elif alias == 'utc': return timestr() elif alias == 'vis': return noNone(weather).readVisibility() elif alias == 'wind': return noNone(weather).readWind() else: # Check for selection-dependant alias strip = current_selection.strip acft = current_selection.acft if alias == 'cralt': return noNone(noNone(strip).lookup(FPL.CRUISE_ALT, fpl=True)) elif alias == 'dest': return noNone(noNone(strip).lookup(FPL.ICAO_ARR, fpl=True)) elif alias == 'dist': coords = noNone(acft).coords() return dist_str( noNone( env.airport_data).navpoint.coordinates.distanceTo(coords)) elif alias == 'nseq': return str(env.strips.stripSequenceNumber(noNone( strip))) # rightly fails with ValueError if strip is loose elif alias == 'qdm': coords = noNone(acft).coords() return coords.headingTo( noNone(env.airport_data).navpoint.coordinates).read() elif alias == 'rack': return noNone(noNone(strip).lookup(rack_detail)) elif alias == 'route': return noNone(noNone(strip).lookup(FPL.ROUTE, fpl=True)) elif alias == 'rwy': box = noNone(noNone(strip).lookup(runway_box_detail)) return env.airport_data.physicalRunwayNameFromUse( box) # code unreachable if env.airport_data == None elif alias == 'sq': sq = noNone(strip).lookup(assigned_SQ_detail) return '%04o' % noNone(sq) elif alias == 'valt': valt = noNone(strip).lookup(assigned_altitude_detail) return noNone(valt) # valt is a "reading" elif alias == 'vhdg': vhdg = noNone(strip).lookup(assigned_heading_detail) return noNone(vhdg).read() elif alias == 'vspd': vspd = noNone(strip).lookup(assigned_speed_detail) return str(noNone(vspd)) elif alias == 'wpnext': coords = noNone(acft).coords() route = noNone(strip).lookup(parsed_route_detail) return str(noNone(route).currentWaypoint(coords)) elif alias == 'wpsid': route = noNone(strip).lookup(parsed_route_detail) return noNone(noNone(route).SID()) elif alias == 'wpstar': route = noNone(strip).lookup(parsed_route_detail) return noNone(noNone(route).STAR()) else: ## Check for custom alias, in order: general notes, location-specific notes, selected strip comments try: return custom_alias_search(alias, settings.general_notes) except ValueError: try: return custom_alias_search(alias, settings.local_notes) except ValueError: comments = noNone(noNone(strip).lookup(FPL.COMMENTS)) return custom_alias_search(alias, comments)
def newRequest(self, acft_callsign): self.model().setStringList([]) self.setWindowTitle('Claiming %s at %s (%s)' % (acft_callsign, timestr(seconds=True), datestr())) self.last_whohas_request = acft_callsign.upper()
def updateClock(self): self.clock_statusBarLabel.setText('UTC ' + timestr(seconds=True))
def suggestedATIS(self, letter, custom_appendix): if self.airport_data == None: return '' atis = 'This is %s information %s recorded at %s UTC' \ % ((settings.location_radio_name if settings.location_radio_name else self.locationName()), letter, timestr()) if any(rwy.use_for_departures or rwy.use_for_arrivals for rwy in env.airport_data.allRunways()): atis += '\nRunway(s) in use: %s' % self.readRunwaysInUse() w = self.primaryWeather() if w == None: atis += '\nNo weather available' else: atis += '\nWind %s' % w.readWind() atis += '\nVisibility %s' % w.readVisibility() temperatures = w.temperatures() if temperatures != None: atis += '\nTemp. %d °C, dew point %d °C' % temperatures qnh = w.QNH() atis += '\nQNH N/A' if qnh == None else '\nQNH %d, QFE %d' % ( qnh, self.QFE(qnh)) if custom_appendix: atis += '\n\n' + custom_appendix atis += '\n\nAdvise %s on initial contact that you have received information %s' \ % ((settings.location_radio_name if settings.location_radio_name else 'ATC'), letter) return atis