Session log is now printed in the table

This commit is contained in:
Veronica K. B. Olsen
2019-10-20 15:52:25 +02:00
parent 50f4d8e073
commit 2fe001b336
3 changed files with 73 additions and 6 deletions
+64 -3
View File
@@ -13,13 +13,17 @@
import logging
import nw
from os import path
from datetime import datetime
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QColor, QPixmap
from PyQt5.QtGui import QIcon, QColor, QPixmap, QFont
from PyQt5.QtWidgets import (
QDialog, QVBoxLayout, QHBoxLayout, QTableWidget, QTableWidgetItem,
QDialogButtonBox, QLabel, QPushButton, QHeaderView
QDialog, QVBoxLayout, QHBoxLayout, QTreeWidget, QTreeWidgetItem, QDialogButtonBox, QHeaderView
)
from nw.enum import nwAlert
from nw.constants import nwConst, nwFiles
logger = logging.getLogger(__name__)
class GuiSessionLogView(QDialog):
@@ -37,6 +41,31 @@ class GuiSessionLogView(QDialog):
self.bottomBox = QHBoxLayout()
self.setWindowTitle("Session Log")
self.setMinimumWidth(420)
self.setMinimumHeight(400)
self.listBox = QTreeWidget()
self.listBox.setHeaderLabels(["Session Start","Length","Words",""])
self.listBox.setIndentation(0)
self.listBox.setColumnWidth(0,180)
self.listBox.setColumnWidth(1,80)
self.listBox.setColumnWidth(2,80)
self.listBox.setColumnWidth(3,0)
hHeader = self.listBox.headerItem()
hHeader.setTextAlignment(1,Qt.AlignRight)
hHeader.setTextAlignment(2,Qt.AlignRight)
self.listFont = QFont("Monospace",10)
self.listBox.sortByColumn(0, Qt.DescendingOrder)
self.listBox.setSortingEnabled(True)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Close)
self.buttonBox.rejected.connect(self._doClose)
self.outerBox.addWidget(self.listBox)
self.outerBox.addWidget(self.buttonBox)
self.setLayout(self.outerBox)
@@ -44,8 +73,40 @@ class GuiSessionLogView(QDialog):
logger.debug("SessionLogView initialisation complete")
self._loadSessionLog()
return
def _loadSessionLog(self):
logFile = path.join(self.theProject.projMeta, nwFiles.SESS_INFO)
if not path.isfile(logFile):
logger.warning("No session log file found for this project.")
return False
logger.debug("Loading session log file")
try:
with open(logFile,mode="r") as inFile:
for inLine in inFile:
inData = inLine.split()
if len(inData) != 8:
continue
dStart = datetime.strptime("%s %s" % (inData[1],inData[2]),nwConst.tStampFmt)
dEnd = datetime.strptime("%s %s" % (inData[4],inData[5]),nwConst.tStampFmt)
nWords = int(inData[7])
newItem = QTreeWidgetItem([str(dStart),str(dEnd-dStart),str(nWords),""])
newItem.setTextAlignment(1,Qt.AlignRight)
newItem.setTextAlignment(2,Qt.AlignRight)
newItem.setFont(0,self.listFont)
newItem.setFont(1,self.listFont)
newItem.setFont(2,self.listFont)
self.listBox.addTopLevelItem(newItem)
except Exception as e:
self.theParent.makeAlert(["Failed to read session log file.",str(e)], nwAlert.ERROR)
return False
return True
def _doClose(self):
self.close()
return