--- a/Project/ProjectProtocolsBrowser.py Sun Nov 12 19:42:02 2017 +0100 +++ b/Project/ProjectProtocolsBrowser.py Mon Nov 13 20:20:06 2017 +0100 @@ -67,7 +67,6 @@ "protoc.exe" or "protoc" if not Utilities.isinpath(self.__protoc): self.__protoc = None - self.omniidl = self.__protoc # TODO: remove this line ProjectBaseBrowser.__init__(self, project, ProjectBrowserProtocolsType, parent) @@ -87,7 +86,6 @@ project.prepareRepopulateItem.connect(self._prepareRepopulateItem) project.completeRepopulateItem.connect(self._completeRepopulateItem) - # TODO: continue from here def _createPopupMenus(self): """ Protected overloaded method to generate the popup menu. @@ -98,12 +96,12 @@ self.dirMultiMenuActions = [] self.sourceMenu = QMenu(self) - if self.omniidl is not None: + if self.__protoc is not None: self.sourceMenu.addAction( - self.tr('Compile interface'), self.__compileInterface) + self.tr('Compile protocol'), self.__compileProtocol) self.sourceMenu.addAction( - self.tr('Compile all interfaces'), - self.__compileAllInterfaces) + self.tr('Compile all protocols'), + self.__compileAllProtocols) self.sourceMenu.addAction(self.tr('Open'), self._openItem) self.sourceMenu.addSeparator() act = self.sourceMenu.addAction( @@ -117,10 +115,10 @@ self.menuActions.append(act) self.sourceMenu.addSeparator() self.sourceMenu.addAction( - self.tr('Add interfaces...'), self.__addInterfaceFiles) + self.tr('Add protocols...'), self.__addProtocolFiles) self.sourceMenu.addAction( - self.tr('Add interfaces directory...'), - self.__addInterfacesDirectory) + self.tr('Add protocols directory...'), + self.__addProtocolsDirectory) self.sourceMenu.addSeparator() self.sourceMenu.addAction( self.tr('Copy Path to Clipboard'), self._copyToClipboard) @@ -132,22 +130,22 @@ self.sourceMenu.addSeparator() self.sourceMenu.addAction(self.tr('Configure...'), self._configure) self.sourceMenu.addAction( - self.tr('Configure CORBA...'), self.__configureCorba) + self.tr('Configure Protobuf...'), self.__configureProtobuf) self.menu = QMenu(self) - if self.omniidl is not None: + if self.__protoc is not None: self.menu.addAction( - self.tr('Compile interface'), self.__compileInterface) + self.tr('Compile protocol'), self.__compileProtocol) self.menu.addAction( - self.tr('Compile all interfaces'), - self.__compileAllInterfaces) + self.tr('Compile all protocols'), + self.__compileAllProtocols) self.menu.addAction(self.tr('Open'), self._openItem) self.menu.addSeparator() self.menu.addAction( - self.tr('Add interfaces...'), self.__addInterfaceFiles) + self.tr('Add protocols...'), self.__addProtocolFiles) self.menu.addAction( - self.tr('Add interfaces directory...'), - self.__addInterfacesDirectory) + self.tr('Add protocols directory...'), + self.__addProtocolsDirectory) self.menu.addSeparator() self.menu.addAction( self.tr('Expand all directories'), self._expandAllDirs) @@ -156,18 +154,18 @@ self.menu.addSeparator() self.menu.addAction(self.tr('Configure...'), self._configure) self.menu.addAction( - self.tr('Configure CORBA...'), self.__configureCorba) + self.tr('Configure Protobuf...'), self.__configureProtobuf) self.backMenu = QMenu(self) - if self.omniidl is not None: + if self.__protoc is not None: self.backMenu.addAction( - self.tr('Compile all interfaces'), - self.__compileAllInterfaces) + self.tr('Compile all protocols'), + self.__compileAllProtocols) self.backMenu.addSeparator() self.backMenu.addAction( - self.tr('Add interfaces...'), self.project.addIdlFiles) + self.tr('Add protocols...'), self.project.addProtoFiles) self.backMenu.addAction( - self.tr('Add interfaces directory...'), self.project.addIdlDir) + self.tr('Add protocols directory...'), self.project.addProtoDir) self.backMenu.addSeparator() self.backMenu.addAction( self.tr('Expand all directories'), self._expandAllDirs) @@ -176,15 +174,15 @@ self.backMenu.addSeparator() self.backMenu.addAction(self.tr('Configure...'), self._configure) self.backMenu.addAction( - self.tr('Configure CORBA...'), self.__configureCorba) + self.tr('Configure Protobuf...'), self.__configureProtobuf) self.backMenu.setEnabled(False) # create the menu for multiple selected files self.multiMenu = QMenu(self) - if self.omniidl is not None: + if self.__protoc is not None: self.multiMenu.addAction( - self.tr('Compile interfaces'), - self.__compileSelectedInterfaces) + self.tr('Compile protocols'), + self.__compileSelectedProtocols) self.multiMenu.addAction(self.tr('Open'), self._openItem) self.multiMenu.addSeparator() act = self.multiMenu.addAction( @@ -201,13 +199,13 @@ self.multiMenu.addSeparator() self.multiMenu.addAction(self.tr('Configure...'), self._configure) self.multiMenu.addAction( - self.tr('Configure CORBA...'), self.__configureCorba) + self.tr('Configure Protobuf...'), self.__configureProtobuf) self.dirMenu = QMenu(self) - if self.omniidl is not None: + if self.__protoc is not None: self.dirMenu.addAction( - self.tr('Compile all interfaces'), - self.__compileAllInterfaces) + self.tr('Compile all protocols'), + self.__compileAllProtocols) self.dirMenu.addSeparator() act = self.dirMenu.addAction( self.tr('Remove from project'), self._removeFile) @@ -217,10 +215,10 @@ self.dirMenuActions.append(act) self.dirMenu.addSeparator() self.dirMenu.addAction( - self.tr('Add interfaces...'), self.__addInterfaceFiles) + self.tr('Add protocols...'), self.__addProtocolFiles) self.dirMenu.addAction( - self.tr('Add interfaces directory...'), - self.__addInterfacesDirectory) + self.tr('Add protocols directory...'), + self.__addProtocolsDirectory) self.dirMenu.addSeparator() self.dirMenu.addAction( self.tr('Copy Path to Clipboard'), self._copyToClipboard) @@ -232,18 +230,18 @@ self.dirMenu.addSeparator() self.dirMenu.addAction(self.tr('Configure...'), self._configure) self.dirMenu.addAction( - self.tr('Configure CORBA...'), self.__configureCorba) + self.tr('Configure Protobuf...'), self.__configureProtobuf) self.dirMultiMenu = QMenu(self) - if self.omniidl is not None: + if self.__protoc is not None: self.dirMultiMenu.addAction( - self.tr('Compile all interfaces'), - self.__compileAllInterfaces) + self.tr('Compile all protocols'), + self.__compileAllProtocols) self.dirMultiMenu.addSeparator() self.dirMultiMenu.addAction( - self.tr('Add interfaces...'), self.project.addIdlFiles) + self.tr('Add protocols...'), self.project.addProtoFiles) self.dirMultiMenu.addAction( - self.tr('Add interfaces directory...'), self.project.addIdlDir) + self.tr('Add protocols directory...'), self.project.addProtoDir) self.dirMultiMenu.addSeparator() self.dirMultiMenu.addAction( self.tr('Expand all directories'), self._expandAllDirs) @@ -252,8 +250,8 @@ self.dirMultiMenu.addSeparator() self.dirMultiMenu.addAction( self.tr('Configure...'), self._configure) - self.dirMultiMenu.addAction(self.tr('Configure CORBA...'), - self.__configureCorba) + self.dirMultiMenu.addAction(self.tr('Configure Protobuf...'), + self.__configureProtobuf) self.sourceMenu.aboutToShow.connect(self.__showContextMenu) self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti) @@ -375,9 +373,9 @@ self.sourceFile[str, int].emit( itm.fileName(), itm.attributeObject().lineno) - def __addInterfaceFiles(self): + def __addProtocolFiles(self): """ - Private method to add interface files to the project. + Private method to add protocol files to the project. """ itm = self.model().item(self.currentIndex()) if isinstance(itm, ProjectBrowserFileItem) or \ @@ -389,11 +387,11 @@ dn = itm.dirName() else: dn = None - self.project.addFiles('interface', dn) + self.project.addFiles('protocol', dn) - def __addInterfacesDirectory(self): + def __addProtocolsDirectory(self): """ - Private method to add interface files of a directory to the project. + Private method to add protocol files of a directory to the project. """ itm = self.model().item(self.currentIndex()) if isinstance(itm, ProjectBrowserFileItem) or \ @@ -405,7 +403,7 @@ dn = itm.dirName() else: dn = None - self.project.addDirectory('interface', dn) + self.project.addDirectory('protocol', dn) def __deleteFile(self): """ @@ -425,8 +423,8 @@ DeleteFilesConfirmationDialog dlg = DeleteFilesConfirmationDialog( self.parent(), - self.tr("Delete interfaces"), - self.tr("Do you really want to delete these interfaces from" + self.tr("Delete Protocols"), + self.tr("Do you really want to delete these protocol files from" " the project?"), files) @@ -442,7 +440,7 @@ def __readStdout(self): """ Private slot to handle the readyReadStandardOutput signal of the - omniidl process. + protoc process. """ if self.compileProc is None: return @@ -451,7 +449,7 @@ self.compileProc.setReadChannel(QProcess.StandardOutput) while self.compileProc and self.compileProc.canReadLine(): - s = 'omniidl: ' + s = 'protoc: ' output = str(self.compileProc.readLine(), ioEncoding, 'replace') s += output self.appendStdout.emit(s) @@ -459,7 +457,7 @@ def __readStderr(self): """ Private slot to handle the readyReadStandardError signal of the - omniidl process. + protoc process. """ if self.compileProc is None: return @@ -468,63 +466,59 @@ self.compileProc.setReadChannel(QProcess.StandardError) while self.compileProc and self.compileProc.canReadLine(): - s = 'omniidl: ' + s = 'protoc: ' error = str(self.compileProc.readLine(), ioEncoding, 'replace') s += error self.appendStderr.emit(s) - def __compileIDLDone(self, exitCode, exitStatus): + def __compileProtocolDone(self, exitCode, exitStatus): """ - Private slot to handle the finished signal of the omniidl process. + Private slot to handle the finished signal of the protoc process. @param exitCode exit code of the process (integer) @param exitStatus exit status of the process (QProcess.ExitStatus) """ - self.compileRunning = False + self.__compileRunning = False ui = e5App().getObject("UserInterface") if exitStatus == QProcess.NormalExit and exitCode == 0: - path = os.path.dirname(self.idlFile) - poaList = glob.glob(os.path.join(path, "*__POA")) - npoaList = [f.replace("__POA", "") for f in poaList] - fileList = glob.glob(os.path.join(path, "*_idl.py")) - for directory in poaList + npoaList: - fileList += Utilities.direntries(directory, True, "*.py") + path = os.path.dirname(self.__protoFile) + fileList = glob.glob(os.path.join(path, "*_pb2.py")) for file in fileList: self.project.appendFile(file) if not self.noDialog and not ui.notificationsEnabled(): E5MessageBox.information( self, - self.tr("Interface Compilation"), + self.tr("Protocol Compilation"), self.tr( - "The compilation of the interface file was" + "The compilation of the protocol file was" " successful.")) else: ui.showNotification( - UI.PixmapCache.getPixmap("corba48.png"), - self.tr("Interface Compilation"), + UI.PixmapCache.getPixmap("protobuf48.png"), + self.tr("Protocol Compilation"), self.tr( - "The compilation of the interface file was" + "The compilation of the protocol file was" " successful.")) else: if not self.noDialog: E5MessageBox.information( self, - self.tr("Interface Compilation"), + self.tr("Protocol Compilation"), self.tr( - "The compilation of the interface file failed.")) + "The compilation of the protocol file failed.")) else: ui.showNotification( - UI.PixmapCache.getPixmap("corba48.png"), - self.tr("Interface Compilation"), + UI.PixmapCache.getPixmap("protobuf48.png"), + self.tr("Protocol Compilation"), self.tr( - "The compilation of the interface file failed.")) + "The compilation of the protocol file failed.")) self.compileProc = None - def __compileIDL(self, fn, noDialog=False, progress=None): + def __compileProto(self, fn, noDialog=False, progress=None): """ - Private method to compile a .idl file to python. + Private method to compile a .proto file to Python. - @param fn filename of the .idl file to be compiled (string) + @param fn filename of the .proto file to be compiled (string) @param noDialog flag indicating silent operations (boolean) @param progress reference to the progress dialog (E5ProgressDialog) @return reference to the compile process (QProcess) @@ -532,26 +526,26 @@ self.compileProc = QProcess() args = [] - args.append("-bpython") - args.append("-I.") + fn = os.path.join(self.project.ppath, fn) + self.__protoFile = fn - fn = os.path.join(self.project.ppath, fn) - self.idlFile = fn - args.append("-C{0}".format(os.path.dirname(fn))) + srcPath = os.path.dirname(fn) + args.append("--proto_path={0}".format(srcPath)) + args.append("--python_out={0}".format(srcPath)) args.append(fn) - self.compileProc.finished.connect(self.__compileIDLDone) + self.compileProc.finished.connect(self.__compileProtocolDone) self.compileProc.readyReadStandardOutput.connect(self.__readStdout) self.compileProc.readyReadStandardError.connect(self.__readStderr) self.noDialog = noDialog - self.compileProc.start(self.omniidl, args) + self.compileProc.start(self.__protoc, args) procStarted = self.compileProc.waitForStarted(5000) if procStarted: - self.compileRunning = True + self.__compileRunning = True return self.compileProc else: - self.compileRunning = False + self.__compileRunning = False if progress is not None: progress.cancel() E5MessageBox.critical( @@ -560,39 +554,39 @@ self.tr( '<p>Could not start {0}.<br>' 'Ensure that it is in the search path.</p>' - ).format(self.omniidl)) + ).format(self.__protoc)) return None - def __compileInterface(self): + def __compileProtocol(self): """ - Private method to compile an interface to python. + Private method to compile a protocol to Python. """ - if self.omniidl is not None: + if self.__protoc is not None: itm = self.model().item(self.currentIndex()) fn2 = itm.fileName() fn = self.project.getRelativePath(fn2) - self.__compileIDL(fn) + self.__compileProto(fn) - def __compileAllInterfaces(self): + def __compileAllProtocols(self): """ - Private method to compile all interfaces to python. + Private method to compile all protocols to Python. """ - if self.omniidl is not None: - numIDLs = len(self.project.pdata["INTERFACES"]) + if self.__protoc is not None: + numProtos = len(self.project.pdata["PROTOCOLS"]) progress = E5ProgressDialog( - self.tr("Compiling interfaces..."), - self.tr("Abort"), 0, numIDLs, - self.tr("%v/%m Interfaces"), self) + self.tr("Compiling Protocols..."), + self.tr("Abort"), 0, numProtos, + self.tr("%v/%m Protocols"), self) progress.setModal(True) progress.setMinimumDuration(0) - progress.setWindowTitle(self.tr("Interfaces")) + progress.setWindowTitle(self.tr("Protocols")) i = 0 - for fn in self.project.pdata["INTERFACES"]: + for fn in self.project.pdata["PROTOCOLS"]: progress.setValue(i) if progress.wasCanceled(): break - proc = self.__compileIDL(fn, True, progress) + proc = self.__compileProto(fn, True, progress) if proc is not None: while proc.state() == QProcess.Running: QApplication.processEvents() @@ -602,32 +596,32 @@ break i += 1 - progress.setValue(numIDLs) + progress.setValue(numProtos) - def __compileSelectedInterfaces(self): + def __compileSelectedProtocols(self): """ - Private method to compile selected interfaces to python. + Private method to compile selected protocols to Python. """ - if self.omniidl is not None: + if self.__protoc is not None: items = self.getSelectedItems() files = [self.project.getRelativePath(itm.fileName()) for itm in items] - numIDLs = len(files) + numProtos = len(files) progress = E5ProgressDialog( - self.tr("Compiling interfaces..."), - self.tr("Abort"), 0, numIDLs, - self.tr("%v/%m Interfaces"), self) + self.tr("Compiling Protocols..."), + self.tr("Abort"), 0, numProtos, + self.tr("%v/%m Protocols"), self) progress.setModal(True) progress.setMinimumDuration(0) - progress.setWindowTitle(self.tr("Interfaces")) + progress.setWindowTitle(self.tr("Protocols")) i = 0 for fn in files: progress.setValue(i) if progress.wasCanceled(): break - proc = self.__compileIDL(fn, True, progress) + proc = self.__compileProto(fn, True, progress) if proc is not None: while proc.state() == QProcess.Running: QApplication.processEvents() @@ -637,10 +631,10 @@ break i += 1 - progress.setValue(numIDLs) + progress.setValue(numProtos) - def __configureCorba(self): + def __configureProtobuf(self): """ Private method to open the configuration dialog. """ - e5App().getObject("UserInterface").showPreferences("corbaPage") + e5App().getObject("UserInterface").showPreferences("protobufPage")