Update project load dialog
This commit is contained in:
@@ -29,8 +29,8 @@ from typing import TYPE_CHECKING
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from PyQt5.QtGui import QKeySequence
|
from PyQt5.QtGui import QCloseEvent, QKeySequence
|
||||||
from PyQt5.QtCore import Qt, QSize
|
from PyQt5.QtCore import Qt, QSize, pyqtSlot
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QDialog, QHBoxLayout, QVBoxLayout, QGridLayout, QPushButton, QTreeWidget,
|
QDialog, QHBoxLayout, QVBoxLayout, QGridLayout, QPushButton, QTreeWidget,
|
||||||
QAbstractItemView, QTreeWidgetItem, QDialogButtonBox, QLabel, QShortcut,
|
QAbstractItemView, QTreeWidgetItem, QDialogButtonBox, QLabel, QShortcut,
|
||||||
@@ -112,8 +112,7 @@ class GuiProjectLoad(QDialog):
|
|||||||
self.selPath = QLineEdit("")
|
self.selPath = QLineEdit("")
|
||||||
self.selPath.setReadOnly(True)
|
self.selPath.setReadOnly(True)
|
||||||
|
|
||||||
self.browseButton = QPushButton("...")
|
self.browseButton = QPushButton(SHARED.theme.getIcon("browse"), "", self)
|
||||||
self.browseButton.setMaximumWidth(int(2.5*SHARED.theme.getTextWidth("...")))
|
|
||||||
self.browseButton.clicked.connect(self._doBrowse)
|
self.browseButton.clicked.connect(self._doBrowse)
|
||||||
|
|
||||||
self.projectForm.addWidget(self.lblRecent, 0, 0, 1, 3)
|
self.projectForm.addWidget(self.lblRecent, 0, 0, 1, 3)
|
||||||
@@ -159,12 +158,12 @@ class GuiProjectLoad(QDialog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Buttons
|
# Private Slots
|
||||||
##
|
##
|
||||||
|
|
||||||
def _doOpenRecent(self):
|
@pyqtSlot()
|
||||||
"""Close the dialog window with a recent project selected.
|
def _doOpenRecent(self) -> None:
|
||||||
"""
|
"""Close the dialog window with a recent project selected."""
|
||||||
self._saveSettings()
|
self._saveSettings()
|
||||||
|
|
||||||
self.openPath = None
|
self.openPath = None
|
||||||
@@ -178,17 +177,17 @@ class GuiProjectLoad(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _doSelectRecent(self):
|
@pyqtSlot()
|
||||||
"""A recent item has been selected.
|
def _doSelectRecent(self) -> None:
|
||||||
"""
|
"""Update path when a recent item has been selected."""
|
||||||
selList = self.listBox.selectedItems()
|
selList = self.listBox.selectedItems()
|
||||||
if selList:
|
if selList:
|
||||||
self.selPath.setText(selList[0].data(self.C_NAME, self.D_PATH))
|
self.selPath.setText(selList[0].data(self.C_NAME, self.D_PATH))
|
||||||
return
|
return
|
||||||
|
|
||||||
def _doBrowse(self):
|
@pyqtSlot()
|
||||||
"""Browse for a folder path.
|
def _doBrowse(self) -> None:
|
||||||
"""
|
"""Browse for a folder path."""
|
||||||
extFilter = [
|
extFilter = [
|
||||||
self.tr("novelWriter Project File ({0})").format(nwFiles.PROJ_FILE),
|
self.tr("novelWriter Project File ({0})").format(nwFiles.PROJ_FILE),
|
||||||
self.tr("All files ({0})").format("*"),
|
self.tr("All files ({0})").format("*"),
|
||||||
@@ -205,26 +204,26 @@ class GuiProjectLoad(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _doCancel(self):
|
@pyqtSlot()
|
||||||
"""Close the dialog window without doing anything.
|
def _doCancel(self) -> None:
|
||||||
"""
|
"""Close the dialog window without doing anything."""
|
||||||
self.openPath = None
|
self.openPath = None
|
||||||
self.openState = self.NONE_STATE
|
self.openState = self.NONE_STATE
|
||||||
self.close()
|
self.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
def _doNewProject(self):
|
@pyqtSlot()
|
||||||
"""Create a new project.
|
def _doNewProject(self) -> None:
|
||||||
"""
|
"""Create a new project."""
|
||||||
self._saveSettings()
|
self._saveSettings()
|
||||||
self.openPath = None
|
self.openPath = None
|
||||||
self.openState = self.NEW_STATE
|
self.openState = self.NEW_STATE
|
||||||
self.accept()
|
self.accept()
|
||||||
return
|
return
|
||||||
|
|
||||||
def _doDeleteRecent(self):
|
@pyqtSlot()
|
||||||
"""Remove an entry from the recent projects list.
|
def _doDeleteRecent(self) -> None:
|
||||||
"""
|
"""Remove an entry from the recent projects list."""
|
||||||
selList = self.listBox.selectedItems()
|
selList = self.listBox.selectedItems()
|
||||||
if selList:
|
if selList:
|
||||||
projName = selList[0].text(self.C_NAME)
|
projName = selList[0].text(self.C_NAME)
|
||||||
@@ -244,20 +243,18 @@ class GuiProjectLoad(QDialog):
|
|||||||
# Events
|
# Events
|
||||||
##
|
##
|
||||||
|
|
||||||
def closeEvent(self, theEvent):
|
def closeEvent(self, event: QCloseEvent) -> None:
|
||||||
"""Capture the user closing the dialog so we can save settings.
|
"""Capture the user closing the dialog and save settings."""
|
||||||
"""
|
|
||||||
self._saveSettings()
|
self._saveSettings()
|
||||||
theEvent.accept()
|
event.accept()
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|
||||||
def _saveSettings(self):
|
def _saveSettings(self) -> None:
|
||||||
"""Save the changes made to the dialog.
|
"""Save the changes made to the dialog."""
|
||||||
"""
|
|
||||||
colWidths = [0, 0, 0]
|
colWidths = [0, 0, 0]
|
||||||
colWidths[self.C_NAME] = self.listBox.columnWidth(self.C_NAME)
|
colWidths[self.C_NAME] = self.listBox.columnWidth(self.C_NAME)
|
||||||
colWidths[self.C_COUNT] = self.listBox.columnWidth(self.C_COUNT)
|
colWidths[self.C_COUNT] = self.listBox.columnWidth(self.C_COUNT)
|
||||||
@@ -265,9 +262,8 @@ class GuiProjectLoad(QDialog):
|
|||||||
CONFIG.setProjLoadColWidths(colWidths)
|
CONFIG.setProjLoadColWidths(colWidths)
|
||||||
return
|
return
|
||||||
|
|
||||||
def _populateList(self):
|
def _populateList(self) -> None:
|
||||||
"""Populate the list box with recent project data.
|
"""Populate the list box with recent project data."""
|
||||||
"""
|
|
||||||
self.listBox.clear()
|
self.listBox.clear()
|
||||||
dataList = CONFIG.recentProjects.listEntries()
|
dataList = CONFIG.recentProjects.listEntries()
|
||||||
sortList = sorted(dataList, key=lambda x: x[3], reverse=True)
|
sortList = sorted(dataList, key=lambda x: x[3], reverse=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user