test comit

This commit is contained in:
HomeWorld
2010-10-09 17:02:46 +03:00
parent c3dca31d8f
commit 2d3868dea9
7 changed files with 308 additions and 308 deletions

View File

@@ -1,20 +1,20 @@
from gui.contextMenu import ContextMenu
from gui.itemStats import ItemStatsDialog
import gui.mainFrame
import service
class DamagePattern(ContextMenu):
def __init__(self):
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def display(self, context, selection):
return context in ("resistancesViewFull",)
def getText(self, context, selection):
sDP = service.DamagePattern.getInstance()
return map(lambda p: p.name, sDP.getDamagePatternList())
def activate(self, context, selection, i):
pass
DamagePattern.register()
from gui.contextMenu import ContextMenu
from gui.itemStats import ItemStatsDialog
import gui.mainFrame
import service
class DamagePattern(ContextMenu):
def __init__(self):
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def display(self, context, selection):
return context in ("resistancesViewFull",)
def getText(self, context, selection):
sDP = service.DamagePattern.getInstance()
return map(lambda p: p.name, sDP.getDamagePatternList())
def activate(self, context, selection, i):
pass
DamagePattern.register()

View File

@@ -1,29 +1,29 @@
from gui.contextMenu import ContextMenu
from gui.itemStats import ItemStatsDialog
import gui.mainFrame
import service
class ItemStats(ContextMenu):
def __init__(self):
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def display(self, context, selection):
return context in ("item", "ship", "module", "ammo", "skill")
def getText(self, context, selection):
return "%s stats" % context.capitalize()
def activate(self, context, selection, i):
if context == "ship":
fitID = self.mainFrame.getActiveFit()
cFit = service.Fit.getInstance()
stuff = cFit.getFit(fitID).ship
else:
stuff = selection[0]
if context == "module" and stuff.isEmpty:
return
dlg=ItemStatsDialog(stuff, context)
ItemStats.register()
from gui.contextMenu import ContextMenu
from gui.itemStats import ItemStatsDialog
import gui.mainFrame
import service
class ItemStats(ContextMenu):
def __init__(self):
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def display(self, context, selection):
return context in ("item", "ship", "module", "ammo", "skill")
def getText(self, context, selection):
return "%s stats" % context.capitalize()
def activate(self, context, selection, i):
if context == "ship":
fitID = self.mainFrame.getActiveFit()
cFit = service.Fit.getInstance()
stuff = cFit.getFit(fitID).ship
else:
stuff = selection[0]
if context == "module" and stuff.isEmpty:
return
dlg=ItemStatsDialog(stuff, context)
ItemStats.register()

View File

@@ -1,49 +1,49 @@
#===============================================================================
# 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 import builtinViewColumns
from gui.viewColumn import ViewColumn
from gui import bitmapLoader
class ModuleAmmo(ViewColumn):
name = "Module Ammo"
def __init__(self, fittingView, params):
ViewColumn.__init__(self, fittingView)
self.columnText = "Ammo"
def getText(self, mod):
return mod.charge.name if mod.charge is not None else ""
def getImageId(self, mod):
if mod.charge is None:
iconId = -1
else:
iconFile = mod.charge.icon.iconFile if mod.item.icon else ""
if iconFile:
bitmap = bitmapLoader.getBitmap(iconFile, "pack")
if bitmap is None:
iconId = -1
else:
iconId = self.fittingView.imageList.Add(bitmap)
else:
iconId = -1
return iconId
ModuleAmmo.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 import builtinViewColumns
from gui.viewColumn import ViewColumn
from gui import bitmapLoader
class ModuleAmmo(ViewColumn):
name = "Module Ammo"
def __init__(self, fittingView, params):
ViewColumn.__init__(self, fittingView)
self.columnText = "Ammo"
def getText(self, mod):
return mod.charge.name if mod.charge is not None else ""
def getImageId(self, mod):
if mod.charge is None:
iconId = -1
else:
iconFile = mod.charge.icon.iconFile if mod.item.icon else ""
if iconFile:
bitmap = bitmapLoader.getBitmap(iconFile, "pack")
if bitmap is None:
iconId = -1
else:
iconId = self.fittingView.imageList.Add(bitmap)
else:
iconId = -1
return iconId
ModuleAmmo.register()

View File

@@ -1,39 +1,39 @@
#===============================================================================
# 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
import bitmapLoader
class CachingImageList(wx.ImageList):
def __init__(self, width, height):
wx.ImageList.__init__(self, width, height)
self.map = {}
def Add(self, *loaderArgs):
key = "".join(loaderArgs)
if key not in self.map:
bitmap = bitmapLoader.getBitmap(*loaderArgs)
if bitmap is None:
return -1
id = wx.ImageList.Add(self,bitmap)
self.map[key] = id
else:
id = self.map[key]
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
import bitmapLoader
class CachingImageList(wx.ImageList):
def __init__(self, width, height):
wx.ImageList.__init__(self, width, height)
self.map = {}
def Add(self, *loaderArgs):
key = "".join(loaderArgs)
if key not in self.map:
bitmap = bitmapLoader.getBitmap(*loaderArgs)
if bitmap is None:
return -1
id = wx.ImageList.Add(self,bitmap)
self.map[key] = id
else:
id = self.map[key]
return id

View File

