1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-02 00:21:05 +03:00

Rename plugin callback to dashboard_entry

This commit is contained in:
Jonathan Harris 2018-01-29 23:39:00 +00:00
parent a081b6b637
commit 75edff5fc3
4 changed files with 21 additions and 21 deletions

View File

@ -57,7 +57,7 @@ import prefs
import plug import plug
from hotkey import hotkeymgr from hotkey import hotkeymgr
from monitor import monitor from monitor import monitor
from status import status from dashboard import dashboard
from theme import theme from theme import theme
@ -270,7 +270,7 @@ class AppWindow:
self.w.bind('<KP_Enter>', self.getandsend) self.w.bind('<KP_Enter>', self.getandsend)
self.w.bind_all('<<Invoke>>', self.getandsend) # Hotkey monitoring self.w.bind_all('<<Invoke>>', self.getandsend) # Hotkey monitoring
self.w.bind_all('<<JournalEvent>>', self.journal_event) # Journal monitoring self.w.bind_all('<<JournalEvent>>', self.journal_event) # Journal monitoring
self.w.bind_all('<<StatusEvent>>', self.status_event) # Cmdr Status monitoring self.w.bind_all('<<DashboardEvent>>', self.dashboard_event) # Dashboard monitoring
self.w.bind_all('<<PluginError>>', self.plugin_error) # Statusbar self.w.bind_all('<<PluginError>>', self.plugin_error) # Statusbar
self.w.bind_all('<<Quit>>', self.onexit) # Updater self.w.bind_all('<<Quit>>', self.onexit) # Updater
@ -630,8 +630,8 @@ class AppWindow:
hotkeymgr.play_bad() hotkeymgr.play_bad()
if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started: if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started:
# Can start status monitoring # Can start dashboard monitoring
if not status.start(self.w, monitor.started): if not dashboard.start(self.w, monitor.started):
print "Can't start Status monitoring" print "Can't start Status monitoring"
# Don't send to EDDN while on crew # Don't send to EDDN while on crew
@ -686,11 +686,11 @@ class AppWindow:
hotkeymgr.play_bad() hotkeymgr.play_bad()
# Handle Status event # Handle Status event
def status_event(self, event): def dashboard_event(self, event):
entry = status.status entry = dashboard.status
if entry: if entry:
# Currently we don't do anything with these events # Currently we don't do anything with these events
err = plug.notify_status(monitor.cmdr, monitor.is_beta, entry) err = plug.notify_dashboard_entry(monitor.cmdr, monitor.is_beta, entry)
if err: if err:
self.status['text'] = err self.status['text'] = err
if not config.getint('hotkey_mute'): if not config.getint('hotkey_mute'):
@ -797,7 +797,7 @@ class AppWindow:
config.set('geometry', '+{1}+{2}'.format(*self.w.geometry().split('+'))) config.set('geometry', '+{1}+{2}'.format(*self.w.geometry().split('+')))
self.w.withdraw() # Following items can take a few seconds, so hide the main window while they happen self.w.withdraw() # Following items can take a few seconds, so hide the main window while they happen
hotkeymgr.unregister() hotkeymgr.unregister()
status.close() dashboard.close()
monitor.close() monitor.close()
plug.notify_stop() plug.notify_stop()
self.eddn.close() self.eddn.close()

View File

@ -128,12 +128,12 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
sys.stderr.write("Arrived at {}\n".format(entry['StarSystem'])) sys.stderr.write("Arrived at {}\n".format(entry['StarSystem']))
``` ```
### Player Status ### Player Dashboard
This gets called periodically - typically about once a second - whith the players live status This gets called when something on the player's cockpit display changes - typically about once a second when in orbital flight
```python ```python
def status(cmdr, is_beta, entry): def dashboard_entry(cmdr, is_beta, entry):
deployed = entry['Flags'] & 1<<6 deployed = entry['Flags'] & 1<<6
sys.stderr.write("Hardpoints {}\n", deployed and "deployed" or "stowed") sys.stderr.write("Hardpoints {}\n", deployed and "deployed" or "stowed")
``` ```
@ -154,7 +154,7 @@ The data is a dictionary and full of lots of wonderful stuff!
## Error messages ## Error messages
You can display an error in EDMC's status area by returning a string from your `journal_entry()`, `status()` or `cmdr_data()` function, or asynchronously (e.g. from a "worker" thread that is performing a long running operation) by calling `plug.show_error()`. Either method will cause the "bad" sound to be played (unless the user has muted sound). You can display an error in EDMC's status area by returning a string from your `journal_entry()`, `status_entry()` or `cmdr_data()` function, or asynchronously (e.g. from a "worker" thread that is performing a long running operation) by calling `plug.show_error()`. Either method will cause the "bad" sound to be played (unless the user has muted sound).
The status area is shared between EDMC itself and all other plugins, so your message won't be displayed for very long. Create a dedicated widget if you need to display routine status information. The status area is shared between EDMC itself and all other plugins, so your message won't be displayed for very long. Create a dedicated widget if you need to display routine status information.

