Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option for HTML Export, to produce a minimal html version #611

Merged
merged 2 commits into from
May 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions gui/builtinPreferenceViews/pyfaHTMLExportPreferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class PFHTMLExportPref ( PreferenceView):
desc2 = "Enabling automatic exporting will update the HTML file after any change "+\
"to a fit is made. Under certain circumstance, this may cause performance issues."
desc3 = "Preferred website to view fits while not using in-game browser can be selected below."
desc4 = "Export Fittings in a minmal HTML Version, just containing the Fittingslinks " +\
"without any visual styling or javscript features"

def populatePanel( self, panel ):
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
Expand Down Expand Up @@ -57,6 +59,17 @@ def populatePanel( self, panel ):
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.stDesc4 = wx.StaticText( panel, wx.ID_ANY, self.desc4, wx.DefaultPosition, wx.DefaultSize, 0 )
self.stDesc4.Wrap(dlgWidth - 50)
mainSizer.Add( self.stDesc4, 0, wx.ALL, 5 )

self.exportMinimal = wx.CheckBox( panel, wx.ID_ANY, u"Enable minimal export Format", wx.DefaultPosition, wx.DefaultSize, 0 )
self.exportMinimal.SetValue(self.HTMLExportSettings.getMinimalEnabled())
self.exportMinimal.Bind(wx.EVT_CHECKBOX, self.OnMinimalEnabledChange)
mainSizer.Add( self.exportMinimal, 0, wx.ALL|wx.EXPAND, 5 )

self.stDesc3 = wx.StaticText( panel, wx.ID_ANY, self.desc3, wx.DefaultPosition, wx.DefaultSize, 0 )
self.stDesc3.Wrap(dlgWidth - 50)
Expand Down Expand Up @@ -93,6 +106,9 @@ def selectHTMLExportFilePath(self, event):

def OnExportEnabledChange(self, event):
self.HTMLExportSettings.setEnabled(self.exportEnabled.GetValue())

def OnMinimalEnabledChange(self, event):
self.HTMLExportSettings.setMinimalEnabled(self.exportMinimal.GetValue())

def OnCHWebsiteTypeSelect(self, event):
choice = self.chWebsiteType.GetStringSelection()
Expand Down
76 changes: 65 additions & 11 deletions gui/utils/exportHtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,36 @@ def run(self):
timestamp = time.localtime(time.time())
localDate = "%d/%02d/%02d %02d:%02d" % (timestamp[0], timestamp[1], timestamp[2], timestamp[3], timestamp[4])

minimal = settings.getMinimalEnabled();
website = settings.getWebsite()
if website == "o.smium.org":
dnaUrl = "https://o.smium.org/loadout/dna/"
elif website == "null-sec.com":
dnaUrl = "https://null-sec.com/hangar/?dna="

if minimal:
HTML = self.generateMinimalHTML(sMkt,sFit, dnaUrl)
else:
HTML = self.generateFullHTML(sMkt,sFit, dnaUrl)

try:
FILE = open(settings.getPath(), "w")
FILE.write(HTML.encode('utf-8'))
FILE.close()
except IOError:
print "Failed to write to " + settings.getPath()
pass

if self.callback:
wx.CallAfter(self.callback, -1)



def generateFullHTML(self,sMkt,sFit,dnaUrl):
""" Generate the complete HTML with styling and javascript """
timestamp = time.localtime(time.time())
localDate = "%d/%02d/%02d %02d:%02d" % (timestamp[0], timestamp[1], timestamp[2], timestamp[3], timestamp[4])

HTML = """
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -130,7 +154,7 @@ def run(self):
$('a[data-dna]').each(function( index ) {
var dna = $(this).data('dna');
if (typeof CCPEVE !== 'undefined') { // inside IGB
$(this).attr('href', 'javascript:CCPEVE.showFitting("'+dna+'");'); }
$(this).attr('href', 'javascript:CCPEVE.showFitting("'+dna+'");');}
else { // outside IGB
$(this).attr('href', '%s'+dna); }
});
Expand Down Expand Up @@ -217,16 +241,46 @@ def run(self):
</div>
</div>
</body>
</html>"""
</html>"""

try:
FILE = open(settings.getPath(), "w")
FILE.write(HTML.encode('utf-8'))
FILE.close()
except IOError:
print "Failed to write to " + settings.getPath()
pass

if self.callback:
wx.CallAfter(self.callback, -1)
return HTML




def generateMinimalHTML(self,sMkt,sFit,dnaUrl):
""" Generate a minimal HTML version of the fittings, without any javascript or styling"""
categoryList = list(sMkt.getShipRoot())
categoryList.sort(key=lambda ship: ship.name)

count = 0
HTML = ''
for group in categoryList:
# init market group string to give ships something to attach to


ships = list(sMkt.getShipList(group.ID))
ships.sort(key=lambda ship: ship.name)

ships.sort(key=lambda ship: ship.name)

for ship in ships:
fits = sFit.getFitsWithShip(ship.ID)
for fit in fits:
if self.stopRunning:
return
try:
dnaFit = sFit.exportDna(fit[0])
HTML += '<a class="inGameBrowserLink" target="_blank" href=javascript:CCPEVE.showFitting("'+dnaFit+'");>IGB</a>' +\
' / <a class="outOfGameBrowserLink" target="_blank" href="' + dnaUrl + dnaFit + '">OOGB</a> '+ship.name +': '+ fit[1]+ '<br> \n'
except:
continue
finally:
if self.callback:
wx.CallAfter(self.callback, count)
count += 1
return HTML;



10 changes: 9 additions & 1 deletion service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,22 @@ def getInstance(cls):
return cls._instance

def __init__(self):
serviceHTMLExportDefaultSettings = {"enabled": False, "path": config.pyfaPath + os.sep + 'pyfaFits.html', "website": "null-sec.com" }
serviceHTMLExportDefaultSettings = {"enabled": False, "path": config.pyfaPath + os.sep + 'pyfaFits.html', "website": "null-sec.com", "minimal": False }
self.serviceHTMLExportSettings = SettingsProvider.getInstance().getSettings("pyfaServiceHTMLExportSettings", serviceHTMLExportDefaultSettings)

def getEnabled(self):
return self.serviceHTMLExportSettings["enabled"]

def setEnabled(self, enabled):
self.serviceHTMLExportSettings["enabled"] = enabled


def getMinimalEnabled(self):
return self.serviceHTMLExportSettings["minimal"]

def setMinimalEnabled(self, minimal):
self.serviceHTMLExportSettings["minimal"] = minimal


def getPath(self):
return self.serviceHTMLExportSettings["path"]
Expand Down