diff --git a/gui/builtinPreferenceViews/pyfaDatabasePreferences.py b/gui/builtinPreferenceViews/pyfaDatabasePreferences.py index 608dc0197..6b48d08bf 100644 --- a/gui/builtinPreferenceViews/pyfaDatabasePreferences.py +++ b/gui/builtinPreferenceViews/pyfaDatabasePreferences.py @@ -2,7 +2,10 @@ import wx from gui.preferenceView import PreferenceView from gui.bitmapLoader import BitmapLoader +from gui.utils import helpers_wxPython as wxHelpers import config +from eos.db.saveddata.queries import getTargetResistsList, getDamagePatternList, clearPrices, remove +from eos.db.saveddata.loadDefaultDatabaseValues import DefaultDatabaseValues import logging @@ -66,13 +69,61 @@ class PFGeneralPref(PreferenceView): self.cbsaveInRoot.SetValue(config.saveInRoot) self.cbsaveInRoot.Bind(wx.EVT_CHECKBOX, self.onCBsaveInRoot) - self.inputUserPath.Bind(wx.EVT_LEAVE_WINDOW, self.OnWindowLeave) - self.inputFitDB.Bind(wx.EVT_LEAVE_WINDOW, self.OnWindowLeave) - self.inputGameDB.Bind(wx.EVT_LEAVE_WINDOW, self.OnWindowLeave) + # self.inputUserPath.Bind(wx.EVT_LEAVE_WINDOW, self.OnWindowLeave) + # self.inputFitDB.Bind(wx.EVT_LEAVE_WINDOW, self.OnWindowLeave) + # self.inputGameDB.Bind(wx.EVT_LEAVE_WINDOW, self.OnWindowLeave) + + self.m_staticline2 = wx.StaticLine(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) + mainSizer.Add(self.m_staticline2, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) + + self.stSubTitleTwo = wx.StaticText(panel, wx.ID_ANY, u"(DANGER ZONE!\nUsing these options will permanantly delete data out of the database.)", + wx.DefaultPosition, wx.DefaultSize, 0) + self.stSubTitleTwo.Wrap(-1) + mainSizer.Add(self.stSubTitleTwo, 0, wx.ALL, 3) + + self.m_staticline3 = wx.StaticLine(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) + mainSizer.Add(self.m_staticline3, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) + + btnSizer = wx.BoxSizer(wx.VERTICAL) + btnSizer.AddSpacer((0, 0), 1, wx.EXPAND, 5) + + self.btnDeleteDamagePatterns = wx.Button(panel, wx.ID_ANY, u"Delete All Damage Pattern Profiles", wx.DefaultPosition, wx.DefaultSize, 0) + btnSizer.Add(self.btnDeleteDamagePatterns, 0, wx.ALL, 5) + + self.btnDeleteTargetResists = wx.Button(panel, wx.ID_ANY, u"Delete All Target Resist Profiles", wx.DefaultPosition, wx.DefaultSize, 0) + btnSizer.Add(self.btnDeleteTargetResists, 0, wx.ALL, 5) + + self.btnPrices = wx.Button(panel, wx.ID_ANY, u"Delete All Prices", wx.DefaultPosition, wx.DefaultSize, 0) + btnSizer.Add(self.btnPrices, 0, wx.ALL, 5) + + mainSizer.Add(btnSizer, 0, wx.EXPAND, 5) + + self.btnDeleteDamagePatterns.Bind(wx.EVT_BUTTON, self.DeleteDamagePatterns) + self.btnDeleteTargetResists.Bind(wx.EVT_BUTTON, self.DeleteTargetResists) + self.btnPrices.Bind(wx.EVT_BUTTON, self.DeletePrices) panel.SetSizer(mainSizer) panel.Layout() + def DeleteDamagePatterns(self, event): + question = u"This is a destructive action that will delete all damage pattern profiles.\nAre you sure you want to do this?" + if wxHelpers.YesNoDialog(question): + for damage_pattern in getDamagePatternList(): + remove(damage_pattern) + DefaultDatabaseValues.importRequiredDefaults() + + def DeleteTargetResists(self, event): + question = u"This is a destructive action that will delete all target resist profiles.\nAre you sure you want to do this?" + if wxHelpers.YesNoDialog(question): + for target_resist in getTargetResistsList(): + remove(target_resist) + DefaultDatabaseValues.importRequiredDefaults() + + def DeletePrices(self, event): + question = u"This is a destructive action that will delete all cached prices out of the database.\nAre you sure you want to do this?" + if wxHelpers.YesNoDialog(question): + clearPrices() + def onCBsaveInRoot(self, event): # We don't want users to be able to actually change this, # so if they try and change it, set it back to the current setting @@ -86,26 +137,5 @@ class PFGeneralPref(PreferenceView): def getImage(self): return BitmapLoader.getBitmap("settings_database", "gui") - def OnWindowLeave(self, event): - # We don't want to do anything when they leave, - # but in the future we'd want to make sure settings - # changed get saved. - pass - - ''' - #Set database path - config.defPaths(self.inputFitDBPath.GetValue()) - - logger.debug("Running database import") - if self.cbimportDefaults is True: - # Import default database values - # Import values that must exist otherwise Pyfa breaks - DefaultDatabaseValues.importRequiredDefaults() - # Import default values for damage profiles - DefaultDatabaseValues.importDamageProfileDefaults() - # Import default values for target resist profiles - DefaultDatabaseValues.importResistProfileDefaults() - ''' - PFGeneralPref.register() diff --git a/gui/utils/helpers_wxPython.py b/gui/utils/helpers_wxPython.py new file mode 100644 index 000000000..79f8ed206 --- /dev/null +++ b/gui/utils/helpers_wxPython.py @@ -0,0 +1,8 @@ +import wx + + +def YesNoDialog(question=u'Are you sure you want to do this?', caption=u'Yes or no?'): + dlg = wx.MessageDialog(None, question, caption, wx.YES_NO | wx.ICON_QUESTION) + result = dlg.ShowModal() == wx.ID_YES + dlg.Destroy() + return result