Project/Project.py

changeset 5969
584c21b6587a
parent 5968
c5112b5cb7a9
child 6048
82ad8ec9548c
--- a/Project/Project.py	Sun Nov 12 19:42:02 2017 +0100
+++ b/Project/Project.py	Mon Nov 13 20:20:06 2017 +0100
@@ -43,7 +43,6 @@
 import Utilities
 
 
-# TODO: add support for 'PROTOCOLS' (analog INTERFACES)
 class Project(QObject):
     """
     Class implementing the project management functionality.
@@ -60,6 +59,8 @@
     @signal projectSourceRemoved(str) emitted after a source was removed
     @signal projectInterfaceAdded(str) emitted after a new IDL file was added
     @signal projectInterfaceRemoved(str) emitted after a IDL file was removed
+    @signal projectProtocolAdded(str) emitted after a new proto file was added
+    @signal projectProtocolRemoved(str) emitted after a proto file was removed
     @signal projectResourceAdded(str) emitted after a new resource file was
         added
     @signal projectResourceRemoved(str) emitted after a resource was removed
@@ -112,6 +113,8 @@
     projectSourceRemoved = pyqtSignal(str)
     projectInterfaceAdded = pyqtSignal(str)
     projectInterfaceRemoved = pyqtSignal(str)
+    projectProtocolAdded = pyqtSignal(str)
+    projectProtocolRemoved = pyqtSignal(str)
     projectResourceAdded = pyqtSignal(str)
     projectResourceRemoved = pyqtSignal(str)
     projectOthersAdded = pyqtSignal(str)
@@ -546,6 +549,9 @@
         # IDL interfaces
         self.pdata["FILETYPES"]["*.idl"] = "INTERFACES"
         
+        # Protobuf Files
+        self.pdata["FILETYPES"]["*.proto"] = "PROTOCOLS"
+        
         # Forms
         if self.pdata["PROJECTTYPE"] in ["Qt4", "PyQt5",
                                          "E6Plugin", "PySide"]:
@@ -765,6 +771,7 @@
             self.__checkFilesExist("SOURCES")
             self.__checkFilesExist("FORMS")
             self.__checkFilesExist("INTERFACES")
+            self.__checkFilesExist("PROTOCOLS")
             self.__checkFilesExist("TRANSLATIONS")
             self.__checkFilesExist("RESOURCES")
             self.__checkFilesExist("OTHERS")
@@ -773,6 +780,7 @@
             for fn in self.pdata["SOURCES"] + \
                 self.pdata["FORMS"] + \
                 self.pdata["INTERFACES"] + \
+                self.pdata["PROTOCOLS"] + \
                 self.pdata["RESOURCES"] + \
                     self.pdata["TRANSLATIONS"]:
                 dn = os.path.dirname(fn)
@@ -1460,7 +1468,8 @@
         if filetype == "__IGNORE__":
             return
         
-        if filetype in ["SOURCES", "FORMS", "INTERFACES", "RESOURCES"]:
+        if filetype in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS",
+                        "RESOURCES"]:
             if filetype == "SOURCES":
                 if newfn not in self.pdata["SOURCES"]:
                     self.pdata["SOURCES"].append(newfn)
@@ -1486,6 +1495,15 @@
                     dirty = True
                 else:
                     updateModel and self.repopulateItem(newfn)
+            elif filetype == "PROTOCOLS":
+                if newfn not in self.pdata["PROTOCOLS"]:
+                    self.pdata["PROTOCOLS"].append(newfn)
+                    self.projectProtocolAdded.emit(newfn)
+                    updateModel and \
+                        self.__model.addNewItem("PROTOCOLS", newfn)
+                    dirty = True
+                else:
+                    updateModel and self.repopulateItem(newfn)
             elif filetype == "RESOURCES":
                 if newfn not in self.pdata["RESOURCES"]:
                     self.pdata["RESOURCES"].append(newfn)
@@ -1523,8 +1541,9 @@
         Public slot used to add files to the project.
         
         @param fileTypeFilter filter to be used by the add file dialog
-            (string out of source, form, resource, interface, others)
+        @type str out of source, form, resource, interface, protocol, others
         @param startdir start directory for the selection dialog
+        @type str
         """
         if startdir is None:
             startdir = self.ppath
@@ -1674,8 +1693,9 @@
         Public method used to add all files of a directory to the project.
         
         @param fileTypeFilter filter to be used by the add directory dialog
-            (string out of source, form, resource, interface, others)
-        @param startdir start directory for the selection dialog (string)
+        @type str out of source, form, resource, interface, protocol, others
+        @param startdir start directory for the selection dialog
+        @type str
         """
         if startdir is None:
             startdir = self.ppath
@@ -1747,6 +1767,12 @@
         """
         self.addFiles('interface')
         
