diff --git a/gui/builtinPreferenceViews/__init__.py b/gui/builtinPreferenceViews/__init__.py
index 80439fce9..186166994 100644
--- a/gui/builtinPreferenceViews/__init__.py
+++ b/gui/builtinPreferenceViews/__init__.py
@@ -1 +1 @@
-__all__ = ["pyfaGlobalPreferences"]
+__all__ = ["pyfaGlobalPreferences","pyfaHTMLExportPreferences"]
diff --git a/gui/builtinPreferenceViews/pyfaHTMLExportPreferences.py b/gui/builtinPreferenceViews/pyfaHTMLExportPreferences.py
new file mode 100644
index 000000000..66a6dc2fd
--- /dev/null
+++ b/gui/builtinPreferenceViews/pyfaHTMLExportPreferences.py
@@ -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()
\ No newline at end of file
diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py
index 6f81f984a..dac586877 100644
--- a/gui/builtinViews/fittingView.py
+++ b/gui/builtinViews/fittingView.py
@@ -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):
diff --git a/gui/utils/exportHtml.py b/gui/utils/exportHtml.py
new file mode 100644
index 000000000..35f63769d
--- /dev/null
+++ b/gui/utils/exportHtml.py
@@ -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 = """
+
+
+
+ My Page
+
+
+
+
+
+
+
+
+
PyFa fits
+
+
+ """
+
+ HTML += '
';
+ 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 = '' + ship.name + '
'
+ fits = sFit.getFitsWithShip(ship.ID)
+ for fit in fits:
+ if self.stopRunning:
+ return;
+ dnaFit = sFit.exportDna(fit[0])
+ HTMLship += "- " + fit[1] + "
"
+
+ HTMLship += "
"
+ if len(fits) > 0:
+ HTML += HTMLship
+
+ HTML += """
+
+
+
+
+ """
+
+ try:
+ FILE = open(settings.getPath(), "w")
+ FILE.write(HTML);
+ FILE.close();
+ except IOError:
+ print "Failed to write to " + settings.getPath()
+ pass
+
diff --git a/service/settings.py b/service/settings.py
index ccb890a4d..8f6e3a8e9 100644
--- a/service/settings.py
+++ b/service/settings.py
@@ -1,182 +1,215 @@
-#===============================================================================
-# Copyright (C) 2010 Diego Duclos
-#
-# This file is part of pyfa.
-#
-# pyfa is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# pyfa is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with pyfa. If not, see .
-#===============================================================================
-
-import cPickle
-import os.path
-import config
-import urllib2
-
-class SettingsProvider():
- BASE_PATH = os.path.join(config.savePath, "settings")
- settings = {}
- _instance = None
- @classmethod
- def getInstance(cls):
- if cls._instance == None:
- cls._instance = SettingsProvider()
-
- return cls._instance
-
- def __init__(self):
- if not os.path.exists(self.BASE_PATH):
- os.mkdir(self.BASE_PATH);
-
- def getSettings(self, area, defaults=None):
- s = self.settings.get(area)
- if s is None:
- p = os.path.join(self.BASE_PATH, area)
-
- if not os.path.exists(p):
- info = {}
- if defaults:
- for item in defaults:
- info[item] = defaults[item]
-
- else:
- try:
- f = open(p, "rb")
- info = cPickle.load(f)
- for item in defaults:
- if item not in info:
- info[item] = defaults[item]
-
- except:
- info = {}
- if defaults:
- for item in defaults:
- info[item] = defaults[item]
-
- self.settings[area] = s = Settings(p, info)
-
- return s
-
- def saveAll(self):
- for settings in self.settings.itervalues():
- settings.save()
-
-class Settings():
- def __init__(self, location, info):
- self.location = location
- self.info = info
-
- def save(self):
- f = open(self.location, "wb")
- cPickle.dump(self.info, f, cPickle.HIGHEST_PROTOCOL)
-
- def __getitem__(self, k):
- return self.info[k]
-
- def __setitem__(self, k, v):
- self.info[k] = v
-
- def __iter__(self):
- return self.info.__iter__()
-
- def iterkeys(self):
- return self.info.iterkeys()
-
- def itervalues(self):
- return self.info.itervalues()
-
- def iteritems(self):
- return self.info.iteritems()
-
- def keys(self):
- return self.info.keys()
-
- def values(self):
- return self.info.values()
-
- def items(self):
- return self.info.items()
-
-class ProxySettings():
- _instance = None
- @classmethod
- def getInstance(cls):
- if cls._instance == None:
- cls._instance = ProxySettings()
-
- return cls._instance
-
- def __init__(self):
-
- # mode
- # 0 - No proxy
- # 1 - Auto-detected proxy settings
- # 2 - Manual proxy settings
- serviceProxyDefaultSettings = {"mode": 1, "type": "https", "address": "", "port": ""}
-
- self.serviceProxySettings = SettingsProvider.getInstance().getSettings("pyfaServiceProxySettings", serviceProxyDefaultSettings)
-
- def getMode(self):
- return self.serviceProxySettings["mode"]
-
- def getAddress(self):
- return self.serviceProxySettings["address"]
-
- def getPort(self):
- return self.serviceProxySettings["port"]
-
- def getType(self):
- return self.serviceProxySettings["type"]
-
- def setMode(self, mode):
- self.serviceProxySettings["mode"] = mode
-
- def setAddress(self, addr):
- self.serviceProxySettings["address"] = addr
-
- def setPort(self, port):
- self.serviceProxySettings["port"] = port
-
- def setType(self, type):
- self.serviceProxySettings["type"] = type
-
- def autodetect(self):
-
- proxy = None
- proxAddr = proxPort = ""
- proxydict = urllib2.ProxyHandler().proxies
- txt = "Auto-detected: "
-
- validPrefixes = ("http", "https")
-
- for prefix in validPrefixes:
- if not prefix in proxydict:
- continue
- proxyline = proxydict[prefix]
- proto = "{0}://".format(prefix)
- if proxyline[:len(proto)] == proto:
- proxyline = proxyline[len(proto):]
- proxAddr, proxPort = proxyline.split(":")
- proxPort = int(proxPort.rstrip("/"))
- proxy = (proxAddr, proxPort)
- break
-
- return proxy
-
- def getProxySettings(self):
-
- if self.getMode() == 0:
- return None
- if self.getMode() == 1:
- return self.autodetect()
- if self.getMode() == 2:
- return (self.getAddress(), int(self.getPort()))
\ No newline at end of file
+#===============================================================================
+# Copyright (C) 2010 Diego Duclos
+#
+# This file is part of pyfa.
+#
+# pyfa is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# pyfa is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with pyfa. If not, see .
+#===============================================================================
+
+import cPickle
+import os.path
+import config
+import urllib2
+
+class SettingsProvider():
+ BASE_PATH = os.path.join(config.savePath, "settings")
+ settings = {}
+ _instance = None
+ @classmethod
+ def getInstance(cls):
+ if cls._instance == None:
+ cls._instance = SettingsProvider()
+
+ return cls._instance
+
+ def __init__(self):
+ if not os.path.exists(self.BASE_PATH):
+ os.mkdir(self.BASE_PATH);
+
+ def getSettings(self, area, defaults=None):
+ s = self.settings.get(area)
+ if s is None:
+ p = os.path.join(self.BASE_PATH, area)
+
+ if not os.path.exists(p):
+ info = {}
+ if defaults:
+ for item in defaults:
+ info[item] = defaults[item]
+
+ else:
+ try:
+ f = open(p, "rb")
+ info = cPickle.load(f)
+ for item in defaults:
+ if item not in info:
+ info[item] = defaults[item]
+
+ except:
+ info = {}
+ if defaults:
+ for item in defaults:
+ info[item] = defaults[item]
+
+ self.settings[area] = s = Settings(p, info)
+
+ return s
+
+ def saveAll(self):
+ for settings in self.settings.itervalues():
+ settings.save()
+
+class Settings():
+ def __init__(self, location, info):
+ self.location = location
+ self.info = info
+
+ def save(self):
+ f = open(self.location, "wb")
+ cPickle.dump(self.info, f, cPickle.HIGHEST_PROTOCOL)
+
+ def __getitem__(self, k):
+ return self.info[k]
+
+ def __setitem__(self, k, v):
+ self.info[k] = v
+
+ def __iter__(self):
+ return self.info.__iter__()
+
+ def iterkeys(self):
+ return self.info.iterkeys()
+
+ def itervalues(self):
+ return self.info.itervalues()
+
+ def iteritems(self):
+ return self.info.iteritems()
+
+ def keys(self):
+ return self.info.keys()
+
+ def values(self):
+ return self.info.values()
+
+ def items(self):
+ return self.info.items()
+
+
+
+class ProxySettings():
+ _instance = None
+ @classmethod
+ def getInstance(cls):
+ if cls._instance == None:
+ cls._instance = ProxySettings()
+
+ return cls._instance
+
+ def __init__(self):
+
+ # mode
+ # 0 - No proxy
+ # 1 - Auto-detected proxy settings
+ # 2 - Manual proxy settings
+ serviceProxyDefaultSettings = {"mode": 1, "type": "https", "address": "", "port": ""}
+
+ self.serviceProxySettings = SettingsProvider.getInstance().getSettings("pyfaServiceProxySettings", serviceProxyDefaultSettings)
+
+ def getMode(self):
+ return self.serviceProxySettings["mode"]
+
+ def getAddress(self):
+ return self.serviceProxySettings["address"]
+
+ def getPort(self):
+ return self.serviceProxySettings["port"]
+
+ def getType(self):
+ return self.serviceProxySettings["type"]
+
+ def setMode(self, mode):
+ self.serviceProxySettings["mode"] = mode
+
+ def setAddress(self, addr):
+ self.serviceProxySettings["address"] = addr
+
+ def setPort(self, port):
+ self.serviceProxySettings["port"] = port
+
+ def setType(self, type):
+ self.serviceProxySettings["type"] = type
+
+ def autodetect(self):
+
+ proxy = None
+ proxAddr = proxPort = ""
+ proxydict = urllib2.ProxyHandler().proxies
+ txt = "Auto-detected: "
+
+ validPrefixes = ("http", "https")
+
+ for prefix in validPrefixes:
+ if not prefix in proxydict:
+ continue
+ proxyline = proxydict[prefix]
+ proto = "{0}://".format(prefix)
+ if proxyline[:len(proto)] == proto:
+ proxyline = proxyline[len(proto):]
+ proxAddr, proxPort = proxyline.split(":")
+ proxPort = int(proxPort.rstrip("/"))
+ proxy = (proxAddr, proxPort)
+ break
+
+ return proxy
+
+ def getProxySettings(self):
+
+ if self.getMode() == 0:
+ return None
+ if self.getMode() == 1:
+ return self.autodetect()
+ if self.getMode() == 2:
+ return (self.getAddress(), int(self.getPort()))
+
+
+
+"""
+Settings used by the HTML export feature.
+"""
+class HTMLExportSettings():
+ _instance = None
+
+ @classmethod
+ def getInstance(cls):
+ if cls._instance == None:
+ cls._instance = HTMLExportSettings()
+
+ return cls._instance
+
+ def __init__(self):
+ serviceHTMLExportDefaultSettings = {"enabled": False, "path": config.pyfaPath + os.sep + 'pyfaFits.html' }
+ self.serviceHTMLExportSettings = SettingsProvider.getInstance().getSettings("pyfaServiceHTMLExportSettings", serviceHTMLExportDefaultSettings)
+
+ def getEnabled(self):
+ return self.serviceHTMLExportSettings["enabled"]
+
+ def setEnabled(self, enabled):
+ self.serviceHTMLExportSettings["enabled"] = enabled
+
+ def getPath(self):
+ return self.serviceHTMLExportSettings["path"]
+
+ def setPath(self, path):
+ self.serviceHTMLExportSettings["path"] = path
\ No newline at end of file