View File

@ -2,7 +2,7 @@ import json
from calendar import timegm from calendar import timegm
from operator import itemgetter from operator import itemgetter
from os import listdir, stat from os import listdir, stat
from os.path import getmtime, isdir, join from os.path import isdir, join
from sys import platform from sys import platform
import time import time
@ -26,7 +26,7 @@ else:
# Status.json handler # Status.json handler
class Status(FileSystemEventHandler): class Dashboard(FileSystemEventHandler):
_POLL = 1 # Fallback polling interval _POLL = 1 # Fallback polling interval
@ -55,7 +55,7 @@ class Status(FileSystemEventHandler):
# File system events are unreliable/non-existent over network drives on Linux. # File system events are unreliable/non-existent over network drives on Linux.
# We can't easily tell whether a path points to a network drive, so assume # We can't easily tell whether a path points to a network drive, so assume
# any non-standard logdir might be on a network drive and poll instead. # any non-standard logdir might be on a network drive and poll instead.
polling = bool(config.get('statusdir')) and platform != 'win32' polling = bool(config.get('journaldir')) and platform != 'win32'
if not polling and not self.observer: if not polling and not self.observer:
self.observer = Observer() self.observer = Observer()
self.observer.daemon = True self.observer.daemon = True
@ -68,7 +68,7 @@ class Status(FileSystemEventHandler):
self.observed = self.observer.schedule(self, self.currentdir) self.observed = self.observer.schedule(self, self.currentdir)
if __debug__: if __debug__:
print '%s status "%s"' % (polling and 'Polling' or 'Monitoring', self.currentdir) print '%s Dashboard "%s"' % (polling and 'Polling' or 'Monitoring', self.currentdir)
# Even if we're not intending to poll, poll at least once to process pre-existing # Even if we're not intending to poll, poll at least once to process pre-existing
# data and to check whether the watchdog thread has crashed due to events not # data and to check whether the watchdog thread has crashed due to events not
@ -79,7 +79,7 @@ class Status(FileSystemEventHandler):
def stop(self): def stop(self):
if __debug__: if __debug__:
print 'Stopping monitoring Status' print 'Stopping monitoring Dashboard'
self.currentdir = None self.currentdir = None
if self.observed: if self.observed:
self.observed = None self.observed = None
@ -123,9 +123,9 @@ class Status(FileSystemEventHandler):
# Status file is shared between beta and live. So filter out status not in this game session. # Status file is shared between beta and live. So filter out status not in this game session.
if timegm(time.strptime(entry['timestamp'], '%Y-%m-%dT%H:%M:%SZ')) >= self.session_start and self.status != entry: if timegm(time.strptime(entry['timestamp'], '%Y-%m-%dT%H:%M:%SZ')) >= self.session_start and self.status != entry:
self.status = entry self.status = entry
self.root.event_generate('<<StatusEvent>>', when="tail") self.root.event_generate('<<DashboardEvent>>', when="tail")
except: except:
if __debug__: print_exc() if __debug__: print_exc()
# singleton # singleton
status = Status() dashboard = Dashboard()

View File

@ -226,7 +226,7 @@ def notify_journal_entry(cmdr, is_beta, system, station, entry, state):
return error return error
def notify_status(cmdr, is_beta, entry): def notify_dashboard_entry(cmdr, is_beta, entry):
""" """
Send a status entry to each plugin. Send a status entry to each plugin.
:param cmdr: The piloting Cmdr name :param cmdr: The piloting Cmdr name
@ -236,7 +236,7 @@ def notify_status(cmdr, is_beta, entry):
""" """
error = None error = None
for plugin in PLUGINS: for plugin in PLUGINS:
status = plugin._get_func('status') status = plugin._get_func('dashboard_entry')
if status: if status:
try: try:
# Pass a copy of the status entry in case the callee modifies it # Pass a copy of the status entry in case the callee modifies it