diff --git a/nw/config.py b/nw/config.py index 0ec3940d..18fd8a47 100644 --- a/nw/config.py +++ b/nw/config.py @@ -49,7 +49,7 @@ class Config: mkdir(self.confPath) # Set default values - self.confChanged = False + self.confChanged = False ## General self.guiTheme = "default" @@ -58,7 +58,9 @@ class Config: self.mainPanePos = [300, 800] ## Text Editor + self.textFixedW = True self.textWidth = 600 + self.textMargin = [40, 40] # Check if config file exists if path.isfile(path.join(self.confPath,self.confFile)): @@ -82,8 +84,8 @@ class Config: # Get options - ## Main - cnfSec = "Main" + ## Sizes + cnfSec = "Sizes" if confParser.has_section(cnfSec): if confParser.has_option(cnfSec,"geometry"): self.winGeometry = self.unpackList( @@ -98,6 +100,18 @@ class Config: 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 cnfSec = "Path" if confParser.has_section(cnfSec): @@ -118,10 +132,21 @@ class Config: cnfSec = "Main" confParser.add_section(cnfSec) 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,"treecols", self.packList(self.treeColWidth)) 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 cnfSec = "Path" confParser.add_section(cnfSec) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index aa3b96e1..504bc0fe 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -31,9 +31,13 @@ class GuiDocEditor(QWidget): self.outerBox = QVBoxLayout() self.guiEditor = QTextEdit() - # self.guiEditor.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - self.guiEditor.setLineWrapMode(QTextEdit.FixedPixelWidth) - self.guiEditor.setLineWrapColumnOrWidth(self.mainConf.textWidth) + if self.mainConf.textFixedW: + self.guiEditor.setLineWrapMode(QTextEdit.FixedPixelWidth) + 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()) @@ -47,42 +51,9 @@ class GuiDocEditor(QWidget): self.guiEditor.setMinimumWidth(400) self.guiEditor.setAcceptRichText(False) - # self.guiEditor.setStyleSheet(""" - # QTextEdit { - # background-color: #141414; - # color: #c7cfd0; - # } - # """) theDoc = self.guiEditor.document() # theDoc.setDefaultFont(QFont("Source Sans Pro",13)) - theDoc.setDocumentMargin(40) - # 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; - # } - # """) + theDoc.setDocumentMargin(0) logger.debug("DocEditor initialisation complete") @@ -97,11 +68,16 @@ class GuiDocEditor(QWidget): 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) + """Automatically adjust the margins so the text is centred, but only if Config.textFixedW is + set to True. + """ + if self.mainConf.textFixedW: + 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 def _buildTabToolBar(self): diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index b59e7970..a60d0873 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -197,11 +197,30 @@ class GuiMain(QMainWindow): self.docTabs.createTab(None,nw.DOCTYPE_ABOUT) return True - # + ## # 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): + """Alert dependent GUI elements that the main pane splitter has been moved. + """ if self.stackPane.currentIndex() == self.stackDoc: self.docEditor.changeWidth() return diff --git a/nw/themes/default.css b/nw/themes/default.css index f2091c06..65ab3161 100644 --- a/nw/themes/default.css +++ b/nw/themes/default.css @@ -1,3 +1,7 @@ +* { + background-color: #999999; +} + QTextEdit { background-color: #141414; color: #c7cfd0;