1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 08:17:13 +03:00

Rationalise startup sequence

This commit is contained in:
Jonathan Harris 2016-09-06 12:26:59 +01:00
parent db543c2901
commit 7f2cf3a286
5 changed files with 29 additions and 32 deletions

View File

@ -122,10 +122,7 @@ class AppWindow:
self.theme_button.grid(row=row, columnspan=2, sticky=tk.NSEW)
theme.register_alternate((self.button, self.theme_button), {'row':row, 'columnspan':2, 'sticky':tk.NSEW})
self.status.grid(columnspan=2, sticky=tk.EW)
theme.button_bind(self.theme_button, self.getandsend)
self.w.bind('<Return>', self.getandsend)
self.w.bind('<KP_Enter>', self.getandsend)
for child in frame.winfo_children():
child.grid_configure(padx=5, pady=(platform=='win32' and 1 or 3))
@ -240,21 +237,16 @@ class AppWindow:
theme.register_highlight(self.station)
theme.apply(self.w)
# Special handling for overrideredict
self.w.bind("<Map>", self.onmap)
self.w.bind("<Map>", self.onmap) # Special handling for overrideredict
self.w.bind('<Return>', self.getandsend)
self.w.bind('<KP_Enter>', self.getandsend)
self.w.bind_all('<<Invoke>>', self.getandsend) # Hotkey monitoring
self.w.bind_all('<<JournalEvent>>', self.journal_event) # Journal monitoring
self.w.bind_all('<<Quit>>', self.onexit) # Updater
# Load updater after UI creation (for WinSparkle)
import update
self.updater = update.Updater(self.w)
self.w.bind_all('<<Quit>>', self.onexit) # user-generated
# Install hotkey monitoring
self.w.bind_all('<<Invoke>>', self.getandsend) # user-generated
hotkeymgr.register(self.w, config.getint('hotkey_code'), config.getint('hotkey_mods'))
# Install log monitoring
self.w.bind_all('<<JournalEvent>>', self.journal_event) # user-generated
monitor.start(self.w)
# First run
if not config.get('username') or not config.get('password'):
@ -309,15 +301,20 @@ class AppWindow:
if __debug__: print_exc()
self.status['text'] = unicode(e)
# Try to obtain exclusive lock on journal cache, even if we don't need it yet
try:
eddn.load()
except Exception as e:
self.status['text'] = unicode(e)
if not getattr(sys, 'frozen', False):
self.updater.checkForUpdates() # Sparkle / WinSparkle does this automatically for packaged apps
# Try to obtain exclusive lock on journal cache, even if we don't need it yet
if not eddn.load():
self.status['text'] = 'Error: Is another copy of this app already running?' # Shouldn't happen - don't bother localizing
# (Re-)install hotkey monitoring
hotkeymgr.register(self.w, config.getint('hotkey_code'), config.getint('hotkey_mods'))
# (Re-)install log monitoring
if not monitor.start(self.w):
self.status['text'] = 'Error: Check %s' % _('E:D journal file location') # Location of the new Journal file in E:D 2.2
self.cooldown()
# callback after verification code

View File

@ -109,7 +109,7 @@
/* Empire rank. [stats.py] */
"Duke" = "Duke";
/* Location of the new Journal file in E:D 2.2. [prefs.py] */
/* Location of the new Journal file in E:D 2.2. [EDMarketConnector.py] */
"E:D journal file location" = "E:D journal file location";
/* Empire rank. [stats.py] */

View File

@ -54,7 +54,8 @@ class _EDDN:
if self.replayfile:
self.replayfile.close()
self.replayfile = None
raise Exception("Error: Is another copy of this app already running?") # Shouldn't happen - don't bother localizing
return False
return True
def flush(self):
self.replayfile.seek(0, SEEK_SET)

View File

@ -96,6 +96,15 @@ class EDLogs(FileSystemEventHandler):
self.stop()
self.currentdir = logdir
# Latest pre-existing logfile - e.g. if E:D is already running. Assumes logs sort alphabetically.
# Do this before setting up the observer in case the journal directory has gone away
try:
logfiles = sorted([x for x in listdir(self.currentdir) if x.startswith('Journal.')])
self.logfile = logfiles and join(self.currentdir, logfiles[-1]) or None
except:
self.logfile = None
return False
# Set up a watchog observer. This is low overhead so is left running irrespective of whether monitoring is desired.
# 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
@ -110,13 +119,6 @@ class EDLogs(FileSystemEventHandler):
if not self.observed and not polling:
self.observed = self.observer.schedule(self, self.currentdir)
# Latest pre-existing logfile - e.g. if E:D is already running. Assumes logs sort alphabetically.
try:
logfiles = sorted([x for x in listdir(self.currentdir) if x.startswith('Journal.')])
self.logfile = logfiles and join(self.currentdir, logfiles[-1]) or None
except:
self.logfile = None
if __debug__:
print '%s "%s"' % (polling and 'Polling' or 'Monitoring', self.currentdir)
print 'Start logfile "%s"' % self.logfile

View File

@ -489,9 +489,6 @@ class PreferencesDialog(tk.Toplevel):
self.callback()
def _destroy(self):
# Re-enable hotkey and log monitoring before exit
hotkeymgr.register(self.parent, config.getint('hotkey_code'), config.getint('hotkey_mods'))
monitor.start(self.parent)
self.parent.wm_attributes('-topmost', config.getint('always_ontop') and 1 or 0)
self.destroy()