initial import
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
*.key
|
||||
__pycache__
|
||||
@@ -0,0 +1,88 @@
|
||||
import sys
|
||||
import requests
|
||||
import tkinter as tk
|
||||
import myNotebook as nb
|
||||
from config import config
|
||||
|
||||
this = sys.modules[__name__] # For holding module globals
|
||||
|
||||
|
||||
def plugin_start3(plugin_dir):
|
||||
"""
|
||||
Plugin is loaded
|
||||
"""
|
||||
return "EDCompanion"
|
||||
|
||||
|
||||
def plugin_stop():
|
||||
"""
|
||||
EDMC is closing
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def plugin_prefs(parent, cmdr, is_beta):
|
||||
"""
|
||||
Return a TK Frame for adding to the EDMC settings dialog.
|
||||
"""
|
||||
PADX = 10
|
||||
BUTTONX = 12 # indent Checkbuttons and Radiobuttons
|
||||
PADY = 2 # close spacing
|
||||
|
||||
frame = nb.Frame(parent)
|
||||
|
||||
this.apikey_label = nb.Label(frame, text='API Key') # EDSM setting
|
||||
this.apikey_label.grid(row=12, padx=PADX, sticky=tk.W)
|
||||
this.apikey = nb.Entry(frame)
|
||||
this.apikey.grid(row=12, column=1, padx=PADX, pady=PADY, sticky=tk.EW)
|
||||
|
||||
prefs_cmdr_changed(cmdr, is_beta)
|
||||
|
||||
return frame
|
||||
|
||||
|
||||
def prefs_cmdr_changed(cmdr, is_beta):
|
||||
this.apikey['state'] = tk.NORMAL
|
||||
this.apikey.delete(0, tk.END)
|
||||
if cmdr:
|
||||
cred = credentials(cmdr)
|
||||
if cred:
|
||||
this.apikey.insert(0, cred)
|
||||
|
||||
|
||||
def prefs_changed(cmdr, is_beta):
|
||||
"""
|
||||
Save settings.
|
||||
"""
|
||||
if cmdr and not is_beta:
|
||||
this.cmdr = cmdr
|
||||
this.FID = None
|
||||
cmdrs = config.get('edcompanion_cmdrs') or []
|
||||
apikeys = config.get('edcompanion_apikeys') or []
|
||||
if cmdr in cmdrs:
|
||||
idx = cmdrs.index(cmdr)
|
||||
apikeys.extend([''] * (1 + idx - len(apikeys)))
|
||||
apikeys[idx] = this.apikey.get().strip()
|
||||
else:
|
||||
config.set('edcompanion_cmdrs', cmdrs + [cmdr])
|
||||
apikeys.append(this.apikey.get().strip())
|
||||
config.set('edcompanion_apikeys', apikeys)
|
||||
|
||||
|
||||
def credentials(cmdr):
|
||||
# Credentials for cmdr
|
||||
if not cmdr:
|
||||
return None
|
||||
|
||||
cmdrs = config.get('edcompanion_cmdrs') or []
|
||||
if cmdr in cmdrs and config.get('edcompanion_apikeys'):
|
||||
return config.get('edcompanion_apikeys')[cmdrs.index(cmdr)]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
cred = credentials(cmdr)
|
||||
if cred and not is_beta:
|
||||
del state['Friends']
|
||||
requests.post("http://192.168.178.29:8080/update/status/" + cred, json=state)
|
||||
Reference in New Issue
Block a user