Handling of window size and change
This commit is contained in:
@@ -52,8 +52,13 @@ class Config:
|
|||||||
self.confChanged = False
|
self.confChanged = False
|
||||||
|
|
||||||
## General
|
## General
|
||||||
|
self.guiTheme = "default"
|
||||||
self.winGeometry = [1100, 650]
|
self.winGeometry = [1100, 650]
|
||||||
self.treeColWidth = [120, 30, 50]
|
self.treeColWidth = [120, 30, 50]
|
||||||
|
self.mainPanePos = [300, 800]
|
||||||
|
|
||||||
|
## Text Editor
|
||||||
|
self.textWidth = 600
|
||||||
|
|
||||||
# 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)):
|
||||||
@@ -88,6 +93,10 @@ class Config:
|
|||||||
self.treeColWidth = self.unpackList(
|
self.treeColWidth = self.unpackList(
|
||||||
confParser.get(cnfSec,"treecols"), 3, self.treeColWidth
|
confParser.get(cnfSec,"treecols"), 3, self.treeColWidth
|
||||||
)
|
)
|
||||||
|
if confParser.has_option(cnfSec,"mainpane"):
|
||||||
|
self.mainPanePos = self.unpackList(
|
||||||
|
confParser.get(cnfSec,"mainpane"), 2, self.mainPanePos
|
||||||
|
)
|
||||||
|
|
||||||
## Path
|
## Path
|
||||||
cnfSec = "Path"
|
cnfSec = "Path"
|
||||||
@@ -111,6 +120,7 @@ class Config:
|
|||||||
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"))
|
||||||
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))
|
||||||
|
|
||||||
## Path
|
## Path
|
||||||
cnfSec = "Path"
|
cnfSec = "Path"
|
||||||
@@ -170,4 +180,8 @@ class Config:
|
|||||||
self.treeColWidth = colWidths
|
self.treeColWidth = colWidths
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def setMainPanePos(self, panePos):
|
||||||
|
self.mainPanePos = panePos
|
||||||
|
return
|
||||||
|
|
||||||
# End Class Config
|
# End Class Config
|
||||||
|
|||||||
+36
-31
@@ -31,47 +31,44 @@ class GuiDocEditor(QWidget):
|
|||||||
|
|
||||||
self.outerBox = QVBoxLayout()
|
self.outerBox = QVBoxLayout()
|
||||||
self.guiEditor = QTextEdit()
|
self.guiEditor = QTextEdit()
|
||||||
self.guiEditor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
# self.guiEditor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||||
|
self.guiEditor.setLineWrapMode(QTextEdit.FixedPixelWidth)
|
||||||
|
self.guiEditor.setLineWrapColumnOrWidth(self.mainConf.textWidth)
|
||||||
|
|
||||||
self.hLight = GuiDocHighlighter(self.guiEditor.document())
|
self.hLight = GuiDocHighlighter(self.guiEditor.document())
|
||||||
|
|
||||||
self.setLayout(self.outerBox)
|
self.setLayout(self.outerBox)
|
||||||
|
|
||||||
self.metaPane = QFrame()
|
|
||||||
self.docPane = QScrollArea()
|
|
||||||
self.metaPane.setFrameShape(QFrame.StyledPanel)
|
|
||||||
self.docPane.setFrameShape(QFrame.StyledPanel)
|
|
||||||
# self.docPane.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
|
||||||
self.splitEdit = QSplitter(Qt.Horizontal)
|
|
||||||
self.splitEdit.addWidget(self.docPane)
|
|
||||||
self.splitEdit.addWidget(self.metaPane)
|
|
||||||
|
|
||||||
self.docBox = QHBoxLayout()
|
|
||||||
self.docPane.setLayout(self.docBox)
|
|
||||||
self.docBox.addStretch(0)
|
|
||||||
self.docBox.addWidget(self.guiEditor)
|
|
||||||
self.docBox.addStretch(0)
|
|
||||||
self.editToolBar = QToolBar()
|
self.editToolBar = QToolBar()
|
||||||
self._buildTabToolBar()
|
self._buildTabToolBar()
|
||||||
|
|
||||||
self.outerBox.addWidget(self.editToolBar)
|
self.outerBox.addWidget(self.editToolBar)
|
||||||
self.outerBox.addWidget(self.splitEdit)
|
self.outerBox.addWidget(self.guiEditor)
|
||||||
|
|
||||||
# self.guiEditor.setFixedWidth(600)
|
self.guiEditor.setMinimumWidth(400)
|
||||||
self.guiEditor.setMinimumWidth(600)
|
|
||||||
self.guiEditor.setAcceptRichText(False)
|
self.guiEditor.setAcceptRichText(False)
|
||||||
# self.guiEditor.setCurrentFont(self.docFont)
|
# self.guiEditor.setStyleSheet("""
|
||||||
# self.guiEditor.setContentsMargins(20,20,20,20)
|
# QTextEdit {
|
||||||
self.guiEditor.setStyleSheet("""
|
# background-color: #141414;
|
||||||
QTextEdit {
|
# color: #c7cfd0;
|
||||||
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(20)
|
theDoc.setDocumentMargin(40)
|
||||||
theDoc.setTextWidth(600)
|
# 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.setPageSize(QSizeF(600,600))
|
||||||
# theDoc.setDefaultStyleSheet("""
|
# theDoc.setDefaultStyleSheet("""
|
||||||
# body {
|
# body {
|
||||||
@@ -91,14 +88,22 @@ class GuiDocEditor(QWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def setText(self, docHtml):
|
def setText(self, theText):
|
||||||
self.guiEditor.setPlainText(docHtml)
|
self.guiEditor.setPlainText(theText)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def getText(self):
|
def getText(self):
|
||||||
theText = self.guiEditor.toPlainText()
|
theText = self.guiEditor.toPlainText()
|
||||||
return theText
|
return theText
|
||||||
|
|
||||||
|
def changeWidth(self):
|
||||||
|
tW = self.guiEditor.width()
|
||||||
|
sW = self.guiEditor.verticalScrollBar().width()
|
||||||
|
tM = int((tW - sW - self.mainConf.textWidth)/2)
|
||||||
|
self.guiEditor.setViewportMargins(tM,0,0,0)
|
||||||
|
# print(tW, sW, tM)
|
||||||
|
return
|
||||||
|
|
||||||
def _buildTabToolBar(self):
|
def _buildTabToolBar(self):
|
||||||
toolBar = self.editToolBar
|
toolBar = self.editToolBar
|
||||||
toolBar.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
toolBar.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
||||||
|
|||||||
+17
-5
@@ -15,7 +15,7 @@ import nw
|
|||||||
|
|
||||||
from os import path
|
from os import path
|
||||||
from PyQt5.QtWidgets import qApp, QWidget, QMainWindow, QHBoxLayout, QVBoxLayout, QFrame, QSplitter, QAction, QToolBar, QFileDialog, QStackedWidget
|
from PyQt5.QtWidgets import qApp, QWidget, QMainWindow, QHBoxLayout, QVBoxLayout, QFrame, QSplitter, QAction, QToolBar, QFileDialog, QStackedWidget
|
||||||
from PyQt5.QtCore import Qt, QSize
|
from PyQt5.QtCore import Qt, QSize, QObject
|
||||||
from PyQt5.QtGui import QIcon, QStandardItemModel
|
from PyQt5.QtGui import QIcon, QStandardItemModel
|
||||||
|
|
||||||
from nw.enum import nwItemType
|
from nw.enum import nwItemType
|
||||||
@@ -69,6 +69,16 @@ class GuiMain(QMainWindow):
|
|||||||
self.treeView.itemDoubleClicked.connect(self._treeDoubleClick)
|
self.treeView.itemDoubleClicked.connect(self._treeDoubleClick)
|
||||||
self.treeView.buildTree()
|
self.treeView.buildTree()
|
||||||
|
|
||||||
|
self.splitMain.setSizes(self.mainConf.mainPanePos)
|
||||||
|
self.splitMain.splitterMoved.connect(self._splitMainMove)
|
||||||
|
|
||||||
|
# Load Theme StyleSheet
|
||||||
|
cssFile = path.join(self.mainConf.themePath,self.mainConf.guiTheme+".css")
|
||||||
|
if path.isfile(cssFile):
|
||||||
|
with open(cssFile,mode="r") as inFile:
|
||||||
|
theCss = inFile.read()
|
||||||
|
self.setStyleSheet(theCss)
|
||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
logger.debug("GUI initialisation complete")
|
logger.debug("GUI initialisation complete")
|
||||||
@@ -136,6 +146,7 @@ class GuiMain(QMainWindow):
|
|||||||
def openDocument(self, tHandle):
|
def openDocument(self, tHandle):
|
||||||
self.stackPane.setCurrentIndex(self.stackDoc)
|
self.stackPane.setCurrentIndex(self.stackDoc)
|
||||||
self.docEditor.setText(self.theDocument.openDocument(tHandle))
|
self.docEditor.setText(self.theDocument.openDocument(tHandle))
|
||||||
|
self.docEditor.changeWidth()
|
||||||
return
|
return
|
||||||
|
|
||||||
def saveDocument(self):
|
def saveDocument(self):
|
||||||
@@ -162,7 +173,7 @@ class GuiMain(QMainWindow):
|
|||||||
logger.info("Exiting %s" % nw.__package__)
|
logger.info("Exiting %s" % nw.__package__)
|
||||||
self.mainConf.setWinSize(self.width(), self.height())
|
self.mainConf.setWinSize(self.width(), self.height())
|
||||||
self.mainConf.setTreeColWidths(self.treeView.getColumnSizes())
|
self.mainConf.setTreeColWidths(self.treeView.getColumnSizes())
|
||||||
print(self.treePane.width())
|
self.mainConf.setMainPanePos(self.splitMain.sizes())
|
||||||
self.mainConf.saveConfig()
|
self.mainConf.saveConfig()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -190,9 +201,10 @@ class GuiMain(QMainWindow):
|
|||||||
# Events
|
# Events
|
||||||
#
|
#
|
||||||
|
|
||||||
def closeEvent(self, guiEvent):
|
def _splitMainMove(self, pWidth, pHeight):
|
||||||
self._closeMain()
|
if self.stackPane.currentIndex() == self.stackDoc:
|
||||||
guiEvent.accept()
|
self.docEditor.changeWidth()
|
||||||
|
return
|
||||||
|
|
||||||
#
|
#
|
||||||
# GUI Builders
|
# GUI Builders
|
||||||
|
|||||||
Reference in New Issue
Block a user