This commit is contained in:
blitzman
2017-02-07 00:32:45 -05:00
parent 3d8c76209d
commit c25a07c95b
8 changed files with 661 additions and 661 deletions

View File

@@ -1,95 +1,95 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
from gui.graph import Graph
from gui.bitmapLoader import BitmapLoader
from eos.graph.fitDps import FitDpsGraph as FitDps
from eos.graph import Data
import gui.mainFrame
from service.attribute import Attribute
class FitDpsGraph(Graph):
propertyAttributeMap = {"angle": "maxVelocity",
"distance": "maxRange",
"signatureRadius": "signatureRadius",
"velocity": "maxVelocity"}
propertyLabelMap = {"angle": "Target Angle (degrees)",
"distance": "Distance to Target (km)",
"signatureRadius": "Target Signature Radius (m)",
"velocity": "Target Velocity (m/s)"}
defaults = FitDps.defaults.copy()
def __init__(self):
Graph.__init__(self)
self.defaults["distance"] = "0-20"
self.name = "DPS"
self.fitDps = None
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def getFields(self):
return self.defaults
def getLabels(self):
return self.propertyLabelMap
def getIcons(self):
icons = {}
sAttr = Attribute.getInstance()
for key, attrName in self.propertyAttributeMap.iteritems():
iconFile = sAttr.getAttributeInfo(attrName).icon.iconFile
bitmap = BitmapLoader.getBitmap(iconFile, "icons")
if bitmap:
icons[key] = bitmap
return icons
def getPoints(self, fit, fields):
fitDps = getattr(self, "fitDps", None)
if fitDps is None or fitDps.fit != fit:
fitDps = self.fitDps = FitDps(fit)
fitDps.clearData()
variable = None
for fieldName, value in fields.iteritems():
d = Data(fieldName, value)
if not d.isConstant():
if variable is None:
variable = fieldName
else:
# We can't handle more then one variable atm, OOPS FUCK OUT
return False, "Can only handle 1 variable"
fitDps.setData(d)
if variable is None:
return False, "No variable"
x = []
y = []
for point, val in fitDps.getIterator():
x.append(point[variable])
y.append(val)
return x, y
FitDpsGraph.register()
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
from gui.graph import Graph
from gui.bitmapLoader import BitmapLoader
from eos.graph.fitDps import FitDpsGraph as FitDps
from eos.graph import Data
import gui.mainFrame
from service.attribute import Attribute
class FitDpsGraph(Graph):
propertyAttributeMap = {"angle": "maxVelocity",
"distance": "maxRange",
"signatureRadius": "signatureRadius",
"velocity": "maxVelocity"}
propertyLabelMap = {"angle": "Target Angle (degrees)",
"distance": "Distance to Target (km)",
"signatureRadius": "Target Signature Radius (m)",
"velocity": "Target Velocity (m/s)"}
defaults = FitDps.defaults.copy()
def __init__(self):
Graph.__init__(self)
self.defaults["distance"] = "0-20"
self.name = "DPS"
self.fitDps = None
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def getFields(self):
return self.defaults
def getLabels(self):
return self.propertyLabelMap
def getIcons(self):
icons = {}
sAttr = Attribute.getInstance()
for key, attrName in self.propertyAttributeMap.iteritems():
iconFile = sAttr.getAttributeInfo(attrName).icon.iconFile
bitmap = BitmapLoader.getBitmap(iconFile, "icons")
if bitmap:
icons[key] = bitmap
return icons
def getPoints(self, fit, fields):
fitDps = getattr(self, "fitDps", None)
if fitDps is None or fitDps.fit != fit:
fitDps = self.fitDps = FitDps(fit)
fitDps.clearData()
variable = None
for fieldName, value in fields.iteritems():
d = Data(fieldName, value)
if not d.isConstant():
if variable is None:
variable = fieldName
else:
# We can't handle more then one variable atm, OOPS FUCK OUT
return False, "Can only handle 1 variable"
fitDps.setData(d)
if variable is None:
return False, "No variable"
x = []
y = []
for point, val in fitDps.getIterator():
x.append(point[variable])
y.append(val)
return x, y
FitDpsGraph.register()

View File

