1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-15 16:50:34 +03:00
2017-07-29 14:42:00 +01:00

69 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
#
# Station display and eddb.io lookup
#
import cPickle
import csv
import os
from os.path import dirname, join, normpath
import sys
import Tkinter as tk
from ttkHyperlinkLabel import HyperlinkLabel
from config import config
STATION_UNDOCKED = u'×' # "Station" name to display when not docked = U+00D7
this = sys.modules[__name__] # For holding module globals
this.system = None # name of current system
with open(join(config.respath, 'systems.p'), 'rb') as h:
this.system_ids = cPickle.load(h)
with open(join(config.respath, 'stations.p'), 'rb') as h:
this.station_ids = cPickle.load(h)
# system_name -> system_id or 0
def system_id(system_name):
return this.system_ids.get(system_name, 0) # return 0 on failure (0 is not a valid id)
# (system_name, station_name) -> station_id or 0
def station_id(system_name, station_name):
return this.station_ids.get((this.system_ids.get(system_name), station_name), 0)
def station_url(text):
if text:
station = station_id(this.system, text)
if station:
return 'https://eddb.io/station/%d' % station
system = system_id(this.system)
if system:
return 'https://eddb.io/system/%d' % system
return None
def plugin_start():
return '~eddb'
def plugin_app(parent):
this.station_label = tk.Label(parent, text = _('Station') + ':') # Main window
this.station = HyperlinkLabel(parent, url = station_url, popup_copy = lambda x: x != STATION_UNDOCKED)
return (this.station_label, this.station)
def prefs_changed():
this.station_label['text'] = _('Station') + ':'
def journal_entry(cmdr, system, station, entry, state):
this.system = system
this.station['text'] = station or (system_id(system) and STATION_UNDOCKED or '')
def cmdr_data(data):
this.station['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (system_id(data['lastSystem']['name']) and STATION_UNDOCKED or '')