Add more functionality to preferences window.

This commit is contained in:
Ebag333
2017-02-27 12:05:38 -08:00
parent dbffdedc92
commit d67573f83a
6 changed files with 53 additions and 9 deletions

View File

@@ -29,6 +29,7 @@ pyfaPath = None
savePath = None
saveDB = None
gameDB = None
logPath = None
def isFrozen():

View File

@@ -3,6 +3,7 @@
# Used by:
# Module: Reactive Armor Hardener
from logbook import Logger
from service.fit import Fit
pyfalog = Logger(__name__)
@@ -13,6 +14,13 @@ type = "active"
def handler(fit, module, context):
damagePattern = fit.damagePattern
sFit = Fit.getInstance()
static_adaptive_behavior = sFit.serviceFittingOptions["useStaticAdaptiveArmorHardener"]
if (damagePattern.emAmount == damagePattern.thermalAmount == damagePattern.kineticAmount == damagePattern.explosiveAmount) and static_adaptive_behavior:
pyfalog.debug("Setting adaptivearmorhardener resists to uniform profile.")
return
# Skip if there is no damage pattern. Example: projected ships or fleet boosters
if damagePattern:

View File

@@ -36,6 +36,10 @@ class PFFittingEnginePref(PreferenceView):
wx.DefaultPosition, wx.DefaultSize, 0)
mainSizer.Add(self.cbGlobalForceReload, 0, wx.ALL | wx.EXPAND, 5)
self.cbUniversalAdaptiveArmorHardener = wx.CheckBox(panel, wx.ID_ANY, u"When damage profile is even, set Reactive Armor Hardener to match (old behavior).",
wx.DefaultPosition, wx.DefaultSize, 0)
mainSizer.Add(self.cbUniversalAdaptiveArmorHardener, 0, wx.ALL | wx.EXPAND, 5)
# Future code once new cap sim is implemented
'''
self.cbGlobalForceReactivationTimer = wx.CheckBox( panel, wx.ID_ANY, u"Factor in reactivation timer", wx.DefaultPosition, wx.DefaultSize, 0 )
@@ -63,15 +67,20 @@ class PFFittingEnginePref(PreferenceView):
self.sFit = Fit.getInstance()
self.cbGlobalForceReload.SetValue(self.sFit.serviceFittingOptions["useGlobalForceReload"])
self.cbGlobalForceReload.Bind(wx.EVT_CHECKBOX, self.OnCBGlobalForceReloadStateChange)
self.cbUniversalAdaptiveArmorHardener.SetValue(self.sFit.serviceFittingOptions["useStaticAdaptiveArmorHardener"])
self.cbUniversalAdaptiveArmorHardener.Bind(wx.EVT_CHECKBOX, self.OnCBUniversalAdaptiveArmorHardenerChange)
panel.SetSizer(mainSizer)
panel.Layout()
def OnCBGlobalForceReloadStateChange(self, event):
self.sFit.serviceFittingOptions["useGlobalForceReload"] = self.cbGlobalForceReload.GetValue()
def OnCBUniversalAdaptiveArmorHardenerChange(self, event):
self.sFit.serviceFittingOptions["useStaticAdaptiveArmorHardener"] = self.cbUniversalAdaptiveArmorHardener.GetValue()
def getImage(self):
return BitmapLoader.getBitmap("prefs_settings", "gui")

View File

@@ -3,6 +3,13 @@ import wx
from gui.preferenceView import PreferenceView
from gui.bitmapLoader import BitmapLoader
import config
from logbook import Logger
pyfalog = Logger(__name__)
def OnDumpLogs(event):
pyfalog.critical("Dump log button was pressed. Writing all logs to log file.")
class PFGeneralPref(PreferenceView):
@@ -27,10 +34,26 @@ class PFGeneralPref(PreferenceView):
self.m_staticline1 = wx.StaticLine(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL)
mainSizer.Add(self.m_staticline1, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5)
# Database path
self.stLogPath = wx.StaticText(panel, wx.ID_ANY, u"Log file location:", wx.DefaultPosition, wx.DefaultSize, 0)
self.stLogPath.Wrap(-1)
mainSizer.Add(self.stLogPath, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
self.inputLogPath = wx.TextCtrl(panel, wx.ID_ANY, config.logPath, wx.DefaultPosition, wx.DefaultSize, 0)
self.inputLogPath.SetEditable(False)
self.inputLogPath.SetBackgroundColour((200, 200, 200))
mainSizer.Add(self.inputLogPath, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, 5)
# Debug Logging
self.cbdebugLogging = wx.CheckBox(panel, wx.ID_ANY, u"Debug Logging Enabled", wx.DefaultPosition, wx.DefaultSize, 0)
mainSizer.Add(self.cbdebugLogging, 0, wx.ALL | wx.EXPAND, 5)
self.stDumpLogs = wx.StaticText(panel, wx.ID_ANY, u"Pressing this button will cause all logs in memory to write to the log file:",
wx.DefaultPosition, wx.DefaultSize, 0)
mainSizer.Add(self.stDumpLogs, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
self.btnDumpLogs = wx.Button(panel, wx.ID_ANY, u"Dump All Logs", wx.DefaultPosition, wx.DefaultSize, 0)
self.btnDumpLogs.Bind(wx.EVT_BUTTON, OnDumpLogs)
mainSizer.Add(self.btnDumpLogs, 0, wx.ALIGN_LEFT, 5)
self.cbdebugLogging.SetValue(config.debug)
self.cbdebugLogging.Bind(wx.EVT_CHECKBOX, self.onCBdebugLogging)

18
pyfa.py
View File

@@ -46,7 +46,7 @@ class PassThroughOptionParser(OptionParser):
largs.append(e.opt_str)
class LoggerWriter:
class LoggerWriter(object):
def __init__(self, level):
# self.level is really like using log.debug(message)
# at least in my case
@@ -159,8 +159,6 @@ if __name__ == "__main__":
# Import everything
# noinspection PyPackageRequirements
import wx
import os
import os.path
try:
# convert to unicode if it is set
@@ -185,8 +183,9 @@ if __name__ == "__main__":
else:
savePath_filename = "Pyfa.log"
savePath_Destination = os.path.join(config.savePath, savePath_filename)
config.logPath = os.path.join(config.savePath, savePath_filename)
# noinspection PyBroadException
try:
if options.debug:
logging_mode = "Debug"
@@ -200,7 +199,7 @@ if __name__ == "__main__":
level=options.logginglevel
),
TimedRotatingFileHandler(
savePath_Destination,
config.logPath,
level=0,
backup_count=3,
bubble=True,
@@ -215,7 +214,7 @@ if __name__ == "__main__":
NullHandler(),
FingersCrossedHandler(
TimedRotatingFileHandler(
savePath_Destination,
config.logPath,
level=0,
backup_count=3,
bubble=False,
@@ -266,15 +265,18 @@ if __name__ == "__main__":
# Output all stdout (print) messages as warnings
try:
sys.stdout = LoggerWriter(pyfalog.warning)
except ValueError, Exception:
except (ValueError, Exception) as e:
pyfalog.critical("Cannot access log file. Continuing without writing stdout to log.")
pyfalog.critical(e)
# Don't redirect stderr (stacktrace) messages if we're in debug mode. Developers want to see them in the console.
if not options.debug:
# Output all stderr (stacktrace) messages as critical
try:
sys.stderr = LoggerWriter(pyfalog.critical)
except ValueError, Exception:
except (ValueError, Exception) as e:
pyfalog.critical("Cannot access log file. Continuing without writing stderr to log.")
pyfalog.critical(e)
pyfalog.info("Starting Pyfa")
pyfalog.info("Running in logging mode: {0}", logging_mode)

View File

@@ -72,6 +72,7 @@ class Fit(object):
"exportCharges": True,
"openFitInNew": False,
"priceSystem": "Jita",
"useStaticAdaptiveArmorHardener": False,
}
self.serviceFittingOptions = SettingsProvider.getInstance().getSettings(