IDLCompilerOptionsDialog: finished implementing a dialog to enter options for the IDL compiler. corba_options

Sun, 29 Jul 2018 14:00:23 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 29 Jul 2018 14:00:23 +0200
branch
corba_options
changeset 6445
2b022e5ba54c
parent 6444
7ce7a43aeeba
child 6446
806446f3cf03

IDLCompilerOptionsDialog: finished implementing a dialog to enter options for the IDL compiler.

Project/IdlCompilerDefineNameDialog.py file | annotate | diff | comparison | revisions
Project/IdlCompilerOptionsDialog.py file | annotate | diff | comparison | revisions
Project/ProjectInterfacesBrowser.py file | annotate | diff | comparison | revisions
--- a/Project/IdlCompilerDefineNameDialog.py	Sun Jul 29 12:53:57 2018 +0200
+++ b/Project/IdlCompilerDefineNameDialog.py	Sun Jul 29 14:00:23 2018 +0200
@@ -1,36 +1,71 @@
 # -*- coding: utf-8 -*-
 
+# Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
 """
-Module implementing IdlCompilerDefineNameDialog.
+Module implementing a dialog to enter the name-value pair to define a variable
+for the IDL compiler.
 """
 
 from PyQt5.QtCore import pyqtSlot
-from PyQt5.QtWidgets import QDialog
+from PyQt5.QtWidgets import QDialog, QDialogButtonBox
 
 from .Ui_IdlCompilerDefineNameDialog import Ui_IdlCompilerDefineNameDialog
 
 
 class IdlCompilerDefineNameDialog(QDialog, Ui_IdlCompilerDefineNameDialog):
     """
-    Class documentation goes here.
+    Class implementing a dialog to enter the name-value pair to define a
+    variable for the IDL compiler.
     """
-    def __init__(self, parent=None):
+    def __init__(self, name="", value="", parent=None):
         """
         Constructor
         
+        @param name name of the variable
+        @type str
+        @param value value of the variable
+        @type str
         @param parent reference to the parent widget
         @type QWidget
         """
         super(IdlCompilerDefineNameDialog, self).__init__(parent)
         self.setupUi(self)
+        
+        self.nameEdit.setText(name)
+        self.valueEdit.setText(value)
+        
+        msh = self.minimumSizeHint()
+        self.resize(max(self.width(), msh.width()), msh.height())
+        
+        self.__updateOkButton()
+    
+    def __updateOkButton(self):
+        """
+        Private slot to update the enable state of the OK button.
+        """
+        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
+            bool(self.nameEdit.text()))
     
     @pyqtSlot(str)
-    def on_nameEdit_textChanged(self, p0):
+    def on_nameEdit_textChanged(self, txt):
         """
-        Slot documentation goes here.
+        Private slot to handle changes of the name.
         
-        @param p0 DESCRIPTION
+        @param txt current text of the name edit
         @type str
         """
-        # TODO: not implemented yet
-        raise NotImplementedError
+        self.__updateOkButton()
+    
+    def getData(self):
+        """
+        Public method to get the entered data.
+        
+        @return tuple containing the variable name and value
+        @rtype tuple of (str, str)
+        """
+        return (
+            self.nameEdit.text().strip(),
+            self.valueEdit.text().strip(),
+        )
--- a/Project/IdlCompilerOptionsDialog.py	Sun Jul 29 12:53:57 2018 +0200
+++ b/Project/IdlCompilerOptionsDialog.py	Sun Jul 29 14:00:23 2018 +0200
@@ -17,6 +17,8 @@
 from E5Gui import E5PathPickerDialog
 from E5Gui.E5PathPicker import E5PathPickerModes
 
+from .IdlCompilerDefineNameDialog import IdlCompilerDefineNameDialog
+
 
 class IdlCompilerOptionsDialog(QDialog, Ui_IdlCompilerOptionsDialog):
     """
@@ -115,11 +117,7 @@
         @return flag indicating that the given directory is already included
         @rtype bool
         """
-        for row in range(self.idList.count()):
-            if self.idList.item(row).text() == directory:
-                return True
-        
-        return False
+        return len(self.idList.findItems(directory, Qt.MatchExactly)) > 0
     
     @pyqtSlot()
     def on_idList_itemSelectionChanged(self):
@@ -227,6 +225,37 @@
         
         self.dnList.sortItems(0, Qt.AscendingOrder)
     
