Finished the handling of text width, window resize, and save and load of editor config.
This commit is contained in:
+28
-3
@@ -49,7 +49,7 @@ class Config:
|
|||||||
mkdir(self.confPath)
|
mkdir(self.confPath)
|
||||||
|
|
||||||
# Set default values
|
# Set default values
|
||||||
self.confChanged = False
|
self.confChanged = False
|
||||||
|
|
||||||
## General
|
## General
|
||||||
self.guiTheme = "default"
|
self.guiTheme = "default"
|
||||||
@@ -58,7 +58,9 @@ class Config:
|
|||||||
self.mainPanePos = [300, 800]
|
self.mainPanePos = [300, 800]
|
||||||
|
|
||||||
## Text Editor
|
## Text Editor
|
||||||
|
self.textFixedW = True
|
||||||
self.textWidth = 600
|
self.textWidth = 600
|
||||||
|
self.textMargin = [40, 40]
|
||||||
|
|
||||||
# Check if config file exists
|
# Check if config file exists
|
||||||
if path.isfile(path.join(self.confPath,self.confFile)):
|
if path.isfile(path.join(self.confPath,self.confFile)):
|
||||||
@@ -82,8 +84,8 @@ class Config:
|
|||||||
|
|
||||||
# Get options
|
# Get options
|
||||||
|
|
||||||
## Main
|
## Sizes
|
||||||
cnfSec = "Main"
|
cnfSec = "Sizes"
|
||||||
if confParser.has_section(cnfSec):
|
if confParser.has_section(cnfSec):
|
||||||
if confParser.has_option(cnfSec,"geometry"):
|
if confParser.has_option(cnfSec,"geometry"):
|
||||||
self.winGeometry = self.unpackList(
|
self.winGeometry = self.unpackList(
|
||||||
@@ -98,6 +100,18 @@ class Config:
|
|||||||
confParser.get(cnfSec,"mainpane"), 2, self.mainPanePos
|
confParser.get(cnfSec,"mainpane"), 2, self.mainPanePos
|
||||||
)
|
)
|
||||||
|
|
||||||
|
## Editor
|
||||||
|
cnfSec = "Editor"
|
||||||
|
if confParser.has_section(cnfSec):
|
||||||
|
if confParser.has_option(cnfSec,"fixedwidth"):
|
||||||
|
self.textFixedW = confParser.getboolean(cnfSec,"fixedwidth")
|
||||||
|
if confParser.has_option(cnfSec,"width"):
|
||||||
|
self.textWidth = confParser.getint(cnfSec,"width")
|
||||||
|
if confParser.has_option(cnfSec,"margins"):
|
||||||
|
self.textMargin = self.unpackList(
|
||||||
|
confParser.get(cnfSec,"margins"), 2, self.textMargin
|
||||||
|
)
|
||||||
|
|
||||||
## Path
|
## Path
|
||||||
cnfSec = "Path"
|
cnfSec = "Path"
|
||||||
if confParser.has_section(cnfSec):
|
if confParser.has_section(cnfSec):
|
||||||
@@ -118,10 +132,21 @@ class Config:
|
|||||||
cnfSec = "Main"
|
cnfSec = "Main"
|
||||||
confParser.add_section(cnfSec)
|
confParser.add_section(cnfSec)
|
||||||
confParser.set(cnfSec,"timestamp", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
confParser.set(cnfSec,"timestamp", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||||
|
|
||||||
|
## Sizes
|
||||||
|
cnfSec = "Sizes"
|
||||||
|
confParser.add_section(cnfSec)
|
||||||
confParser.set(cnfSec,"geometry", self.packList(self.winGeometry))
|
confParser.set(cnfSec,"geometry", self.packList(self.winGeometry))
|
||||||
confParser.set(cnfSec,"treecols", self.packList(self.treeColWidth))
|
confParser.set(cnfSec,"treecols", self.packList(self.treeColWidth))
|
||||||
confParser.set(cnfSec,"mainpane", self.packList(self.mainPanePos))
|
confParser.set(cnfSec,"mainpane", self.packList(self.mainPanePos))
|
||||||
|
|
||||||
|
## Editor
|
||||||
|
cnfSec = "Editor"
|
||||||
|
confParser.add_section(cnfSec)
|
||||||
|
confParser.set(cnfSec,"fixedwidth", str(self.textFixedW))
|
||||||
|
confParser.set(cnfSec,"width", str(self.textWidth))
|
||||||
|
confParser.set(cnfSec,"margins", self.packList(self.textMargin))
|
||||||
|
|
||||||
## Path
|
## Path
|
||||||
cnfSec = "Path"
|
cnfSec = "Path"
|
||||||
confParser.add_section(cnfSec)
|
confParser.add_section(cnfSec)
|
||||||
|
|||||||
+18
-42
@@ -31,9 +31,13 @@ class GuiDocEditor(QWidget):
|
|||||||
|
|
||||||
self.outerBox = QVBoxLayout()
|
self.outerBox = QVBoxLayout()
|
||||||
self.guiEditor = QTextEdit()
|
self.guiEditor = QTextEdit()
|
||||||
# self.guiEditor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
if self.mainConf.textFixedW:
|
||||||
self.guiEditor.setLineWrapMode(QTextEdit.FixedPixelWidth)
|
self.guiEditor.setLineWrapMode(QTextEdit.FixedPixelWidth)
|
||||||
self.guiEditor.setLineWrapColumnOrWidth(self.mainConf.textWidth)
|
self.guiEditor.setLineWrapColumnOrWidth(self.mainConf.textWidth)
|
||||||
|
else:
|
||||||
|
mTB = self.mainConf.textMargin[0]
|
||||||
|
mLR = self.mainConf.textMargin[1]
|
||||||
|
self.guiEditor.setViewportMargins(mLR,mTB,mLR,mTB)
|
||||||
|
|
||||||
self.hLight = GuiDocHighlighter(self.guiEditor.document())
|
self.hLight = GuiDocHighlighter(self.guiEditor.document())
|
||||||
|
|
||||||
@@ -47,42 +51,9 @@ class GuiDocEditor(QWidget):
|
|||||||
|
|
||||||
self.guiEditor.setMinimumWidth(400)
|
self.guiEditor.setMinimumWidth(400)
|
||||||
self.guiEditor.setAcceptRichText(False)
|
self.guiEditor.setAcceptRichText(False)
|
||||||
# self.guiEditor.setStyleSheet("""
|
|
||||||
# QTextEdit {
|
|
||||||
# background-color: #141414;
|
|
||||||
# color: #c7cfd0;
|
|
||||||
# }
|
|
||||||
# """)
|
|
||||||
theDoc = self.guiEditor.document()
|
theDoc = self.guiEditor.document()
|
||||||
# theDoc.setDefaultFont(QFont("Source Sans Pro",13))
|
# theDoc.setDefaultFont(QFont("Source Sans Pro",13))
|
||||||
theDoc.setDocumentMargin(40)
|
theDoc.setDocumentMargin(0)
|
||||||
# theDoc.setTextWidth(200)
|
|
||||||
# theDoc.setDefaultStyleSheet("""
|
|
||||||
# html {
|
|
||||||
# background-color: #ffffff;
|
|
||||||
# padding: 50px;
|
|
||||||
# border: 1px solid #ffffff;
|
|
||||||
# }
|
|
||||||
# body {
|
|
||||||
# background-color: #ffffff;
|
|
||||||
# padding: 50px;
|
|
||||||
# border: 1px solid #ffffff;
|
|
||||||
# }
|
|
||||||
# """)
|
|
||||||
# theDoc.setPageSize(QSizeF(600,600))
|
|
||||||
# theDoc.setDefaultStyleSheet("""
|
|
||||||
# body {
|
|
||||||
# background-color: #ffffff;
|
|
||||||
# }
|
|
||||||
# p {
|
|
||||||
# text-indent: 0px;
|
|
||||||
# margin: 4px 0px;
|
|
||||||
# text-align: justify;
|
|
||||||
# }
|
|
||||||
# p+p {
|
|
||||||
# text-indent: 40px;
|
|
||||||
# }
|
|
||||||
# """)
|
|
||||||
|
|
||||||
logger.debug("DocEditor initialisation complete")
|
logger.debug("DocEditor initialisation complete")
|
||||||
|
|
||||||
@@ -97,11 +68,16 @@ class GuiDocEditor(QWidget):
|
|||||||
return theText
|
return theText
|
||||||
|
|
||||||
def changeWidth(self):
|
def changeWidth(self):
|
||||||
tW = self.guiEditor.width()
|
"""Automatically adjust the margins so the text is centred, but only if Config.textFixedW is
|
||||||
sW = self.guiEditor.verticalScrollBar().width()
|
set to True.
|
||||||
tM = int((tW - sW - self.mainConf.textWidth)/2)
|
"""
|
||||||
self.guiEditor.setViewportMargins(tM,0,0,0)
|
if self.mainConf.textFixedW:
|
||||||
# print(tW, sW, tM)
|
tW = self.guiEditor.width()
|
||||||
|
sW = self.guiEditor.verticalScrollBar().width()
|
||||||
|
tM = int((tW - sW - self.mainConf.textWidth)/2)
|
||||||
|
mTB = self.mainConf.textMargin[0]
|
||||||
|
# print(tW, sW, tM, mTB)
|
||||||
|
self.guiEditor.setViewportMargins(tM,mTB,0,mTB)
|
||||||
return
|
return
|
||||||
|
|
||||||
def _buildTabToolBar(self):
|
def _buildTabToolBar(self):
|
||||||
|
|||||||
+21
-2
@@ -197,11 +197,30 @@ class GuiMain(QMainWindow):
|
|||||||
self.docTabs.createTab(None,nw.DOCTYPE_ABOUT)
|
self.docTabs.createTab(None,nw.DOCTYPE_ABOUT)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#
|
##
|
||||||
# Events
|
# Events
|
||||||
#
|
##
|
||||||
|
|
||||||
|
def resizeEvent(self, theEvent):
|
||||||
|
"""Extend QMainWindow.resizeEvent to signal dependent GUI elements that its pane may have changed size.
|
||||||
|
"""
|
||||||
|
QMainWindow.resizeEvent(self,theEvent)
|
||||||
|
if self.stackPane.currentIndex() == self.stackDoc:
|
||||||
|
self.docEditor.changeWidth()
|
||||||
|
return
|
||||||
|
|
||||||
|
def closeEvent(self, theEvent):
|
||||||
|
self._closeMain()
|
||||||
|
QMainWindow.closeEvent(self,theEvent)
|
||||||
|
return
|
||||||
|
|
||||||
|
##
|
||||||
|
# Signal Handlers
|
||||||
|
##
|
||||||
|
|
||||||
def _splitMainMove(self, pWidth, pHeight):
|
def _splitMainMove(self, pWidth, pHeight):
|
||||||
|
"""Alert dependent GUI elements that the main pane splitter has been moved.
|
||||||
|
"""
|
||||||
if self.stackPane.currentIndex() == self.stackDoc:
|
if self.stackPane.currentIndex() == self.stackDoc:
|
||||||
self.docEditor.changeWidth()
|
self.docEditor.changeWidth()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
* {
|
||||||
|
background-color: #999999;
|
||||||
|
}
|
||||||
|
|
||||||
QTextEdit {
|
QTextEdit {
|
||||||
background-color: #141414;
|
background-color: #141414;
|
||||||
color: #c7cfd0;
|
color: #c7cfd0;
|
||||||
|
|||||||
Reference in New Issue
Block a user