From e245891cb4c1af8a9e8726df39ac1c819db4ee11 Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Mon, 10 Apr 2017 10:53:36 -0700 Subject: [PATCH 1/4] Add delete buttons --- .../pyfaDatabasePreferences.py | 78 +++++++++++++------ gui/utils/helpers_wxPython.py | 8 ++ 2 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 gui/utils/helpers_wxPython.py 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 From 73821cbe49813231af2e0a0ad8dd4a8487f749ce Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Mon, 10 Apr 2017 10:58:35 -0700 Subject: [PATCH 2/4] Formatting --- gui/builtinPreferenceViews/pyfaDatabasePreferences.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/builtinPreferenceViews/pyfaDatabasePreferences.py b/gui/builtinPreferenceViews/pyfaDatabasePreferences.py index 6b48d08bf..fc564ca42 100644 --- a/gui/builtinPreferenceViews/pyfaDatabasePreferences.py +++ b/gui/builtinPreferenceViews/pyfaDatabasePreferences.py @@ -76,7 +76,7 @@ class PFGeneralPref(PreferenceView): 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.)", + 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) From efaede0929c6adab7db7488dd954bde5f1ac5bdf Mon Sep 17 00:00:00 2001 From: blitzmann Date: Mon, 10 Apr 2017 21:40:08 -0400 Subject: [PATCH 3/4] Use queries to bulk-delete target resists and damage profiles --- eos/db/saveddata/queries.py | 14 ++++++++++++++ .../pyfaDatabasePreferences.py | 16 ++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) 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/builtinPreferenceViews/pyfaDatabasePreferences.py b/gui/builtinPreferenceViews/pyfaDatabasePreferences.py index fc564ca42..0fcc87e33 100644 --- a/gui/builtinPreferenceViews/pyfaDatabasePreferences.py +++ b/gui/builtinPreferenceViews/pyfaDatabasePreferences.py @@ -4,7 +4,7 @@ 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.queries import clearPrices, remove, clearDamagePatterns, clearTargetResists from eos.db.saveddata.loadDefaultDatabaseValues import DefaultDatabaseValues import logging @@ -107,21 +107,17 @@ class PFGeneralPref(PreferenceView): 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() + 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): - for target_resist in getTargetResistsList(): - remove(target_resist) - DefaultDatabaseValues.importRequiredDefaults() + 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): + if wxHelpers.YesNoDialog(question, "Confirm"): clearPrices() def onCBsaveInRoot(self, event): From 6f914386ec7fb768feab3d8e7f2f729913c8487e Mon Sep 17 00:00:00 2001 From: blitzmann Date: Mon, 10 Apr 2017 21:58:56 -0400 Subject: [PATCH 4/4] Remove unused function --- gui/builtinContextMenus/priceClear.py | 2 +- gui/builtinPreferenceViews/pyfaDatabasePreferences.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) 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 0fcc87e33..68c877444 100644 --- a/gui/builtinPreferenceViews/pyfaDatabasePreferences.py +++ b/gui/builtinPreferenceViews/pyfaDatabasePreferences.py @@ -4,8 +4,7 @@ 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, remove, clearDamagePatterns, clearTargetResists -from eos.db.saveddata.loadDefaultDatabaseValues import DefaultDatabaseValues +from eos.db.saveddata.queries import clearPrices, clearDamagePatterns, clearTargetResists import logging