diff --git a/bcfplugin/gui/plugin_delegate.py b/bcfplugin/gui/plugin_delegate.py index 778978d..8348572 100644 --- a/bcfplugin/gui/plugin_delegate.py +++ b/bcfplugin/gui/plugin_delegate.py @@ -1,4 +1,5 @@ from copy import copy +from bcfplugin import TMPDIR import bcfplugin.util as util from PySide2.QtWidgets import * @@ -6,44 +7,9 @@ from PySide2.QtCore import (QModelIndex, Slot, QSize, QPoint, Signal, Qt, QRect) -emailRegex = "(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)|(^\s*$)" -commentRegex = "[a-zA-Z0-9.,\-\/ ]* -- {}".format(emailRegex) dueDateRegex = "\d{4}-[01]\d-[0-3]\d" - -authorsDialog = None -authorsLineEdit = None -@Slot() -def setAuthor(): - - global authorsDialog - global authorsLineEdit - - author = authorsLineEdit.text() - util.setAuthor(author) - authorsDialog.close() - - -def openAuthorsDialog(parent): - - global authorsDialog - global authorsLineEdit - - authorsDialog = QDialog(parent) - authorsDialog.setWindowTitle("Enter your e-Mail") - - form = QFormLayout() - emailValidator = QRegExpValidator() - emailValidator.setRegExp(emailRegex) - - authorsLineEdit = QLineEdit(parent) - authorsLineEdit.setValidator(emailValidator) - authorsLineEdit.editingFinished.connect(setAuthor) - - form.addRow("E-Mail:", authorsLineEdit) - authorsDialog.setLayout(form) - authorsDialog.setModal(True) - authorsDialog.exec() - +author = "" +""" Holds the entered email address of the author """ class CommentDelegate(QStyledItemDelegate): @@ -56,7 +22,7 @@ def __init__(self, parent = None): self.updateFonts(self.commentFont) self.widgetWidth = 0 - self._commentYOffset = 2 #TODO relate it to the actual screensize + self._commentYOffset = 2 self._commentYQOffset = None self._commentXOffset = 2 self._commentXQOffset = None @@ -122,14 +88,9 @@ def createEditor(self, parent, option, index): """ Makes the comment and the author available in a QLineEdit """ - modAuthor = "" - if util.isAuthorSet(): - modAuthor = util.getAuthor() - else: - openAuthorsDialog(None) - modAuthor = util.getAuthor() + global author - util.debug("The email you entered is: {}".format(modAuthor)) + author = index.model().getAuthor() comment = index.model().data(index, Qt.EditRole) editor = QLineEdit(comment[0], parent) diff --git a/bcfplugin/gui/plugin_model.py b/bcfplugin/gui/plugin_model.py index 8cbdffd..04c5693 100644 --- a/bcfplugin/gui/plugin_model.py +++ b/bcfplugin/gui/plugin_model.py @@ -14,6 +14,45 @@ from bcfplugin.rdwr.markup import Comment from bcfplugin.frontend.viewController import CamType +emailRegex = "(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)|(^\s*$)" + +authorsDialog = None +authorsLineEdit = None +@Slot() +def setAuthor(): + + global authorsDialog + global authorsLineEdit + + author = authorsLineEdit.text() + authorsDialog.author = author + authorsDialog.done(0) + + +def openAuthorsDialog(parent): + + global authorsDialog + global authorsLineEdit + + authorsDialog = QDialog(parent) + authorsDialog.setWindowTitle("Enter your e-Mail") + + form = QFormLayout() + emailValidator = QRegExpValidator() + emailValidator.setRegExp(emailRegex) + + authorsLineEdit = QLineEdit(parent) + authorsLineEdit.setValidator(emailValidator) + authorsLineEdit.editingFinished.connect(setAuthor) + + form.addRow("E-Mail:", authorsLineEdit) + authorsDialog.setLayout(form) + authorsDialog.exec() + + author = authorsDialog.author + util.debug("We got something very nice {}".format(author)) + util.setAuthor(author) + def openProjectBtnHandler(file): @@ -283,6 +322,21 @@ def referencedViewpoint(self, index): return self.items[index.row()].viewpoint + def getAuthor(self): + + util.debug("This is the current temp directory:"\ + " {}".format(util.getSystemTmp())) + + modAuthor = None + if util.isAuthorSet(): + modAuthor = util.getAuthor() + else: + openAuthorsDialog(None) + modAuthor = util.getAuthor() + + return modAuthor + + class SnapshotModel(QAbstractListModel): diff --git a/bcfplugin/gui/plugin_panel.py b/bcfplugin/gui/plugin_panel.py index 1f6984b..e24d4c4 100644 --- a/bcfplugin/gui/plugin_panel.py +++ b/bcfplugin/gui/plugin_panel.py @@ -25,6 +25,7 @@ def __init__(self): self.running = True self.form = view.MyMainWindow() + self.form.resize(self.form.geometry().width(), self.form.geometry().height()) self.form.setObjectName("BCFPlugin") @@ -68,6 +69,11 @@ def getStandardButtons(self): return int(QDialogButtonBox.Close) + def close(self): + + self.form.closeEvent() + + def reject(self): """ Called when the 'Close' button of the task dialog is pressed, diff --git a/bcfplugin/gui/plugin_view.py b/bcfplugin/gui/plugin_view.py index 4e789b0..752e349 100644 --- a/bcfplugin/gui/plugin_view.py +++ b/bcfplugin/gui/plugin_view.py @@ -59,9 +59,9 @@ def mouseEntered(self, index): itemRect = self.rectForIndex(index) x = itemRect.width() - deleteButton.geometry().width() - y = itemRect.y() + (itemRect.height() - + vOffset = self.verticalOffset() # scroll offset + y = itemRect.y() - vOffset + (itemRect.height() - deleteButton.geometry().height()) / 2 - util.debug("DeleteButton y start: {}".format(y)) deleteButton.move(x, y) deleteButton.show() @@ -265,6 +265,9 @@ def __init__(self): self.viewpointList.activateViewpoint(x, self.viewpointResetBtn)) self.viewpointResetBtn.clicked.connect(self.viewpointsModel.resetView) self.viewpointResetBtn.clicked.connect(self.viewpointResetBtn.hide) + # delete delete button if the view is scrolled + self.commentList.verticalScrollBar().valueChanged.connect(lambda x: + self.commentList.deleteDelBtn()) self.setLayout(self.mainLayout) @@ -345,8 +348,6 @@ def createCommentGroup(self): self.commentLayout.addWidget(self.commentList) self.commentPlaceholder = self.tr("Enter a new comment here") - self.commentValidator = QRegExpValidator() - self.commentValidator.setRegExp(delegate.commentRegex) self.newCommentEdit = QLineEdit() self.newCommentEdit.returnPressed.connect(self.checkAndAddComment) self.newCommentEdit.setPlaceholderText(self.commentPlaceholder) @@ -415,7 +416,6 @@ def openProjectBtnHandler(self): @Slot() def checkAndAddComment(self): - util.debug("Pressed enter on the input") editor = self.newCommentEdit text = editor.text() @@ -446,7 +446,7 @@ def saveProjectHandler(self): dflPath = self.openFilePath filename = QFileDialog.getSaveFileName(self, self.tr("Save BCF File"), dflPath, self.tr("BCF Files (*.bcf *.bcfzip)")) - if filename != "": + if filename[0] != "": util.debug("Got a file to write to: {}.".format(filename)) model.saveProject(filename[0]) @@ -487,6 +487,30 @@ def showTopicMetrics(self): metricsWindow.show() + def closeEvent(self): + + self.showExitSaveDialog() + util.debug("Deleting temporary directory {}".format(util.getSystemTmp())) + util.deleteTmp() + + + def showExitSaveDialog(self): + + dialog = QDialog(self) + buttons = QDialogButtonBox(QDialogButtonBox.Save | + QDialogButtonBox.Close, dialog) + label = QLabel(self.tr("Save before closing?")) + + layout = QVBoxLayout(dialog) + layout.addWidget(label) + layout.addWidget(buttons) + dialog.setLayout(layout) + + buttons.accepted.connect(self.saveProjectHandler) + buttons.rejected.connect(lambda: dialog.done(0)) + dialog.exec() + + if __name__ == "__main__": app = QApplication(sys.argv) diff --git a/bcfplugin/util.py b/bcfplugin/util.py index 60ab386..d990dca 100644 --- a/bcfplugin/util.py +++ b/bcfplugin/util.py @@ -101,6 +101,18 @@ def getSystemTmp(createNew: bool = False): return tmpDir.name +def deleteTmp(): + + """ Delete the temporary directory with all its contents """ + + global tmpDir + + if tmpDir is not None: + print("deleting temporary directory {}".format(tmpDir.name)) + del tmpDir + tmpDir = None + + def printErr(msg, toFile=False): """ Print msg to stderr """