Merge pull request #349 from vkbo/writing_stats

Writing Stats
This commit is contained in:
Veronica K. Berglyd Olsen
2020-06-27 20:23:24 +02:00
committed by GitHub
7 changed files with 49 additions and 47 deletions
+1
View File
@@ -167,6 +167,7 @@ These are as following:
":kbd:`F2`", "If in tree view, edit a document or folder settings. (Same as :kbd:`Ctrl-E`)" ":kbd:`F2`", "If in tree view, edit a document or folder settings. (Same as :kbd:`Ctrl-E`)"
":kbd:`F3`", "Find next occurrence of word in current document. (Same as :kbd:`Ctrl-G`)" ":kbd:`F3`", "Find next occurrence of word in current document. (Same as :kbd:`Ctrl-G`)"
":kbd:`F5`", "Open the Build Novel Project dialog." ":kbd:`F5`", "Open the Build Novel Project dialog."
":kbd:`F6`", "Open the Writing Statistics dialog."
":kbd:`F7`", "Re-run spell checker." ":kbd:`F7`", "Re-run spell checker."
":kbd:`F8`", "Activate Zen Mode, hiding project tree and view panel." ":kbd:`F8`", "Activate Zen Mode, hiding project tree and view panel."
":kbd:`F9`", "Re-build project index." ":kbd:`F9`", "Re-build project index."
+1 -1
View File
@@ -45,7 +45,7 @@ class OptionState():
self.theState = {} self.theState = {}
self.validMap = { self.validMap = {
"GuiSessionLog": { "GuiWritingStats": {
"winWidth", "winWidth",
"winHeight", "winHeight",
"widthCol0", "widthCol0",
+2 -2
View File
@@ -15,7 +15,7 @@ from nw.gui.preferences import GuiPreferences
from nw.gui.projload import GuiProjectLoad from nw.gui.projload import GuiProjectLoad
from nw.gui.projsettings import GuiProjectSettings from nw.gui.projsettings import GuiProjectSettings
from nw.gui.projtree import GuiProjectTree from nw.gui.projtree import GuiProjectTree
from nw.gui.sessionlog import GuiSessionLog from nw.gui.writingstats import GuiWritingStats
from nw.gui.statusbar import GuiMainStatus from nw.gui.statusbar import GuiMainStatus
from nw.gui.theme import GuiIcons, GuiTheme from nw.gui.theme import GuiIcons, GuiTheme
@@ -36,7 +36,7 @@ __all__ = [
"GuiProjectLoad", "GuiProjectLoad",
"GuiProjectSettings", "GuiProjectSettings",
"GuiProjectTree", "GuiProjectTree",
"GuiSessionLog", "GuiWritingStats",
"GuiMainStatus", "GuiMainStatus",
"GuiIcons", "GuiIcons",
"GuiTheme", "GuiTheme",
+7 -6
View File
@@ -207,12 +207,6 @@ class GuiMainMenu(QMenuBar):
self.aBuildProject.triggered.connect(self.theParent.buildProjectDialog) self.aBuildProject.triggered.connect(self.theParent.buildProjectDialog)
self.projMenu.addAction(self.aBuildProject) self.projMenu.addAction(self.aBuildProject)
# Project > Session Log
self.aSessionLog = QAction("Session Log", self)
self.aSessionLog.setStatusTip("Show the session log")
self.aSessionLog.triggered.connect(self.theParent.showSessionLogDialog)
self.projMenu.addAction(self.aSessionLog)
# Project > Separator # Project > Separator
self.projMenu.addSeparator() self.projMenu.addSeparator()
@@ -759,6 +753,13 @@ class GuiMainMenu(QMenuBar):
self.aBackupProject.triggered.connect(self._doBackup) self.aBackupProject.triggered.connect(self._doBackup)
self.toolsMenu.addAction(self.aBackupProject) self.toolsMenu.addAction(self.aBackupProject)
# Tools > Writing Stats
self.aWritingStats = QAction("Show Writing Statistics", self)
self.aWritingStats.setStatusTip("Show the writing statistics dialog")
self.aWritingStats.setShortcut("F6")
self.aWritingStats.triggered.connect(self.theParent.showWritingStatsDialog)
self.toolsMenu.addAction(self.aWritingStats)
# Tools > Settings # Tools > Settings
self.aPreferences = QAction("Preferences", self) self.aPreferences = QAction("Preferences", self)
self.aPreferences.setStatusTip("Preferences") self.aPreferences.setStatusTip("Preferences")
+32 -32
View File
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""novelWriter GUI Session Log Viewer """novelWriter GUI Writing Statistics
novelWriter GUI Session Log Viewer novelWriter GUI Writing Statistics
====================================== ======================================
Class holding the session log view window Class showing the word count and session statistics
File History: File History:
Created: 2019-10-20 [0.3] Created: 2019-10-20 [0.3]
@@ -44,7 +44,7 @@ from nw.gui.custom import QSwitch
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class GuiSessionLog(QDialog): class GuiWritingStats(QDialog):
C_TIME = 0 C_TIME = 0
C_LENGTH = 1 C_LENGTH = 1
@@ -57,7 +57,7 @@ class GuiSessionLog(QDialog):
def __init__(self, theParent, theProject): def __init__(self, theParent, theProject):
QDialog.__init__(self, theParent) QDialog.__init__(self, theParent)
logger.debug("Initialising GuiSessionLog ...") logger.debug("Initialising GuiWritingStats ...")
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.theParent = theParent self.theParent = theParent
@@ -70,23 +70,23 @@ class GuiSessionLog(QDialog):
self.timeFilter = 0.0 self.timeFilter = 0.0
self.wordOffset = 0 self.wordOffset = 0
self.setWindowTitle("Session Log") self.setWindowTitle("Writing Statistics")
self.setMinimumWidth(self.mainConf.pxInt(420)) self.setMinimumWidth(self.mainConf.pxInt(420))
self.setMinimumHeight(self.mainConf.pxInt(400)) self.setMinimumHeight(self.mainConf.pxInt(400))
self.resize( self.resize(
self.mainConf.pxInt(self.optState.getInt("GuiSessionLog", "winWidth", 550)), self.mainConf.pxInt(self.optState.getInt("GuiWritingStats", "winWidth", 550)),
self.mainConf.pxInt(self.optState.getInt("GuiSessionLog", "winHeight", 500)) self.mainConf.pxInt(self.optState.getInt("GuiWritingStats", "winHeight", 500))
) )
# List Box # List Box
wCol0 = self.mainConf.pxInt( wCol0 = self.mainConf.pxInt(
self.optState.getInt("GuiSessionLog", "widthCol0", 180) self.optState.getInt("GuiWritingStats", "widthCol0", 180)
) )
wCol1 = self.mainConf.pxInt( wCol1 = self.mainConf.pxInt(
self.optState.getInt("GuiSessionLog", "widthCol1", 80) self.optState.getInt("GuiWritingStats", "widthCol1", 80)
) )
wCol2 = self.mainConf.pxInt( wCol2 = self.mainConf.pxInt(
self.optState.getInt("GuiSessionLog", "widthCol2", 80) self.optState.getInt("GuiWritingStats", "widthCol2", 80)
) )
self.listBox = QTreeWidget() self.listBox = QTreeWidget()
@@ -106,10 +106,10 @@ class GuiSessionLog(QDialog):
sortValid = (Qt.AscendingOrder, Qt.DescendingOrder) sortValid = (Qt.AscendingOrder, Qt.DescendingOrder)
sortCol = self.optState.validIntRange( sortCol = self.optState.validIntRange(
self.optState.getInt("GuiSessionLog", "sortCol", 0), 0, 2, 0 self.optState.getInt("GuiWritingStats", "sortCol", 0), 0, 2, 0
) )
sortOrder = self.optState.validIntTuple( sortOrder = self.optState.validIntTuple(
self.optState.getInt("GuiSessionLog", "sortOrder", Qt.DescendingOrder), self.optState.getInt("GuiWritingStats", "sortOrder", Qt.DescendingOrder),
sortValid, Qt.DescendingOrder sortValid, Qt.DescendingOrder
) )
self.listBox.sortByColumn(sortCol, sortOrder) self.listBox.sortByColumn(sortCol, sortOrder)
@@ -167,31 +167,31 @@ class GuiSessionLog(QDialog):
self.incNovel = QSwitch(width=2*sPx, height=sPx) self.incNovel = QSwitch(width=2*sPx, height=sPx)
self.incNovel.setChecked( self.incNovel.setChecked(
self.optState.getBool("GuiSessionLog", "incNovel", True) self.optState.getBool("GuiWritingStats", "incNovel", True)
) )
self.incNovel.clicked.connect(self._updateListBox) self.incNovel.clicked.connect(self._updateListBox)
self.incNotes = QSwitch(width=2*sPx, height=sPx) self.incNotes = QSwitch(width=2*sPx, height=sPx)
self.incNotes.setChecked( self.incNotes.setChecked(
self.optState.getBool("GuiSessionLog", "incNotes", True) self.optState.getBool("GuiWritingStats", "incNotes", True)
) )
self.incNotes.clicked.connect(self._updateListBox) self.incNotes.clicked.connect(self._updateListBox)
self.hideZeros = QSwitch(width=2*sPx, height=sPx) self.hideZeros = QSwitch(width=2*sPx, height=sPx)
self.hideZeros.setChecked( self.hideZeros.setChecked(
self.optState.getBool("GuiSessionLog", "hideZeros", True) self.optState.getBool("GuiWritingStats", "hideZeros", True)
) )
self.hideZeros.clicked.connect(self._updateListBox) self.hideZeros.clicked.connect(self._updateListBox)
self.hideNegative = QSwitch(width=2*sPx, height=sPx) self.hideNegative = QSwitch(width=2*sPx, height=sPx)
self.hideNegative.setChecked( self.hideNegative.setChecked(
self.optState.getBool("GuiSessionLog", "hideNegative", False) self.optState.getBool("GuiWritingStats", "hideNegative", False)
) )
self.hideNegative.clicked.connect(self._updateListBox) self.hideNegative.clicked.connect(self._updateListBox)
self.groupByDay = QSwitch(width=2*sPx, height=sPx) self.groupByDay = QSwitch(width=2*sPx, height=sPx)
self.groupByDay.setChecked( self.groupByDay.setChecked(
self.optState.getBool("GuiSessionLog", "groupByDay", False) self.optState.getBool("GuiWritingStats", "groupByDay", False)
) )
self.groupByDay.clicked.connect(self._updateListBox) self.groupByDay.clicked.connect(self._updateListBox)
@@ -233,7 +233,7 @@ class GuiSessionLog(QDialog):
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
logger.debug("GuiSessionLog initialisation complete") logger.debug("GuiWritingStats initialisation complete")
qApp.processEvents() qApp.processEvents()
self._loadLogFile() self._loadLogFile()
@@ -263,18 +263,18 @@ class GuiSessionLog(QDialog):
hideNegative = self.hideNegative.isChecked() hideNegative = self.hideNegative.isChecked()
groupByDay = self.groupByDay.isChecked() groupByDay = self.groupByDay.isChecked()
self.optState.setValue("GuiSessionLog", "winWidth", winWidth) self.optState.setValue("GuiWritingStats", "winWidth", winWidth)
self.optState.setValue("GuiSessionLog", "winHeight", winHeight) self.optState.setValue("GuiWritingStats", "winHeight", winHeight)
self.optState.setValue("GuiSessionLog", "widthCol0", widthCol0) self.optState.setValue("GuiWritingStats", "widthCol0", widthCol0)
self.optState.setValue("GuiSessionLog", "widthCol1", widthCol1) self.optState.setValue("GuiWritingStats", "widthCol1", widthCol1)
self.optState.setValue("GuiSessionLog", "widthCol2", widthCol2) self.optState.setValue("GuiWritingStats", "widthCol2", widthCol2)
self.optState.setValue("GuiSessionLog", "sortCol", sortCol) self.optState.setValue("GuiWritingStats", "sortCol", sortCol)
self.optState.setValue("GuiSessionLog", "sortOrder", sortOrder) self.optState.setValue("GuiWritingStats", "sortOrder", sortOrder)
self.optState.setValue("GuiSessionLog", "incNovel", incNovel) self.optState.setValue("GuiWritingStats", "incNovel", incNovel)
self.optState.setValue("GuiSessionLog", "incNotes", incNotes) self.optState.setValue("GuiWritingStats", "incNotes", incNotes)
self.optState.setValue("GuiSessionLog", "hideZeros", hideZeros) self.optState.setValue("GuiWritingStats", "hideZeros", hideZeros)
self.optState.setValue("GuiSessionLog", "hideNegative", hideNegative) self.optState.setValue("GuiWritingStats", "hideNegative", hideNegative)
self.optState.setValue("GuiSessionLog", "groupByDay", groupByDay) self.optState.setValue("GuiWritingStats", "groupByDay", groupByDay)
self.optState.saveSettings() self.optState.saveSettings()
self.close() self.close()
@@ -553,4 +553,4 @@ class GuiSessionLog(QDialog):
tS = tS - tM*60 - tH*3600 tS = tS - tM*60 - tH*3600
return "%02d:%02d:%02d" % (tH,tM,tS) return "%02d:%02d:%02d" % (tH,tM,tS)
# END Class GuiSessionLog # END Class GuiWritingStats
+3 -3
View File
@@ -43,7 +43,7 @@ from nw.gui import (
GuiBuildNovel, GuiDocEditor, GuiDocMerge, GuiDocSplit, GuiDocViewDetails, GuiBuildNovel, GuiDocEditor, GuiDocMerge, GuiDocSplit, GuiDocViewDetails,
GuiDocViewer, GuiItemDetails, GuiItemEditor, GuiMainMenu, GuiMainStatus, GuiDocViewer, GuiItemDetails, GuiItemEditor, GuiMainMenu, GuiMainStatus,
GuiOutline, GuiOutlineDetails, GuiPreferences, GuiProjectLoad, GuiTheme, GuiOutline, GuiOutlineDetails, GuiPreferences, GuiProjectLoad, GuiTheme,
GuiProjectSettings, GuiProjectTree, GuiSessionLog GuiProjectSettings, GuiProjectTree, GuiWritingStats
) )
from nw.core import NWProject, NWDoc, NWIndex from nw.core import NWProject, NWDoc, NWIndex
from nw.constants import nwFiles, nwItemType, nwAlert from nw.constants import nwFiles, nwItemType, nwAlert
@@ -806,11 +806,11 @@ class GuiMain(QMainWindow):
dlgExport.exec_() dlgExport.exec_()
return True return True
def showSessionLogDialog(self): def showWritingStatsDialog(self):
"""Open the session log dialog. """Open the session log dialog.
""" """
if self.hasProject: if self.hasProject:
dlgTLine = GuiSessionLog(self, self.theProject) dlgTLine = GuiWritingStats(self, self.theProject)
dlgTLine.exec_() dlgTLine.exec_()
return True return True
+3 -3
View File
@@ -10,7 +10,7 @@ from PyQt5.QtCore import Qt
from nw.gui import ( from nw.gui import (
GuiProjectSettings, GuiItemEditor, GuiAbout, GuiBuildNovel, GuiProjectSettings, GuiItemEditor, GuiAbout, GuiBuildNovel,
GuiDocMerge, GuiDocSplit, GuiSessionLog GuiDocMerge, GuiDocSplit, GuiWritingStats
) )
from nw.constants import * from nw.constants import *
@@ -410,7 +410,7 @@ def testItemEditor(qtbot, nwTempGUI, nwRef, nwTemp):
# qtbot.stopForInteraction() # qtbot.stopForInteraction()
@pytest.mark.gui @pytest.mark.gui
def testSessionLogExport(qtbot, nwTempGUI, nwRef, nwTemp): def testWritingStatsExport(qtbot, nwTempGUI, nwRef, nwTemp):
nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI, "--data=%s" % nwTemp]) nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
@@ -421,7 +421,7 @@ def testSessionLogExport(qtbot, nwTempGUI, nwRef, nwTemp):
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
nwGUI.mainConf.lastPath = nwTempGUI nwGUI.mainConf.lastPath = nwTempGUI
sessLog = GuiSessionLog(nwGUI, nwGUI.theProject) sessLog = GuiWritingStats(nwGUI, nwGUI.theProject)
sessLog.show() sessLog.show()
qtbot.wait(stepDelay) qtbot.wait(stepDelay)