+    def addProtoFiles(self):
+        """
+        Public slot to add protocol files to the current project.
+        """
+        self.addFiles('protocol')
+        
     def addResourceFiles(self):
         """
         Public slot to add Qt resources to the current project.
@@ -1779,6 +1805,13 @@
         """
         self.addDirectory('interface')
         
+    def addProtoDir(self):
+        """
+        Public slot to add all protocol files of a directory to the current
+        project.
+        """
+        self.addDirectory('protocol')
+        
     def addResourceDir(self):
         """
         Public slot to add all Qt resource files of a directory to the current
@@ -1856,6 +1889,7 @@
            fn in self.pdata["FORMS"] or \
            fn in self.pdata["TRANSLATIONS"] or \
            fn in self.pdata["INTERFACES"] or \
+           fn in self.pdata["PROTOCOLS"] or \
            fn in self.pdata["RESOURCES"] or \
            fn in self.pdata["OTHERS"]:
             self.renameFileInPdata(oldfn, newfn, isSourceFile)
@@ -1892,7 +1926,8 @@
         """
         filelist = []
         start = self.getRelativePath(start)
-        for key in ["SOURCES", "FORMS", "INTERFACES", "RESOURCES", "OTHERS"]:
+        for key in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS", "RESOURCES",
+                    "OTHERS"]:
             for entry in self.pdata[key][:]:
                 if entry.startswith(start):
                     filelist.append(os.path.join(self.ppath, entry))
@@ -1906,13 +1941,13 @@
         
         # init data store for the reorganization
         newPdata = {}
-        for key in ["SOURCES", "FORMS", "INTERFACES", "RESOURCES", "OTHERS",
-                    "TRANSLATIONS"]:
+        for key in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS", "RESOURCES",
+                    "OTHERS", "TRANSLATIONS"]:
             newPdata[key] = []
         
         # iterate over all files checking for a reassignment
-        for key in ["SOURCES", "FORMS", "INTERFACES", "RESOURCES", "OTHERS",
-                    "TRANSLATIONS"]:
+        for key in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS", "RESOURCES",
+                    "OTHERS", "TRANSLATIONS"]:
             for fn in self.pdata[key][:]:
                 filetype = key
                 bfn = os.path.basename(fn)
@@ -1929,8 +1964,8 @@
         
         if reorganized:
             # copy the reorganized files back to the project
-            for key in ["SOURCES", "FORMS", "INTERFACES", "RESOURCES",
-                        "OTHERS", "TRANSLATIONS"]:
+            for key in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS",
+                        "RESOURCES", "OTHERS", "TRANSLATIONS"]:
                 self.pdata[key] = newPdata[key][:]
             
             # repopulate the model
@@ -1946,7 +1981,8 @@
         """
         olddn = self.getRelativePath(olddn)
         newdn = self.getRelativePath(newdn)
-        for key in ["SOURCES", "FORMS", "INTERFACES", "RESOURCES", "OTHERS"]:
+        for key in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS", "RESOURCES",
+                    "OTHERS"]:
             for entry in self.pdata[key][:]:
                 if entry.startswith(olddn):
                     entry = entry.replace(olddn, newdn)
@@ -1964,7 +2000,8 @@
         olddn = self.getRelativePath(olddn)
         newdn = self.getRelativePath(newdn)
         typeStrings = []
-        for key in ["SOURCES", "FORMS", "INTERFACES", "RESOURCES", "OTHERS"]:
+        for key in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS", "RESOURCES",
+                    "OTHERS"]:
             for entry in self.pdata[key][:]:
                 if entry.startswith(olddn):
                     if key not in typeStrings:
@@ -2006,6 +2043,9 @@
         elif fn in self.pdata["INTERFACES"]:
             self.pdata["INTERFACES"].remove(fn)
             self.projectInterfaceRemoved.emit(fn)
+        elif fn in self.pdata["PROTOCOLS"]:
+            self.pdata["PROTOCOLS"].remove(fn)
+            self.projectProtocolRemoved.emit(fn)
         elif fn in self.pdata["RESOURCES"]:
             self.pdata["RESOURCES"].remove(fn)
             self.projectResourceRemoved.emit(fn)
@@ -2039,7 +2079,7 @@
             dn2 = dn + os.sep
         else:
             dn2 = dn
-        for key in ["SOURCES", "FORMS", "INTERFACES", "RESOURCES",
+        for key in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS", "RESOURCES",
                     "TRANSLATIONS", ]:
             for entry in self.pdata[key][:]:
                 if entry.startswith(dn2):
@@ -2131,6 +2171,7 @@
         if fn in self.pdata["SOURCES"] or \
            fn in self.pdata["FORMS"] or \
            fn in self.pdata["INTERFACES"] or \
+           fn in self.pdata["PROTOCOLS"] or \
            fn in self.pdata["RESOURCES"] or \
            fn in self.pdata["OTHERS"]:
             return True
@@ -3117,7 +3158,7 @@
         Public method to get the file entries of the given type.
         
         @param fileType project file type (one of SOURCES, FORMS, RESOURCES,
-            INTERFACES, OTHERS, TRANSLATIONS)
+            INTERFACES, PROTOCOLS, OTHERS, TRANSLATIONS)
         @type str
         @param normalized flag indicating normalized file names are wanted
         @type boolean
@@ -3126,7 +3167,7 @@
         @exception ValueError raised when an unsupported file type is given
         """
         if fileType not in ["SOURCES", "FORMS", "RESOURCES", "INTERFACES",
-                            "OTHERS", "TRANSLATIONS"]:
+                            "PROTOCOLS", "OTHERS", "TRANSLATIONS"]:
             raise ValueError("Given file type has incorrect value.")
         
         if normalized:
