Some reshuffling of loading into document viewer
This commit is contained in:
+48
-7
@@ -13,32 +13,40 @@
|
|||||||
import logging
|
import logging
|
||||||
import nw
|
import nw
|
||||||
|
|
||||||
|
from PyQt5.QtCore import Qt
|
||||||
from PyQt5.QtWidgets import QTextBrowser
|
from PyQt5.QtWidgets import QTextBrowser
|
||||||
|
from PyQt5.QtGui import QTextOption
|
||||||
|
|
||||||
|
from nw.convert.tokenizer import Tokenizer
|
||||||
|
from nw.convert.tohtml import ToHtml
|
||||||
|
from nw.enum import nwItemType
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class GuiDocViewer(QTextBrowser):
|
class GuiDocViewer(QTextBrowser):
|
||||||
|
|
||||||
def __init__(self, theParent):
|
def __init__(self, theParent, theProject):
|
||||||
QTextBrowser.__init__(self)
|
QTextBrowser.__init__(self)
|
||||||
|
|
||||||
logger.debug("Initialising DocViewer ...")
|
logger.debug("Initialising DocViewer ...")
|
||||||
|
|
||||||
# Class Variables
|
# Class Variables
|
||||||
self.mainConf = nw.CONFIG
|
self.mainConf = nw.CONFIG
|
||||||
self.theParent = theParent
|
self.theProject = theProject
|
||||||
self.theTheme = theParent.theTheme
|
self.theParent = theParent
|
||||||
|
self.theTheme = theParent.theTheme
|
||||||
|
self.theHandle = None
|
||||||
|
|
||||||
self.theDoc = self.document()
|
self.theQDoc = self.document()
|
||||||
self.theDoc.setDefaultStyleSheet((
|
self.theQDoc.setDefaultStyleSheet((
|
||||||
"h1, h2, h3, h4 {{"
|
"h1, h2, h3, h4 {{"
|
||||||
" color: rgb({0},{1},{2});"
|
" color: rgb({0},{1},{2});"
|
||||||
"}}"
|
"}}"
|
||||||
).format(
|
).format(
|
||||||
*self.theTheme.colHead
|
*self.theTheme.colHead
|
||||||
))
|
))
|
||||||
self.theDoc.setDocumentMargin(self.mainConf.textMargin[0])
|
|
||||||
self.setMinimumWidth(300)
|
self.setMinimumWidth(300)
|
||||||
|
self.initEditor()
|
||||||
|
|
||||||
logger.debug("DocViewer initialisation complete")
|
logger.debug("DocViewer initialisation complete")
|
||||||
|
|
||||||
@@ -48,4 +56,37 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
self.clear()
|
self.clear()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def initEditor(self):
|
||||||
|
"""Set editor settings from mani config.
|
||||||
|
"""
|
||||||
|
self.theQDoc.setDocumentMargin(self.mainConf.textMargin[0])
|
||||||
|
theOpt = QTextOption()
|
||||||
|
if self.mainConf.doJustify:
|
||||||
|
theOpt.setAlignment(Qt.AlignJustify)
|
||||||
|
self.theQDoc.setDefaultTextOption(theOpt)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def loadText(self, tHandle):
|
||||||
|
|
||||||
|
tItem = self.theProject.getItem(tHandle)
|
||||||
|
if tItem is None:
|
||||||
|
logger.warning("Item not found")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if tItem.itemType != nwItemType.FILE:
|
||||||
|
return False
|
||||||
|
|
||||||
|
logger.debug("Generating preview for item %s" % tHandle)
|
||||||
|
aDoc = ToHtml(self.theProject, self.theParent)
|
||||||
|
aDoc.setText(tHandle)
|
||||||
|
aDoc.doAutoReplace()
|
||||||
|
aDoc.tokenizeText()
|
||||||
|
aDoc.doConvert()
|
||||||
|
self.setHtml(aDoc.theResult)
|
||||||
|
self.theHandle = tHandle
|
||||||
|
self.theProject.setLastViewed(tHandle)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
# END Class GuiDocViewer
|
# END Class GuiDocViewer
|
||||||
|
|||||||
+2
-18
@@ -35,8 +35,6 @@ from nw.project.project import NWProject
|
|||||||
from nw.project.document import NWDoc
|
from nw.project.document import NWDoc
|
||||||
from nw.project.item import NWItem
|
from nw.project.item import NWItem
|
||||||
from nw.project.index import NWIndex
|
from nw.project.index import NWIndex
|
||||||
from nw.convert.tokenizer import Tokenizer
|
|
||||||
from nw.convert.tohtml import ToHtml
|
|
||||||
from nw.tools.wordcount import countWords
|
from nw.tools.wordcount import countWords
|
||||||
from nw.theme import Theme
|
from nw.theme import Theme
|
||||||
from nw.enum import nwItemType, nwAlert
|
from nw.enum import nwItemType, nwAlert
|
||||||
@@ -64,7 +62,7 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
# Main GUI Elements
|
# Main GUI Elements
|
||||||
self.docEditor = GuiDocEditor(self)
|
self.docEditor = GuiDocEditor(self)
|
||||||
self.docViewer = GuiDocViewer(self)
|
self.docViewer = GuiDocViewer(self, self.theProject)
|
||||||
self.docDetails = GuiDocDetails(self, self.theProject)
|
self.docDetails = GuiDocDetails(self, self.theProject)
|
||||||
self.treeView = GuiDocTree(self, self.theProject)
|
self.treeView = GuiDocTree(self, self.theProject)
|
||||||
self.mainMenu = GuiMainMenu(self, self.theProject)
|
self.mainMenu = GuiMainMenu(self, self.theProject)
|
||||||
@@ -319,21 +317,7 @@ class GuiMain(QMainWindow):
|
|||||||
logger.warning("No document selected")
|
logger.warning("No document selected")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
tItem = self.theProject.getItem(tHandle)
|
if self.docViewer.loadText(tHandle):
|
||||||
if tItem is None:
|
|
||||||
logger.warning("Item not found")
|
|
||||||
return False
|
|
||||||
|
|
||||||
if tItem.itemType == nwItemType.FILE:
|
|
||||||
logger.debug("Generating preview for item %s" % tHandle)
|
|
||||||
aDoc = ToHtml(self.theProject, self)
|
|
||||||
aDoc.setText(tHandle)
|
|
||||||
aDoc.doAutoReplace()
|
|
||||||
aDoc.tokenizeText()
|
|
||||||
aDoc.doConvert()
|
|
||||||
self.docViewer.setHtml(aDoc.theResult)
|
|
||||||
self.theProject.setLastViewed(tHandle)
|
|
||||||
|
|
||||||
bPos = self.splitMain.sizes()
|
bPos = self.splitMain.sizes()
|
||||||
self.docViewer.setVisible(True)
|
self.docViewer.setVisible(True)
|
||||||
vPos = [0,0]
|
vPos = [0,0]
|
||||||
|
|||||||
Reference in New Issue
Block a user