Added booster fit toggling in database, menu label toggling, and migration code

This commit is contained in:
blitzmann
2014-02-20 23:26:26 -05:00
parent aaadcb9b45
commit 3842913fe1
4 changed files with 51 additions and 15 deletions

View File

@@ -3,7 +3,7 @@ import sqlalchemy
def update(saveddata_engine):
checkPriceFailures(saveddata_engine)
checkApiDefaultChar(saveddata_engine)
checkFitBooster(saveddata_engine)
def checkPriceFailures(saveddata_engine):
# Check if we have 'failed' column
@@ -39,3 +39,21 @@ def checkApiDefaultChar(saveddata_engine):
except sqlalchemy.exc.DatabaseError:
saveddata_engine.execute("ALTER TABLE characters ADD COLUMN defaultChar INTEGER;")
saveddata_engine.execute("ALTER TABLE characters ADD COLUMN chars VARCHAR;")
def checkFitBooster(saveddata_engine):
try:
saveddata_engine.execute("SELECT * FROM fits LIMIT 1")
# If table doesn't exist, it means we're doing everything from scratch
# and sqlalchemy will process everything as needed
except sqlalchemy.exc.DatabaseError:
pass
# If not, we're running on top of existing DB
else:
# Check that we have columns
try:
saveddata_engine.execute("SELECT booster FROM fits LIMIT 1")
# If we don't, create them
# This is ugly as hell, but we can't use proper migrate packages as it
# will require us to rebuild skeletons, including mac
except sqlalchemy.exc.DatabaseError:
saveddata_engine.execute("ALTER TABLE fits ADD COLUMN booster BOOLEAN;")

View File

@@ -17,7 +17,7 @@
# along with eos. If not, see <http://www.gnu.org/licenses/>.
#===============================================================================
from sqlalchemy import Table, Column, Integer, ForeignKey, String
from sqlalchemy import Table, Column, Integer, ForeignKey, String, Boolean
from sqlalchemy.orm import relation, mapper
from sqlalchemy.sql import and_
@@ -36,7 +36,8 @@ fits_table = Table("fits", saveddata_meta,
Column("name", String, nullable = False),
Column("timestamp", Integer, nullable = False),
Column("characterID", ForeignKey("characters.ID"), nullable = True),
Column("damagePatternID", ForeignKey("damagePatterns.ID"), nullable=True))
Column("damagePatternID", ForeignKey("damagePatterns.ID"), nullable=True),
Column("booster", Boolean, nullable = False, index = True))
projectedFits_table = Table("projectedFits", saveddata_meta,
Column("sourceID", ForeignKey("fits.ID"), primary_key = True),

View File

@@ -806,8 +806,9 @@ class ShipBrowser(wx.Panel):
self._stage3ShipName = shipName
self._stage3Data = shipID
for ID, name, timestamp in fitList:
self.lpane.AddWidget(FitItem(self.lpane, ID, (shipName, name, timestamp),shipID))
for ID, name, booster, timestamp in fitList:
print
self.lpane.AddWidget(FitItem(self.lpane, ID, (shipName, name, booster, timestamp),shipID))
self.lpane.RefreshList()
self.lpane.Thaw()
@@ -1314,7 +1315,7 @@ class PFBitmapFrame(wx.Frame):
class FitItem(SFItem.SFBrowserItem):
def __init__(self, parent, fitID=None, shipFittingInfo=("Test", "cnc's avatar", 0 ), shipID = None, itemData=None,
def __init__(self, parent, fitID=None, shipFittingInfo=("Test", "cnc's avatar", 0, 0 ), shipID = None, itemData=None,
id=wx.ID_ANY, pos=wx.DefaultPosition,
size=(0, 40), style=0):
@@ -1350,9 +1351,16 @@ class FitItem(SFItem.SFBrowserItem):
if not self.shipBmp:
self.shipBmp = bitmapLoader.getBitmap("ship_no_image_big","icons")
self.fitMenu = wx.Menu()
item = self.fitMenu.Append(-1, "Flag As Booster Fit")
self.Bind(wx.EVT_MENU, self.OnPopupItemSelected, item)
self.shipFittingInfo = shipFittingInfo
self.shipName, self.fitName, self.fitBooster, self.timestamp = shipFittingInfo
# access these by index based on toggle for booster fit
self.toggleItemLabels = ["Set Booster Fit", "Remove Booster Fit"]
self.fitMenu = wx.Menu()
self.toggleItem = self.fitMenu.Append(-1, self.toggleItemLabels[self.fitBooster])
self.Bind(wx.EVT_MENU, self.OnPopupItemSelected, self.toggleItem)
if self.activeFit:
# If there is an active fit, get menu for setting individual boosters
@@ -1361,9 +1369,6 @@ class FitItem(SFItem.SFBrowserItem):
self.fitMenu.AppendMenu(wx.ID_ANY, 'Set Booster', boosterMenu)
self.mainFrame.additionsPane.gangPage.draggedFitID = self.fitID
self.shipFittingInfo = shipFittingInfo
self.shipName, self.fitName, self.timestamp = shipFittingInfo
self.copyBmp = bitmapLoader.getBitmap("fit_add_small", "icons")
self.renameBmp = bitmapLoader.getBitmap("fit_rename_small", "icons")
self.deleteBmp = bitmapLoader.getBitmap("fit_delete_small","icons")
@@ -1440,7 +1445,13 @@ class FitItem(SFItem.SFBrowserItem):
def OnPopupItemSelected(self, event):
''' Fires when fit menu item is selected '''
print "Set booster flag in DB"
# currently only have one menu option (toggle booster)
sFit = service.Fit.getInstance()
sFit.toggleBoostFit(self.fitID)
self.fitBooster = not self.fitBooster
self.toggleItem.SetItemLabel(self.toggleItemLabels[self.fitBooster])
event.Skip()
def OnContextMenu(self, event):
@@ -1684,7 +1695,7 @@ class FitItem(SFItem.SFBrowserItem):
mdc.DrawBitmap(self.shipBmp, self.shipBmpx, self.shipBmpy, 0)
shipName, fittings, timestamp = self.shipFittingInfo
shipName, fittings, booster, timestamp = self.shipFittingInfo
mdc.SetFont(self.fontNormal)

View File

@@ -95,10 +95,11 @@ class Fit(object):
return names
def getFitsWithShip(self, id):
''' Lists fits of shipID, used with shipBrowser '''
fits = eos.db.getFitsWithShip(id)
names = []
for fit in fits:
names.append((fit.ID, fit.name, fit.timestamp))
names.append((fit.ID, fit.name, fit.booster, fit.timestamp))
return names
@@ -129,6 +130,11 @@ class Fit(object):
self.recalc(fit)
return fit.ID
def toggleBoostFit(self, fitID):
fit = eos.db.getFit(fitID)
fit.booster = not fit.booster
eos.db.commit()
def renameFit(self, fitID, newName):
fit = eos.db.getFit(fitID)
fit.name = newName