Merge branch 'charImplants' into singularity
# Conflicts: # eos/db/saveddata/fit.py # gui/builtinContextMenus/itemStats.py
This commit is contained in:
@@ -10,6 +10,7 @@ from service.update import Update
|
||||
from service.price import Price
|
||||
from service.network import Network
|
||||
from service.eveapi import EVEAPIConnection, ParseXML
|
||||
from service.implantSet import ImplantSets
|
||||
|
||||
import wx
|
||||
if not 'wxMac' in wx.PlatformInfo or ('wxMac' in wx.PlatformInfo and wx.VERSION >= (3,0)):
|
||||
|
||||
@@ -32,7 +32,9 @@ import eos.db
|
||||
import eos.types
|
||||
import service
|
||||
import config
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class CharacterImportThread(threading.Thread):
|
||||
def __init__(self, paths, callback):
|
||||
@@ -48,9 +50,8 @@ class CharacterImportThread(threading.Thread):
|
||||
# we try to parse api XML data first
|
||||
with open(path, mode='r') as charFile:
|
||||
sheet = service.ParseXML(charFile)
|
||||
charID = sCharacter.new()
|
||||
sCharacter.rename(charID, sheet.name+" (imported)")
|
||||
sCharacter.apiUpdateCharSheet(charID, sheet.skills)
|
||||
char = sCharacter.new(sheet.name+" (imported)")
|
||||
sCharacter.apiUpdateCharSheet(char.ID, sheet.skills)
|
||||
except:
|
||||
# if it's not api XML data, try this
|
||||
# this is a horrible logic flow, but whatever
|
||||
@@ -67,9 +68,8 @@ class CharacterImportThread(threading.Thread):
|
||||
"typeID": int(skill.getAttribute("typeID")),
|
||||
"level": int(skill.getAttribute("level")),
|
||||
})
|
||||
charID = sCharacter.new()
|
||||
sCharacter.rename(charID, name+" (EVEMon)")
|
||||
sCharacter.apiUpdateCharSheet(charID, skills)
|
||||
char = sCharacter.new(name+" (EVEMon)")
|
||||
sCharacter.apiUpdateCharSheet(char.ID, skills)
|
||||
except:
|
||||
continue
|
||||
|
||||
@@ -114,6 +114,11 @@ class Character(object):
|
||||
|
||||
return cls.instance
|
||||
|
||||
def __init__(self):
|
||||
# Simply initializes default characters in case they aren't in the database yet
|
||||
self.all0()
|
||||
self.all5()
|
||||
|
||||
def exportText(self):
|
||||
data = "Pyfa exported plan for \""+self.skillReqsDict['charname']+"\"\n"
|
||||
data += "=" * 79 + "\n"
|
||||
@@ -183,10 +188,7 @@ class Character(object):
|
||||
return self.all5().ID
|
||||
|
||||
def getCharacterList(self):
|
||||
baseChars = [eos.types.Character.getAll0(), eos.types.Character.getAll5()]
|
||||
sFit = service.Fit.getInstance()
|
||||
|
||||
return map(lambda c: (c.ID, c.name if not c.isDirty else "{} *".format(c.name), c == sFit.character), eos.db.getCharacterList())
|
||||
return eos.db.getCharacterList()
|
||||
|
||||
def getCharacter(self, charID):
|
||||
char = eos.db.getCharacter(charID)
|
||||
@@ -246,25 +248,21 @@ class Character(object):
|
||||
def getCharName(self, charID):
|
||||
return eos.db.getCharacter(charID).name
|
||||
|
||||
def new(self):
|
||||
char = eos.types.Character("New Character")
|
||||
def new(self, name="New Character"):
|
||||
char = eos.types.Character(name)
|
||||
eos.db.save(char)
|
||||
return char.ID
|
||||
return char
|
||||
|
||||
def rename(self, charID, newName):
|
||||
char = eos.db.getCharacter(charID)
|
||||
def rename(self, char, newName):
|
||||
char.name = newName
|
||||
eos.db.commit()
|
||||
|
||||
def copy(self, charID):
|
||||
char = eos.db.getCharacter(charID)
|
||||
def copy(self, char):
|
||||
newChar = copy.deepcopy(char)
|
||||
eos.db.save(newChar)
|
||||
return newChar.ID
|
||||
return newChar
|
||||
|
||||
def delete(self, charID):
|
||||
char = eos.db.getCharacter(charID)
|
||||
eos.db.commit()
|
||||
def delete(self, char):
|
||||
eos.db.remove(char)
|
||||
|
||||
def getApiDetails(self, charID):
|
||||
@@ -343,13 +341,18 @@ class Character(object):
|
||||
|
||||
def addImplant(self, charID, itemID):
|
||||
char = eos.db.getCharacter(charID)
|
||||
implant = eos.types.Implant(eos.db.getItem(itemID))
|
||||
char.implants.freeSlot(implant.slot)
|
||||
char.implants.append(implant)
|
||||
if char.ro:
|
||||
logger.error("Trying to add implant to read-only character")
|
||||
return
|
||||
|
||||
def removeImplant(self, charID, slot):
|
||||
implant = eos.types.Implant(eos.db.getItem(itemID))
|
||||
char.implants.append(implant)
|
||||
eos.db.commit()
|
||||
|
||||
def removeImplant(self, charID, implant):
|
||||
char = eos.db.getCharacter(charID)
|
||||
char.implants.freeSlot(slot)
|
||||
char.implants.remove(implant)
|
||||
eos.db.commit()
|
||||
|
||||
def getImplants(self, charID):
|
||||
char = eos.db.getCharacter(charID)
|
||||
|
||||
@@ -46,9 +46,10 @@ class DamagePattern():
|
||||
def getDamagePattern(self, name):
|
||||
return eos.db.getDamagePattern(name)
|
||||
|
||||
def newPattern(self):
|
||||
def newPattern(self, name):
|
||||
p = eos.types.DamagePattern(0, 0, 0, 0)
|
||||
p.name = ""
|
||||
p.name = name
|
||||
eos.db.save(p)
|
||||
return p
|
||||
|
||||
def renamePattern(self, p, newName):
|
||||
|
||||
@@ -277,7 +277,7 @@ class Fit(object):
|
||||
fit.timestamp))
|
||||
return fits
|
||||
|
||||
def addImplant(self, fitID, itemID):
|
||||
def addImplant(self, fitID, itemID, recalc=True):
|
||||
if fitID is None:
|
||||
return False
|
||||
|
||||
@@ -289,7 +289,8 @@ class Fit(object):
|
||||
return False
|
||||
|
||||
fit.implants.append(implant)
|
||||
self.recalc(fit)
|
||||
if recalc:
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
def removeImplant(self, fitID, position):
|
||||
@@ -760,6 +761,14 @@ class Fit(object):
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
def toggleImplantSource(self, fitID, source):
|
||||
fit = eos.db.getFit(fitID)
|
||||
fit.implantSource = source
|
||||
|
||||
eos.db.commit()
|
||||
self.recalc(fit)
|
||||
return True
|
||||
|
||||
def toggleBooster(self, fitID, i):
|
||||
fit = eos.db.getFit(fitID)
|
||||
booster = fit.boosters[i]
|
||||
|
||||
125
service/implantSet.py
Normal file
125
service/implantSet.py
Normal file
@@ -0,0 +1,125 @@
|
||||
#===============================================================================
|
||||
# Copyright (C) 2016 Ryan Holmes
|
||||
#
|
||||
# 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
|
||||
import copy
|
||||
import service.market
|
||||
|
||||
class ImportError(Exception):
|
||||
pass
|
||||
|
||||
class ImplantSets():
|
||||
instance = None
|
||||
@classmethod
|
||||
def getInstance(cls):
|
||||
if cls.instance is None:
|
||||
cls.instance = ImplantSets()
|
||||
|
||||
return cls.instance
|
||||
|
||||
def getImplantSetList(self):
|
||||
return eos.db.getImplantSetList(None)
|
||||
|
||||
def getImplantSet(self, name):
|
||||
return eos.db.getImplantSet(name)
|
||||
|
||||
def getImplants(self, setID):
|
||||
set = eos.db.getImplantSet(setID)
|
||||
return set.implants
|
||||
|
||||
def addImplant(self, setID, itemID):
|
||||
set = eos.db.getImplantSet(setID)
|
||||
implant = eos.types.Implant(eos.db.getItem(itemID))
|
||||
set.implants.append(implant)
|
||||
eos.db.commit()
|
||||
|
||||
def removeImplant(self, setID, implant):
|
||||
set = eos.db.getImplantSet(setID)
|
||||
set.implants.remove(implant)
|
||||
eos.db.commit()
|
||||
|
||||
def newSet(self, name):
|
||||
s = eos.types.ImplantSet()
|
||||
s.name = name
|
||||
eos.db.save(s)
|
||||
return s
|
||||
|
||||
def renameSet(self, s, newName):
|
||||
s.name = newName
|
||||
eos.db.save(s)
|
||||
|
||||
def deleteSet(self, s):
|
||||
eos.db.remove(s)
|
||||
|
||||
def copySet(self, s):
|
||||
newS = copy.deepcopy(s)
|
||||
eos.db.save(newS)
|
||||
return newS
|
||||
|
||||
def saveChanges(self, s):
|
||||
eos.db.save(s)
|
||||
|
||||
def importSets(self, text):
|
||||
sMkt = service.Market.getInstance()
|
||||
lines = text.splitlines()
|
||||
newSets = []
|
||||
errors = 0
|
||||
current = None
|
||||
lookup = {}
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
line = line.strip()
|
||||
try:
|
||||
if line == '' or line[0] == "#": # comments / empty string
|
||||
continue
|
||||
if line[:1] == "[" and line[-1:] == "]":
|
||||
current = eos.types.ImplantSet(line[1:-1])
|
||||
newSets.append(current)
|
||||
else:
|
||||
item = sMkt.getItem(line)
|
||||
current.implants.append(eos.types.Implant(item))
|
||||
except:
|
||||
errors += 1
|
||||
continue
|
||||
|
||||
for set in self.getImplantSetList():
|
||||
lookup[set.name] = set
|
||||
|
||||
for set in newSets:
|
||||
if set.name in lookup:
|
||||
match = lookup[set.name]
|
||||
for implant in set.implants:
|
||||
match.implants.append(eos.types.Implant(implant.item))
|
||||
else:
|
||||
eos.db.save(set)
|
||||
|
||||
eos.db.commit()
|
||||
|
||||
lenImports = len(newSets)
|
||||
if lenImports == 0:
|
||||
raise ImportError("No patterns found for import")
|
||||
if errors > 0:
|
||||
raise ImportError("%d sets imported from clipboard; %d errors"%(lenImports, errors))
|
||||
|
||||
def exportSets(self):
|
||||
patterns = self.getImplantSetList()
|
||||
patterns.sort(key=lambda p: p.name)
|
||||
return eos.types.ImplantSet.exportSets(*patterns)
|
||||
|
||||
@@ -29,12 +29,15 @@ import eos.types
|
||||
from service.settings import SettingsProvider, NetworkSettings
|
||||
import service
|
||||
import service.conversions as conversions
|
||||
import logging
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from utils.compat import OrderedDict
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Event which tells threads dependent on Market that it's initialized
|
||||
mktRdy = threading.Event()
|
||||
|
||||
@@ -120,11 +123,14 @@ class SearchWorkerThread(threading.Thread):
|
||||
self.searchRequest = None
|
||||
cv.release()
|
||||
sMkt = Market.getInstance()
|
||||
if filterOn:
|
||||
if filterOn is True:
|
||||
# Rely on category data provided by eos as we don't hardcode them much in service
|
||||
filter = eos.types.Category.name.in_(sMkt.SEARCH_CATEGORIES)
|
||||
elif filterOn: # filter by selected categories
|
||||
filter = eos.types.Category.name.in_(filterOn)
|
||||
else:
|
||||
filter=None
|
||||
|
||||
results = eos.db.searchItems(request, where=filter,
|
||||
join=(eos.types.Item.group, eos.types.Group.category),
|
||||
eager=("icon", "group.category", "metaGroup", "metaGroup.parent"))
|
||||
@@ -346,20 +352,25 @@ class Market():
|
||||
|
||||
def getItem(self, identity, *args, **kwargs):
|
||||
"""Get item by its ID or name"""
|
||||
if isinstance(identity, eos.types.Item):
|
||||
item = identity
|
||||
elif isinstance(identity, int):
|
||||
item = eos.db.getItem(identity, *args, **kwargs)
|
||||
elif isinstance(identity, basestring):
|
||||
# We normally lookup with string when we are using import/export
|
||||
# features. Check against overrides
|
||||
identity = conversions.all.get(identity, identity)
|
||||
item = eos.db.getItem(identity, *args, **kwargs)
|
||||
elif isinstance(identity, float):
|
||||
id = int(identity)
|
||||
item = eos.db.getItem(id, *args, **kwargs)
|
||||
else:
|
||||
raise TypeError("Need Item object, integer, float or string as argument")
|
||||
try:
|
||||
if isinstance(identity, eos.types.Item):
|
||||
item = identity
|
||||
elif isinstance(identity, int):
|
||||
item = eos.db.getItem(identity, *args, **kwargs)
|
||||
elif isinstance(identity, basestring):
|
||||
# We normally lookup with string when we are using import/export
|
||||
# features. Check against overrides
|
||||
identity = conversions.all.get(identity, identity)
|
||||
item = eos.db.getItem(identity, *args, **kwargs)
|
||||
elif isinstance(identity, float):
|
||||
id = int(identity)
|
||||
item = eos.db.getItem(id, *args, **kwargs)
|
||||
else:
|
||||
raise TypeError("Need Item object, integer, float or string as argument")
|
||||
except:
|
||||
logger.error("Could not get item: %s", identity)
|
||||
raise
|
||||
|
||||
return item
|
||||
|
||||
def getGroup(self, identity, *args, **kwargs):
|
||||
|
||||
@@ -39,9 +39,10 @@ class TargetResists():
|
||||
def getTargetResists(self, name):
|
||||
return eos.db.getTargetResists(name)
|
||||
|
||||
def newPattern(self):
|
||||
def newPattern(self, name):
|
||||
p = eos.types.TargetResists(0.0, 0.0, 0.0, 0.0)
|
||||
p.name = ""
|
||||
p.name = name
|
||||
eos.db.save(p)
|
||||
return p
|
||||
|
||||
def renamePattern(self, p, newName):
|
||||
|
||||
Reference in New Issue
Block a user