Start conversion of various wait dialogs to wx.ProgresDialog. Implemented new wx.ProgresDialog for fitting backup

This commit is contained in:
blitzmann
2014-12-15 18:32:03 -05:00
parent 1b3c058eab
commit 25e30672fe
5 changed files with 42 additions and 13 deletions

View File

@@ -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:":

View File

@@ -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.

View File

@@ -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()

View File

@@ -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)

View File

@@ -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()