@@ -1,58 +1,58 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
import wx
from eos.types import Fighter
from gui.viewColumn import ViewColumn
from gui.bitmapLoader import BitmapLoader
class Ammo(ViewColumn):
name = "Ammo"
def __init__(self, fittingView, params):
ViewColumn.__init__(self, fittingView)
self.mask = wx.LIST_MASK_IMAGE
self.imageId = fittingView.imageList.GetImageIndex("damagePattern_small", "gui")
self.bitmap = BitmapLoader.getBitmap("damagePattern_small", "gui")
def getText(self, stuff):
if isinstance(stuff, Fighter):
# this is an experiment, not sure I like it. But it saves us from duplicating code.
col = self.columns['Fighter Abilities'](self.fittingView, {})
text = col.getText(stuff)
del col
return text
if getattr(stuff, "charge", None) is not None:
charges = stuff.numCharges
if charges > 0:
cycles = stuff.numShots
if cycles != 0 and charges != cycles:
return "%s (%d, %d cycles)" % (stuff.charge.name, charges, cycles)
else:
return "%s (%d)" % (stuff.charge.name, charges)
else:
return stuff.charge.name
return ""
def getImageId(self, mod):
return -1
Ammo.register()
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
import wx
from eos.types import Fighter
from gui.viewColumn import ViewColumn
from gui.bitmapLoader import BitmapLoader
class Ammo(ViewColumn):
name = "Ammo"
def __init__(self, fittingView, params):
ViewColumn.__init__(self, fittingView)
self.mask = wx.LIST_MASK_IMAGE
self.imageId = fittingView.imageList.GetImageIndex("damagePattern_small", "gui")
self.bitmap = BitmapLoader.getBitmap("damagePattern_small", "gui")
def getText(self, stuff):
if isinstance(stuff, Fighter):
# this is an experiment, not sure I like it. But it saves us from duplicating code.
col = self.columns['Fighter Abilities'](self.fittingView, {})
text = col.getText(stuff)
del col
return text
if getattr(stuff, "charge", None) is not None:
charges = stuff.numCharges
if charges > 0:
cycles = stuff.numShots
if cycles != 0 and charges != cycles:
return "%s (%d, %d cycles)" % (stuff.charge.name, charges, cycles)
else:
return "%s (%d)" % (stuff.charge.name, charges)
else:
return stuff.charge.name
return ""
def getImageId(self, mod):
return -1
Ammo.register()

View File

@@ -1,56 +1,56 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
from gui.viewColumn import ViewColumn
import wx
from eos.types import Module
class AmmoIcon(ViewColumn):
name = "Ammo Icon"
def __init__(self, fittingView, params):
ViewColumn.__init__(self, fittingView)
self.size = 24
self.maxsize = self.size
self.mask = wx.LIST_MASK_IMAGE
self.columnText = ""
def getText(self, mod):
return ""
def getImageId(self, stuff):
if not isinstance(stuff, Module):
return -1
if stuff.charge is None:
return -1
else:
iconFile = stuff.charge.icon.iconFile if stuff.charge.icon else ""
if iconFile:
return self.fittingView.imageList.GetImageIndex(iconFile, "icons")
else:
return -1
def getToolTip(self, mod):
if isinstance(mod, Module) and mod.charge is not None:
return mod.charge.name
AmmoIcon.register()
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
from gui.viewColumn import ViewColumn
import wx
from eos.types import Module
class AmmoIcon(ViewColumn):
name = "Ammo Icon"
def __init__(self, fittingView, params):
ViewColumn.__init__(self, fittingView)
self.size = 24
self.maxsize = self.size
self.mask = wx.LIST_MASK_IMAGE
self.columnText = ""
def getText(self, mod):
return ""
def getImageId(self, stuff):
if not isinstance(stuff, Module):
return -1
if stuff.charge is None:
return -1
else:
iconFile = stuff.charge.icon.iconFile if stuff.charge.icon else ""
if iconFile:
return self.fittingView.imageList.GetImageIndex(iconFile, "icons")
else:
return -1
def getToolTip(self, mod):
if isinstance(mod, Module) and mod.charge is not None:
return mod.charge.name
AmmoIcon.register()

View File

