diff --git a/gui/mainFrame.py b/gui/mainFrame.py
index 0c507b1ce..053fe08f7 100644
--- a/gui/mainFrame.py
+++ b/gui/mainFrame.py
@@ -336,21 +336,32 @@ class MainFrame(wx.Frame):
dlg=wx.FileDialog(
self,
"Open One Or More Fitting Files",
- wildcard = "EFT text fitting files (*.cfg)|*.cfg|" \
- "EVE XML fitting files (*.xml)|*.xml|" \
+ wildcard = "EVE XML fitting files (*.xml)|*.xml|" \
+ "EFT text fitting files (*.cfg)|*.cfg|" \
"All Files (*)|*",
style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE)
if (dlg.ShowModal() == wx.ID_OK):
- 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)
+ self.progressDialog = wx.ProgressDialog("Importing fits", " "*100, parent=self,
+ style = wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME)
+ self.progressDialog.message = None
+ sFit.importFitsThreaded(dlg.GetPaths(), self.importCallback)
+ self.progressDialog.ShowModal()
+ dlg.Destroy()
+
+ def importCallback(self, info):
+ if info == -1:
+ self.progressDialog.Destroy()
+ elif info != self.progressDialog.message and info is not None:
+ self.progressDialog.message = info
+ self.progressDialog.Pulse(info)
+ else:
+ self.progressDialog.Pulse()
+
+ # @todo: implement saveImportedFits where needed, modify _openAfterImport
+ #sFit = service.Fit.getInstance()
+ #IDs = sFit.saveImportedFits(fits)
+ #self._openAfterImport(len(fits), IDs)
def _openAfterImport(self, importCount, fitIDs):
if importCount == 1:
diff --git a/service/fit.py b/service/fit.py
index a9005e5a5..3c5faa9fc 100644
--- a/service/fit.py
+++ b/service/fit.py
@@ -17,7 +17,6 @@
# along with pyfa. If not, see .
#===============================================================================
-import os.path
import locale
import copy
import threading
@@ -53,6 +52,7 @@ class FitBackupThread(threading.Thread):
backupFile.close()
wx.CallAfter(self.callback, -1)
+
class FitImportThread(threading.Thread):
def __init__(self, paths, callback):
threading.Thread.__init__(self)
@@ -60,14 +60,10 @@ class FitImportThread(threading.Thread):
self.callback = callback
def run(self):
- importedFits = []
- paths = self.paths
sFit = Fit.getInstance()
- for path in paths:
- pathImported = sFit.importFit(path)
- if pathImported is not None:
- importedFits += pathImported
- wx.CallAfter(self.callback, importedFits)
+ sFit.importFitFromFiles(self.paths, self.callback)
+
+ wx.CallAfter(self.callback, -1)
class Fit(object):
@@ -772,26 +768,37 @@ class Fit(object):
thread = FitImportThread(paths, callback)
thread.start()
- def importFit(self, path):
- filename = os.path.split(path)[1]
-
+ def importFitFromFiles(self, paths, callback=None):
defcodepage = locale.getpreferredencoding()
- file = open(path, "r")
- srcString = file.read()
- # If file had ANSI encoding, convert it to unicode using system
- # default codepage, or use fallback cp1252 on any encoding errors
- if isinstance(srcString, str):
- try:
- srcString = unicode(srcString, defcodepage)
- except UnicodeDecodeError:
- srcString = unicode(srcString, "cp1252")
+ fitImport = []
+ for path in paths:
+ if callback: # Pulse
+ wx.CallAfter(callback, "Processing file:\n%s"%path)
- _, fits = Port.importAuto(srcString, filename)
- for fit in fits:
+ file = open(path, "r")
+ srcString = file.read()
+ # If file had ANSI encoding, convert it to unicode using system
+ # default codepage, or use fallback cp1252 on any encoding errors
+ if isinstance(srcString, str):
+ try:
+ srcString = unicode(srcString, defcodepage)
+ except UnicodeDecodeError:
+ srcString = unicode(srcString, "cp1252")
+
+ _, fits = Port.importAuto(srcString, path, callback=callback)
+ fitImport += fits
+
+ IDs = []
+ for i, fit in enumerate(fitImport):
fit.character = self.character
fit.damagePattern = self.pattern
fit.targetResists = self.targetResists
+ eos.db.save(fit)
+ IDs.append(fit.ID)
+ if callback: # Pulse
+ wx.CallAfter(callback, "Saving fit\n%d/%d"%(i+1, len(fitImport)))
+
return fits
def importFitFromBuffer(self, bufferStr, activeFit=None):
diff --git a/service/port.py b/service/port.py
index 535665d3d..800447d19 100644
--- a/service/port.py
+++ b/service/port.py
@@ -19,7 +19,6 @@
import re
import xml.dom
-import json
from eos.types import State, Slot, Module, Cargo, Fit, Ship, Drone, Implant, Booster
import service
@@ -36,20 +35,20 @@ class Port(object):
"""Service which houses all import/export format functions"""
@classmethod
- def importAuto(cls, string, sourceFileName=None, activeFit=None):
+ def importAuto(cls, string, sourceFileName=None, activeFit=None, callback=None):
# Get first line and strip space symbols of it to avoid possible detection errors
firstLine = re.split("[\n\r]+", string.strip(), maxsplit=1)[0]
firstLine = firstLine.strip()
# If XML-style start of tag encountered, detect as XML
if re.match("<", firstLine):
- return "XML", cls.importXml(string)
+ return "XML", cls.importXml(string, callback)
# If we've got source file name which is used to describe ship name
# and first line contains something like [setup name], detect as eft config file
if re.match("\[.*\]", firstLine) and sourceFileName is not None:
shipName = sourceFileName.rsplit('.')[0]
- return "EFT Config", cls.importEftCfg(shipName, string)
+ return "EFT Config", cls.importEftCfg(shipName, string, callback)
# If no file is specified and there's comma between brackets,
# consider that we have [ship, setup name] and detect like eft export format
@@ -201,7 +200,7 @@ class Port(object):
return fit
@staticmethod
- def importEftCfg(shipname, contents):
+ def importEftCfg(shipname, contents, callback=None):
"""Handle import from EFT config store file"""
# Check if we have such ship in database, bail if we don't
@@ -347,6 +346,9 @@ class Port(object):
f.modules.append(m)
# Append fit to list of fits
fits.append(f)
+
+ if callback:
+ wx.CallAfter(callback, None)
# Skip fit silently if we get an exception
except Exception:
pass
@@ -354,14 +356,16 @@ class Port(object):
return fits
@staticmethod
- def importXml(text):
+ def importXml(text, callback=None):
sMkt = service.Market.getInstance()
doc = xml.dom.minidom.parseString(text.encode("utf-8"))
fittings = doc.getElementsByTagName("fittings").item(0)
fittings = fittings.getElementsByTagName("fitting")
fits = []
- for fitting in fittings:
+
+ for i, fitting in enumerate(fittings):
+ print "fitting"
f = Fit()
f.name = fitting.getAttribute("name")
# Maelstrom
@@ -403,6 +407,8 @@ class Port(object):
except KeyboardInterrupt:
continue
fits.append(f)
+ if callback:
+ wx.CallAfter(callback, None)
return fits