def prefs_changed(cmdr, is_beta): this.distances = list() for settingsUiElement in this.settingsUiElements: systemText = settingsUiElement.systemEntry.get() xText = settingsUiElement.xEntry.get() yText = settingsUiElement.yEntry.get() zText = settingsUiElement.zEntry.get() if systemText and xText and yText and zText: try: d = dict() d["system"] = systemText.strip() d["x"] = Locale.numberFromString(xText.strip()) d["y"] = Locale.numberFromString(yText.strip()) d["z"] = Locale.numberFromString(zText.strip()) this.distances.append(d) except Exception as e: # error while parsing the numbers print(e) sys.stderr.write( "DistanceCalc: Error while parsing the coordinates for {0}" .format(systemText.strip())) continue config.set("DistanceCalc", json.dumps(this.distances)) settings = this.travelledTotalOption.get() | ( this.travelledSessionOption.get() << 1) | ( this.travelledSessionSelected.get() << 2) config.set("DistanceCalc_options", settings) updateMainUi() updateDistances()
def prefs_changed(): this.distances = list() for (system, x, y, z) in this.settingUiEntries: systemText = system.get() xText = x.get() yText = y.get() zText = z.get() if systemText and xText and yText and zText: try: d = dict() d["system"] = systemText.strip() d["x"] = Locale.numberFromString(xText.strip()) d["y"] = Locale.numberFromString(yText.strip()) d["z"] = Locale.numberFromString(zText.strip()) this.distances.append(d) except: # error while parsing the numbers sys.stderr.write( "DistanceCalc: Error while parsing the coordinates for {0}" .format(systemText.strip())) continue config.set("DistanceCalc", json.dumps(this.distances)) settings = this.travelledTotalOption.get() | ( this.travelledSessionOption.get() << 1) | ( this.travelledSessionSelected.get() << 2) config.set("DistanceCalc_options", settings) updateUi() updateDistances()
def journal_entry(cmdr, is_beta, system, station, entry, state): if this.system != system: this.system = system write_file('EDMC System.txt', this.system) if 'StarPos' in entry and this.starpos != tuple(entry['StarPos']): this.starpos = tuple(entry['StarPos']) write_file( 'EDMC StarPos.txt', '%s %s %s' % (Locale.stringFromNumber(this.starpos[0], 5), Locale.stringFromNumber(this.starpos[1], 5), Locale.stringFromNumber(this.starpos[2], 5))) if this.station != station: this.station = station write_file('EDMC Station.txt', this.station) if entry['event'] in [ 'FSDJump', 'LeaveBody', 'Location', 'SupercruiseEntry', 'SupercruiseExit' ] and entry.get('BodyType') in [None, 'Station']: if this.body: this.body = None write_file('EDMC Body.txt') elif 'Body' in entry: # StartUp, ApproachBody, Location, SupercruiseExit if this.body != entry['Body']: this.body = entry['Body'] write_file('EDMC Body.txt', this.body) elif entry['event'] == 'StartUp': this.body = None write_file('EDMC Body.txt') if this.stationorbody != (this.station or this.body): this.stationorbody = (this.station or this.body) write_file('EDMC Station or Body.txt', this.stationorbody) if this.stationorbodyorsystem != (this.station or this.body or this.system): this.stationorbodyorsystem = (this.station or this.body or this.system) write_file('EDMC Station or Body or System.txt', this.stationorbodyorsystem) if this.shiptype != state['ShipType']: this.shiptype = state['ShipType'] write_file('EDMC ShipType.txt', ship_map.get(this.shiptype, this.shiptype)) if this.shipname != (state['ShipName'] or this.shiptype): this.shipname = (state['ShipName'] or this.shiptype) write_file( 'EDMC ShipName.txt', state['ShipName'] and state['ShipName'] or ship_map.get(this.shiptype, this.shiptype)) if this.shipident != state['ShipIdent']: this.shipident = state['ShipIdent'] write_file('EDMC ShipID.txt', ship_map.get(this.shipident, this.shipident))
def dashboard_entry(cmdr, is_beta, entry): if 'Latitude' in entry and 'Longitude' in entry: if this.latlon != (entry['Latitude'], entry['Longitude']): this.latlon = (entry['Latitude'], entry['Longitude']) write_file( 'EDMC LatLon.txt', '%s %s' % (Locale.stringFromNumber(this.latlon[0], 6), Locale.stringFromNumber(this.latlon[1], 6))) elif this.latlon: this.latlon = None write_file('EDMC LatLon.txt')
def update_jumpspeed_speed(self): """ Set the jump speed rate in the EDMC window """ msg = " {}".format(Locale.stringFromNumber(self.speed(), 2)) self.speed_widget["foreground"] = COLOR_NORM[self.appdesign] self.speed_widget.after(0, self.speed_widget.config, {"text": msg}) msgnow = " {} |".format(Locale.stringFromNumber(self.speednow(), 2)) self.speednow_widget["foreground"] = COLOR_NORM[self.appdesign] self.speednow_widget.after(0, self.speednow_widget.config, {"text": msgnow})
def updateCounts(): ''' Update displayed totals whenever the counts are updated ''' item,session, total = this.evacuatedLabels[1] session["text"] = "{0}".format(Locale.stringFromNumber(counts[0],0)) total["text"] = "{0}".format(Locale.stringFromNumber(totals[0],0)) for i in range(2,len(this.evacuatedLabels)): item,session, total = this.evacuatedLabels[i] if this.sarSettings[i-2] == 1: session["text"] = "{0}".format(Locale.stringFromNumber(counts[i-1],0)) total["text"] = "{0}".format(Locale.stringFromNumber(totals[i-1],0))
def update_transaction_rate(self): """ Set the transaction rate rate in the EDMC window """ msg = " {}".format(Locale.stringFromNumber(self.rate(), 2)) self.rate_widget["foreground"] = COLOR_NORM[self.appdesign] self.rate_widget.after(0, self.rate_widget.config, {"text": msg}) msgnow = " {} |".format(Locale.stringFromNumber(self.ratenow(), 2)) self.ratenow_widget["foreground"] = COLOR_NORM[self.appdesign] self.ratenow_widget.after(0, self.ratenow_widget.config, {"text": msgnow})
def updateUI(event=None): eliteSystem = this.lastEventInfo.get(BG_SYSTEM, None) message = this.lastEventInfo.get(BG_MESSAGE, None) if (this.enabled or this.overwrite.get()) and eliteSystem: this.errorLabel.grid_remove() this.unconfirmedSystem.grid(row=0, column=1, sticky=tk.W) this.unconfirmedSystem["text"] = eliteSystem.name this.unconfirmedSystem[ "url"] = "https://www.edsm.net/show-system?systemName={}".format( urllib2.quote(eliteSystem.name)) this.unconfirmedSystem["state"] = "enabled" distanceText = u"{distance} Ly".format( distance=Locale.stringFromNumber(eliteSystem.distance, 2)) if eliteSystem.uncertainty > 0: distanceText = distanceText + u" (\u00B1{uncertainty})".format( uncertainty=eliteSystem.uncertainty) this.distanceValue["text"] = distanceText this.actionText["text"] = eliteSystem.action_text if this.clipboard.get(): this.frame.clipboard_clear() this.frame.clipboard_append(eliteSystem.name) else: this.unconfirmedSystem.grid_remove() this.errorLabel.grid(row=0, column=1, sticky=tk.W) this.distanceValue["text"] = "?" this.actionText["text"] = "?" if not this.enabled and not this.overwrite.get(): this.errorLabel["text"] = "EDSM/EDDN is disabled" else: this.errorLabel["text"] = message or "?"
def update(self): if self.visible(): capi_update=self.patrol_list and self.system and self.capi_update journal_update=self.patrol_list and self.system if journal_update or capi_update: self.sort_patrol() p=Systems.edsmGetSystem(self.system) self.nearest=self.getNearest(p) self.hyperlink['text']=self.nearest.get("system") self.hyperlink['url']="https://www.edsm.net/en/system?systemName={}".format(quote_plus(self.nearest.get("system"))) self.distance['text']="{}ly".format(Locale.stringFromNumber(getDistance(p,self.nearest.get("coords")),2)) self.infolink['text']=self.nearest.get("instructions") self.infolink['url']=self.parseurl(self.nearest.get("url")) self.infolink.grid() self.distance.grid() self.prev.grid() self.next.grid() self.capi_update=False else: if self.system: self.hyperlink['text'] = "Fetching patrols..." else: self.hyperlink['text'] = "Waiting for location" self.infolink.grid_remove() self.distance.grid_remove() self.prev.grid_remove() self.next.grid_remove()
def update_earned(self): """ Set the transaction speed rate in the EDMC window :param msg: :return: """ msg = "{} Cr".format(Locale.stringFromNumber(self.trip_earnings() + self.saved_earnings, 2)) self.earned_widget.after(0, self.earned_widget.config, {"text": msg})
def write_all(): write_file('EDMC System.txt', this.system) write_file( 'EDMC StarPos.txt', '%s %s %s' % (Locale.stringFromNumber( this.starpos[0], 5), Locale.stringFromNumber(this.starpos[1], 5), Locale.stringFromNumber(this.starpos[2], 5))) write_file('EDMC Station.txt', this.station) write_file('EDMC Body.txt', this.body) write_file( 'EDMC LatLon.txt', '%s %s' % (Locale.stringFromNumber( this.latlon[0], 6), Locale.stringFromNumber(this.latlon[1], 6))) write_file('EDMC Station or Body.txt', this.stationorbody) write_file('EDMC Station or Body or System.txt', this.stationorbodyorsystem) write_file('EDMC ShipType.txt', this.shiptype) write_file('EDMC ShipName.txt', this.shipname)
def update_jumpspeed_speed(self): """ Set the jump speed rate in the EDMC window :param msg: :return: """ msg = "{} Ly/hr".format(Locale.stringFromNumber(self.speed(), 2)) self.speed_widget.after(0, self.speed_widget.config, {"text": msg})
def getBGSInstructions(self, bgs): target = 0.50 <= float(bgs.get("influence")) <= 0.65 over = float(bgs.get("influence")) > 0.65 under = float(bgs.get("influence")) < 0.50 if self.getStates("active_states", bgs): states = " States: {}".format(self.getStates("active_states", bgs)) else: states = "" # 2019-03-24T11:14:38.000Z d1 = datetime.strptime(bgs.get("updated_at"), '%Y-%m-%dT%H:%M:%S.%fZ') d2 = datetime.now() last_updated = (d2 - d1).days if last_updated == 0: update_text = "" elif last_updated == 1: update_text = ". Last updated 1 day ago" elif last_updated < 7: update_text = ". Last updated {} days ago".format(last_updated) elif last_updated > 6: update_text = ". Last updated {} days ago. Please jump into the system to update the stats".format( last_updated) # if self.getStates("pending_states",bgs): # pstates=" Pending: {}".format(self.getStates("pending_states",bgs)) # else: # pstates="" # debug(bgs) if target: retval = "Canonn Influence {}%{}{}".format( Locale.stringFromNumber(float(bgs.get("influence") * 100), 2), states, update_text) if over: retval = "Canonn Influence {}%{} Check #mission_minor_faction on discord for instructions.{}".format( Locale.stringFromNumber(float(bgs.get("influence") * 100), 2), states, update_text) if under: retval = "Canonn Influence {}%{} Please complete missions for Canonn to increase our influence{}".format( Locale.stringFromNumber(float(bgs.get("influence") * 100), 2), states, update_text) debug("{}: {}".format(bgs.get("system_name"), retval)) return retval
def update_jumpspeed_dist(self): """ Set the jump speed rate in the EDMC window :param msg: :return: """ msg = "{} Ly".format(Locale.stringFromNumber(self.trip_distance() + self.saved_distance, 2)) self.dist_widget.after(0, self.dist_widget.config, {"text": msg})
def update_transaction_rate(self): """ Set the transaction rate rate in the EDMC window :param msg: :return: """ msg = "{} Visits/hr".format(Locale.stringFromNumber(self.rate(), 2)) self.rate_widget.after(0, self.rate_widget.config, {"text": msg})
def update_hourlyincome(self): """ Set the transaction speed rate in the EDMC window :param msg: :return: """ msg = "{} Cr/hr".format(Locale.stringFromNumber(self.speed(), 2)) self.speed_widget.after(0, self.speed_widget.config, {"text": msg})
def journal_entry(cmdr, is_beta, system, station, entry, state): if entry['event'] == 'Scan': try: if not float(entry['DistanceFromArrivalLS']): # Only calculate for arrival star r = float(entry['Radius']) t = float(entry['SurfaceTemperature']) for i in range(len(WORLDS)): (name, high, low, subType) = WORLDS[i] (label, edsm, near, dash, far, ls) = this.worlds[i] far_dist = int(0.5 + dfort(r, t, low)) radius = int(0.5 + r / LS) if far_dist <= radius: near['text'] = '' dash['text'] = u'×' far['text'] = '' ls['text'] = '' else: if not high: near['text'] = Locale.stringFromNumber(radius) else: near['text'] = Locale.stringFromNumber(int(0.5 + dfort(r, t, high))) dash['text'] = '-' far['text'] = Locale.stringFromNumber(far_dist) ls['text'] = 'ls' except: for (label, edsm, near, dash, far, ls) in this.worlds: near['text'] = '' dash['text'] = '' far['text'] = '' ls['text'] = '?' elif entry['event'] == 'FSDJump': for (label, edsm, near, dash, far, ls) in this.worlds: edsm['text'] = '' edsm['url'] = '' near['text'] = '' dash['text'] = '' far['text'] = '' ls['text'] = '' if entry['event'] in ['Location', 'FSDJump'] and get_setting() & SETTING_EDSM: thread = threading.Thread(target = edsm_worker, name = 'EDSM worker', args = (entry['StarSystem'],)) thread.daemon = True thread.start()
def updateDistances(): if not this.coordinates: for (_, distance) in this.distanceLabels: distance["text"] = "? Ly" else: for i in range(len(this.distances)): system = this.distances[i] distance = calculateDistance(system["x"], system["y"], system["z"], *this.coordinates) this.distanceLabels[i][1]["text"] = "{0} Ly".format( Locale.stringFromNumber(distance, 2)) _, distance = this.travelledLabels[0] distance["text"] = "{0} Ly".format( Locale.stringFromNumber(this.distanceTotal, 2)) _, distance = this.travelledLabels[1] distance["text"] = "{0} Ly".format( Locale.stringFromNumber(this.distanceSession, 2))
def update_earned(self): """ Set the transaction sum in the EDMC window """ msg = " {}".format( Locale.stringFromNumber(self.trip_earnings() + self.saved_earnings, 0)) self.earned_widget["foreground"] = COLOR_NORM[self.appdesign] self.earned_widget.after(0, self.earned_widget.config, {"text": msg})
def fill_entries(system_name: str, x: Union[str, int, float], y: Union[str, int, float], z: Union[str, int, float], system_entry: nb.Entry, x_entry: nb.Entry, y_entry: nb.Entry, z_entry: nb.Entry): system_entry.insert(0, system_name) if type(x) == str: x_entry.insert(0, x) else: x_entry.insert(0, Locale.string_from_number(x, 3)) if type(y) == str: y_entry.insert(0, y) else: y_entry.insert(0, Locale.string_from_number(y, 3)) if type(z) == str: z_entry.insert(0, z) else: z_entry.insert(0, Locale.string_from_number(z, 3))
def update_distances(self): if not self.coordinates: for (_, distance) in self.distance_labels: distance["text"] = "? Ly" else: for i in range(len(self.distances)): system = self.distances[i] distance = self.calculate_distance(system["x"], system["y"], system["z"], *self.coordinates) self.distance_labels[i][1]["text"] = "{0} Ly".format( Locale.string_from_number(distance, 2)) _, distance = self.travelled_labels[0] distance["text"] = "{0} Ly".format( Locale.string_from_number(self.distance_total, 2)) _, distance = self.travelled_labels[1] distance["text"] = "{0} Ly".format( Locale.string_from_number(self.distance_session, 2))
def update_prefs_ui(self, event=None): for i, settings_ui_element in enumerate(self.settings_ui_elements): if settings_ui_element.has_data: if settings_ui_element.success: self.clear_input_fields(i) settings_ui_element.system_entry.insert( 0, settings_ui_element.system_name) settings_ui_element.x_entry.insert( 0, Locale.string_from_number(settings_ui_element.x)) settings_ui_element.y_entry.insert( 0, Locale.string_from_number(settings_ui_element.y)) settings_ui_element.z_entry.insert( 0, Locale.string_from_number(settings_ui_element.z)) self.error_label["text"] = settings_ui_element.status_text self.error_label.config(foreground="dark green") else: self.error_label["text"] = settings_ui_element.status_text self.error_label.config(foreground="red") settings_ui_element.edsm_button["state"] = tk.NORMAL settings_ui_element.reset_response_data()
def update_single(self): """ Set the transaction speed rate for trip in the EDMC window """ msg = "{}".format(Locale.stringFromNumber(self.trip_earnings(), 0)) if self.trip_earnings() > 0: self.single_widget["foreground"] = COLOR_NORM[self.appdesign] else: self.single_widget["foreground"] = COLOR_RED[self.appdesign] self.single_widget.grid(row=2, column=1, sticky=tk.E, columnspan=2) self.single_widget.after(0, self.single_widget.config, {"text": msg})
def validate(action, index, value_if_allowed, prior_value, text, validation_type, trigger_type, widget_name): if value_if_allowed == "-" or value_if_allowed == "": return True elif text in "0123456789.," or text == value_if_allowed: try: t = type(Locale.numberFromString(value_if_allowed)) if t is float or t is int: return True except ValueError: return False return False
def update_hourlyincome(self): """ Set the transaction speed rate in the EDMC window """ msg = " {}".format(Locale.stringFromNumber(self.speed(), 2)) if self.speed() > 0: self.speed_widget["foreground"] = COLOR_NORM[self.appdesign] else: self.speed_widget["foreground"] = COLOR_RED[self.appdesign] self.speed_widget.grid(row=1, column=2, sticky=tk.E) self.speed_widget.after(0, self.speed_widget.config, {"text": msg}) msgnow = " {} |".format(Locale.stringFromNumber(self.speednow(), 2)) if self.speednow() > 0: self.speednow_widget["foreground"] = COLOR_NORM[self.appdesign] else: self.speednow_widget["foreground"] = COLOR_RED[self.appdesign] self.speednow_widget.grid(row=1, column=1, sticky=tk.E) self.speednow_widget.after(0, self.speednow_widget.config, {"text": msgnow})
def updateValues(r,t,name): this.starused['text'] = name this.starused['url'] = 'https://www.edsm.net/show-system?systemName=%s&bodyName=%s' % (quote(this.systemName), quote(name)) for i in range(len(WORLDS)): (name, high, low, subType) = WORLDS[i] (label, edsm, near, dash, far, ls) = this.worlds[i] far_dist = int(0.5 + dfort(r, t, low)) radius = int(0.5 + r / LS) if far_dist <= radius: near['text'] = '' dash['text'] = u'×' far['text'] = '' ls['text'] = '' else: if not high: near['text'] = Locale.stringFromNumber(radius) else: near['text'] = Locale.stringFromNumber(int(0.5 + dfort(r, t, high))) dash['text'] = '-' far['text'] = Locale.stringFromNumber(far_dist) ls['text'] = 'ls' return 0
def updateUi(): # labels for distances to systems row = 0 for (system, distance) in this.distanceLabels: if len(this.distances) >= row + 1: s = this.distances[row] system.grid(row=row, column=0, sticky=tk.W) system["text"] = "Distance {0}:".format(s["system"]) distance.grid(row=row, column=1, sticky=tk.W) distance["text"] = "? Ly" row += 1 else: system.grid_remove() distance.grid_remove() # labels for total travelled distance settingTotal, settingSession, settingSessionOption = getSettingsTravelled() description, distance = this.travelledLabels[0] for i in range(len(this.travelledLabels)): description, distance = this.travelledLabels[i] if (i == 0 and settingTotal) or (i == 1 and settingSession): description.grid(row=row, column=0, sticky=tk.W) description["text"] = "Travelled ({0}):".format("total" if i == 0 else "session") distance.grid(row=row, column=1, sticky=tk.W) distance["text"] = "{0} Ly".format( Locale.stringFromNumber(this.distanceTotal, 2) if i == 0 else Locale.stringFromNumber(this.distanceSession, 2)) row += 1 else: description.grid_remove() distance.grid_remove() if row == 0: this.emptyFrame.grid(row=0) else: this.emptyFrame.grid_remove()
def update_main_ui(self): # labels for distances to systems row = 0 for (system, distance) in self.distance_labels: if len(self.distances) >= row + 1: s = self.distances[row] system.grid(row=row, column=0, sticky=tk.W) system["text"] = "Distance {0}:".format(s["system"]) distance.grid(row=row, column=1, sticky=tk.W) distance["text"] = "? Ly" row += 1 else: system.grid_remove() distance.grid_remove() # labels for total travelled distance setting_total, setting_session, setting_session_option = self.get_settings_travelled( ) for i in range(len(self.travelled_labels)): description, distance = self.travelled_labels[i] if (i == 0 and setting_total) or (i == 1 and setting_session): description.grid(row=row, column=0, sticky=tk.W) description["text"] = "Travelled ({0}):".format( "total" if i == 0 else "session") distance.grid(row=row, column=1, sticky=tk.W) distance["text"] = "{0} Ly".format( Locale.string_from_number(self.distance_total, 2) if i == 0 else Locale.string_from_number(self.distance_session, 2)) row += 1 else: description.grid_remove() distance.grid_remove() if row == 0: self.empty_frame.grid(row=0) else: self.empty_frame.grid_remove()
def fillSystemInformationFromEDSM(label, systemEntry, xEntry, yEntry, zEntry): # TODO fix possible issues because of thread-safety if systemEntry.get() == "": label["text"] = "No system name provided." label.config(foreground="red") return # nothing to do here edsmUrl = "https://www.edsm.net/api-v1/system?systemName={SYSTEM}&showCoordinates=1".format( SYSTEM=urllib2.quote(systemEntry.get())) systemInformation = None try: url = urllib2.urlopen(edsmUrl, timeout=15) response = url.read() edsmJson = json.loads(response) if "name" in edsmJson and "coords" in edsmJson: clearInputFields(systemEntry, xEntry, yEntry, zEntry) systemEntry.insert(0, edsmJson["name"]) xEntry.insert(0, Locale.stringFromNumber(edsmJson["coords"]["x"])) yEntry.insert(0, Locale.stringFromNumber(edsmJson["coords"]["y"])) zEntry.insert(0, Locale.stringFromNumber(edsmJson["coords"]["z"])) label["text"] = "Coordinates filled in for system {0}".format( edsmJson["name"]) label.config(foreground="dark green") else: label[ "text"] = "Could not get system information for {0} from EDSM".format( systemEntry.get()) label.config(foreground="red") except: label[ "text"] = "Could not get system information for {0} from EDSM".format( systemEntry.get()) label.config(foreground="red") sys.stderr.write( "DistanceCalc: Could not get system information for {0} from EDSM". format(systemEntry.get()))
def updatePrefsUI(event=None): for settingsUiElement in this.settingsUiElements: if settingsUiElement.hasData: if settingsUiElement.success: clearInputFields(settingsUiElement.systemEntry, settingsUiElement.xEntry, settingsUiElement.yEntry, settingsUiElement.zEntry) settingsUiElement.systemEntry.insert( 0, settingsUiElement.systemName) settingsUiElement.xEntry.insert( 0, Locale.stringFromNumber(settingsUiElement.x)) settingsUiElement.yEntry.insert( 0, Locale.stringFromNumber(settingsUiElement.y)) settingsUiElement.zEntry.insert( 0, Locale.stringFromNumber(settingsUiElement.z)) this.errorLabel["text"] = settingsUiElement.statusText this.errorLabel.config(foreground="dark green") else: this.errorLabel["text"] = settingsUiElement.statusText this.errorLabel.config(foreground="red") settingsUiElement.edsmButton["state"] = tk.NORMAL settingsUiElement.resetResponseData()