From a15e73cf48bf4db13b8ffcfb88a815d2d43b25fc Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:07:35 +0200 Subject: [PATCH 1/7] Proper handling of files with configparser --- nw/config.py | 12 ++++++------ nw/gui/theme.py | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/nw/config.py b/nw/config.py index 4995cafa..b8b375d9 100644 --- a/nw/config.py +++ b/nw/config.py @@ -310,10 +310,10 @@ class Config: """ logger.debug("Loading config file") 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)) @@ -562,10 +562,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/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 From b1b30fb828f8a6aaafb32625237b49952700c02a Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:09:23 +0200 Subject: [PATCH 2/7] Fixed typo in docs --- docs/source/interface.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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:: From 3dc59d393c4b3eaf13cdaadee0f8f7d6dab03975 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:28:17 +0200 Subject: [PATCH 3/7] Fixed clipping of document bar --- nw/gui/docbars.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/nw/gui/docbars.py b/nw/gui/docbars.py index e1240e2d..66f6a2b5 100644 --- a/nw/gui/docbars.py +++ b/nw/gui/docbars.py @@ -33,7 +33,7 @@ from PyQt5.QtCore import Qt, QSize from PyQt5.QtGui import QPalette, QColor from PyQt5.QtWidgets import ( qApp, QWidget, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, - QHBoxLayout + QHBoxLayout, QSizePolicy ) from nw.constants import nwDocAction, nwUnicode @@ -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)) + iPx = self.theTheme.textIconSize + hSp = self.mainConf.pxInt(6) + self.buttonSize = iPx + 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,11 @@ 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.AlignTop | Qt.AlignHCenter) + self.theTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) + self.theTitle.setMinimumHeight(self.theTheme.fontPixelSize) self.theTitle.setFrameShape(QFrame.NoFrame) self.theTitle.setLineWidth(0) self.theTitle.setPalette(self.thePalette) @@ -210,8 +215,6 @@ 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) @@ -241,10 +244,8 @@ class GuiDocTitleBar(QWidget): 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 +316,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): From f24ec180b2e389da194cf70325703ce5f2719bec Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:40:34 +0200 Subject: [PATCH 4/7] Fixed the size of the doc title bar when the scroll bar is present --- nw/gui/doceditor.py | 14 ++++++++------ nw/gui/docviewer.py | 8 +++++++- 2 files changed, 15 insertions(+), 7 deletions(-) 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) From ad38550c3282113605f9c815ac8224438d80859b Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:56:59 +0200 Subject: [PATCH 5/7] Tweaked the doc title bar sizes a bit more --- nw/gui/docbars.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/nw/gui/docbars.py b/nw/gui/docbars.py index 66f6a2b5..640565d9 100644 --- a/nw/gui/docbars.py +++ b/nw/gui/docbars.py @@ -33,7 +33,7 @@ from PyQt5.QtCore import Qt, QSize from PyQt5.QtGui import QPalette, QColor from PyQt5.QtWidgets import ( qApp, QWidget, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, - QHBoxLayout, QSizePolicy + QHBoxLayout ) from nw.constants import nwDocAction, nwUnicode @@ -187,9 +187,9 @@ class GuiDocTitleBar(QWidget): self.thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) self.thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) - iPx = self.theTheme.textIconSize + fPx = int(0.9*self.theTheme.fontPixelSize) hSp = self.mainConf.pxInt(6) - self.buttonSize = iPx + hSp + self.buttonSize = fPx + hSp # Main Widget Settings self.setContentsMargins(2*self.buttonSize, 0, 0, 0) @@ -203,9 +203,8 @@ class GuiDocTitleBar(QWidget): self.theTitle.setMargin(0) self.theTitle.setContentsMargins(0, 0, 0, 0) self.theTitle.setAutoFillBackground(True) - self.theTitle.setAlignment(Qt.AlignTop | Qt.AlignHCenter) - self.theTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) - self.theTitle.setMinimumHeight(self.theTheme.fontPixelSize) + 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) @@ -218,8 +217,8 @@ class GuiDocTitleBar(QWidget): 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) @@ -228,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) @@ -237,8 +236,8 @@ 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) @@ -246,12 +245,12 @@ class GuiDocTitleBar(QWidget): # Assemble Layout self.outerBox = QHBoxLayout() self.outerBox.setSpacing(hSp) - self.outerBox.addWidget(self.theTitle, 1) + self.outerBox.addWidget(self.theTitle, 1, Qt.AlignBottom) if self.isEditor: - self.outerBox.addWidget(self.minmaxButton, 0) + self.outerBox.addWidget(self.minmaxButton, 0, Qt.AlignBottom) else: - self.outerBox.addWidget(self.refreshButton, 0) - self.outerBox.addWidget(self.closeButton, 0) + self.outerBox.addWidget(self.refreshButton, 0, Qt.AlignBottom) + self.outerBox.addWidget(self.closeButton, 0, Qt.AlignBottom) self.setLayout(self.outerBox) logger.debug("GuiDocTitleBar initialisation complete") From aa81009760291df7514971897e1dbc1c8fb525a3 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 8 Jun 2020 17:59:24 +0200 Subject: [PATCH 6/7] Drop the alignment settings --- nw/gui/docbars.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nw/gui/docbars.py b/nw/gui/docbars.py index 640565d9..6720933d 100644 --- a/nw/gui/docbars.py +++ b/nw/gui/docbars.py @@ -245,12 +245,12 @@ class GuiDocTitleBar(QWidget): # Assemble Layout self.outerBox = QHBoxLayout() self.outerBox.setSpacing(hSp) - self.outerBox.addWidget(self.theTitle, 1, Qt.AlignBottom) + self.outerBox.addWidget(self.theTitle, 1) if self.isEditor: - self.outerBox.addWidget(self.minmaxButton, 0, Qt.AlignBottom) + self.outerBox.addWidget(self.minmaxButton, 0) else: - self.outerBox.addWidget(self.refreshButton, 0, Qt.AlignBottom) - self.outerBox.addWidget(self.closeButton, 0, Qt.AlignBottom) + self.outerBox.addWidget(self.refreshButton, 0) + self.outerBox.addWidget(self.closeButton, 0) self.setLayout(self.outerBox) logger.debug("GuiDocTitleBar initialisation complete") From 0a6e89e2f6c7b1d6e9a7592a5b45d2a301704c2f Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 8 Jun 2020 18:58:41 +0200 Subject: [PATCH 7/7] Fixed conf with None path --- nw/config.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nw/config.py b/nw/config.py index b8b375d9..a8435188 100644 --- a/nw/config.py +++ b/nw/config.py @@ -309,6 +309,9 @@ 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: @@ -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