From ff793d4358a4fc80a89a4497274de9d6310fc047 Mon Sep 17 00:00:00 2001 From: AccentuSoft Date: Mon, 13 Jun 2022 20:15:18 +0300 Subject: [PATCH] Rearranged code snippets to put them in more reasonable places (i.e. extra helper classes are now pulled from ResourceHandler.py rather than ResolutionManager.py. --- Core/Interface/DockBarTwo.py | 17 +---- Core/Interface/MenuBar.py | 2 +- Core/ResolutionManager.py | 95 --------------------------- Core/ResourceHandler.py | 121 +++++++++++++++++++++++++++++++++-- LinkScope.py | 2 +- 5 files changed, 120 insertions(+), 117 deletions(-) diff --git a/Core/Interface/DockBarTwo.py b/Core/Interface/DockBarTwo.py index 694d55d..e71cbb1 100644 --- a/Core/Interface/DockBarTwo.py +++ b/Core/Interface/DockBarTwo.py @@ -4,6 +4,7 @@ from pathlib import Path import magic from PySide6 import QtWidgets, QtCore, QtGui from Core.Interface import Stylesheets +from Core.ResourceHandler import MinSizeStackedLayout class DockBarTwo(QtWidgets.QDockWidget): @@ -377,22 +378,6 @@ class EntityDetails(QtWidgets.QWidget): self.detailsLayout.setCurrentIndex(2) -class MinSizeStackedLayout(QtWidgets.QStackedLayout): - """ - Resize the layout to always take up the appropriate space for the currently selected widget. - Otherwise, large widgets (due to selecting entities with long strings of text) will stretch - out the ScrollArea and make the other, non-selected widgets to look bad when the layout - switches over. - - https://stackoverflow.com/a/34300567 - """ - def sizeHint(self) -> QtCore.QSize: - return self.currentWidget().sizeHint() - - def minimumSize(self) -> QtCore.QSize: - return self.currentWidget().minimumSize() - - class SingleLinkItem(QtWidgets.QWidget): def __init__(self, parent, mainWindow): diff --git a/Core/Interface/MenuBar.py b/Core/Interface/MenuBar.py index 9256829..de51ee8 100644 --- a/Core/Interface/MenuBar.py +++ b/Core/Interface/MenuBar.py @@ -29,7 +29,7 @@ from PySide6 import QtWidgets, QtGui, QtCore from Core.GlobalVariables import user_agents from Core.Interface import Stylesheets from Core.Interface.Entity import BaseNode -from Core.ResolutionManager import StringPropertyInput, FilePropertyInput, SingleChoicePropertyInput, \ +from Core.ResourceHandler import StringPropertyInput, FilePropertyInput, SingleChoicePropertyInput, \ MultiChoicePropertyInput diff --git a/Core/ResolutionManager.py b/Core/ResolutionManager.py index 18aa19d..40db5d6 100644 --- a/Core/ResolutionManager.py +++ b/Core/ResolutionManager.py @@ -151,98 +151,3 @@ class ResolutionManager: resolutionClass = self.resolutions[category][resolution]['resolution']() result = resolutionClass.resolution(resolutionEntitiesInput, parameters) return result - - -class StringPropertyInput(QtWidgets.QLineEdit): - - def __init__(self, placeholderText, defaultText): - super(StringPropertyInput, self).__init__() - self.setPlaceholderText(placeholderText) - if defaultText is not None: - self.setText(defaultText) - - def getValue(self): - return self.text() - - -class FilePropertyInput(QtWidgets.QLineEdit): - - def __init__(self, placeholderText, defaultText): - super(FilePropertyInput, self).__init__() - self.setPlaceholderText(placeholderText) - if defaultText is not None: - self.setText(defaultText) - self.fileDialog = QtWidgets.QFileDialog() - - def getValue(self): - return self.text() - - def mousePressEvent(self, event: QtGui.QMouseEvent) -> None: - fileChosen = self.fileDialog.getOpenFileName(self, - "Open File", - str(Path.home()), - options=QtWidgets.QFileDialog.DontUseNativeDialog) - self.setText(fileChosen[0]) - - -class SingleChoicePropertyInput(QtWidgets.QGroupBox): - - def __init__(self, optionsSet: set, defaultOption): - # Ensure that the options given are an actual set (i.e. each one is unique) - enforceOptionsSet = set(optionsSet) - super(SingleChoicePropertyInput, self).__init__(title='Option Selection') - vboxLayout = QtWidgets.QVBoxLayout() - self.setLayout(vboxLayout) - - self.options = [] - if defaultOption is None: - defaultOption = '' - - for option in enforceOptionsSet: - radioButton = QtWidgets.QRadioButton(option) - radioButton.setStyleSheet(Stylesheets.RADIO_BUTTON_STYLESHEET) - if option == defaultOption: - radioButton.setChecked(True) - else: - radioButton.setChecked(False) - self.options.append(radioButton) - vboxLayout.addWidget(radioButton) - - def getValue(self): - for option in self.options: - if option.isChecked(): - return option.text() - - return '' - - -class MultiChoicePropertyInput(QtWidgets.QGroupBox): - - def __init__(self, optionsSet: set, defaultOptions): - # Ensure that the options given are an actual set (i.e. each one is unique) - enforceOptionsSet = set(optionsSet) - super(MultiChoicePropertyInput, self).__init__(title='Option Selection') - vboxLayout = QtWidgets.QVBoxLayout() - self.setLayout(vboxLayout) - - self.options = [] - if defaultOptions is None: - defaultOptions = [] - - for option in enforceOptionsSet: - checkBox = QtWidgets.QCheckBox(option) - checkBox.setStyleSheet(Stylesheets.CHECK_BOX_STYLESHEET) - if option in defaultOptions: - checkBox.setChecked(True) - else: - checkBox.setChecked(False) - self.options.append(checkBox) - vboxLayout.addWidget(checkBox) - - def getValue(self): - valuesSelected = [] - for option in self.options: - if option.isChecked(): - valuesSelected.append(option.text()) - - return valuesSelected diff --git a/Core/ResourceHandler.py b/Core/ResourceHandler.py index ff392c4..5611983 100644 --- a/Core/ResourceHandler.py +++ b/Core/ResourceHandler.py @@ -14,8 +14,10 @@ from ast import literal_eval from base64 import b64decode from dateutil import parser -from PySide6.QtGui import QIcon -from PySide6.QtCore import QByteArray +from PySide6.QtCore import QByteArray, QSize +from PySide6 import QtWidgets, QtGui + +from Core.Interface import Stylesheets class ResourceHandler: @@ -357,11 +359,11 @@ class ResourceHandler: def getLinkPicture(self): picture = Path(self.mainWindow.SETTINGS.value("Program/BaseDir")) / "Resources" / "Icons" / "Resolution.png" - return QIcon(str(picture)).pixmap(40, 40) + return QtGui.QIcon(str(picture)).pixmap(40, 40) def getLinkArrowPicture(self): picture = Path(self.mainWindow.SETTINGS.value("Program/BaseDir")) / "Resources" / "Icons" / "Right-Arrow.svg" - return QIcon(str(picture)).pixmap(40, 40) + return QtGui.QIcon(str(picture)).pixmap(40, 40) def deconstructGraph(self, graph: nx.DiGraph) -> tuple: nodes = {} @@ -416,3 +418,114 @@ class ResourceHandler: returnGraph.add_edge(*edgeUID, **graphEdges[edge]) return returnGraph + + +class StringPropertyInput(QtWidgets.QLineEdit): + + def __init__(self, placeholderText, defaultText): + super(StringPropertyInput, self).__init__() + self.setPlaceholderText(placeholderText) + if defaultText is not None: + self.setText(defaultText) + + def getValue(self): + return self.text() + + +class FilePropertyInput(QtWidgets.QLineEdit): + + def __init__(self, placeholderText, defaultText): + super(FilePropertyInput, self).__init__() + self.setPlaceholderText(placeholderText) + if defaultText is not None: + self.setText(defaultText) + self.fileDialog = QtWidgets.QFileDialog() + + def getValue(self): + return self.text() + + def mousePressEvent(self, event: QtGui.QMouseEvent) -> None: + fileChosen = self.fileDialog.getOpenFileName(self, + "Open File", + str(Path.home()), + options=QtWidgets.QFileDialog.DontUseNativeDialog) + self.setText(fileChosen[0]) + + +class SingleChoicePropertyInput(QtWidgets.QGroupBox): + + def __init__(self, optionsSet: set, defaultOption): + # Ensure that the options given are an actual set (i.e. each one is unique) + enforceOptionsSet = set(optionsSet) + super(SingleChoicePropertyInput, self).__init__(title='Option Selection') + vboxLayout = QtWidgets.QVBoxLayout() + self.setLayout(vboxLayout) + + self.options = [] + if defaultOption is None: + defaultOption = '' + + for option in enforceOptionsSet: + radioButton = QtWidgets.QRadioButton(option) + radioButton.setStyleSheet(Stylesheets.RADIO_BUTTON_STYLESHEET) + if option == defaultOption: + radioButton.setChecked(True) + else: + radioButton.setChecked(False) + self.options.append(radioButton) + vboxLayout.addWidget(radioButton) + + def getValue(self): + for option in self.options: + if option.isChecked(): + return option.text() + + return '' + + +class MultiChoicePropertyInput(QtWidgets.QGroupBox): + + def __init__(self, optionsSet: set, defaultOptions): + # Ensure that the options given are an actual set (i.e. each one is unique) + enforceOptionsSet = set(optionsSet) + super(MultiChoicePropertyInput, self).__init__(title='Option Selection') + vboxLayout = QtWidgets.QVBoxLayout() + self.setLayout(vboxLayout) + + self.options = [] + if defaultOptions is None: + defaultOptions = [] + + for option in enforceOptionsSet: + checkBox = QtWidgets.QCheckBox(option) + checkBox.setStyleSheet(Stylesheets.CHECK_BOX_STYLESHEET) + if option in defaultOptions: + checkBox.setChecked(True) + else: + checkBox.setChecked(False) + self.options.append(checkBox) + vboxLayout.addWidget(checkBox) + + def getValue(self): + valuesSelected = [] + for option in self.options: + if option.isChecked(): + valuesSelected.append(option.text()) + + return valuesSelected + + +class MinSizeStackedLayout(QtWidgets.QStackedLayout): + """ + Resize the layout to always take up the appropriate space for the currently selected widget. + Otherwise, large widgets (due to selecting entities with long strings of text) will stretch + out the ScrollArea and make the other, non-selected widgets to look bad when the layout + switches over. + + https://stackoverflow.com/a/34300567 + """ + def sizeHint(self) -> QSize: + return self.currentWidget().sizeHint() + + def minimumSize(self) -> QSize: + return self.currentWidget().minimumSize() diff --git a/LinkScope.py b/LinkScope.py index 277a5d4..cb256f1 100644 --- a/LinkScope.py +++ b/LinkScope.py @@ -29,7 +29,7 @@ from Core import EntityDB from Core import ResolutionManager from Core import URLManager from Core import FrontendCommunicationsHandler -from Core.ResolutionManager import StringPropertyInput, FilePropertyInput, SingleChoicePropertyInput, \ +from Core.ResourceHandler import StringPropertyInput, FilePropertyInput, SingleChoicePropertyInput, \ MultiChoicePropertyInput from Core.Interface import CentralPane from Core.Interface import DockBarOne, DockBarTwo, DockBarThree