Skip to content

Commit

Permalink
Adds a new notes pane for each fit
Browse files Browse the repository at this point in the history
This allows users to save text notes for each fit. They may do this for history, or usage, etc.
  • Loading branch information
resinneublem committed Nov 20, 2016
1 parent 2281fae commit 78cbed5
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
14 changes: 14 additions & 0 deletions eos/db/migrations/upgrade16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Migration 16
- Alters fits table to introduce notes attribute
"""

import sqlalchemy

def upgrade(saveddata_engine):
# Update fits schema to include notes attribute
try:
saveddata_engine.execute("SELECT notes FROM fits LIMIT 1")
except sqlalchemy.exc.DatabaseError:
saveddata_engine.execute("ALTER TABLE fits ADD COLUMN notes VARCHAR;")
1 change: 1 addition & 0 deletions eos/db/saveddata/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
Column("targetResistsID", ForeignKey("targetResists.ID"), nullable=True),
Column("modeID", Integer, nullable=True),
Column("implantLocation", Integer, nullable=False, default=ImplantLocation.FIT),
Column("notes", String, nullable = True),
)

projectedFits_table = Table("projectedFits", saveddata_meta,
Expand Down
1 change: 1 addition & 0 deletions eos/saveddata/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ def __deepcopy__(self, memo):
copy.name = "%s copy" % self.name
copy.damagePattern = self.damagePattern
copy.targetResists = self.targetResists
copy.notes = self.notes

toCopy = (
"modules",
Expand Down
7 changes: 6 additions & 1 deletion gui/additionsPane.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from gui.cargoView import CargoView
from gui.implantView import ImplantView
from gui.projectedView import ProjectedView
from gui.notesView import NotesView
from gui.pyfatogglepanel import TogglePanel
from gui.gangView import GangView
from gui.bitmapLoader import BitmapLoader
Expand Down Expand Up @@ -57,6 +58,7 @@ def __init__(self, parent):
projectedImg = BitmapLoader.getImage("projected_small", "gui")
gangImg = BitmapLoader.getImage("fleet_fc_small", "gui")
cargoImg = BitmapLoader.getImage("cargo_small", "gui")
notesImg = BitmapLoader.getImage("skill_small", "gui")

self.drone = DroneView(self.notebook)
self.notebook.AddPage(self.drone, "Drones", tabImage = droneImg, showClose = False)
Expand All @@ -79,9 +81,12 @@ def __init__(self, parent):
self.gangPage = GangView(self.notebook)
self.notebook.AddPage(self.gangPage, "Fleet", tabImage = gangImg, showClose = False)

self.notes = NotesView(self.notebook)
self.notebook.AddPage(self.notes, "Notes", tabImage = notesImg, showClose = False)

self.notebook.SetSelection(0)

PANES = ["Drones", "Fighters", "Cargo", "Implants", "Boosters", "Projected", "Fleet"]
PANES = ["Drones", "Fighters", "Cargo", "Implants", "Boosters", "Projected", "Fleet", "Notes"]
def select(self, name):
self.notebook.SetSelection(self.PANES.index(name))

Expand Down
45 changes: 45 additions & 0 deletions gui/notesView.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import wx

import service
import gui.globalEvents as GE
import gui.mainFrame

class NotesView(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.lastFitId = None
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.editNotes = wx.TextCtrl(self, style=wx.TE_MULTILINE)
mainSizer.Add(self.editNotes, 1, wx.EXPAND)
self.SetSizer(mainSizer)
self.mainFrame.Bind(GE.FIT_CHANGED, self.fitChanged)
self.Bind(wx.EVT_TEXT, self.onText)
self.saveTimer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.delayedSave, self.saveTimer)

def fitChanged(self, event):
sFit = service.Fit.getInstance()
fit = sFit.getFit(event.fitID)

self.Parent.Parent.DisablePage(self, not fit or fit.isStructure)

if event.fitID is None and self.lastFitId is not None:
self.lastFitId = None
event.Skip()
return
elif event.fitID != self.lastFitId:
self.lastFitId = event.fitID
self.editNotes.SetValue(fit.notes or "")

def onText(self, event):
# delay the save so we're not writing to sqlite on every keystroke
self.saveTimer.Stop() # cancel the existing timer
self.saveTimer.Start(1000, True)

def delayedSave(self, event):
sFit = service.Fit.getInstance()
fit = sFit.getFit(self.lastFitId)
newNotes = self.editNotes.GetValue()
fit.notes = newNotes
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fit.ID))

0 comments on commit 78cbed5

Please sign in to comment.