@@ -1,37 +1,37 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
import wx
from gui.bitmapLoader import BitmapLoader
class CachingImageList(wx.ImageList):
def __init__(self, width, height):
wx.ImageList.__init__(self, width, height)
self.map = {}
def GetImageIndex(self, *loaderArgs):
id_ = self.map.get(loaderArgs)
if id_ is None:
bitmap = BitmapLoader.getBitmap(*loaderArgs)
if bitmap is None:
return -1
id_ = self.map[loaderArgs] = wx.ImageList.Add(self, bitmap)
return id_
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
import wx
from gui.bitmapLoader import BitmapLoader
class CachingImageList(wx.ImageList):
def __init__(self, width, height):
wx.ImageList.__init__(self, width, height)
self.map = {}
def GetImageIndex(self, *loaderArgs):
id_ = self.map.get(loaderArgs)
if id_ is None:
bitmap = BitmapLoader.getBitmap(*loaderArgs)
if bitmap is None:
return -1
id_ = self.map[loaderArgs] = wx.ImageList.Add(self, bitmap)
return id_

View File

@@ -1,38 +1,38 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
class Graph(object):
views = []
@classmethod
def register(cls):
Graph.views.append(cls)
def __init__(self):
self.name = ""
def getFields(self, fit, fields):
raise NotImplementedError()
def getIcons(self):
return None
from gui.builtinGraphs import * # noqa
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
class Graph(object):
views = []
@classmethod
def register(cls):
Graph.views.append(cls)
def __init__(self):
self.name = ""
def getFields(self, fit, fields):
raise NotImplementedError()
def getIcons(self):
return None
from gui.builtinGraphs import * # noqa

View File

@@ -1,80 +1,80 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
import wx
from gui.preferenceView import PreferenceView
from gui.bitmapLoader import BitmapLoader
class PreferenceDialog(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent, id=wx.ID_ANY, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE)
self.SetTitle("pyfa - Preferences")
i = wx.IconFromBitmap(BitmapLoader.getBitmap("preferences_small", "gui"))
self.SetIcon(i)
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.listbook = wx.Listbook(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LB_DEFAULT)
self.listview = self.listbook.GetListView()
# self.listview.SetMinSize((500, -1))
# self.listview.SetSize((500, -1))
self.imageList = wx.ImageList(32, 32)
self.listbook.SetImageList(self.imageList)
mainSizer.Add(self.listbook, 1, wx.EXPAND | wx.TOP | wx.BOTTOM | wx.LEFT, 5)
self.m_staticline2 = wx.StaticLine(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL)
mainSizer.Add(self.m_staticline2, 0, wx.EXPAND, 5)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer.AddSpacer((0, 0), 1, wx.EXPAND, 5)
self.btnOK = wx.Button(self, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0)
btnSizer.Add(self.btnOK, 0, wx.ALL, 5)
mainSizer.Add(btnSizer, 0, wx.EXPAND, 5)
self.SetSizer(mainSizer)
self.Centre(wx.BOTH)
for prefView in PreferenceView.views:
page = wx.Panel(self.listbook)
bmp = prefView.getImage()
if bmp:
imgID = self.imageList.Add(bmp)
else:
imgID = -1
prefView.populatePanel(page)
self.listbook.AddPage(page, prefView.title, imageId=imgID)
# Set the height based on a condition. Can all the panels fit in the current height?
# If not, use the .GetBestVirtualSize() to ensure that all content is available.
minHeight = 360
bestFit = self.GetBestVirtualSize()
if minHeight > bestFit[1]:
self.SetSizeWH(450, minHeight)
else:
self.SetSizeWH(450, bestFit[1])
self.Layout()
self.btnOK.Bind(wx.EVT_BUTTON, self.OnBtnOK)
def OnBtnOK(self, event):
self.Close()
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
import wx
from gui.preferenceView import PreferenceView
from gui.bitmapLoader import BitmapLoader
class PreferenceDialog(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent, id=wx.ID_ANY, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE)
self.SetTitle("pyfa - Preferences")
i = wx.IconFromBitmap(BitmapLoader.getBitmap("preferences_small", "gui"))
self.SetIcon(i)
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.listbook = wx.Listbook(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LB_DEFAULT)
self.listview = self.listbook.GetListView()
# self.listview.SetMinSize((500, -1))
# self.listview.SetSize((500, -1))
self.imageList = wx.ImageList(32, 32)
self.listbook.SetImageList(self.imageList)
mainSizer.Add(self.listbook, 1, wx.EXPAND | wx.TOP | wx.BOTTOM | wx.LEFT, 5)
self.m_staticline2 = wx.StaticLine(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL)
mainSizer.Add(self.m_staticline2, 0, wx.EXPAND, 5)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer.AddSpacer((0, 0), 1, wx.EXPAND, 5)
self.btnOK = wx.Button(self, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0)
btnSizer.Add(self.btnOK, 0, wx.ALL, 5)
mainSizer.Add(btnSizer, 0, wx.EXPAND, 5)
self.SetSizer(mainSizer)
self.Centre(wx.BOTH)
for prefView in PreferenceView.views:
page = wx.Panel(self.listbook)
bmp = prefView.getImage()
if bmp:
imgID = self.imageList.Add(bmp)
else:
imgID = -1
prefView.populatePanel(page)
self.listbook.AddPage(page, prefView.title, imageId=imgID)
# Set the height based on a condition. Can all the panels fit in the current height?
# If not, use the .GetBestVirtualSize() to ensure that all content is available.
minHeight = 360
bestFit = self.GetBestVirtualSize()
if minHeight > bestFit[1]:
self.SetSizeWH(450, minHeight)
else:
self.SetSizeWH(450, bestFit[1])
self.Layout()
self.btnOK.Bind(wx.EVT_BUTTON, self.OnBtnOK)
def OnBtnOK(self, event):
self.Close()

