Project/ProjectProtocolsBrowser.py

changeset 5969
584c21b6587a
parent 5968
c5112b5cb7a9
child 5970
411f7ba577d5
equal deleted inserted replaced
5968:c5112b5cb7a9 5969:584c21b6587a
65 if self.__protoc == "": 65 if self.__protoc == "":
66 self.__protoc = Utilities.isWindowsPlatform() and \ 66 self.__protoc = Utilities.isWindowsPlatform() and \
67 "protoc.exe" or "protoc" 67 "protoc.exe" or "protoc"
68 if not Utilities.isinpath(self.__protoc): 68 if not Utilities.isinpath(self.__protoc):
69 self.__protoc = None 69 self.__protoc = None
70 self.omniidl = self.__protoc # TODO: remove this line
71 70
72 ProjectBaseBrowser.__init__(self, project, 71 ProjectBaseBrowser.__init__(self, project,
73 ProjectBrowserProtocolsType, parent) 72 ProjectBrowserProtocolsType, parent)
74 73
75 self.selectedItemsFilter = \ 74 self.selectedItemsFilter = \
85 )) 84 ))
86 85
87 project.prepareRepopulateItem.connect(self._prepareRepopulateItem) 86 project.prepareRepopulateItem.connect(self._prepareRepopulateItem)
88 project.completeRepopulateItem.connect(self._completeRepopulateItem) 87 project.completeRepopulateItem.connect(self._completeRepopulateItem)
89 88
90 # TODO: continue from here
91 def _createPopupMenus(self): 89 def _createPopupMenus(self):
92 """ 90 """
93 Protected overloaded method to generate the popup menu. 91 Protected overloaded method to generate the popup menu.
94 """ 92 """
95 self.menuActions = [] 93 self.menuActions = []
96 self.multiMenuActions = [] 94 self.multiMenuActions = []
97 self.dirMenuActions = [] 95 self.dirMenuActions = []
98 self.dirMultiMenuActions = [] 96 self.dirMultiMenuActions = []
99 97
100 self.sourceMenu = QMenu(self) 98 self.sourceMenu = QMenu(self)
101 if self.omniidl is not None: 99 if self.__protoc is not None:
102 self.sourceMenu.addAction( 100 self.sourceMenu.addAction(
103 self.tr('Compile interface'), self.__compileInterface) 101 self.tr('Compile protocol'), self.__compileProtocol)
104 self.sourceMenu.addAction( 102 self.sourceMenu.addAction(
105 self.tr('Compile all interfaces'), 103 self.tr('Compile all protocols'),
106 self.__compileAllInterfaces) 104 self.__compileAllProtocols)
107 self.sourceMenu.addAction(self.tr('Open'), self._openItem) 105 self.sourceMenu.addAction(self.tr('Open'), self._openItem)
108 self.sourceMenu.addSeparator() 106 self.sourceMenu.addSeparator()
109 act = self.sourceMenu.addAction( 107 act = self.sourceMenu.addAction(
110 self.tr('Rename file'), self._renameFile) 108 self.tr('Rename file'), self._renameFile)
111 self.menuActions.append(act) 109 self.menuActions.append(act)
115 act = self.sourceMenu.addAction( 113 act = self.sourceMenu.addAction(
116 self.tr('Delete'), self.__deleteFile) 114 self.tr('Delete'), self.__deleteFile)
117 self.menuActions.append(act) 115 self.menuActions.append(act)
118 self.sourceMenu.addSeparator() 116 self.sourceMenu.addSeparator()
119 self.sourceMenu.addAction( 117 self.sourceMenu.addAction(
120 self.tr('Add interfaces...'), self.__addInterfaceFiles) 118 self.tr('Add protocols...'), self.__addProtocolFiles)
121 self.sourceMenu.addAction( 119 self.sourceMenu.addAction(
122 self.tr('Add interfaces directory...'), 120 self.tr('Add protocols directory...'),
123 self.__addInterfacesDirectory) 121 self.__addProtocolsDirectory)
124 self.sourceMenu.addSeparator() 122 self.sourceMenu.addSeparator()
125 self.sourceMenu.addAction( 123 self.sourceMenu.addAction(
126 self.tr('Copy Path to Clipboard'), self._copyToClipboard) 124 self.tr('Copy Path to Clipboard'), self._copyToClipboard)
127 self.sourceMenu.addSeparator() 125 self.sourceMenu.addSeparator()
128 self.sourceMenu.addAction( 126 self.sourceMenu.addAction(
130 self.sourceMenu.addAction( 128 self.sourceMenu.addAction(
131 self.tr('Collapse all directories'), self._collapseAllDirs) 129 self.tr('Collapse all directories'), self._collapseAllDirs)
132 self.sourceMenu.addSeparator() 130 self.sourceMenu.addSeparator()
133 self.sourceMenu.addAction(self.tr('Configure...'), self._configure) 131 self.sourceMenu.addAction(self.tr('Configure...'), self._configure)
134 self.sourceMenu.addAction( 132 self.sourceMenu.addAction(
135 self.tr('Configure CORBA...'), self.__configureCorba) 133 self.tr('Configure Protobuf...'), self.__configureProtobuf)
136 134
137 self.menu = QMenu(self) 135 self.menu = QMenu(self)
138 if self.omniidl is not None: 136 if self.__protoc is not None:
139 self.menu.addAction( 137 self.menu.addAction(
140 self.tr('Compile interface'), self.__compileInterface) 138 self.tr('Compile protocol'), self.__compileProtocol)
141 self.menu.addAction( 139 self.menu.addAction(
142 self.tr('Compile all interfaces'), 140 self.tr('Compile all protocols'),
143 self.__compileAllInterfaces) 141 self.__compileAllProtocols)
144 self.menu.addAction(self.tr('Open'), self._openItem) 142 self.menu.addAction(self.tr('Open'), self._openItem)
145 self.menu.addSeparator() 143 self.menu.addSeparator()
146 self.menu.addAction( 144 self.menu.addAction(
147 self.tr('Add interfaces...'), self.__addInterfaceFiles) 145 self.tr('Add protocols...'), self.__addProtocolFiles)
148 self.menu.addAction( 146 self.menu.addAction(
149 self.tr('Add interfaces directory...'), 147 self.tr('Add protocols directory...'),
150 self.__addInterfacesDirectory) 148 self.__addProtocolsDirectory)
151 self.menu.addSeparator() 149 self.menu.addSeparator()
152 self.menu.addAction( 150 self.menu.addAction(
153 self.tr('Expand all directories'), self._expandAllDirs) 151 self.tr('Expand all directories'), self._expandAllDirs)
154 self.menu.addAction( 152 self.menu.addAction(
155 self.tr('Collapse all directories'), self._collapseAllDirs) 153 self.tr('Collapse all directories'), self._collapseAllDirs)
156 self.menu.addSeparator() 154 self.menu.addSeparator()
157 self.menu.addAction(self.tr('Configure...'), self._configure) 155 self.menu.addAction(self.tr('Configure...'), self._configure)
158 self.menu.addAction( 156 self.menu.addAction(
159 self.tr('Configure CORBA...'), self.__configureCorba) 157 self.tr('Configure Protobuf...'), self.__configureProtobuf)
160 158
161 self.backMenu = QMenu(self) 159 self.backMenu = QMenu(self)
162 if self.omniidl is not None: 160 if self.__protoc is not None:
163 self.backMenu.addAction( 161 self.backMenu.addAction(
164 self.tr('Compile all interfaces'), 162 self.tr('Compile all protocols'),
165 self.__compileAllInterfaces) 163 self.__compileAllProtocols)
166 self.backMenu.addSeparator() 164 self.backMenu.addSeparator()
167 self.backMenu.addAction( 165 self.backMenu.addAction(
168 self.tr('Add interfaces...'), self.project.addIdlFiles) 166 self.tr('Add protocols...'), self.project.addProtoFiles)
169 self.backMenu.addAction( 167 self.backMenu.addAction(
170 self.tr('Add interfaces directory...'), self.project.addIdlDir) 168 self.tr('Add protocols directory...'), self.project.addProtoDir)
171 self.backMenu.addSeparator() 169 self.backMenu.addSeparator()
172 self.backMenu.addAction( 170 self.backMenu.addAction(
173 self.tr('Expand all directories'), self._expandAllDirs) 171 self.tr('Expand all directories'), self._expandAllDirs)
174 self.backMenu.addAction( 172 self.backMenu.addAction(
175 self.tr('Collapse all directories'), self._collapseAllDirs) 173 self.tr('Collapse all directories'), self._collapseAllDirs)
176 self.backMenu.addSeparator() 174 self.backMenu.addSeparator()
177 self.backMenu.addAction(self.tr('Configure...'), self._configure) 175 self.backMenu.addAction(self.tr('Configure...'), self._configure)
178 self.backMenu.addAction( 176 self.backMenu.addAction(
179 self.tr('Configure CORBA...'), self.__configureCorba) 177 self.tr('Configure Protobuf...'), self.__configureProtobuf)
180 self.backMenu.setEnabled(False) 178 self.backMenu.setEnabled(False)
181 179
182 # create the menu for multiple selected files 180 # create the menu for multiple selected files
183 self.multiMenu = QMenu(self) 181 self.multiMenu = QMenu(self)
184 if self.omniidl is not None: 182 if self.__protoc is not None:
185 self.multiMenu.addAction( 183 self.multiMenu.addAction(
186 self.tr('Compile interfaces'), 184 self.tr('Compile protocols'),
187 self.__compileSelectedInterfaces) 185 self.__compileSelectedProtocols)
188 self.multiMenu.addAction(self.tr('Open'), self._openItem) 186 self.multiMenu.addAction(self.tr('Open'), self._openItem)
189 self.multiMenu.addSeparator() 187 self.multiMenu.addSeparator()
190 act = self.multiMenu.addAction( 188 act = self.multiMenu.addAction(
191 self.tr('Remove from project'), self._removeFile) 189 self.tr('Remove from project'), self._removeFile)
192 self.multiMenuActions.append(act) 190 self.multiMenuActions.append(act)
199 self.multiMenu.addAction( 197 self.multiMenu.addAction(
200 self.tr('Collapse all directories'), self._collapseAllDirs) 198 self.tr('Collapse all directories'), self._collapseAllDirs)
201 self.multiMenu.addSeparator() 199 self.multiMenu.addSeparator()
202 self.multiMenu.addAction(self.tr('Configure...'), self._configure) 200 self.multiMenu.addAction(self.tr('Configure...'), self._configure)
203 self.multiMenu.addAction( 201 self.multiMenu.addAction(
204 self.tr('Configure CORBA...'), self.__configureCorba) 202 self.tr('Configure Protobuf...'), self.__configureProtobuf)
205 203
206 self.dirMenu = QMenu(self) 204 self.dirMenu = QMenu(self)
207 if self.omniidl is not None: 205 if self.__protoc is not None:
208 self.dirMenu.addAction( 206 self.dirMenu.addAction(
209 self.tr('Compile all interfaces'), 207 self.tr('Compile all protocols'),
210 self.__compileAllInterfaces) 208 self.__compileAllProtocols)
211 self.dirMenu.addSeparator() 209 self.dirMenu.addSeparator()
212 act = self.dirMenu.addAction( 210 act = self.dirMenu.addAction(
213 self.tr('Remove from project'), self._removeFile) 211 self.tr('Remove from project'), self._removeFile)
214 self.dirMenuActions.append(act) 212 self.dirMenuActions.append(act)
215 act = self.dirMenu.addAction( 213 act = self.dirMenu.addAction(
216 self.tr('Delete'), self._deleteDirectory) 214 self.tr('Delete'), self._deleteDirectory)
217 self.dirMenuActions.append(act) 215 self.dirMenuActions.append(act)
218 self.dirMenu.addSeparator() 216 self.dirMenu.addSeparator()
219 self.dirMenu.addAction( 217 self.dirMenu.addAction(
220 self.tr('Add interfaces...'), self.__addInterfaceFiles) 218 self.tr('Add protocols...'), self.__addProtocolFiles)
221 self.dirMenu.addAction( 219 self.dirMenu.addAction(
222 self.tr('Add interfaces directory...'), 220 self.tr('Add protocols directory...'),
223 self.__addInterfacesDirectory) 221 self.__addProtocolsDirectory)
224 self.dirMenu.addSeparator() 222 self.dirMenu.addSeparator()
225 self.dirMenu.addAction( 223 self.dirMenu.addAction(
226 self.tr('Copy Path to Clipboard'), self._copyToClipboard) 224 self.tr('Copy Path to Clipboard'), self._copyToClipboard)
227 self.dirMenu.addSeparator() 225 self.dirMenu.addSeparator()
228 self.dirMenu.addAction( 226 self.dirMenu.addAction(
230 self.dirMenu.addAction( 228 self.dirMenu.addAction(
231 self.tr('Collapse all directories'), self._collapseAllDirs) 229 self.tr('Collapse all directories'), self._collapseAllDirs)
232 self.dirMenu.addSeparator() 230 self.dirMenu.addSeparator()
233 self.dirMenu.addAction(self.tr('Configure...'), self._configure) 231 self.dirMenu.addAction(self.tr('Configure...'), self._configure)
234 self.dirMenu.addAction( 232 self.dirMenu.addAction(
235 self.tr('Configure CORBA...'), self.__configureCorba) 233 self.tr('Configure Protobuf...'), self.__configureProtobuf)
236 234
237 self.dirMultiMenu = QMenu(self) 235 self.dirMultiMenu = QMenu(self)
238 if self.omniidl is not None: 236 if self.__protoc is not None:
239 self.dirMultiMenu.addAction( 237 self.dirMultiMenu.addAction(
240 self.tr('Compile all interfaces'), 238 self.tr('Compile all protocols'),
241 self.__compileAllInterfaces) 239 self.__compileAllProtocols)
242 self.dirMultiMenu.addSeparator() 240 self.dirMultiMenu.addSeparator()
243 self.dirMultiMenu.addAction( 241 self.dirMultiMenu.addAction(
244 self.tr('Add interfaces...'), self.project.addIdlFiles) 242 self.tr('Add protocols...'), self.project.addProtoFiles)
245 self.dirMultiMenu.addAction( 243 self.dirMultiMenu.addAction(
246 self.tr('Add interfaces directory...'), self.project.addIdlDir) 244 self.tr('Add protocols directory...'), self.project.addProtoDir)
247 self.dirMultiMenu.addSeparator() 245 self.dirMultiMenu.addSeparator()
248 self.dirMultiMenu.addAction( 246 self.dirMultiMenu.addAction(
249 self.tr('Expand all directories'), self._expandAllDirs) 247 self.tr('Expand all directories'), self._expandAllDirs)
250 self.dirMultiMenu.addAction( 248 self.dirMultiMenu.addAction(
251 self.tr('Collapse all directories'), self._collapseAllDirs) 249 self.tr('Collapse all directories'), self._collapseAllDirs)
252 self.dirMultiMenu.addSeparator() 250 self.dirMultiMenu.addSeparator()
253 self.dirMultiMenu.addAction( 251 self.dirMultiMenu.addAction(
254 self.tr('Configure...'), self._configure) 252 self.tr('Configure...'), self._configure)
255 self.dirMultiMenu.addAction(self.tr('Configure CORBA...'), 253 self.dirMultiMenu.addAction(self.tr('Configure Protobuf...'),
256 self.__configureCorba) 254 self.__configureProtobuf)
257 255
258 self.sourceMenu.aboutToShow.connect(self.__showContextMenu) 256 self.sourceMenu.aboutToShow.connect(self.__showContextMenu)
259 self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti) 257 self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti)
260 self.dirMenu.aboutToShow.connect(self.__showContextMenuDir) 258 self.dirMenu.aboutToShow.connect(self.__showContextMenuDir)
261 self.dirMultiMenu.aboutToShow.connect(self.__showContextMenuDirMulti) 259 self.dirMultiMenu.aboutToShow.connect(self.__showContextMenuDirMulti)
373 itm.fileName(), itm.functionObject().lineno) 371 itm.fileName(), itm.functionObject().lineno)
374 elif isinstance(itm, BrowserClassAttributeItem): 372 elif isinstance(itm, BrowserClassAttributeItem):
375 self.sourceFile[str, int].emit( 373 self.sourceFile[str, int].emit(
376 itm.fileName(), itm.attributeObject().lineno) 374 itm.fileName(), itm.attributeObject().lineno)
377 375
378 def __addInterfaceFiles(self): 376 def __addProtocolFiles(self):
379 """ 377 """
380 Private method to add interface files to the project. 378 Private method to add protocol files to the project.
381 """ 379 """
382 itm = self.model().item(self.currentIndex()) 380 itm = self.model().item(self.currentIndex())
383 if isinstance(itm, ProjectBrowserFileItem) or \ 381 if isinstance(itm, ProjectBrowserFileItem) or \
384 isinstance(itm, BrowserClassItem) or \ 382 isinstance(itm, BrowserClassItem) or \
385 isinstance(itm, BrowserMethodItem): 383 isinstance(itm, BrowserMethodItem):
387 elif isinstance(itm, ProjectBrowserSimpleDirectoryItem) or \ 385 elif isinstance(itm, ProjectBrowserSimpleDirectoryItem) or \
388 isinstance(itm, ProjectBrowserDirectoryItem): 386 isinstance(itm, ProjectBrowserDirectoryItem):
389 dn = itm.dirName() 387 dn = itm.dirName()
390 else: 388 else:
391 dn = None 389 dn = None
392 self.project.addFiles('interface', dn) 390 self.project.addFiles('protocol', dn)
393 391
394 def __addInterfacesDirectory(self): 392 def __addProtocolsDirectory(self):
395 """ 393 """
396 Private method to add interface files of a directory to the project. 394 Private method to add protocol files of a directory to the project.
397 """ 395 """
398 itm = self.model().item(self.currentIndex()) 396 itm = self.model().item(self.currentIndex())
399 if isinstance(itm, ProjectBrowserFileItem) or \ 397 if isinstance(itm, ProjectBrowserFileItem) or \
400 isinstance(itm, BrowserClassItem) or \ 398 isinstance(itm, BrowserClassItem) or \
401 isinstance(itm, BrowserMethodItem): 399 isinstance(itm, BrowserMethodItem):
403 elif isinstance(itm, ProjectBrowserSimpleDirectoryItem) or \ 401 elif isinstance(itm, ProjectBrowserSimpleDirectoryItem) or \
404 isinstance(itm, ProjectBrowserDirectoryItem): 402 isinstance(itm, ProjectBrowserDirectoryItem):
405 dn = itm.dirName() 403 dn = itm.dirName()
406 else: 404 else:
407 dn = None 405 dn = None
408 self.project.addDirectory('interface', dn) 406 self.project.addDirectory('protocol', dn)
409 407
410 def __deleteFile(self): 408 def __deleteFile(self):
411 """ 409 """
412 Private method to delete files from the project. 410 Private method to delete files from the project.
413 """ 411 """
423 421
424 from UI.DeleteFilesConfirmationDialog import \ 422 from UI.DeleteFilesConfirmationDialog import \
425 DeleteFilesConfirmationDialog 423 DeleteFilesConfirmationDialog
426 dlg = DeleteFilesConfirmationDialog( 424 dlg = DeleteFilesConfirmationDialog(
427 self.parent(), 425 self.parent(),
428 self.tr("Delete interfaces"), 426 self.tr("Delete Protocols"),
429 self.tr("Do you really want to delete these interfaces from" 427 self.tr("Do you really want to delete these protocol files from"
430 " the project?"), 428 " the project?"),
431 files) 429 files)
432 430
433 if dlg.exec_() == QDialog.Accepted: 431 if dlg.exec_() == QDialog.Accepted:
434 for fn2, fn in zip(fullNames, files): 432 for fn2, fn in zip(fullNames, files):
440 ########################################################################### 438 ###########################################################################
441 439
442 def __readStdout(self): 440 def __readStdout(self):
443 """ 441 """
444 Private slot to handle the readyReadStandardOutput signal of the 442 Private slot to handle the readyReadStandardOutput signal of the
445 omniidl process. 443 protoc process.
446 """ 444 """
447 if self.compileProc is None: 445 if self.compileProc is None:
448 return 446 return
449 447
450 ioEncoding = Preferences.getSystem("IOEncoding") 448 ioEncoding = Preferences.getSystem("IOEncoding")
451 449
452 self.compileProc.setReadChannel(QProcess.StandardOutput) 450 self.compileProc.setReadChannel(QProcess.StandardOutput)
453 while self.compileProc and self.compileProc.canReadLine(): 451 while self.compileProc and self.compileProc.canReadLine():
454 s = 'omniidl: ' 452 s = 'protoc: '
455 output = str(self.compileProc.readLine(), ioEncoding, 'replace') 453 output = str(self.compileProc.readLine(), ioEncoding, 'replace')
456 s += output 454 s += output
457 self.appendStdout.emit(s) 455 self.appendStdout.emit(s)
458 456
459 def __readStderr(self): 457 def __readStderr(self):
460 """ 458 """
461 Private slot to handle the readyReadStandardError signal of the 459 Private slot to handle the readyReadStandardError signal of the
462 omniidl process. 460 protoc process.
463 """ 461 """
464 if self.compileProc is None: 462 if self.compileProc is None:
465 return 463 return
466 464
467 ioEncoding = Preferences.getSystem("IOEncoding") 465 ioEncoding = Preferences.getSystem("IOEncoding")
468 466
469 self.compileProc.setReadChannel(QProcess.StandardError) 467 self.compileProc.setReadChannel(QProcess.StandardError)
470 while self.compileProc and self.compileProc.canReadLine(): 468 while self.compileProc and self.compileProc.canReadLine():
471 s = 'omniidl: ' 469 s = 'protoc: '
472 error = str(self.compileProc.readLine(), ioEncoding, 'replace') 470 error = str(self.compileProc.readLine(), ioEncoding, 'replace')
473 s += error 471 s += error
474 self.appendStderr.emit(s) 472 self.appendStderr.emit(s)
475 473
476 def __compileIDLDone(self, exitCode, exitStatus): 474 def __compileProtocolDone(self, exitCode, exitStatus):
477 """ 475 """
478 Private slot to handle the finished signal of the omniidl process. 476 Private slot to handle the finished signal of the protoc process.
479 477
480 @param exitCode exit code of the process (integer) 478 @param exitCode exit code of the process (integer)
481 @param exitStatus exit status of the process (QProcess.ExitStatus) 479 @param exitStatus exit status of the process (QProcess.ExitStatus)
482 """ 480 """
483 self.compileRunning = False 481 self.__compileRunning = False
484 ui = e5App().getObject("UserInterface") 482 ui = e5App().getObject("UserInterface")
485 if exitStatus == QProcess.NormalExit and exitCode == 0: 483 if exitStatus == QProcess.NormalExit and exitCode == 0:
486 path = os.path.dirname(self.idlFile) 484 path = os.path.dirname(self.__protoFile)
487 poaList = glob.glob(os.path.join(path, "*__POA")) 485 fileList = glob.glob(os.path.join(path, "*_pb2.py"))
488 npoaList = [f.replace("__POA", "") for f in poaList]
489 fileList = glob.glob(os.path.join(path, "*_idl.py"))
490 for directory in poaList + npoaList:
491 fileList += Utilities.direntries(directory, True, "*.py")
492 for file in fileList: 486 for file in fileList:
493 self.project.appendFile(file) 487 self.project.appendFile(file)
494 if not self.noDialog and not ui.notificationsEnabled(): 488 if not self.noDialog and not ui.notificationsEnabled():
495 E5MessageBox.information( 489 E5MessageBox.information(
496 self, 490 self,
497 self.tr("Interface Compilation"), 491 self.tr("Protocol Compilation"),
498 self.tr( 492 self.tr(
499 "The compilation of the interface file was" 493 "The compilation of the protocol file was"
500 " successful.")) 494 " successful."))
501 else: 495 else:
502 ui.showNotification( 496 ui.showNotification(
503 UI.PixmapCache.getPixmap("corba48.png"), 497 UI.PixmapCache.getPixmap("protobuf48.png"),
504 self.tr("Interface Compilation"), 498 self.tr("Protocol Compilation"),
505 self.tr( 499 self.tr(
506 "The compilation of the interface file was" 500 "The compilation of the protocol file was"
507 " successful.")) 501 " successful."))
508 else: 502 else:
509 if not self.noDialog: 503 if not self.noDialog:
510 E5MessageBox.information( 504 E5MessageBox.information(
511 self, 505 self,
512 self.tr("Interface Compilation"), 506 self.tr("Protocol Compilation"),
513 self.tr( 507 self.tr(
514 "The compilation of the interface file failed.")) 508 "The compilation of the protocol file failed."))
515 else: 509 else:
516 ui.showNotification( 510 ui.showNotification(
517 UI.PixmapCache.getPixmap("corba48.png"), 511 UI.PixmapCache.getPixmap("protobuf48.png"),
518 self.tr("Interface Compilation"), 512 self.tr("Protocol Compilation"),
519 self.tr( 513 self.tr(
520 "The compilation of the interface file failed.")) 514 "The compilation of the protocol file failed."))
521 self.compileProc = None 515 self.compileProc = None
522 516
523 def __compileIDL(self, fn, noDialog=False, progress=None): 517 def __compileProto(self, fn, noDialog=False, progress=None):
524 """ 518 """
525 Private method to compile a .idl file to python. 519 Private method to compile a .proto file to Python.
526 520
527 @param fn filename of the .idl file to be compiled (string) 521 @param fn filename of the .proto file to be compiled (string)
528 @param noDialog flag indicating silent operations (boolean) 522 @param noDialog flag indicating silent operations (boolean)
529 @param progress reference to the progress dialog (E5ProgressDialog) 523 @param progress reference to the progress dialog (E5ProgressDialog)
530 @return reference to the compile process (QProcess) 524 @return reference to the compile process (QProcess)
531 """ 525 """
532 self.compileProc = QProcess() 526 self.compileProc = QProcess()
533 args = [] 527 args = []
534 528
535 args.append("-bpython")
536 args.append("-I.")
537
538 fn = os.path.join(self.project.ppath, fn) 529 fn = os.path.join(self.project.ppath, fn)
539 self.idlFile = fn 530 self.__protoFile = fn
540 args.append("-C{0}".format(os.path.dirname(fn))) 531
532 srcPath = os.path.dirname(fn)
533 args.append("--proto_path={0}".format(srcPath))
534 args.append("--python_out={0}".format(srcPath))
541 args.append(fn) 535 args.append(fn)
542 536
543 self.compileProc.finished.connect(self.__compileIDLDone) 537 self.compileProc.finished.connect(self.__compileProtocolDone)
544 self.compileProc.readyReadStandardOutput.connect(self.__readStdout) 538 self.compileProc.readyReadStandardOutput.connect(self.__readStdout)
545 self.compileProc.readyReadStandardError.connect(self.__readStderr) 539 self.compileProc.readyReadStandardError.connect(self.__readStderr)
546 540
547 self.noDialog = noDialog 541 self.noDialog = noDialog
548 self.compileProc.start(self.omniidl, args) 542 self.compileProc.start(self.__protoc, args)
549 procStarted = self.compileProc.waitForStarted(5000) 543 procStarted = self.compileProc.waitForStarted(5000)
550 if procStarted: 544 if procStarted:
551 self.compileRunning = True 545 self.__compileRunning = True
552 return self.compileProc 546 return self.compileProc
553 else: 547 else:
554 self.compileRunning = False 548 self.__compileRunning = False
555 if progress is not None: 549 if progress is not None:
556 progress.cancel() 550 progress.cancel()
557 E5MessageBox.critical( 551 E5MessageBox.critical(
558 self, 552 self,
559 self.tr('Process Generation Error'), 553 self.tr('Process Generation Error'),
560 self.tr( 554 self.tr(
561 '<p>Could not start {0}.<br>' 555 '<p>Could not start {0}.<br>'
562 'Ensure that it is in the search path.</p>' 556 'Ensure that it is in the search path.</p>'
563 ).format(self.omniidl)) 557 ).format(self.__protoc))
564 return None 558 return None
565 559
566 def __compileInterface(self): 560 def __compileProtocol(self):
567 """ 561 """
568 Private method to compile an interface to python. 562 Private method to compile a protocol to Python.
569 """ 563 """
570 if self.omniidl is not None: 564 if self.__protoc is not None:
571 itm = self.model().item(self.currentIndex()) 565 itm = self.model().item(self.currentIndex())
572 fn2 = itm.fileName() 566 fn2 = itm.fileName()
573 fn = self.project.getRelativePath(fn2) 567 fn = self.project.getRelativePath(fn2)
574 self.__compileIDL(fn) 568 self.__compileProto(fn)
575 569
576 def __compileAllInterfaces(self): 570 def __compileAllProtocols(self):
577 """ 571 """
578 Private method to compile all interfaces to python. 572 Private method to compile all protocols to Python.
579 """ 573 """
580 if self.omniidl is not None: 574 if self.__protoc is not None:
581 numIDLs = len(self.project.pdata["INTERFACES"]) 575 numProtos = len(self.project.pdata["PROTOCOLS"])
582 progress = E5ProgressDialog( 576 progress = E5ProgressDialog(
583 self.tr("Compiling interfaces..."), 577 self.tr("Compiling Protocols..."),
584 self.tr("Abort"), 0, numIDLs, 578 self.tr("Abort"), 0, numProtos,
585 self.tr("%v/%m Interfaces"), self) 579 self.tr("%v/%m Protocols"), self)
586 progress.setModal(True) 580 progress.setModal(True)
587 progress.setMinimumDuration(0) 581 progress.setMinimumDuration(0)
588 progress.setWindowTitle(self.tr("Interfaces")) 582 progress.setWindowTitle(self.tr("Protocols"))
589 i = 0 583 i = 0
590 584
591 for fn in self.project.pdata["INTERFACES"]: 585 for fn in self.project.pdata["PROTOCOLS"]:
592 progress.setValue(i) 586 progress.setValue(i)
593 if progress.wasCanceled(): 587 if progress.wasCanceled():
594 break 588 break
595 proc = self.__compileIDL(fn, True, progress) 589 proc = self.__compileProto(fn, True, progress)
596 if proc is not None: 590 if proc is not None:
597 while proc.state() == QProcess.Running: 591 while proc.state() == QProcess.Running:
598 QApplication.processEvents() 592 QApplication.processEvents()
599 QThread.msleep(300) 593 QThread.msleep(300)
600 QApplication.processEvents() 594 QApplication.processEvents()
601 else: 595 else:
602 break 596 break
603 i += 1 597 i += 1
604 598
605 progress.setValue(numIDLs) 599 progress.setValue(numProtos)
606 600
607 def __compileSelectedInterfaces(self): 601 def __compileSelectedProtocols(self):
608 """ 602 """
609 Private method to compile selected interfaces to python. 603 Private method to compile selected protocols to Python.
610 """ 604 """
611 if self.omniidl is not None: 605 if self.__protoc is not None:
612 items = self.getSelectedItems() 606 items = self.getSelectedItems()
613 607
614 files = [self.project.getRelativePath(itm.fileName()) 608 files = [self.project.getRelativePath(itm.fileName())
615 for itm in items] 609 for itm in items]
616 numIDLs = len(files) 610 numProtos = len(files)
617 progress = E5ProgressDialog( 611 progress = E5ProgressDialog(
618 self.tr("Compiling interfaces..."), 612 self.tr("Compiling Protocols..."),
619 self.tr("Abort"), 0, numIDLs, 613 self.tr("Abort"), 0, numProtos,
620 self.tr("%v/%m Interfaces"), self) 614 self.tr("%v/%m Protocols"), self)
621 progress.setModal(True) 615 progress.setModal(True)
622 progress.setMinimumDuration(0) 616 progress.setMinimumDuration(0)
623 progress.setWindowTitle(self.tr("Interfaces")) 617 progress.setWindowTitle(self.tr("Protocols"))
624 i = 0 618 i = 0
625 619
626 for fn in files: 620 for fn in files:
627 progress.setValue(i) 621 progress.setValue(i)
628 if progress.wasCanceled(): 622 if progress.wasCanceled():
629 break 623 break
630 proc = self.__compileIDL(fn, True, progress) 624 proc = self.__compileProto(fn, True, progress)
631 if proc is not None: 625 if proc is not None:
632 while proc.state() == QProcess.Running: 626 while proc.state() == QProcess.Running:
633 QApplication.processEvents() 627 QApplication.processEvents()
634 QThread.msleep(300) 628 QThread.msleep(300)
635 QApplication.processEvents() 629 QApplication.processEvents()
636 else: 630 else:
637 break 631 break
638 i += 1 632 i += 1
639 633
640 progress.setValue(numIDLs) 634 progress.setValue(numProtos)
641 635
642 def __configureCorba(self): 636 def __configureProtobuf(self):
643 """ 637 """
644 Private method to open the configuration dialog. 638 Private method to open the configuration dialog.
645 """ 639 """
646 e5App().getObject("UserInterface").showPreferences("corbaPage") 640 e5App().getObject("UserInterface").showPreferences("protobufPage")

eric ide

mercurial