From 19474dbc5e9b82ff5f2a0005b049f8515f3980f7 Mon Sep 17 00:00:00 2001
From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com>
Date: Fri, 12 Jun 2020 20:10:00 +0200
Subject: [PATCH 1/2] Pop a dialog box before removing an item from the recent
entries list
---
nw/gui/projload.py | 62 +++++++++++++++++++++++++++++++---------------
1 file changed, 42 insertions(+), 20 deletions(-)
diff --git a/nw/gui/projload.py b/nw/gui/projload.py
index 06a32f72..3fabfde5 100644
--- a/nw/gui/projload.py
+++ b/nw/gui/projload.py
@@ -36,7 +36,7 @@ from PyQt5.QtGui import QKeySequence
from PyQt5.QtWidgets import (
QDialog, QHBoxLayout, QVBoxLayout, QGridLayout, QPushButton, QTreeWidget,
QAbstractItemView, QTreeWidgetItem, QDialogButtonBox, QLabel, QShortcut,
- QFileDialog, QLineEdit
+ QFileDialog, QLineEdit, QMessageBox
)
from nw.common import formatInt
@@ -50,6 +50,10 @@ class GuiProjectLoad(QDialog):
NEW_STATE = 1
OPEN_STATE = 2
+ C_NAME = 0
+ C_COUNT = 1
+ C_TIME = 2
+
def __init__(self, theParent):
QDialog.__init__(self, theParent)
@@ -92,8 +96,8 @@ class GuiProjectLoad(QDialog):
self.listBox.setIconSize(QSize(iPx, iPx))
treeHead = self.listBox.headerItem()
- treeHead.setTextAlignment(1, Qt.AlignRight)
- treeHead.setTextAlignment(2, Qt.AlignRight)
+ treeHead.setTextAlignment(self.C_COUNT, Qt.AlignRight)
+ treeHead.setTextAlignment(self.C_TIME, Qt.AlignRight)
self.lblRecent = QLabel("Recently Opened Projects")
self.lblPath = QLabel("Path")
@@ -150,7 +154,7 @@ class GuiProjectLoad(QDialog):
self._saveDialogState()
selItems = self.listBox.selectedItems()
if selItems:
- self.openPath = selItems[0].data(0, Qt.UserRole)
+ self.openPath = selItems[0].data(self.C_NAME, Qt.UserRole)
self.openState = self.OPEN_STATE
self.accept()
else:
@@ -163,7 +167,7 @@ class GuiProjectLoad(QDialog):
"""
selList = self.listBox.selectedItems()
if selList:
- self.selPath.setText(selList[0].data(0, Qt.UserRole))
+ self.selPath.setText(selList[0].data(self.C_NAME, Qt.UserRole))
return
def _doBrowse(self):
@@ -210,8 +214,23 @@ class GuiProjectLoad(QDialog):
"""
selList = self.listBox.selectedItems()
if selList:
- self.mainConf.removeFromRecentCache(selList[0].text(3))
- self._populateList()
+ doRemove = False
+ if self.mainConf.showGUI:
+ msgBox = QMessageBox()
+ msgRes = msgBox.question(
+ self, "Remove Entry",
+ "Remove the selected entry from the recent projects list?"
+ )
+ doRemove = (msgRes == QMessageBox.Yes)
+ else:
+ doRemove = True
+
+ if doRemove:
+ self.mainConf.removeFromRecentCache(
+ selList[0].data(self.C_NAME, Qt.UserRole)
+ )
+ self._populateList()
+
return
##
@@ -221,9 +240,10 @@ class GuiProjectLoad(QDialog):
def _saveDialogState(self):
"""Save the changes made to the dialog.
"""
- colWidths = [50]*3
- for i in range(3):
- colWidths[i] = self.listBox.columnWidth(i)
+ colWidths = [0, 0, 0]
+ colWidths[self.C_NAME] = self.listBox.columnWidth(self.C_NAME)
+ colWidths[self.C_COUNT] = self.listBox.columnWidth(self.C_COUNT)
+ colWidths[self.C_TIME] = self.listBox.columnWidth(self.C_TIME)
self.mainConf.setProjColWidths(colWidths)
return
@@ -251,22 +271,24 @@ class GuiProjectLoad(QDialog):
hasSelection = False
for timeStamp in sorted(listOrder, reverse=True):
newItem = QTreeWidgetItem([""]*4)
- newItem.setIcon(0, self.theParent.theTheme.getIcon("proj_nwx"))
- newItem.setText(0, listData[timeStamp][0])
- newItem.setData(0, Qt.UserRole, listData[timeStamp][2])
- newItem.setText(1, formatInt(listData[timeStamp][1]))
- newItem.setText(2, datetime.fromtimestamp(timeStamp).strftime("%x %X"))
- newItem.setTextAlignment(0, Qt.AlignLeft | Qt.AlignVCenter)
- newItem.setTextAlignment(1, Qt.AlignRight | Qt.AlignVCenter)
- newItem.setTextAlignment(2, Qt.AlignRight | Qt.AlignVCenter)
+ newItem.setIcon(self.C_NAME, self.theParent.theTheme.getIcon("proj_nwx"))
+ newItem.setText(self.C_NAME, listData[timeStamp][0])
+ newItem.setData(self.C_NAME, Qt.UserRole, listData[timeStamp][2])
+ newItem.setText(self.C_COUNT, formatInt(listData[timeStamp][1]))
+ newItem.setText(self.C_TIME, datetime.fromtimestamp(timeStamp).strftime("%x %X"))
+ newItem.setTextAlignment(self.C_NAME, Qt.AlignLeft | Qt.AlignVCenter)
+ newItem.setTextAlignment(self.C_COUNT, Qt.AlignRight | Qt.AlignVCenter)
+ newItem.setTextAlignment(self.C_TIME, Qt.AlignRight | Qt.AlignVCenter)
self.listBox.addTopLevelItem(newItem)
if not hasSelection:
newItem.setSelected(True)
hasSelection = True
projColWidth = self.mainConf.getProjColWidths()
- for i in range(3):
- self.listBox.setColumnWidth(i, projColWidth[i])
+ if len(projColWidth) == 3:
+ self.listBox.setColumnWidth(self.C_NAME, projColWidth[self.C_NAME])
+ self.listBox.setColumnWidth(self.C_COUNT, projColWidth[self.C_COUNT])
+ self.listBox.setColumnWidth(self.C_TIME, projColWidth[self.C_TIME])
return
From ee303491e48a6ab9afebd1f6f5edf77da6f06b6f Mon Sep 17 00:00:00 2001
From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com>
Date: Fri, 12 Jun 2020 20:18:58 +0200
Subject: [PATCH 2/2] Only one standard icon size
---
nw/gui/itemdetails.py | 4 ++--
nw/gui/outline.py | 2 +-
nw/gui/projload.py | 6 +++---
nw/gui/projsettings.py | 2 +-
nw/gui/statusbar.py | 2 +-
nw/gui/theme.py | 2 --
6 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/nw/gui/itemdetails.py b/nw/gui/itemdetails.py
index 182fb3fd..4d0f5641 100644
--- a/nw/gui/itemdetails.py
+++ b/nw/gui/itemdetails.py
@@ -56,8 +56,8 @@ class GuiItemDetails(QWidget):
self.setLayout(self.mainBox)
self.pS = 0.9*self.theTheme.fontPointSize
- self.iPx = self.theTheme.textIconSize
- self.sPx = int(round(0.8*self.theTheme.textIconSize))
+ self.iPx = self.theTheme.baseIconSize
+ self.sPx = int(round(0.8*self.theTheme.baseIconSize))
self.expCheck = self.theTheme.getPixmap("check", (self.iPx, self.iPx))
self.expCross = self.theTheme.getPixmap("cross", (self.iPx, self.iPx))
diff --git a/nw/gui/outline.py b/nw/gui/outline.py
index b2c45f86..1b1aa11c 100644
--- a/nw/gui/outline.py
+++ b/nw/gui/outline.py
@@ -102,7 +102,7 @@ class GuiOutline(QTreeWidget):
self.itemDoubleClicked.connect(self._treeDoubleClick)
self.itemSelectionChanged.connect(self._itemSelected)
- iPx = self.theTheme.textIconSize
+ iPx = self.theTheme.baseIconSize
self.setIconSize(QSize(iPx, iPx))
self.setIndentation(iPx)
diff --git a/nw/gui/projload.py b/nw/gui/projload.py
index 3fabfde5..738a493c 100644
--- a/nw/gui/projload.py
+++ b/nw/gui/projload.py
@@ -66,7 +66,8 @@ class GuiProjectLoad(QDialog):
self.openPath = None
sPx = self.mainConf.pxInt(16)
- iPx = self.mainConf.pxInt(96)
+ nPx = self.mainConf.pxInt(96)
+ iPx = self.theTheme.baseIconSize
self.outerBox = QVBoxLayout()
self.innerBox = QHBoxLayout()
@@ -78,13 +79,12 @@ class GuiProjectLoad(QDialog):
self.setMinimumHeight(self.mainConf.pxInt(400))
self.setModal(True)
- self.guiDeco = self.theTheme.loadDecoration("nwicon", (iPx, iPx))
+ self.guiDeco = self.theTheme.loadDecoration("nwicon", (nPx, nPx))
self.innerBox.addWidget(self.guiDeco, 0, Qt.AlignTop)
self.projectForm = QGridLayout()
self.projectForm.setContentsMargins(0, 0, 0, 0)
- iPx = self.theTheme.textIconSize
self.listBox = QTreeWidget()
self.listBox.setSelectionMode(QAbstractItemView.SingleSelection)
self.listBox.setDragDropMode(QAbstractItemView.NoDragDrop)
diff --git a/nw/gui/projsettings.py b/nw/gui/projsettings.py
index 11b6a014..0afaefbf 100644
--- a/nw/gui/projsettings.py
+++ b/nw/gui/projsettings.py
@@ -282,7 +282,7 @@ class GuiProjectEditStatus(QWidget):
self.colChanged = False
self.selColour = None
- self.iPx = self.theTheme.textIconSize
+ self.iPx = self.theTheme.baseIconSize
self.outerBox = QVBoxLayout()
self.mainBox = QHBoxLayout()
diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py
index a40e4022..c851a218 100644
--- a/nw/gui/statusbar.py
+++ b/nw/gui/statusbar.py
@@ -61,7 +61,7 @@ class GuiMainStatus(QStatusBar):
colTrue = QColor(*self.theTheme.statUnsaved)
colFalse = QColor(*self.theTheme.statSaved)
- iPx = self.theTheme.textIconSize
+ iPx = self.theTheme.baseIconSize
# Permanent Widgets
# =================
diff --git a/nw/gui/theme.py b/nw/gui/theme.py
index 98c9a7b9..30bcb621 100644
--- a/nw/gui/theme.py
+++ b/nw/gui/theme.py
@@ -143,7 +143,6 @@ class GuiTheme:
self.fontPointSize = self.guiFont.pointSizeF()
self.fontPixelSize = int(round(qMetric.height()))
self.baseIconSize = int(round(qMetric.ascent()))
- self.textIconSize = int(round(qMetric.ascent() + qMetric.leading()))
self.textNHeight = qMetric.boundingRect("N").height()
self.textNWidth = qMetric.boundingRect("N").width()
@@ -151,7 +150,6 @@ class GuiTheme:
logger.verbose("GUI Font Point Size: %.2f" % self.fontPointSize)
logger.verbose("GUI Font Pixel Size: %d" % self.fontPixelSize)
logger.verbose("GUI Base Icon Size: %d" % self.baseIconSize)
- logger.verbose("GUI Text Icon Size: %d" % self.textIconSize)
logger.verbose("Text 'N' Height: %d" % self.textNHeight)
logger.verbose("Text 'N' Width: %d" % self.textNWidth)