View File

@@ -1,40 +1,40 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
import wx
class PreferenceView(object):
views = []
@classmethod
def register(cls):
PreferenceView.views.append(cls())
def populatePanel(self, panel):
raise NotImplementedError()
def refreshPanel(self, fit):
raise NotImplementedError()
def getImage(self):
return wx.NullBitmap
from gui.builtinPreferenceViews import * # noqa
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
import wx
class PreferenceView(object):
views = []
@classmethod
def register(cls):
PreferenceView.views.append(cls())
def populatePanel(self, panel):
raise NotImplementedError()
def refreshPanel(self, fit):
raise NotImplementedError()
def getImage(self):
return wx.NullBitmap
from gui.builtinPreferenceViews import * # noqa

View File

@@ -1,257 +1,257 @@
#!/usr/bin/env python
"""
Script for generating distributables based on platform skeletons.
User supplies path for pyfa code base, root skeleton directory, and where the
builds go. The builds are automatically named depending on the pyfa config
values of `version` and `tag`. If it's a Stable release, the naming
convention is:
pyfa-pyfaversion-expansion-expversion-platform
If it is not Stable (tag=git), we determine if the pyfa code base includes
the git repo to use as an ID. If not, uses randomly generated 6-character ID.
The unstable naming convention:
pyfa-YYYMMDD-id-platform
dist.py can also build the Windows installer provided that it has a path to
Inno Setup (and, for generating on non-Windows platforms, that WINE is
installed). To build the EXE file, `win` must be included in the platforms to
be built.
"""
#@todo: ensure build directory can be written to
# todo: default build and dist directories
from optparse import OptionParser
import os.path
import shutil
import sys
import tarfile
import datetime
import random
import string
import zipfile
import errno
from subprocess import call
class FileStub():
def write(self, *args):
pass
def flush(self, *args):
pass
i = 0
def loginfo(path, names):
# Print out a "progress" and return directories / files to ignore
global i
i += 1
if i % 10 == 0:
sys.stdout.write(".")
sys.stdout.flush()
return ()
def copyanything(src, dst):
try:
shutil.copytree(src, dst, ignore=loginfo)
except: # python >2.5
try:
shutil.copy(src, dst)
except:
raise
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for x in range(size))
def zipdir(path, zip):
for root, dirs, files in os.walk(path):
for file in files:
zip.write(os.path.join(root, file))
skels = ['win', 'src', 'mac', 'mac-deprecated']
iscc = "C:\Program Files (x86)\Inno Setup 5\ISCC.exe" # inno script location via wine
if __name__ == "__main__":
oldstd = sys.stdout
parser = OptionParser()
parser.add_option("-s", "--skeleton", dest="skeleton", help="Location of Pyfa-skel directory")
parser.add_option("-b", "--base", dest="base", help="Location of cleaned read-only base directory")
parser.add_option("-d", "--destination", dest="destination", help="Where to copy our distributable")
parser.add_option("-p", "--platforms", dest="platforms", help="Comma-separated list of platforms to build", default=','.join(skels))
parser.add_option("-q", "--quiet", dest="silent", action="store_true")
parser.add_option("-w", "--winexe", dest="winexe", action="store_true", help="Build the Windows installer file (needs Inno Setup). Must include 'win' in platform options")
parser.add_option("-z", "--zip", dest="zip", action="store_true", help="zip archive instead of tar")
options, args = parser.parse_args()
if options.skeleton is None or options.base is None or options.destination is None:
print "Need --skeleton argument as well as --base and --destination argument"
parser.print_help()
sys.exit()
if options.silent:
sys.stdout = FileStub()
options.platforms = options.platforms.split(",")
for skel in skels:
if skel not in options.platforms:
continue
print "\n======== %s ========"%skel
info = {}
config = {}
setup = {}
skeleton = os.path.expanduser(os.path.join(options.skeleton, skel))
execfile(os.path.join(options.base, "config.py"), config)
execfile(os.path.join(skeleton, "info.py"), info)
execfile(os.path.join(options.base, "setup.py"), setup)
destination = os.path.expanduser(options.destination)
if not os.path.isdir(destination) or not os.access(destination, os.W_OK | os.X_OK):
print "Destination directory does not exist or is not writable: {}".format(destination)
sys.exit()
dirName = info["arcname"]
nowdt = datetime.datetime.now()
now = "%04d%02d%02d" % (nowdt.year, nowdt.month, nowdt.day)
git = False
if config['tag'].lower() == "git":
try: # if there is a git repo associated with base, use master commit
with open(os.path.join(options.base, ".git", "refs", "heads", "master"), 'r') as f:
id = f.readline()[0:6]
git = True
except: # else, use custom ID
id = id_generator()
fileName = "pyfa-{}-{}-{}".format(now, id, info["os"])
else:
fileName = "pyfa-{}-{}-{}-{}".format(
config['version'],
config['expansionName'].lower(),
config['expansionVersion'],
info["os"]
)
archiveName = "{}.{}".format(fileName, "zip" if options.zip else "tar.bz2")
tmpDir = os.path.join(os.getcwd(), dirName) # tmp directory where files are copied
tmpFile = os.path.join(os.getcwd(), archiveName)
try:
print "Copying skeleton to ", tmpDir
shutil.copytree(skeleton, tmpDir, ignore=loginfo)
print
source = os.path.expanduser(options.base)
root = os.path.join(tmpDir, info["base"])
# it is easier to work from the source directory
oldcwd = os.getcwd()
os.chdir(source)
if info["library"]:
print "Injecting files into", info["library"]
libraryFile = os.path.join(root, info["library"])
with zipfile.ZipFile(libraryFile, 'a') as library:
for dir in setup['packages']:
zipdir(dir, library)
library.write('pyfa.py', 'pyfa__main__.py')
library.write('config.py')
else: # platforms where we don't have a packaged library
print "Copying modules into", root
for dir in setup['packages']:
copyanything(dir, os.path.join(root, dir))
# add some additional files to root dir for these platforms
# (hopefully can figure out a way later for OS X to use the one in
# it's library)
if skel == 'mac':
setup['include_files'] += ['pyfa.py']
if skel in ('src', 'mac-deprecated'):
setup['include_files'] += ['pyfa.py', 'config.py']
print
print "Copying included files:",
for file in setup['include_files']:
if isinstance(file, basestring):
print file,
copyanything(file, os.path.join(root, file))
print
print "Creating images zipfile:",
os.chdir('imgs')
imagesFile = os.path.join(root, "imgs.zip")
with zipfile.ZipFile(imagesFile, 'w') as images:
for dir in setup['icon_dirs']:
print dir,
zipdir(dir, images)
os.chdir(oldcwd)
print
print "Creating archive"
if options.zip:
archive = zipfile.ZipFile(tmpFile, 'w', compression=zipfile.ZIP_DEFLATED)
zipdir(dirName, archive)
archive.close()
else:
archive = tarfile.open(tmpFile, "w:bz2")
archive.add(tmpDir, arcname=info["arcname"])
archive.close()
print "Moving archive to ", destination
shutil.move(tmpFile, destination)
if "win" in skel and options.winexe:
print "Compiling EXE"
if config['tag'].lower() == "git":
if git: # if git repo info available, use git commit
expansion = "git-%s"%(id)
else: # if there is no git repo, use timestamp
expansion = now
else: # if code is Stable, use expansion name
expansion = "%s %s"%(config['expansionName'], config['expansionVersion']),
calllist = ["wine"] if 'win' not in sys.platform else []
call(calllist + [
iscc,
"pyfa-setup.iss",
"/dMyAppVersion=%s"%(config['version']),
"/dMyAppExpansion=%s"%(expansion),
"/dMyAppDir=pyfa",
"/dMyOutputDir=%s"%destination,
"/dMyOutputFile=%s"%fileName]) #stdout=devnull, stderr=devnull
print "EXE completed"
except Exception as e:
print "Encountered an error: \n\t", e
raise
finally:
print "Deleting tmp files\n"
try:
shutil.rmtree("dist") # Inno dir
except:
pass
try:
shutil.rmtree(tmpDir)
except:
pass
try:
os.unlink(tmpFile)
except:
pass
sys.stdout = oldstd
if os.path.isdir(destination):
print os.path.join(destination, os.path.split(tmpFile)[1])
else:
print destination
#!/usr/bin/env python
"""
Script for generating distributables based on platform skeletons.
User supplies path for pyfa code base, root skeleton directory, and where the
builds go. The builds are automatically named depending on the pyfa config
values of `version` and `tag`. If it's a Stable release, the naming
convention is:
pyfa-pyfaversion-expansion-expversion-platform
If it is not Stable (tag=git), we determine if the pyfa code base includes
the git repo to use as an ID. If not, uses randomly generated 6-character ID.
The unstable naming convention:
pyfa-YYYMMDD-id-platform
dist.py can also build the Windows installer provided that it has a path to
Inno Setup (and, for generating on non-Windows platforms, that WINE is
installed). To build the EXE file, `win` must be included in the platforms to
be built.
"""
#@todo: ensure build directory can be written to
# todo: default build and dist directories
from optparse import OptionParser
import os.path
import shutil
import sys
import tarfile
import datetime
import random
import string
import zipfile
import errno
from subprocess import call
class FileStub():
def write(self, *args):
pass
def flush(self, *args):
pass
i = 0
def loginfo(path, names):
# Print out a "progress" and return directories / files to ignore
global i
i += 1
if i % 10 == 0:
sys.stdout.write(".")
sys.stdout.flush()
return ()
def copyanything(src, dst):
try:
shutil.copytree(src, dst, ignore=loginfo)
except: # python >2.5
try:
shutil.copy(src, dst)
except:
raise
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for x in range(size))
def zipdir(path, zip):
for root, dirs, files in os.walk(path):
for file in files:
zip.write(os.path.join(root, file))
skels = ['win', 'src', 'mac', 'mac-deprecated']
iscc = "C:\Program Files (x86)\Inno Setup 5\ISCC.exe" # inno script location via wine
if __name__ == "__main__":
oldstd = sys.stdout
parser = OptionParser()
parser.add_option("-s", "--skeleton", dest="skeleton", help="Location of Pyfa-skel directory")
parser.add_option("-b", "--base", dest="base", help="Location of cleaned read-only base directory")
parser.add_option("-d", "--destination", dest="destination", help="Where to copy our distributable")
parser.add_option("-p", "--platforms", dest="platforms", help="Comma-separated list of platforms to build", default=','.join(skels))
parser.add_option("-q", "--quiet", dest="silent", action="store_true")
parser.add_option("-w", "--winexe", dest="winexe", action="store_true", help="Build the Windows installer file (needs Inno Setup). Must include 'win' in platform options")
parser.add_option("-z", "--zip", dest="zip", action="store_true", help="zip archive instead of tar")
options, args = parser.parse_args()
if options.skeleton is None or options.base is None or options.destination is None:
print "Need --skeleton argument as well as --base and --destination argument"
parser.print_help()
sys.exit()
if options.silent:
sys.stdout = FileStub()
options.platforms = options.platforms.split(",")
for skel in skels:
if skel not in options.platforms:
continue
print "\n======== %s ========"%skel
info = {}
config = {}
setup = {}
skeleton = os.path.expanduser(os.path.join(options.skeleton, skel))
execfile(os.path.join(options.base, "config.py"), config)
execfile(os.path.join(skeleton, "info.py"), info)
execfile(os.path.join(options.base, "setup.py"), setup)
destination = os.path.expanduser(options.destination)
if not os.path.isdir(destination) or not os.access(destination, os.W_OK | os.X_OK):
print "Destination directory does not exist or is not writable: {}".format(destination)
sys.exit()
dirName = info["arcname"]
nowdt = datetime.datetime.now()
now = "%04d%02d%02d" % (nowdt.year, nowdt.month, nowdt.day)
git = False
if config['tag'].lower() == "git":
try: # if there is a git repo associated with base, use master commit
with open(os.path.join(options.base, ".git", "refs", "heads", "master"), 'r') as f:
id = f.readline()[0:6]
git = True
except: # else, use custom ID
id = id_generator()
fileName = "pyfa-{}-{}-{}".format(now, id, info["os"])
else:
fileName = "pyfa-{}-{}-{}-{}".format(
config['version'],
config['expansionName'].lower(),
config['expansionVersion'],
info["os"]
)
archiveName = "{}.{}".format(fileName, "zip" if options.zip else "tar.bz2")
tmpDir = os.path.join(os.getcwd(), dirName) # tmp directory where files are copied
tmpFile = os.path.join(os.getcwd(), archiveName)
try:
print "Copying skeleton to ", tmpDir
shutil.copytree(skeleton, tmpDir, ignore=loginfo)
print
source = os.path.expanduser(options.base)
root = os.path.join(tmpDir, info["base"])
# it is easier to work from the source directory
oldcwd = os.getcwd()
os.chdir(source)
if info["library"]:
print "Injecting files into", info["library"]
libraryFile = os.path.join(root, info["library"])
with zipfile.ZipFile(libraryFile, 'a') as library:
for dir in setup['packages']:
zipdir(dir, library)
library.write('pyfa.py', 'pyfa__main__.py')
library.write('config.py')
else: # platforms where we don't have a packaged library
print "Copying modules into", root
for dir in setup['packages']:
copyanything(dir, os.path.join(root, dir))
# add some additional files to root dir for these platforms
# (hopefully can figure out a way later for OS X to use the one in
# it's library)
if skel == 'mac':
setup['include_files'] += ['pyfa.py']
if skel in ('src', 'mac-deprecated'):
setup['include_files'] += ['pyfa.py', 'config.py']
print
print "Copying included files:",
for file in setup['include_files']:
if isinstance(file, basestring):
print file,
copyanything(file, os.path.join(root, file))
print
print "Creating images zipfile:",
os.chdir('imgs')
imagesFile = os.path.join(root, "imgs.zip")
with zipfile.ZipFile(imagesFile, 'w') as images:
for dir in setup['icon_dirs']:
print dir,
zipdir(dir, images)
os.chdir(oldcwd)
print
print "Creating archive"
if options.zip:
archive = zipfile.ZipFile(tmpFile, 'w', compression=zipfile.ZIP_DEFLATED)
zipdir(dirName, archive)
archive.close()
else:
archive = tarfile.open(tmpFile, "w:bz2")
archive.add(tmpDir, arcname=info["arcname"])
archive.close()
print "Moving archive to ", destination
shutil.move(tmpFile, destination)
if "win" in skel and options.winexe:
print "Compiling EXE"
if config['tag'].lower() == "git":
if git: # if git repo info available, use git commit
expansion = "git-%s"%(id)
else: # if there is no git repo, use timestamp
expansion = now
else: # if code is Stable, use expansion name
expansion = "%s %s"%(config['expansionName'], config['expansionVersion']),
calllist = ["wine"] if 'win' not in sys.platform else []
call(calllist + [
iscc,
"pyfa-setup.iss",
"/dMyAppVersion=%s"%(config['version']),
"/dMyAppExpansion=%s"%(expansion),
"/dMyAppDir=pyfa",
"/dMyOutputDir=%s"%destination,
"/dMyOutputFile=%s"%fileName]) #stdout=devnull, stderr=devnull
print "EXE completed"
except Exception as e:
print "Encountered an error: \n\t", e
raise
finally:
print "Deleting tmp files\n"
try:
shutil.rmtree("dist") # Inno dir
except:
pass
try:
shutil.rmtree(tmpDir)
except:
pass
try:
os.unlink(tmpFile)
except:
pass
sys.stdout = oldstd
if os.path.isdir(destination):
print os.path.join(destination, os.path.split(tmpFile)[1])
else:
print destination