diff --git a/eos/db/saveddata/queries.py b/eos/db/saveddata/queries.py index 4a58a8a82..1088c1b0f 100644 --- a/eos/db/saveddata/queries.py +++ b/eos/db/saveddata/queries.py @@ -332,6 +332,13 @@ def getDamagePatternList(eager=None): return patterns +def clearDamagePatterns(): + with sd_lock: + deleted_rows = saveddata_session.query(DamagePattern).filter(DamagePattern.name != 'Uniform').delete() + commit() + return deleted_rows + + def getTargetResistsList(eager=None): eager = processEager(eager) with sd_lock: @@ -339,6 +346,13 @@ def getTargetResistsList(eager=None): return patterns +def clearTargetResists(): + with sd_lock: + deleted_rows = saveddata_session.query(TargetResists).delete() + commit() + return deleted_rows + + def getImplantSetList(eager=None): eager = processEager(eager) with sd_lock: diff --git a/gui/builtinContextMenus/priceClear.py b/gui/builtinContextMenus/priceClear.py index b49673f96..9afdb0815 100644 --- a/gui/builtinContextMenus/priceClear.py +++ b/gui/builtinContextMenus/priceClear.py @@ -16,7 +16,7 @@ class PriceClear(ContextMenu): if not self.settings.get('priceClear'): return False - return srcContext == "priceViewFull" + return srcContext in ("priceViewFull", "priceViewMinimal") def getText(self, itmContext, selection): return "Reset Price Cache" diff --git a/gui/builtinPreferenceViews/pyfaDatabasePreferences.py b/gui/builtinPreferenceViews/pyfaDatabasePreferences.py index 608dc0197..68c877444 100644 --- a/gui/builtinPreferenceViews/pyfaDatabasePreferences.py +++ b/gui/builtinPreferenceViews/pyfaDatabasePreferences.py @@ -2,7 +2,9 @@ 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 clearPrices, clearDamagePatterns, clearTargetResists import logging @@ -66,13 +68,57 @@ 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, "Confirm"): + clearDamagePatterns() + + 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, "Confirm"): + clearTargetResists() + + 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, "Confirm"): + 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 +132,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