diff --git a/docs/source/interface.rst b/docs/source/interface.rst index 8a2c140b..4b4a8662 100644 --- a/docs/source/interface.rst +++ b/docs/source/interface.rst @@ -87,7 +87,7 @@ Synopsis Feature The "Synopsis" column of the Outline View takes its information from a specially formatted comment. In order to flag a comment as a Synopsis, add the word "Synopsis:" as the first word of the comment. -The ";" is required, and "synopsis" is not case sensitive. +The ":" is required, and "synopsis" is not case sensitive. If it is correctly formatted, the syntax highlighter will indicate this by altering the colour of the word. .. note:: diff --git a/nw/config.py b/nw/config.py index 4995cafa..a8435188 100644 --- a/nw/config.py +++ b/nw/config.py @@ -309,11 +309,14 @@ class Config: """Load preferences from file and replace default settings. """ logger.debug("Loading config file") + if self.confPath is None: + return False + cnfParse = configparser.ConfigParser() + cnfPath = path.join(self.confPath, self.confFile) try: - cnfParse.read_file( - open(path.join(self.confPath,self.confFile),mode="r",encoding="utf8") - ) + with open(cnfPath, mode="r", encoding="utf8") as inFile: + cnfParse.read_file(inFile) except Exception as e: logger.error("Could not load config file") logger.error(str(e)) @@ -484,6 +487,9 @@ class Config: """Save the current preferences to file. """ logger.debug("Saving config file") + if self.confPath is None: + return False + cnfParse = configparser.ConfigParser() # Set options @@ -562,10 +568,10 @@ class Config: cnfParse.set(cnfSec,"lastpath", str(self.lastPath)) # Write config file + cnfPath = path.join(self.confPath, self.confFile) try: - cnfParse.write( - open(path.join(self.confPath, self.confFile), mode="w", encoding="utf8") - ) + with open(cnfPath, mode="w", encoding="utf8") as outFile: + cnfParse.write(outFile) self.confChanged = False except Exception as e: logger.error("Could not save config file") diff --git a/nw/gui/docbars.py b/nw/gui/docbars.py index e1240e2d..6720933d 100644 --- a/nw/gui/docbars.py +++ b/nw/gui/docbars.py @@ -187,8 +187,12 @@ class GuiDocTitleBar(QWidget): self.thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) self.thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) + fPx = int(0.9*self.theTheme.fontPixelSize) + hSp = self.mainConf.pxInt(6) + self.buttonSize = fPx + hSp + # Main Widget Settings - self.setContentsMargins(0, 0, 0, 0) + self.setContentsMargins(2*self.buttonSize, 0, 0, 0) self.setAutoFillBackground(True) self.setPalette(self.thePalette) @@ -197,10 +201,10 @@ class GuiDocTitleBar(QWidget): self.theTitle.setText("") self.theTitle.setIndent(0) self.theTitle.setMargin(0) - self.theTitle.setContentsMargins(10, 0, 0, 0) + self.theTitle.setContentsMargins(0, 0, 0, 0) self.theTitle.setAutoFillBackground(True) - self.theTitle.setAlignment(Qt.AlignCenter) - self.theTitle.setWordWrap(True) + self.theTitle.setAlignment(Qt.AlignHCenter | Qt.AlignTop) + self.theTitle.setFixedHeight(fPx) self.theTitle.setFrameShape(QFrame.NoFrame) self.theTitle.setLineWidth(0) self.theTitle.setPalette(self.thePalette) @@ -210,13 +214,11 @@ class GuiDocTitleBar(QWidget): self.theTitle.setFont(lblFont) # Buttons - iPx = self.theTheme.textIconSize - self.closeButton = QPushButton("") self.closeButton.setIcon(self.theTheme.getIcon("close")) self.closeButton.setContentsMargins(0, 0, 0, 0) - self.closeButton.setIconSize(QSize(iPx, iPx)) - self.closeButton.setFixedSize(iPx, iPx) + self.closeButton.setIconSize(QSize(fPx, fPx)) + self.closeButton.setFixedSize(fPx, fPx) self.closeButton.setFlat(True) self.closeButton.setVisible(False) self.closeButton.clicked.connect(self._closeDocument) @@ -225,8 +227,8 @@ class GuiDocTitleBar(QWidget): self.minmaxButton = QPushButton("") self.minmaxButton.setIcon(self.theTheme.getIcon("maximise")) self.minmaxButton.setContentsMargins(0, 0, 0, 0) - self.minmaxButton.setIconSize(QSize(iPx, iPx)) - self.minmaxButton.setFixedSize(iPx, iPx) + self.minmaxButton.setIconSize(QSize(fPx, fPx)) + self.minmaxButton.setFixedSize(fPx, fPx) self.minmaxButton.setFlat(True) self.minmaxButton.setVisible(False) self.minmaxButton.clicked.connect(self._minmaxDocument) @@ -234,17 +236,15 @@ class GuiDocTitleBar(QWidget): self.refreshButton = QPushButton("") self.refreshButton.setIcon(self.theTheme.getIcon("refresh")) self.refreshButton.setContentsMargins(0, 0, 0, 0) - self.refreshButton.setIconSize(QSize(iPx, iPx)) - self.refreshButton.setFixedSize(iPx, iPx) + self.refreshButton.setIconSize(QSize(fPx, fPx)) + self.refreshButton.setFixedSize(fPx, fPx) self.refreshButton.setFlat(True) self.refreshButton.setVisible(False) self.refreshButton.clicked.connect(self._refreshDocument) # Assemble Layout - hSp = self.mainConf.pxInt(6) self.outerBox = QHBoxLayout() self.outerBox.setSpacing(hSp) - self.outerBox.addSpacing(2*(iPx + hSp)) self.outerBox.addWidget(self.theTitle, 1) if self.isEditor: self.outerBox.addWidget(self.minmaxButton, 0) @@ -315,11 +315,14 @@ class GuiDocTitleBar(QWidget): """Switch on or off zen mode. """ self.theParent.theParent.toggleZenMode() - self.closeButton.setVisible(not self.theParent.theParent.isZenMode) if self.theParent.theParent.isZenMode: self.minmaxButton.setIcon(self.theTheme.getIcon("minimise")) + self.setContentsMargins(self.buttonSize, 0, 0, 0) + self.closeButton.setVisible(False) else: self.minmaxButton.setIcon(self.theTheme.getIcon("maximise")) + self.setContentsMargins(2*self.buttonSize, 0, 0, 0) + self.closeButton.setVisible(True) return def _refreshDocument(self): diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index e523c6f7..81c37e04 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -314,12 +314,14 @@ class GuiDocEditor(QTextEdit): just ensure the margins are set correctly. """ cM = self.mainConf.getTextMargin() + + vBar = self.verticalScrollBar() + if vBar.isVisible(): + sW = vBar.width() + else: + sW = 0 + if self.mainConf.textFixedW or self.theParent.isZenMode: - vBar = self.verticalScrollBar() - if vBar.isVisible(): - sW = vBar.width() - else: - sW = 0 if self.theParent.isZenMode: tW = self.mainConf.getZenWidth() else: @@ -332,7 +334,7 @@ class GuiDocEditor(QTextEdit): tM = cM tB = self.lineWidth() - tW = self.width() - 2*tB + tW = self.width() - 2*tB - sW tH = self.docTitle.height() tT = cM - tH self.docTitle.setGeometry(tB, tB, tW, tH) diff --git a/nw/gui/docviewer.py b/nw/gui/docviewer.py index 0624a321..c43c6cc0 100644 --- a/nw/gui/docviewer.py +++ b/nw/gui/docviewer.py @@ -224,8 +224,14 @@ class GuiDocViewer(QTextBrowser): Config.textFixedW is enabled or we're in Zen mode. Otherwise, just ensure the margins are set correctly. """ + vBar = self.verticalScrollBar() + if vBar.isVisible(): + sW = vBar.width() + else: + sW = 0 + tB = self.lineWidth() - tW = self.width() - 2*tB + tW = self.width() - 2*tB - sW tH = self.docTitle.height() tT = self.mainConf.getTextMargin() - tH self.docTitle.setGeometry(tB, tB, tW, tH) diff --git a/nw/gui/theme.py b/nw/gui/theme.py index 8288e1fa..9d513262 100644 --- a/nw/gui/theme.py +++ b/nw/gui/theme.py @@ -265,7 +265,8 @@ class GuiTheme: # Config File confParser = configparser.ConfigParser() try: - confParser.read_file(open(self.confFile,mode="r",encoding="utf8")) + with open(self.confFile, mode="r", encoding="utf8") as inFile: + confParser.read_file(inFile) except Exception as e: logger.error("Could not load theme settings from: %s" % self.confFile) return False @@ -319,7 +320,8 @@ class GuiTheme: confParser = configparser.ConfigParser() try: - confParser.read_file(open(self.syntaxFile, mode="r", encoding="utf8")) + with open(self.syntaxFile, mode="r", encoding="utf8") as inFile: + confParser.read_file(inFile) except Exception as e: logger.error("Could not load syntax colours from: %s" % self.syntaxFile) return False @@ -370,7 +372,8 @@ class GuiTheme: themeConf = path.join(self.mainConf.themeRoot, self.guiPath, themeDir, self.confName) logger.verbose("Checking theme config for '%s'" % themeDir) try: - confParser.read_file(open(themeConf, mode="r", encoding="utf8")) + with open(themeConf, mode="r", encoding="utf8") as inFile: + confParser.read_file(inFile) except Exception as e: self.theParent.makeAlert( ["Could not load theme config file.",str(e)], nwAlert.ERROR @@ -402,7 +405,8 @@ class GuiTheme: continue logger.verbose("Checking theme syntax for '%s'" % syntaxFile) try: - confParser.read_file(open(syntaxPath, mode="r", encoding="utf8")) + with open(syntaxPath, mode="r", encoding="utf8") as inFile: + confParser.read_file(inFile) except Exception as e: self.theParent.makeAlert( ["Could not load syntax file.",str(e)], nwAlert.ERROR @@ -588,7 +592,8 @@ class GuiIcons: # Config File confParser = configparser.ConfigParser() try: - confParser.read_file(open(self.confFile, mode="r", encoding="utf8")) + with open(self.confFile, mode="r", encoding="utf8") as inFile: + confParser.read_file(inFile) except Exception as e: logger.error("Could not load icon theme settings from: %s" % self.confFile) return False @@ -682,7 +687,8 @@ class GuiIcons: themeConf = path.join(themePath, self.confName) logger.verbose("Checking icon theme config for '%s'" % themeDir) try: - confParser.read_file(open(themeConf, mode="r", encoding="utf8")) + with open(themeConf, mode="r", encoding="utf8") as inFile: + confParser.read_file(inFile) except Exception as e: self.theParent.makeAlert( ["Could not load theme config file.",str(e)], nwAlert.ERROR