@@ -3448,7 +3489,7 @@
         @param fn filename to be checked (string)
         @return flag indicating membership (boolean)
         """
-        for group in ["SOURCES", "FORMS", "INTERFACES",
+        for group in ["SOURCES", "FORMS", "INTERFACES", "PROTOCOLS",
                       "RESOURCES", "TRANSLATIONS", "OTHERS"]:
             if self.__checkProjectFileGroup(fn, group):
                 return True
@@ -3516,6 +3557,18 @@
         """
         return self.__checkProjectFileGroup(fn, "INTERFACES")
         
+    def isProjectProtocol(self, fn):
+        """
+        Public method used to check, if the passed in filename belongs to the
+        project protocols.
+        
+        @param fn filename to be checked
+        @type str
+        @return flag indicating membership
+        @rtype bool
+        """
+        return self.__checkProjectFileGroup(fn, "PROTOCOLS")
+    
     def isProjectResource(self, fn):
         """
         Public method used to check, if the passed in filename belongs to the
@@ -3654,8 +3707,9 @@
             'Search new files in the project directory.'))
         act.setWhatsThis(self.tr(
             """<b>Search new files...</b>"""
-            """<p>This searches for new files (sources, *.ui, *.idl) in"""
-            """ the project directory and registered subdirectories.</p>"""
+            """<p>This searches for new files (sources, *.ui, *.idl,"""
+            """ *.proto) in the project directory and registered"""
+            """ subdirectories.</p>"""
         ))
         act.triggered.connect(self.__searchNewFiles)
         self.actions.append(act)
@@ -3711,11 +3765,11 @@
             self.tr('Show the project filetype associations'))
         self.filetypesAct.setWhatsThis(self.tr(
             """<b>Filetype Associations...</b>"""
-            """<p>This shows a dialog to edit the filetype associations of"""
+            """<p>This shows a dialog to edit the file type associations of"""
             """ the project. These associations determine the type"""
-            """ (source, form, interface or others) with a filename"""
-            """ pattern. They are used when adding a file to the project"""
-            """ and when performing a search for new files.</p>"""
+            """ (source, form, interface, protocol or others) with a"""
+            """ filename pattern. They are used when adding a file to the"""
+            """ project and when performing a search for new files.</p>"""
         ))
         self.filetypesAct.triggered.connect(
             self.__showFiletypeAssociations)
@@ -4308,6 +4362,8 @@
                     fn not in self.pdata["FORMS"]) or \
                    (filetype == "INTERFACES" and
                     fn not in self.pdata["INTERFACES"]) or \
+                   (filetype == "PROTOCOLS" and
+                    fn not in self.pdata["PROTOCOLS"]) or \
                    (filetype == "RESOURCES" and
                     fn not in self.pdata["RESOURCES"]) or \
                    (filetype == "OTHERS" and fn not in self.pdata["OTHERS"]):
@@ -4877,7 +4933,7 @@
         # build the list of entries
         lst_ = []
         for key in ["SOURCES", "FORMS", "RESOURCES", "TRANSLATIONS",
-                    "INTERFACES", "OTHERS"]:
+                    "INTERFACES", "PROTOCOLS", "OTHERS"]:
             lst_.extend(self.pdata[key])
         lst = []
         for entry in lst_:

eric ide

mercurial