Implement fit backup in a seperate thread with a (not so) pwetty dialog

This commit is contained in:
cncfanatics
2010-11-04 07:17:58 +01:00
parent 397c14c6f2
commit 73ed7a2d05
2 changed files with 34 additions and 8 deletions

View File

@@ -334,9 +334,15 @@ class MainFrame(wx.Frame):
filePath = saveDialog.GetPath()
if '.' not in os.path.basename(filePath):
filePath += ".xml"
sFit.backupFits(filePath )
self.waitDialog = WaitDialog(self)
sFit.backupFits(filePath, self.closeWaitDialog)
self.waitDialog.ShowModal()
saveDialog.Destroy()
def closeWaitDialog(self):
self.waitDialog.Destroy()
def toggleShipBrowser(self, event):
self.GetToolBar().toggleShipBrowser(event)
@@ -352,3 +358,9 @@ class MainFrame(wx.Frame):
wnd = self
InspectionTool().Show(wnd, True)
class WaitDialog(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__ (self, parent, id=wx.ID_ANY, title=u"Please wait ...", size=wx.Size(200, 100),
style=wx.DEFAULT_FRAME_STYLE | wx.FRAME_FLOAT_ON_PARENT | wx.TAB_TRAVERSAL)
wx.StaticText(self, wx.ID_ANY, "Please wait ...")

View File

@@ -23,6 +23,24 @@ from eos.types import State, Slot
import copy
from service.damagePattern import DamagePattern
from service.character import Character
import threading
import wx
class FitBackupThread(threading.Thread):
def __init__(self, path, callback):
threading.Thread.__init__(self)
self.path = path
self.callback = callback
def run(self):
path = self.path
sFit = Fit.getInstance()
allFits = map(lambda x: x[0], sFit.getAllFits())
backedUpFits = sFit.exportXml(*allFits)
backupFile = open(path, "w")
backupFile.write(backedUpFits)
backupFile.close()
wx.CallAfter(self.callback)
class Fit(object):
instance = None
@@ -45,7 +63,6 @@ class Fit(object):
return names
def getFitsWithShip(self, id):
fits = eos.db.getFitsWithShip(id)
names = []
@@ -469,12 +486,9 @@ class Fit(object):
fits = map(lambda id: eos.db.getFit(id), fitIDs)
return eos.types.Fit.exportXml(*fits)
def backupFits(self, path):
allFits = map(lambda x: x[0], self.getAllFits())
backedUpFits = self.exportXml(*allFits)
backupFile = open(path, "w")
backupFile.write(backedUpFits)
backupFile.close()
def backupFits(self, path, callback):
thread = FitBackupThread(path, callback)
thread.start()
def importFit(self, path):
f = file(path)