Merge branch 'master' of evefit.org:pyfa
This commit is contained in:
@@ -100,6 +100,9 @@ class Fit(object):
|
||||
return fit
|
||||
|
||||
def addDrone(self, fitID, itemID):
|
||||
if fitID == None:
|
||||
return
|
||||
|
||||
fit = eos.db.getFit(fitID)
|
||||
item = eos.db.getItem(itemID, eager=("attributes", "group.category"))
|
||||
if item.category.name == "Drone":
|
||||
@@ -109,7 +112,6 @@ class Fit(object):
|
||||
fit.calculateModifiedAttributes()
|
||||
return fit
|
||||
|
||||
|
||||
def removeDrone(self, fitID, i):
|
||||
fit = eos.db.getFit(fitID)
|
||||
fit.drones.removeItem(fit.drones[i].item, 1)
|
||||
@@ -118,3 +120,25 @@ class Fit(object):
|
||||
fit.clear()
|
||||
fit.calculateModifiedAttributes()
|
||||
return fit
|
||||
|
||||
def activateDrone(self, fitID, i):
|
||||
fit = eos.db.getFit(fitID)
|
||||
d = fit.drones[i]
|
||||
if d.amountActive < d.amount:
|
||||
d.amountActive += 1
|
||||
|
||||
eos.db.saveddata_session.flush()
|
||||
fit.clear()
|
||||
fit.calculateModifiedAttributes()
|
||||
return fit
|
||||
|
||||
def deactivateDrone(self, fitID, i):
|
||||
fit = eos.db.getFit(fitID)
|
||||
d = fit.drones[i]
|
||||
if d.amountActive > 0:
|
||||
d.amountActive -= 1
|
||||
|
||||
eos.db.saveddata_session.flush()
|
||||
fit.clear()
|
||||
fit.calculateModifiedAttributes()
|
||||
return fit
|
||||
|
||||
@@ -64,6 +64,13 @@ class Display(wx.ListCtrl):
|
||||
col.resized = False
|
||||
self.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER if col.size is wx.LIST_AUTOSIZE else col.size)
|
||||
|
||||
def getColIndex(self, colClass):
|
||||
for i, col in enumerate(self.activeColumns):
|
||||
if col.__class__ == colClass:
|
||||
return i
|
||||
|
||||
return None
|
||||
|
||||
def resizeChecker(self, event):
|
||||
if self.activeColumns[event.Column].resizable is False:
|
||||
event.Veto()
|
||||
@@ -100,3 +107,11 @@ class Display(wx.ListCtrl):
|
||||
|
||||
for sel in selection:
|
||||
self.Select(sel)
|
||||
|
||||
def getColumn(self, point):
|
||||
x = point[0]
|
||||
total = 0
|
||||
for col in xrange(self.GetColumnCount()):
|
||||
total += self.GetColumnWidth(col)
|
||||
if total >= x:
|
||||
return col
|
||||
|
||||
@@ -42,6 +42,7 @@ class DroneView(d.Display):
|
||||
self.mainFrame.Bind(fv.FIT_CHANGED, self.fitChanged)
|
||||
self.mainFrame.Bind(mb.ITEM_SELECTED, self.addItem)
|
||||
self.Bind(wx.EVT_LEFT_DCLICK, self.removeItem)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.click)
|
||||
|
||||
def fitChanged(self, event):
|
||||
cFit = controller.Fit.getInstance()
|
||||
@@ -59,11 +60,25 @@ class DroneView(d.Display):
|
||||
def removeItem(self, event):
|
||||
row, _ = self.HitTest(event.Position)
|
||||
if row != -1:
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
cFit = controller.Fit.getInstance()
|
||||
cFit.removeDrone(fitID, self.GetItemData(row))
|
||||
col = self.getColumn(event.Position)
|
||||
if col not in (self.getColIndex(DroneMore), self.getColIndex(DroneLess)):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
cFit = controller.Fit.getInstance()
|
||||
cFit.removeDrone(fitID, self.GetItemData(row))
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
|
||||
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
|
||||
def click(self, event):
|
||||
row, _ = self.HitTest(event.Position)
|
||||
if row != -1:
|
||||
col = self.getColumn(event.Position)
|
||||
cFit = controller.Fit.getInstance()
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
if col == self.getColIndex(DroneMore):
|
||||
cFit.activateDrone(fitID, row)
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
|
||||
elif col == self.getColIndex(DroneLess):
|
||||
cFit.deactivateDrone(fitID, row)
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=fitID))
|
||||
|
||||
class DroneMore(ViewColumn):
|
||||
name = "Activate Drone"
|
||||
|
||||
29
util.py
29
util.py
@@ -1,19 +1,48 @@
|
||||
def shorten(val, prec=4, lowest=0, highest=0):
|
||||
"""
|
||||
Add suffix to value, transform value to match new suffix and round it.
|
||||
|
||||
Keyword arguments:
|
||||
val -- value to process
|
||||
prec -- precision of final number (number of significant positions to show)
|
||||
lowest -- lowest order for suffixizing
|
||||
highest -- highest order for suffixizing
|
||||
|
||||
Suffixes below lowest and above highest orders won't be used.
|
||||
"""
|
||||
# Take numbers only matching/above lowest possible positive suffix
|
||||
if abs(val) >= 1000 and highest >= 3:
|
||||
suffixmap = {3 : "k", 6 : "M", 9 : "G"}
|
||||
# Start from highest possible suffix
|
||||
for key in sorted(suffixmap, reverse = True):
|
||||
# Find first suitable suffix and check if it's not above highest order
|
||||
if val >= 10**key and key <= highest:
|
||||
return u"{0}{1}".format(process(val/float(10**key), prec), suffixmap[key])
|
||||
# Take numbers between 0 and 1, and matching/below highest possible negative suffix
|
||||
elif abs(val) < 1 and val != 0 and lowest <= -3:
|
||||
suffixmap = {-6 : u'\u03bc', -3 : "m"}
|
||||
# Start from lowest possible suffix
|
||||
for key in sorted(suffixmap, reverse = False):
|
||||
# Check if mantissa with next suffix is in range [1, 1000)
|
||||
# Here we assume that each next order is greater than previous by 3
|
||||
if val < 10**(key+3) and key >= lowest:
|
||||
return u"{0}{1}".format(process(val/float(10**key), prec), suffixmap[key])
|
||||
# No suitable suffixes are found withing given order borders, or value
|
||||
# is already within [1, 1000) boundaries, just return rounded value with no suffix
|
||||
else:
|
||||
return u"{0}".format(process(val, prec))
|
||||
|
||||
|
||||
def process(val, prec):
|
||||
"""
|
||||
Round number.
|
||||
|
||||
Keyword arguments:
|
||||
val -- value to round
|
||||
prec -- precision of final number (number of significant positions to show)
|
||||
|
||||
Integer numbers are not rounded, only fractional part.
|
||||
"""
|
||||
# Check if we have no integer and some fraction after bunch of zeroes,
|
||||
# counting these zeros in process
|
||||
shiftFraction, integersNumber = 0, 0
|
||||
|
||||
Reference in New Issue
Block a user