From d585894935ca95aad4ccd5bdac3fe1b75390855b Mon Sep 17 00:00:00 2001 From: sudo-panda Date: Mon, 12 Aug 2019 01:35:00 +0530 Subject: [PATCH] Modify code to reselect sub states with parent This solves #6. --- .../gui/dialogs/dupparamsdialog.py | 168 ------------------ .../{paramsdialog.py => importdialog.py} | 5 +- src/visualstates/gui/visualstates.py | 4 +- 3 files changed, 4 insertions(+), 173 deletions(-) delete mode 100644 src/visualstates/gui/dialogs/dupparamsdialog.py rename src/visualstates/gui/dialogs/{paramsdialog.py => importdialog.py} (98%) diff --git a/src/visualstates/gui/dialogs/dupparamsdialog.py b/src/visualstates/gui/dialogs/dupparamsdialog.py deleted file mode 100644 index 87d0ddd..0000000 --- a/src/visualstates/gui/dialogs/dupparamsdialog.py +++ /dev/null @@ -1,168 +0,0 @@ -''' - Copyright (C) 1997-2019 JDERobot Developers Team - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - - Authors : Baidyanath Kundu (kundubaidya99@gmail.com) - - ''' -import sys -from PyQt5.QtWidgets import QDialog, QLabel, QLineEdit, \ - QPushButton, QApplication, QHBoxLayout, QVBoxLayout, \ - QMessageBox -from PyQt5.QtCore import pyqtSignal -from visualstates.core.parameter import Parameter, isParamName -from PyQt5.QtCore import * - - -class DuplicateParamsDialog(QDialog): - def __init__(self, name, newParam, oldParam, newParams, oldParams): - super(QDialog, self).__init__() - self.setWindowTitle(name) - self.newParam = newParam - self.oldParam = oldParam - self.newParams = newParams - self.oldParams = oldParams - self.newName = None - self.setFixedSize(600, 400) - - self.drawWindow() - - def drawWindow(self): - VLayout = QVBoxLayout() - VLayout.setAlignment(Qt.AlignTop) - if self.newParam.type == self.oldParam.type: - msg = QLabel('You can keep the same name for both parameters if you think their descriptions are same or you can change the name of the new one') - else: - msg = QLabel('Change the name of the imported parameter') - msg.setFixedHeight(50) - msg.setWordWrap(True) - VLayout.addWidget(msg) - - rowLayout = QHBoxLayout() - spaceLbl = QLabel('') - spaceLbl.setFixedWidth(100) - rowLayout.addWidget(spaceLbl) - titleLblStyleSheet = 'QLabel {font-weight: bold;}' - importLbl = QLabel('Imported:') - importLbl.setFixedWidth(235) - importLbl.setStyleSheet(titleLblStyleSheet) - rowLayout.addWidget(importLbl) - existLbl = QLabel('Existing:') - existLbl.setFixedWidth(235) - existLbl.setStyleSheet(titleLblStyleSheet) - rowLayout.addWidget(existLbl) - VLayout.addLayout(rowLayout) - - rowLayout = QHBoxLayout() - lblLayout = QVBoxLayout() - lblLayout.setAlignment(Qt.AlignTop) - nameLbl = QLabel('Name:') - nameLbl.setFixedWidth(100) - nameLbl.setFixedHeight(25) - lblLayout.addWidget(nameLbl) - typeLbl = QLabel('Type:') - typeLbl.setFixedWidth(100) - typeLbl.setFixedHeight(25) - lblLayout.addWidget(typeLbl) - valueLbl = QLabel('Value:') - valueLbl.setFixedWidth(100) - valueLbl.setFixedHeight(25) - lblLayout.addWidget(valueLbl) - descLbl = QLabel('Description:') - descLbl.setFixedWidth(100) - lblLayout.addWidget(descLbl) - rowLayout.addLayout(lblLayout) - - importLayout = QVBoxLayout() - importLayout.setAlignment(Qt.AlignTop) - self.newName = QLineEdit(self.newParam.name) - self.newName.setFixedWidth(235) - self.newName.setFixedHeight(25) - importLayout.addWidget(self.newName) - typeLbl = QLabel(self.newParam.type) - typeLbl.setFixedHeight(25) - importLayout.addWidget(typeLbl) - valueLbl = QLabel(self.newParam.value) - valueLbl.setFixedHeight(25) - importLayout.addWidget(valueLbl) - descLbl = QLabel(self.newParam.desc) - descLbl.setFixedHeight(180) - descLbl.setWordWrap(True) - descLbl.setAlignment(Qt.AlignTop) - importLayout.addWidget(descLbl) - rowLayout.addLayout(importLayout) - - existLayout = QVBoxLayout() - existLayout.setAlignment(Qt.AlignTop) - nameLbl = QLabel(self.oldParam.name) - nameLbl.setFixedWidth(235) - nameLbl.setFixedHeight(25) - existLayout.addWidget(nameLbl) - typeLbl = QLabel(self.oldParam.type) - typeLbl.setFixedHeight(25) - existLayout.addWidget(typeLbl) - valueLbl = QLabel(self.oldParam.value) - valueLbl.setFixedHeight(25) - existLayout.addWidget(valueLbl) - descLbl = QLabel(self.oldParam.desc) - descLbl.setFixedHeight(180) - descLbl.setWordWrap(True) - descLbl.setAlignment(Qt.AlignTop) - existLayout.addWidget(descLbl) - rowLayout.addLayout(existLayout) - - VLayout.addLayout(rowLayout) - - btnLayout = QHBoxLayout() - btnLayout.setAlignment(Qt.AlignRight) - doneBtn = QPushButton("Done") - doneBtn.setFixedWidth(80) - doneBtn.clicked.connect(self.doneClicked) - btnLayout.addWidget(doneBtn) - VLayout.addLayout(btnLayout) - self.setLayout(VLayout) - - def closeEvent(self, event): - self.doneClicked() - - def doneClicked(self): - if isParamName(self.newName.text()): - if self.newParam.name == self.newName.text(): - if self.newParam.type == self.oldParam.type: - self.close() - else: - QMessageBox.warning(self, 'Error', 'Imported and existing parameters\ncan\'t have the same name.') - else: - for param in self.oldParams: - if param.name == self.newName.text(): - QMessageBox.warning(self, 'Error', 'Name conflicts with another existing parameter.') - return - for param in self.newParams: - if param.name == self.newName.text(): - QMessageBox.warning(self, 'Error', 'Name conflicts with another existing parameter.') - return - self.close() - else: - QMessageBox.warning(self, 'Error', 'Name not valid') - - def getName(self): - return self.newName.text() - -if __name__ == '__main__': - app = QApplication(sys.argv) - param1 = Parameter('Name', 'String', 'Value', 'Description') - param2 = Parameter('Name', 'String', 'Value', 'Description') - dialog = DuplicateParamsDialog('Resolve Duplicate Parameters', param1, param2, [], []) - dialog.exec_() \ No newline at end of file diff --git a/src/visualstates/gui/dialogs/paramsdialog.py b/src/visualstates/gui/dialogs/importdialog.py similarity index 98% rename from src/visualstates/gui/dialogs/paramsdialog.py rename to src/visualstates/gui/dialogs/importdialog.py index 5390643..3e33581 100644 --- a/src/visualstates/gui/dialogs/paramsdialog.py +++ b/src/visualstates/gui/dialogs/importdialog.py @@ -27,7 +27,7 @@ from ..tools.clickablelabel import ClickableLabel from functools import partial -class ImportedParamsDialog(QDialog): +class ImportDialog(QDialog): paramsChanged = pyqtSignal(list) def __init__(self, name, file): @@ -139,8 +139,7 @@ def setStateEnabled(self, stateUIs, state): else: UI.setEnabled(state) if isinstance(UI, QCheckBox): - if not state: - UI.setChecked(state) + UI.setChecked(state) def toggleView(self, widget): label = self.sender() diff --git a/src/visualstates/gui/visualstates.py b/src/visualstates/gui/visualstates.py index 2dbfce9..3fead10 100644 --- a/src/visualstates/gui/visualstates.py +++ b/src/visualstates/gui/visualstates.py @@ -27,7 +27,7 @@ from .dialogs.namespacedialog import NamespaceDialog from .dialogs.librariesdialog import LibrariesDialog from .dialogs.rosconfigdialog import RosConfigDialog -from .dialogs.paramsdialog import ImportedParamsDialog +from .dialogs.importdialog import ImportDialog from ..configs.rosconfig import RosConfig from ..generators.cpprosgenerator import CppRosGenerator from ..generators.pythonrosgenerator import PythonRosGenerator @@ -267,7 +267,7 @@ def importFile(self, file): for childState in file[0].getChildren(): childState.setInitial(False) - displayParamDialog = ImportedParamsDialog("Imported Parameters", file) + displayParamDialog = ImportDialog("Imported States and Parameters", file) if displayParamDialog.exec_(): file = displayParamDialog.file # Update importing Namespaces