mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-21 11:27:38 +03:00
Merge pull request #540 from Athanasius/fix/407-upload_output_settings_reset
Fix/407 upload output settings reset
This commit is contained in:
commit
476f7384cf
@ -14,6 +14,8 @@ import tkinter as tk
|
||||
from ttkHyperlinkLabel import HyperlinkLabel
|
||||
import myNotebook as nb
|
||||
|
||||
from prefs import prefsVersion
|
||||
|
||||
if sys.platform != 'win32':
|
||||
from fcntl import lockf, LOCK_EX, LOCK_NB
|
||||
|
||||
@ -347,7 +349,10 @@ def plugin_prefs(parent, cmdr, is_beta):
|
||||
BUTTONX = 12 # indent Checkbuttons and Radiobuttons
|
||||
PADY = 2 # close spacing
|
||||
|
||||
output = config.getint('output') or (config.OUT_MKT_EDDN | config.OUT_SYS_EDDN) # default settings
|
||||
if prefsVersion.shouldSetDefaults('0.0.0.0', not bool(config.getint('output'))):
|
||||
output = (config.OUT_MKT_EDDN | config.OUT_SYS_EDDN) # default settings
|
||||
else:
|
||||
output = config.getint('output')
|
||||
|
||||
eddnframe = nb.Frame(parent)
|
||||
|
||||
@ -371,7 +376,7 @@ def prefsvarchanged(event=None):
|
||||
|
||||
def prefs_changed(cmdr, is_beta):
|
||||
config.set('output',
|
||||
(config.getint('output') & (config.OUT_MKT_TD | config.OUT_MKT_CSV | config.OUT_SHIP |config. OUT_MKT_MANUAL)) +
|
||||
(config.getint('output') & (config.OUT_MKT_TD | config.OUT_MKT_CSV | config.OUT_SHIP |config.OUT_MKT_MANUAL)) +
|
||||
(this.eddn_station.get() and config.OUT_MKT_EDDN) +
|
||||
(this.eddn_system.get() and config.OUT_SYS_EDDN) +
|
||||
(this.eddn_delay.get() and config.OUT_SYS_DELAY))
|
||||
|
72
prefs.py
72
prefs.py
@ -10,7 +10,7 @@ from tkinter import colorchooser as tkColorChooser
|
||||
from ttkHyperlinkLabel import HyperlinkLabel
|
||||
import myNotebook as nb
|
||||
|
||||
from config import applongname, config
|
||||
from config import applongname, config, appversion
|
||||
from hotkey import hotkeymgr
|
||||
from l10n import Translations
|
||||
from monitor import monitor
|
||||
@ -18,6 +18,70 @@ from theme import theme
|
||||
|
||||
import plug
|
||||
|
||||
###########################################################################
|
||||
# Versioned preferences, so we know whether to set an 'on' default on
|
||||
# 'new' preferences, or not.
|
||||
###########################################################################
|
||||
|
||||
|
||||
class PrefsVersion(object):
|
||||
versions = {
|
||||
'0.0.0.0': 1,
|
||||
'1.0.0.0': 2,
|
||||
'3.4.6.0': 3,
|
||||
'3.5.1.0': 4,
|
||||
# Only add new versions that add new Preferences
|
||||
'current': 4, # Should always match the last specific version, but only increment after you've added the new version. Guess at it if anticipating a new version.
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
return
|
||||
|
||||
def stringToSerial(self, versionStr: str) -> int:
|
||||
"""
|
||||
Convert a version string into a preferences version serial number.
|
||||
|
||||
If the version string isn't known returns the 'current' (latest) serial number.
|
||||
|
||||
:param versionStr:
|
||||
:return int:
|
||||
"""
|
||||
if versionStr in self.versions:
|
||||
return self.versions[versionStr]
|
||||
|
||||
return self.versions['current']
|
||||
|
||||
###########################################################################
|
||||
# Should defaults be set, given the settings were added after 'addedAfter' ?
|
||||
#
|
||||
# config.get('PrefsVersion') is the version preferences we last saved for
|
||||
###########################################################################
|
||||
def shouldSetDefaults(self, addedAfter: str, oldTest : bool=True) -> bool:
|
||||
pv = config.getint('PrefsVersion')
|
||||
# If no PrefsVersion yet exists then return oldTest
|
||||
if not pv:
|
||||
return oldTest
|
||||
|
||||
# Convert addedAfter to a version serial number
|
||||
if addedAfter not in self.versions:
|
||||
# Assume it was added at the start
|
||||
aa = 1
|
||||
else:
|
||||
aa = self.versions[addedAfter]
|
||||
# Sanity check, if something was added after then current should be greater
|
||||
if aa >= self.versions['current']:
|
||||
raise Exception('ERROR: Call to prefs.py:PrefsVersion.shouldSetDefaults() with "addedAfter" >= current latest in "versions" table. You probably need to increase "current" serial number.')
|
||||
|
||||
# If this preference was added after the saved PrefsVersion we should set defaults
|
||||
if aa >= pv:
|
||||
return True
|
||||
|
||||
return False
|
||||
###########################################################################
|
||||
|
||||
prefsVersion = PrefsVersion()
|
||||
###########################################################################
|
||||
|
||||
if platform == 'darwin':
|
||||
import objc
|
||||
from Foundation import NSFileManager
|
||||
@ -103,7 +167,10 @@ class PreferencesDialog(tk.Toplevel):
|
||||
outframe = nb.Frame(notebook)
|
||||
outframe.columnconfigure(0, weight=1)
|
||||
|
||||
output = config.getint('output') or config.OUT_SHIP # default settings
|
||||
if prefsVersion.shouldSetDefaults('0.0.0.0', not bool(config.getint('output'))):
|
||||
output = config.OUT_SHIP # default settings
|
||||
else:
|
||||
output = config.getint('output')
|
||||
|
||||
self.out_label = nb.Label(outframe, text=_('Please choose what data to save'))
|
||||
self.out_label.grid(columnspan=2, padx=PADX, sticky=tk.W)
|
||||
@ -499,6 +566,7 @@ class PreferencesDialog(tk.Toplevel):
|
||||
|
||||
|
||||
def apply(self):
|
||||
config.set('PrefsVersion', prefsVersion.stringToSerial(appversion))
|
||||
config.set('output',
|
||||
(self.out_td.get() and config.OUT_MKT_TD) +
|
||||
(self.out_csv.get() and config.OUT_MKT_CSV) +
|
||||
|
Loading…
x
Reference in New Issue
Block a user