+    def __generateDefinedNamesList(self):
+        """
+        Private method to prepare the list of 'Defined Names'.
+        
+        @return list of 'Defined Names'
+        @rtype list of str
+        """
+        definedNames = []
+        for row in range(self.dnList.topLevelItemCount()):
+            itm = self.dnList.topLevelItem(row)
+            name = itm.text(0).strip()
+            value = itm.text(1).strip()
+            if value:
+                definedNames.append("{0}={1}".format(name, value))
+            else:
+                definedNames.append(name)
+        
+        return definedNames
+    
+    def __definedNamesContain(self, name):
+        """
+        Private method to test, if the currently defined 'Defined Names'
+        contain a given one.
+        
+        @param name variable name to be tested
+        @type str
+        @return flag indicating that the given name is already included
+        @rtype bool
+        """
+        return len(self.dnList.findItems(name, Qt.MatchExactly, 0)) > 0
+    
     @pyqtSlot()
     def on_dnList_itemSelectionChanged(self):
         """
@@ -237,26 +266,51 @@
     @pyqtSlot()
     def on_dnAddButton_clicked(self):
         """
-        Slot documentation goes here.
+        Private slot to add a 'Define Name' entry.
         """
-        # TODO: not implemented yet
-        raise NotImplementedError
+        dlg = IdlCompilerDefineNameDialog(parent=self)
+        if dlg.exec_() == QDialog.Accepted:
+            name, value = dlg.getData()
+            if not self.__definedNamesContain(name):
+                QTreeWidgetItem(self.dnList, [name, value])
+        
+        self.dnList.sortItems(0, Qt.AscendingOrder)
     
     @pyqtSlot()
     def on_dnDeleteButton_clicked(self):
         """
-        Slot documentation goes here.
+        Private slot to delete the selected 'Define Name' entry.
         """
-        # TODO: not implemented yet
-        raise NotImplementedError
+        itm = self.dnList.selectedItems()[0]
+        index = self.dnList.indexOfTopLevelItem(itm)
+        self.dnList.takeTopLevelItem(index)
+        del itm
     
     @pyqtSlot()
     def on_dnEditButton_clicked(self):
         """
-        Slot documentation goes here.
+        Private slot to edit the selected 'Define Name' entry.
         """
-        # TODO: not implemented yet
-        raise NotImplementedError
+        itm = self.dnList.selectedItems()[0]
+        
+        dlg = IdlCompilerDefineNameDialog(
+            name=itm.text(0), value=itm.text(1), parent=self)
+        if dlg.exec_() == QDialog.Accepted:
+            name, value = dlg.getData()
+            if self.__definedNamesContain(name) and itm.text(0) != name:
+                # the entry exists already, delete the edited one
+                index = self.dnList.indexOfTopLevelItem(itm)
+                self.dnList.takeTopLevelItem(index)
+                del itm
+                
+                # change the named one
+                itm = self.dnList.findItems(name, Qt.MatchExactly, 0)[0]
+                itm.setText(1, value)
+            else:
+                itm.setText(0, name)
+                itm.setText(1, value)
+        
+        self.dnList.sortItems(0, Qt.AscendingOrder)
     
     #######################################################################
     ## Methods implementing the 'Undefine Name' option
@@ -292,11 +346,7 @@
         @return flag indicating that the given name is already included
         @rtype bool
         """
-        for row in range(self.unList.count()):
-            if self.unList.item(row).text() == name:
-                return True
-        
-        return False
+        return len(self.unList.findItems(name, Qt.MatchExactly)) > 0
     
     @pyqtSlot()
     def on_unList_itemSelectionChanged(self):
@@ -365,6 +415,6 @@
         """
         return (
             self.__generateIncludeDirectoriesList(),
-            [],
+            self.__generateDefinedNamesList(),
             self.__generateUndefinedNamesList(),
         )
--- a/Project/ProjectInterfacesBrowser.py	Sun Jul 29 12:53:57 2018 +0200
+++ b/Project/ProjectInterfacesBrowser.py	Sun Jul 29 14:00:23 2018 +0200
@@ -678,14 +678,6 @@
         """
         params = self.project.pdata["IDLPARAMS"]
         
-        # TODO: remove this test code once done
-        params = {
-            "IncludeDirs": ["sub3", "sub2"],
-            "DefinedNames": ["n2", "n1=1", "n3 = h e l p"],
-            "UndefinedNames": ["v5", "v2", "aa"],
-        }
-        
-        # TODO: implement IDL compiler options dialog
         from .IdlCompilerOptionsDialog import IdlCompilerOptionsDialog
         dlg = IdlCompilerOptionsDialog(
             params["IncludeDirs"][:], params["DefinedNames"][:],

eric ide

mercurial