forked from pyfa-org/Pyfa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows users to save text notes for each fit. They may do this for history, or usage, etc.
- Loading branch information
1 parent
2281fae
commit 78cbed5
Showing
5 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |