import threading
import time
import service
import wx
class exportHtml():
_instance = None
@classmethod
def getInstance(cls):
if cls._instance == None:
cls._instance = exportHtml()
return cls._instance
def __init__(self):
self.thread = exportHtmlThread()
def refreshFittingHtml(self, force = False, callback = False):
settings = service.settings.HTMLExportSettings.getInstance()
if (force or settings.getEnabled()):
self.thread.stop()
self.thread = exportHtmlThread(callback)
self.thread.start()
class exportHtmlThread(threading.Thread):
def __init__(self, callback = False):
threading.Thread.__init__(self)
self.callback = callback
self.stopRunning = False
def stop(self):
self.stopRunning = True
def run(self):
# wait 1 second just in case a lot of modifications get made
time.sleep(1);
if self.stopRunning:
return;
sMkt = service.Market.getInstance()
sFit = service.Fit.getInstance()
settings = service.settings.HTMLExportSettings.getInstance()
timestamp = time.localtime(time.time())
localDate = "%d/%02d/%02d %02d:%02d" % (timestamp[0], timestamp[1], timestamp[2], timestamp[3], timestamp[4])
HTML = """
Pyfa Fittings
Pyfa fits
Last updated: %s ()
""" % (time.time(), localDate)
HTML += '
\n'
categoryList = list(sMkt.getShipRoot())
categoryList.sort(key=lambda ship: ship.name)
for group in categoryList:
# init market group string to give ships something to attach to
HTMLgroup = ''
ships = list(sMkt.getShipList(group.ID))
ships.sort(key=lambda ship: ship.name)
# Keep track of how many ships per group
groupFits = 0
for ship in ships:
fits = sFit.getFitsWithShip(ship.ID)
if len(fits) > 0:
groupFits += len(fits)
if len(fits) == 1:
if self.stopRunning:
return
fit = fits[0]
dnaFit = sFit.exportDna(fit[0])
HTMLgroup += (
'