From 25e30672fe70d8796d6e1bb4279836d7ea50399f Mon Sep 17 00:00:00 2001 From: blitzmann Date: Mon, 15 Dec 2014 18:32:03 -0500 Subject: [PATCH] Start conversion of various wait dialogs to wx.ProgresDialog. Implemented new wx.ProgresDialog for fitting backup --- eos/db/__init__.py | 2 +- eos/db/saveddata/queries.py | 5 +++++ gui/mainFrame.py | 28 +++++++++++++++++++++++----- service/fit.py | 12 +++++++----- service/port.py | 8 ++++++-- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/eos/db/__init__.py b/eos/db/__init__.py index bedb917d6..8867d63c5 100644 --- a/eos/db/__init__.py +++ b/eos/db/__init__.py @@ -75,7 +75,7 @@ from eos.db.saveddata.queries import getUser, getCharacter, getFit, getFitsWithS getFitList, getFleetList, getFleet, save, remove, commit, add, \ getCharactersForUser, getMiscData, getSquadsIDsWithFitID, getWing, \ getSquad, getBoosterFits, getProjectedFits, getTargetResistsList, getTargetResists,\ - clearPrices + clearPrices, countAllFits #If using in memory saveddata, you'll want to reflect it so the data structure is good. if config.saveddata_connectionstring == "sqlite:///:memory:": diff --git a/eos/db/saveddata/queries.py b/eos/db/saveddata/queries.py index 9fee22561..be7c078fc 100644 --- a/eos/db/saveddata/queries.py +++ b/eos/db/saveddata/queries.py @@ -267,6 +267,11 @@ def getBoosterFits(ownerID=None, where=None, eager=None): fits = saveddata_session.query(Fit).options(*eager).filter(filter).all() return fits +def countAllFits(): + with sd_lock: + count = saveddata_session.query(Fit).count() + return count + def countFitsWithShip(shipID, ownerID=None, where=None, eager=None): """ Get all the fits using a certain ship. diff --git a/gui/mainFrame.py b/gui/mainFrame.py index 2d71da48a..0c507b1ce 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -54,6 +54,9 @@ from gui.utils.clipboard import toClipboard, fromClipboard from gui.fleetBrowser import FleetBrowser from gui.updateDialog import UpdateDialog from gui.builtinViews import * + +from time import gmtime, strftime + import locale locale.setlocale(locale.LC_ALL, '') @@ -571,22 +574,37 @@ class MainFrame(wx.Frame): pass dlg.Destroy() + def updateProgressDialog(self,count): + if count == -1: + self.progressDialog.Destroy() + else: + self.progressDialog.Update(count) + def backupToXml(self, event): sFit = service.Fit.getInstance() + + defaultFile = "pyfa-fits-%s.xml"%strftime("%Y%m%d_%H%M%S", gmtime()) + saveDialog = wx.FileDialog( self, "Save Backup As...", wildcard = "EVE XML fitting file (*.xml)|*.xml", - style = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) + style = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, + defaultFile=defaultFile) + if (saveDialog.ShowModal() == wx.ID_OK): filePath = saveDialog.GetPath() if '.' not in os.path.basename(filePath): filePath += ".xml" - self.waitDialog = animUtils.WaitDialog(self) - sFit.backupFits(filePath, self.closeWaitDialog) - self.waitDialog.ShowModal() - saveDialog.Destroy() + max = sFit.countAllFits() + self.progressDialog = wx.ProgressDialog("Backup fits", + "Backing up %d fits to: %s"%(max, filePath), + maximum = max, parent=self, + style = wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME) + + sFit.backupFits(filePath, self.updateProgressDialog) + self.progressDialog.ShowModal() def exportSkillsNeeded(self, event): sCharacter = service.Character.getInstance() diff --git a/service/fit.py b/service/fit.py index e731c3edf..a9005e5a5 100644 --- a/service/fit.py +++ b/service/fit.py @@ -47,12 +47,11 @@ class FitBackupThread(threading.Thread): path = self.path sFit = Fit.getInstance() allFits = map(lambda x: x[0], sFit.getAllFits()) - backedUpFits = sFit.exportXml(*allFits) + backedUpFits = sFit.exportXml(self.callback, *allFits) backupFile = open(path, "w", encoding="utf-8") backupFile.write(backedUpFits) backupFile.close() - wx.CallAfter(self.callback) - + wx.CallAfter(self.callback, -1) class FitImportThread(threading.Thread): def __init__(self, paths, callback): @@ -127,6 +126,9 @@ class Fit(object): return names + def countAllFits(self): + return eos.db.countAllFits() + def countFitsWithShip(self, shipID): count = eos.db.countFitsWithShip(shipID) return count @@ -758,9 +760,9 @@ class Fit(object): fit = eos.db.getFit(fitID) return Port.exportDna(fit) - def exportXml(self, *fitIDs): + def exportXml(self, callback = None, *fitIDs): fits = map(lambda fitID: eos.db.getFit(fitID), fitIDs) - return Port.exportXml(*fits) + return Port.exportXml(callback, *fits) def backupFits(self, path, callback): thread = FitBackupThread(path, callback) diff --git a/service/port.py b/service/port.py index b69a69007..535665d3d 100644 --- a/service/port.py +++ b/service/port.py @@ -23,6 +23,7 @@ import json from eos.types import State, Slot, Module, Cargo, Fit, Ship, Drone, Implant, Booster import service +import wx try: from collections import OrderedDict @@ -503,11 +504,11 @@ class Port(object): return dna + "::" @classmethod - def exportXml(cls, *fits): + def exportXml(cls, callback=None, *fits): doc = xml.dom.minidom.Document() fittings = doc.createElement("fittings") doc.appendChild(fittings) - for fit in fits: + for i, fit in enumerate(fits): try: fitting = doc.createElement("fitting") fitting.setAttribute("name", fit.name) @@ -571,5 +572,8 @@ class Port(object): except: print "Failed on fitID: %d"%fit.ID continue + finally: + if callback: + wx.CallAfter(callback, i) return doc.toprettyxml()