From 367d2c5014d83da3e9c79580643e687104ccb9b4 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Sun, 26 May 2019 14:39:13 +0200 Subject: [PATCH] Added a log file that appends session stats. --- nw/constants.py | 1 + nw/gui/winmain.py | 3 ++- nw/project/project.py | 26 +++++++++++++++++++ .../sampleNovel/data_6/36b6aa9b697b_main.nwd | 6 ++++- sample/sampleNovel/meta/sessionInfo.log | 3 +++ sample/sampleNovel/nwProject.nwx | 10 +++---- 6 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 sample/sampleNovel/meta/sessionInfo.log diff --git a/nw/constants.py b/nw/constants.py index f8a37ae7..478a7f5f 100644 --- a/nw/constants.py +++ b/nw/constants.py @@ -17,6 +17,7 @@ class nwFiles(): APP_ICON = "novelWriter.svg" PROJ_FILE = "nwProject.nwx" PROJ_DICT = "wordlist.txt" + SESS_INFO = "sessionInfo.log" # END Class nwFiles diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index 3d1b4f26..021024c7 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -237,7 +237,7 @@ class GuiMain(QMainWindow): saveOK = True if saveOK: - self.theProject.clearProject() + self.theProject.closeProject() self.clearGUI() self.hasProject = False @@ -451,6 +451,7 @@ class GuiMain(QMainWindow): self.saveDocument() if self._takeProjectAction(): self.saveProject() + self.theProject.closeProject() self.mainConf.setWinSize(self.width(), self.height()) self.mainConf.setTreeColWidths(self.treeView.getColumnSizes()) self.mainConf.setMainPanePos(self.splitMain.sizes()) diff --git a/nw/project/project.py b/nw/project/project.py index d5c700e2..6ddb992d 100644 --- a/nw/project/project.py +++ b/nw/project/project.py @@ -35,6 +35,7 @@ class NWProject(): self.theParent = theParent self.mainConf = self.theParent.mainConf self.projChanged = None + self.projOpened = None # Debug self.handleSeed = None @@ -135,6 +136,7 @@ class NWProject(): def clearProject(self): self.projChanged = None + self.projOpened = None # Project Settings self.projTree = {} @@ -251,6 +253,7 @@ class NWProject(): self._scanProjectFolder() self.setProjectChanged(False) + self.projOpened = time() return True @@ -321,6 +324,11 @@ class NWProject(): return True + def closeProject(self): + self._appendSessionStats() + self.clearProject() + return True + ## # Set Functions ## @@ -594,6 +602,24 @@ class NWProject(): return + def _appendSessionStats(self): + + if self.projMeta is None: + return False + + with open(path.join(self.projMeta, nwFiles.SESS_INFO), mode="a+") as outFile: + print(( + "Start: {opened:s} " + "End: {closed:s} " + "Words: {words:8d}" + ).format( + opened = datetime.fromtimestamp(self.projOpened).strftime("%Y-%m-%d %H:%M:%S"), + closed = datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + words = self.getSessionWordCount(), + ), file=outFile) + + return True + def _makeHandle(self, addSeed=""): if self.handleSeed is None: newSeed = str(time()) + addSeed diff --git a/sample/sampleNovel/data_6/36b6aa9b697b_main.nwd b/sample/sampleNovel/data_6/36b6aa9b697b_main.nwd index 72d112c6..52aacd59 100644 --- a/sample/sampleNovel/data_6/36b6aa9b697b_main.nwd +++ b/sample/sampleNovel/data_6/36b6aa9b697b_main.nwd @@ -13,8 +13,12 @@ Some text here would look good as well, and maybe some "dialogue"? So, this is some __text__ that we’ve been adding to this document. It is utterly meaningless text, _but_ since this is just dummy text, that doesn’t really matter. The text is perfectly happy to live in this document regardless. -This paragraph is also meaningless. At least a bit. It’s also very short. +This paragraph is also meaningless. At least a bit. It’s also very short. But we could make it less meaningless if we wanted to … This one is a bit longer. “It also has some dialogue in it” she said, before she moved on to check if the spellchecker worked. It did. “Cool,” she concluded. +@ToDo: Stuff that will be done at some point + + + diff --git a/sample/sampleNovel/meta/sessionInfo.log b/sample/sampleNovel/meta/sessionInfo.log new file mode 100644 index 00000000..c4442696 --- /dev/null +++ b/sample/sampleNovel/meta/sessionInfo.log @@ -0,0 +1,3 @@ +Start: 2019-05-26 14:28:28 End: 2019-05-26 14:28:38 Words: -23 +Start: 2019-05-26 14:31:12 End: 2019-05-26 14:31:34 Words: 12 +Start: 2019-05-26 14:33:27 End: 2019-05-26 14:33:31 Words: 0 diff --git a/sample/sampleNovel/nwProject.nwx b/sample/sampleNovel/nwProject.nwx index a6fdb23c..a4d878b0 100644 --- a/sample/sampleNovel/nwProject.nwx +++ b/sample/sampleNovel/nwProject.nwx @@ -1,5 +1,5 @@ - + Sample Project Sample Project @@ -10,7 +10,7 @@ True 636b6aa9b697b None - 523 + 535 New Notes @@ -73,10 +73,10 @@ Notes False SCENE - 577 - 104 + 633 + 116 5 - 655 + 551 New File