Repository navigation
Expand file tree
/
Copy pathload.py
More file actions
143 lines (112 loc) · 4.01 KB
/
Copy pathload.py
File metadata and controls
143 lines (112 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""
A dummy plugin for testing and illustrative purposes.
It doesn't do anything very useful, but it does implement the plugin interface. It's used to enable unit testing of
the unit test harness making it a test harness test harness.
It could also serve as a template for a new plugin.
It displays journal events as they occur and stores the latest journal, dashboard, and carrier data in global variables for inspection.
"""
import tkinter as tk
from dataclasses import dataclass, field
from typing import Dict
from companion import CAPIData # type: ignore
import myNotebook as nb # type: ignore
from demoplugin.utils.debug import Debug, catch_exceptions
from demoplugin.utils.updater import Updater, Notices, read_version_file
from demoplugin.ui import UI
PLUGIN_NAME = "DemoPlugin"
GH_OWNER = "dwomble" # Github owner name
GH_PROJECT = 'EDMC-DemoPlugin' # Github project name
GH_MAIN = "main" # Github main branch name
@dataclass
class Plugin:
name:str = PLUGIN_NAME
version:str = "0.0.0"
plugin_dir:str = ""
updater:Updater|None = None
notices:Notices|None = None
frame:tk.Frame|None = None
ui:UI|None = None
closing:bool = False
@dataclass
class Dashboard:
cmdr:str = ""
is_beta:bool = False
entry:Dict[str, int] = field(default_factory=dict)
parent:tk.Frame|None = None
frame:tk.Frame|None = None
@dataclass
class Journal:
cmdr:str = ""
is_beta:bool = False
system:str = ""
station:str = ""
entry:Dict[str, int] = field(default_factory=dict)
state:Dict[str, int] = field(default_factory=dict)
@dataclass
class Carrier:
data = None
plugin:Plugin = Plugin()
dashboard:Dashboard = Dashboard()
journal:Journal = Journal()
carrier:Carrier = Carrier()
def get_overlay(modern:bool):
""" Try loading an overlay plugin. Return True if it was successful, False if not. """
try:
from EDMCOverlay import edmcoverlay # type: ignore
if modern:
from overlay_plugin.overlay_api import define_plugin_group # type: ignore
return edmcoverlay.Overlay()
except ImportError:
pass
return None
def plugin_start3(plugin_dir):
""" Load this plugin into EDMC """
version = read_version_file(plugin_dir, "0.0.0")
plugin.version = str(version)
plugin.plugin_dir = plugin_dir
plugin.updater = Updater(str(plugin.plugin_dir), GH_OWNER, GH_PROJECT)
# Let's not since this is a dummy plugin
#plugin.updater.check_for_update(version)
plugin.notices = Notices(GH_OWNER, GH_PROJECT, GH_MAIN)
plugin.notices.check_for_notices()
return PLUGIN_NAME
def plugin_stop():
""" EDMC is closing """
if plugin.updater and plugin.updater.install_update:
plugin.updater.install(["data"])
plugin.closing = True
@catch_exceptions
def plugin_app(parent:tk.Frame):
""" Return a TK Frame for adding to the EDMC main window """
# An extra unweighted wrapper here would block EDMC's stretch from reaching self.frame's own weighted column
plugin.ui = UI(parent)
plugin.frame = plugin.ui.frame
return plugin.frame
def plugin_prefs(parent:tk.Frame, cmdr:str, is_beta:bool):
""" Return a TK Frame for adding to the EDMC settings dialog """
prefs:nb.Frame = nb.Frame(parent)
return prefs
def prefs_changed(cmdr:str, is_beta:bool) -> None:
""" Save settings. """
pass
def journal_entry(cmdr, is_beta, system, station, entry, state):
""" Parse an incoming journal entry and store the data we need """
journal.cmdr = cmdr
journal.is_beta = is_beta
journal.system = system
journal.station = station
journal.entry = entry
journal.state = state
if not plugin.ui:
return
plugin.ui.add_entry(entry)
def dashboard_entry(cmdr:str, is_beta:bool, entry:dict) -> None:
""" Handle dashboard state changes """
dashboard.cmdr = cmdr
dashboard.is_beta = is_beta
dashboard.entry = entry
if plugin.ui:
plugin.ui.update_dashboard(entry)
def capi_fleetcarrier(data:CAPIData):
""" Handle Fleet carrier data """
carrier.data = data