@@ -1,87 +1,87 @@
#===============================================================================
# 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 ContextMenu(object):
menus = []
@classmethod
def register(cls):
ContextMenu.menus.append(cls)
@classmethod
def getMenu(cls, selection, *contexts):
menu = wx.Menu()
menu.info = {}
menu.selection = selection
empty = True
menu.Bind(wx.EVT_MENU, cls.handler)
for i, context in enumerate(contexts):
amount = 0
for menuHandler in cls.menus:
m = menuHandler()
if m.display(context, selection):
amount += 1
texts = m.getText(context, selection)
if isinstance(texts, basestring):
texts = (texts,)
for it, text in enumerate(texts):
id = wx.NewId()
item = wx.MenuItem(menu, id, text)
menu.info[id] = (m, context, it)
bitmap = m.getBitmap(context, selection)
if bitmap:
item.SetBitmap(bitmap)
menu.AppendItem(item)
empty = False
if amount > 0 and i != len(contexts) - 1:
menu.AppendSeparator()
return menu if not empty else None
@classmethod
def handler(cls, event):
menu = event.EventObject
stuff = menu.info.get(event.Id)
if stuff is not None:
m, context, i = stuff
selection = menu.selection
if not hasattr(selection, "__iter__"):
selection = (selection,)
m.activate(context, selection, i)
event.Skip()
def display(self, context, selection):
raise NotImplementedError()
def activate(self, context, selection, i):
raise NotImplementedError()
def getText(self, context, selection):
raise NotImplementedError()
def getBitmap(self, context, selection):
return None
from gui.builtinContextMenus import *
#===============================================================================
# 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 ContextMenu(object):
menus = []
@classmethod
def register(cls):
ContextMenu.menus.append(cls)
@classmethod
def getMenu(cls, selection, *contexts):
menu = wx.Menu()
menu.info = {}
menu.selection = selection
empty = True
menu.Bind(wx.EVT_MENU, cls.handler)
for i, context in enumerate(contexts):
amount = 0
for menuHandler in cls.menus:
m = menuHandler()
if m.display(context, selection):
amount += 1
texts = m.getText(context, selection)
if isinstance(texts, basestring):
texts = (texts,)
for it, text in enumerate(texts):
id = wx.NewId()
item = wx.MenuItem(menu, id, text)
menu.info[id] = (m, context, it)
bitmap = m.getBitmap(context, selection)
if bitmap:
item.SetBitmap(bitmap)
menu.AppendItem(item)
empty = False
if amount > 0 and i != len(contexts) - 1:
menu.AppendSeparator()
return menu if not empty else None
@classmethod
def handler(cls, event):
menu = event.EventObject
stuff = menu.info.get(event.Id)
if stuff is not None:
m, context, i = stuff
selection = menu.selection
if not hasattr(selection, "__iter__"):
selection = (selection,)
m.activate(context, selection, i)
event.Skip()
def display(self, context, selection):
raise NotImplementedError()
def activate(self, context, selection, i):
raise NotImplementedError()
def getText(self, context, selection):
raise NotImplementedError()
def getBitmap(self, context, selection):
return None
from gui.builtinContextMenus import *

View File

@@ -1,46 +1,46 @@
#===============================================================================
# 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 eos.db
import eos.types
class DamagePattern():
instance = None
@classmethod
def getInstance(cls):
if cls.instance is None:
cls.instance = DamagePattern()
return cls.instance
def __init__(self):
self.getDamagePatternList()
def getDamagePatternList(self):
patterns = eos.db.getDamagePatternList()
if len(patterns) == 0:
uniform = eos.types.DamagePattern(25, 25, 25, 25)
uniform.name = "Uniform"
eos.db.save(uniform)
patterns.append(uniform)
return patterns
def getDamagePattern(self, name):
#===============================================================================
# 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 eos.db
import eos.types
class DamagePattern():
instance = None
@classmethod
def getInstance(cls):
if cls.instance is None:
cls.instance = DamagePattern()
return cls.instance
def __init__(self):
self.getDamagePatternList()
def getDamagePatternList(self):
patterns = eos.db.getDamagePatternList()
if len(patterns) == 0:
uniform = eos.types.DamagePattern(25, 25, 25, 25)
uniform.name = "Uniform"
eos.db.save(uniform)
patterns.append(uniform)
return patterns
def getDamagePattern(self, name):
return eos.db.getDamagePattern(name)

View File

@@ -1,39 +1,39 @@
#===============================================================================
# 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 threading
import service
import eos.db
class PrefetchThread(threading.Thread):
def run(self):
# We're a daemon thread, as such, interpreter might get shut down while we do stuff
# Make sure we don't throw tracebacks to console
try:
eos.db.getItemsByCategory("Skill", eager=("effects", "attributes", "icon"))
cMarket = service.Market.getInstance()
root = cMarket.getShipRoot()
for id, _ in root:
cMarket.getShipList(id)
except:
return
prefetch = PrefetchThread()
prefetch.daemon = True
prefetch.start()
#===============================================================================
# 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 threading
import service
import eos.db
class PrefetchThread(threading.Thread):
def run(self):
# We're a daemon thread, as such, interpreter might get shut down while we do stuff
# Make sure we don't throw tracebacks to console
try:
eos.db.getItemsByCategory("Skill", eager=("effects", "attributes", "icon"))
cMarket = service.Market.getInstance()
root = cMarket.getShipRoot()
for id, _ in root:
cMarket.getShipList(id)
except:
return
prefetch = PrefetchThread()
prefetch.daemon = True
prefetch.start()