Add html export support
This commit is contained in:
@@ -1 +1 @@
|
||||
__all__ = ["pyfaGlobalPreferences"]
|
||||
__all__ = ["pyfaGlobalPreferences","pyfaHTMLExportPreferences"]
|
||||
|
||||
74
gui/builtinPreferenceViews/pyfaHTMLExportPreferences.py
Normal file
74
gui/builtinPreferenceViews/pyfaHTMLExportPreferences.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import wx
|
||||
import service
|
||||
import urllib2
|
||||
import os
|
||||
|
||||
from gui.preferenceView import PreferenceView
|
||||
from gui import bitmapLoader
|
||||
|
||||
import gui.mainFrame
|
||||
import service
|
||||
import gui.globalEvents as GE
|
||||
|
||||
|
||||
class PFHTMLExportPref ( PreferenceView):
|
||||
title = "Pyfa HTML Export Options"
|
||||
desc = """Turning this feature on will create a HTML file at the specified location
|
||||
with all your fits in it. If you browse to this HTML file from the
|
||||
in-game browser you can easily view and import your fits by clicking on them.
|
||||
The file will be updated every time a fit changes or gets added.
|
||||
"""
|
||||
|
||||
def populatePanel( self, panel ):
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.HTMLExportSettings = service.settings.HTMLExportSettings.getInstance()
|
||||
self.dirtySettings = False
|
||||
|
||||
mainSizer = wx.BoxSizer( wx.VERTICAL )
|
||||
|
||||
self.stTitle = wx.StaticText( panel, wx.ID_ANY, self.title, wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
self.stTitle.Wrap( -1 )
|
||||
self.stTitle.SetFont( wx.Font( 12, 70, 90, 90, False, wx.EmptyString ) )
|
||||
mainSizer.Add( self.stTitle, 0, wx.ALL, 5 )
|
||||
|
||||
self.stDesc = wx.StaticText( panel, wx.ID_ANY, self.desc, wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
mainSizer.Add( self.stDesc, 0, wx.ALL, 5 )
|
||||
|
||||
self.exportEnabled = wx.CheckBox( panel, wx.ID_ANY, u"Enable HTML export", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
self.exportEnabled.SetValue(self.HTMLExportSettings.getEnabled())
|
||||
self.exportEnabled.Bind(wx.EVT_CHECKBOX, self.OnExportEnabledChange)
|
||||
mainSizer.Add( self.exportEnabled, 0, wx.ALL|wx.EXPAND, 5 )
|
||||
|
||||
self.PathLinkCtrl = wx.HyperlinkCtrl( panel, wx.ID_ANY, str(self.HTMLExportSettings.getPath()), 'file:///' + str(self.HTMLExportSettings.getPath()), wx.DefaultPosition, wx.DefaultSize, wx.HL_ALIGN_LEFT|wx.NO_BORDER|wx.HL_CONTEXTMENU )
|
||||
mainSizer.Add( self.PathLinkCtrl, 0, wx.ALL|wx.EXPAND, 5)
|
||||
|
||||
self.fileSelectDialog = wx.FileDialog(None, "Save Fitting As...", wildcard = "EvE IGB HTML fitting file (*.html)|*.html", style = wx.FD_SAVE)
|
||||
self.fileSelectDialog.SetPath(self.HTMLExportSettings.getPath())
|
||||
self.fileSelectDialog.SetFilename(os.path.basename(self.HTMLExportSettings.getPath()));
|
||||
|
||||
self.fileSelectButton = wx.Button(panel, -1, "Set export destination", pos=(0,0))
|
||||
self.fileSelectButton.Bind(wx.EVT_BUTTON, self.selectHTMLExportFilePath)
|
||||
mainSizer.Add( self.fileSelectButton, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
|
||||
panel.SetSizer( mainSizer )
|
||||
panel.Layout()
|
||||
|
||||
def setPathLinkCtrlValues(self, path):
|
||||
self.PathLinkCtrl.SetLabel(self.HTMLExportSettings.getPath())
|
||||
self.PathLinkCtrl.SetURL('file:///' + self.HTMLExportSettings.getPath())
|
||||
self.PathLinkCtrl.SetSize(wx.DefaultSize);
|
||||
self.PathLinkCtrl.Refresh()
|
||||
|
||||
def selectHTMLExportFilePath(self, event):
|
||||
if self.fileSelectDialog.ShowModal() == wx.ID_OK:
|
||||
self.HTMLExportSettings.setPath(self.fileSelectDialog.GetPath())
|
||||
self.dirtySettings = True
|
||||
self.setPathLinkCtrlValues(self.HTMLExportSettings.getPath())
|
||||
|
||||
def OnExportEnabledChange(self, event):
|
||||
self.HTMLExportSettings.setEnabled(self.exportEnabled.GetValue())
|
||||
|
||||
def getImage(self):
|
||||
return bitmapLoader.getBitmap("pyfa64", "icons")
|
||||
|
||||
PFHTMLExportPref.register()
|
||||
@@ -30,6 +30,7 @@ from eos.types import Slot
|
||||
from gui.builtinViewColumns.state import State
|
||||
from gui import bitmapLoader
|
||||
import gui.builtinViews.emptyView
|
||||
from gui.utils.exportHtml import exportHtml
|
||||
|
||||
import gui.globalEvents as GE
|
||||
|
||||
@@ -374,13 +375,17 @@ class FittingView(d.Display):
|
||||
if self.activeFitID is not None and self.activeFitID == event.fitID:
|
||||
self.generateMods()
|
||||
self.refresh(self.mods)
|
||||
|
||||
|
||||
exportHtml.getInstance().refreshFittingHTMl()
|
||||
|
||||
self.Show(self.activeFitID is not None and self.activeFitID == event.fitID)
|
||||
except wx._core.PyDeadObjectError:
|
||||
pass
|
||||
finally:
|
||||
event.Skip()
|
||||
|
||||
|
||||
|
||||
def scheduleMenu(self, event):
|
||||
event.Skip()
|
||||
if self.getColumn(event.Position) != self.getColIndex(State):
|
||||
|
||||
95
gui/utils/exportHtml.py
Normal file
95
gui/utils/exportHtml.py
Normal file
@@ -0,0 +1,95 @@
|
||||
import threading
|
||||
import time
|
||||
import service
|
||||
|
||||
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):
|
||||
settings = service.settings.HTMLExportSettings.getInstance()
|
||||
|
||||
if (settings.getEnabled()):
|
||||
self.thread.stop()
|
||||
self.thread = exportHtmlThread()
|
||||
self.thread.start()
|
||||
|
||||
class exportHtmlThread(threading.Thread):
|
||||
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
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;
|
||||
|
||||
sMarket = service.Market.getInstance()
|
||||
sFit = service.Fit.getInstance()
|
||||
settings = service.settings.HTMLExportSettings.getInstance()
|
||||
|
||||
HTML = """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>My Page</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
|
||||
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
|
||||
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="canvas" data-role="page">
|
||||
<div data-role="header">
|
||||
<h1>PyFa fits</h1>
|
||||
</div>
|
||||
<div data-role="content">
|
||||
"""
|
||||
|
||||
HTML += '<ul data-role="listview" data-inset="true" data-filter="true">';
|
||||
categoryList = [];
|
||||
self.categoryList = list(sMarket.getShipRoot())
|
||||
self.categoryList.sort(key=lambda ship: ship.name)
|
||||
for shipType in self.categoryList:
|
||||
ships = sMarket.getShipList(shipType.ID)
|
||||
for ship in ships:
|
||||
HTMLship = '<li><h2>' + ship.name + '</h2><ul>'
|
||||
fits = sFit.getFitsWithShip(ship.ID)
|
||||
for fit in fits:
|
||||
if self.stopRunning:
|
||||
return;
|
||||
dnaFit = sFit.exportDna(fit[0])
|
||||
HTMLship += "<li><a href=\"javascript:CCPEVE.showFitting('" + dnaFit + "');\" >" + fit[1] + "</a></li>"
|
||||
|
||||
HTMLship += "</ul></li>"
|
||||
if len(fits) > 0:
|
||||
HTML += HTMLship
|
||||
|
||||
HTML += """
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
"""
|
||||
|
||||
try:
|
||||
FILE = open(settings.getPath(), "w")
|
||||
FILE.write(HTML);
|
||||
FILE.close();
|
||||
except IOError:
|
||||
print "Failed to write to " + settings.getPath()
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user