Made file import threaded with nice animation
This commit is contained in:
@@ -253,14 +253,17 @@ class MainFrame(wx.Frame):
|
||||
wildcard = "EFT text fitting files (*.cfg)|*.cfg|EvE XML fitting files (*.xml)|*.xml|All Files (*)|*",
|
||||
style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE)
|
||||
if (dlg.ShowModal() == wx.ID_OK):
|
||||
# try:
|
||||
for importPath in dlg.GetPaths():
|
||||
fits += sFit.importFit(importPath)
|
||||
IDs = sFit.saveImportedFits(fits)
|
||||
self._openAfterImport(len(fits), IDs)
|
||||
# except:
|
||||
# wx.MessageBox("Error importing from file.", "Error", wx.OK | wx.ICON_ERROR, self)
|
||||
dlg.Destroy()
|
||||
self.waitDialog = animUtils.WaitDialog(self, title = "Importing")
|
||||
sFit.importFitsThreaded(dlg.GetPaths(), self.importCallback)
|
||||
dlg.Destroy()
|
||||
self.waitDialog.ShowModal()
|
||||
|
||||
|
||||
def importCallback(self, fits):
|
||||
self.waitDialog.Destroy()
|
||||
sFit = service.Fit.getInstance()
|
||||
IDs = sFit.saveImportedFits(fits)
|
||||
self._openAfterImport(len(fits), IDs)
|
||||
|
||||
def _openAfterImport(self, importCount, fitIDs):
|
||||
if importCount == 1:
|
||||
|
||||
@@ -48,6 +48,20 @@ class FitBackupThread(threading.Thread):
|
||||
backupFile.close()
|
||||
wx.CallAfter(self.callback)
|
||||
|
||||
class FitImportThread(threading.Thread):
|
||||
def __init__(self, paths, callback):
|
||||
threading.Thread.__init__(self)
|
||||
self.paths = paths
|
||||
self.callback = callback
|
||||
|
||||
def run(self):
|
||||
importedFits = []
|
||||
paths = self.paths
|
||||
sFit = Fit.getInstance()
|
||||
for path in paths:
|
||||
importedFits += sFit.importFit(path)
|
||||
wx.CallAfter(self.callback, importedFits)
|
||||
|
||||
class Fit(object):
|
||||
instance = None
|
||||
@classmethod
|
||||
@@ -513,6 +527,10 @@ class Fit(object):
|
||||
thread = FitBackupThread(path, callback)
|
||||
thread.start()
|
||||
|
||||
def importFitsThreaded(self, paths, callback):
|
||||
thread = FitImportThread(paths, callback)
|
||||
thread.start()
|
||||
|
||||
def importFit(self, path):
|
||||
filename = os.path.split(path)[1]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user