ExtensionCorba/ProjectInterfacesBrowser.py

changeset 1
d4384e4d7aff
child 2
68c017d640b0
equal deleted inserted replaced
0:02171512ef2f 1:d4384e4d7aff
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the a class used to display the interfaces (IDL) part
8 of the project.
9 """
10
11 import contextlib
12 import glob
13 import os
14
15 from PyQt6.QtCore import QProcess, QThread, pyqtSignal
16 from PyQt6.QtWidgets import QApplication, QDialog, QMenu
17
18 from eric7 import Preferences, Utilities
19 from eric7.EricGui import EricPixmapCache
20 from eric7.EricWidgets import EricMessageBox
21 from eric7.EricWidgets.EricApplication import ericApp
22 from eric7.EricWidgets.EricProgressDialog import EricProgressDialog
23 from eric7.Project.FileCategoryRepositoryItem import FileCategoryRepositoryItem
24 from eric7.Project.ProjectBaseBrowser import ProjectBaseBrowser
25 from eric7.Project.ProjectBrowserModel import (
26 ProjectBrowserDirectoryItem,
27 ProjectBrowserFileItem,
28 ProjectBrowserSimpleDirectoryItem,
29 )
30 from eric7.Project.ProjectBrowserRepositoryItem import ProjectBrowserRepositoryItem
31 from eric7.UI.BrowserModel import (
32 BrowserClassAttributeItem,
33 BrowserClassItem,
34 BrowserFileItem,
35 BrowserMethodItem,
36 )
37 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
38 from eric7.UI.NotificationWidget import NotificationTypes
39
40
41 class ProjectInterfacesBrowser(ProjectBaseBrowser):
42 """
43 A class used to display the interfaces (IDL) part of the project.
44
45 @signal appendStdout(str) emitted after something was received from
46 a QProcess on stdout
47 @signal appendStderr(str) emitted after something was received from
48 a QProcess on stderr
49 @signal showMenu(str, QMenu) emitted when a menu is about to be shown.
50 The name of the menu and a reference to the menu are given.
51 """
52
53 appendStdout = pyqtSignal(str)
54 appendStderr = pyqtSignal(str)
55 showMenu = pyqtSignal(str, QMenu)
56
57 FileFilter = "idl"
58
59 def __init__(self, plugin, parent=None):
60 """
61 Constructor
62
63 @param plugin reference to the plugin object
64 @type CorbaExtensionPlugin
65 @param parent parent widget of this browser
66 @type QWidget
67 """
68 project = ericApp().getObject("Project")
69 projectBrowser = ericApp().getObject("ProjectBrowser")
70
71 self.omniidl = plugin.getPreferences("omniidl")
72 if self.omniidl == "":
73 self.omniidl = "omniidl.exe" if Utilities.isWindowsPlatform() else "omniidl"
74 if not Utilities.isinpath(self.omniidl):
75 self.omniidl = None
76
77 ProjectBaseBrowser.__init__(self, project, self.FileFilter, parent)
78
79 self.selectedItemsFilter = [
80 ProjectBrowserFileItem,
81 ProjectBrowserSimpleDirectoryItem,
82 ]
83
84 self.setWindowTitle(self.tr("Interfaces"))
85
86 self.setWhatsThis(
87 self.tr(
88 """<b>Project IDL Browser</b>"""
89 """<p>This allows to easily see all CORBA IDL files contained in the"""
90 """ current project. Several actions can be executed via the context"""
91 """ menu.</p>"""
92 )
93 )
94
95 # Add the file category handled by the browser.
96 project.addFileCategory(
97 "INTERFACES",
98 FileCategoryRepositoryItem(
99 fileCategoryFilterTemplate=self.tr("CORBA IDL Files ({0})"),
100 fileCategoryUserString=self.tr("CORBA IDL Files"),
101 fileCategoryTyeString=self.tr("IDL Files"),
102 fileCategoryExtensions=["*.idl"],
103 ),
104 )
105
106 # Add the project browser type to the browser type repository.
107 projectBrowser.addTypedProjectBrowser(
108 "interfaces",
109 ProjectBrowserRepositoryItem(
110 projectBrowser=self,
111 projectBrowserUserString=self.tr("CORBA IDL Browser"),
112 priority=50,
113 fileCategory="INTERFACES",
114 fileFilter=self.FileFilter,
115 getIcon=self.getIcon,
116 ),
117 )
118
119 # Connect signals of Project.
120 project.prepareRepopulateItem.connect(self._prepareRepopulateItem)
121 project.completeRepopulateItem.connect(self._completeRepopulateItem)
122 project.projectClosed.connect(self._projectClosed)
123 project.projectOpened.connect(self._projectOpened)
124 project.newProject.connect(self._newProject)
125 project.reinitVCS.connect(self._initMenusAndVcs)
126 project.projectPropertiesChanged.connect(self._initMenusAndVcs)
127
128 # Connect signals of ProjectBrowser.
129 projectBrowser.preferencesChanged.connect(self.handlePreferencesChanged)
130
131 # Connect some of our own signals.
132 self.appendStderr.connect(projectBrowser.appendStderr)
133 self.appendStdout.connect(projectBrowser.appendStdout)
134 self.closeSourceWindow.connect(projectBrowser.closeSourceWindow)
135 self.sourceFile[str].connect(projectBrowser.sourceFile[str])
136 self.sourceFile[str, int].connect(projectBrowser.sourceFile[str, int])
137
138 def deactivate(self):
139 """
140 Public method to deactivate the browser.
141 """
142 project = ericApp().getObject("Project")
143 projectBrowser = ericApp().getObject("ProjectBrowser")
144
145 # Disconnect some of our own signals.
146 self.appendStderr.disconnect(projectBrowser.appendStderr)
147 self.appendStdout.disconnect(projectBrowser.appendStdout)
148 self.closeSourceWindow.disconnect(projectBrowser.closeSourceWindow)
149 self.sourceFile[str].disconnect(projectBrowser.sourceFile[str])
150 self.sourceFile[str, int].disconnect(projectBrowser.sourceFile[str, int])
151
152 # Disconnect signals of ProjectBrowser.
153 projectBrowser.preferencesChanged.disconnect(self.handlePreferencesChanged)
154
155 # Disconnect signals of Project.
156 project.prepareRepopulateItem.disconnect(self._prepareRepopulateItem)
157 project.completeRepopulateItem.disconnect(self._completeRepopulateItem)
158 project.projectClosed.disconnect(self._projectClosed)
159 project.projectOpened.disconnect(self._projectOpened)
160 project.newProject.disconnect(self._newProject)
161 project.reinitVCS.disconnect(self._initMenusAndVcs)
162 project.projectPropertiesChanged.disconnect(self._initMenusAndVcs)
163
164 # Remove the project browser type from the browser type repository.
165 projectBrowser.removeTypedProjectBrowser("interfaces")
166
167 # Remove the file category handled by the browser.
168 project.addFileCategory("INTERFACES")
169
170 def getIcon(self):
171 """
172 Public method to get an icon for the project browser.
173
174 @return icon for the browser
175 @rtype QIcon
176 """
177 iconSuffix = "dark" if ericApp().usesDarkPalette() else "light"
178
179 return EricPixmapCache.getIcon(
180 os.path.join(
181 os.path.dirname(__file__),
182 "icons",
183 "projectInterfaces-{0}".format(iconSuffix),
184 )
185 )
186
187 def _createPopupMenus(self):
188 """
189 Protected overloaded method to generate the popup menu.
190 """
191 self.menuActions = []
192 self.multiMenuActions = []
193 self.dirMenuActions = []
194 self.dirMultiMenuActions = []
195
196 self.sourceMenu = QMenu(self)
197 if self.omniidl is not None:
198 self.sourceMenu.addAction(
199 self.tr("Compile interface"), self.__compileInterface
200 )
201 self.sourceMenu.addAction(
202 self.tr("Compile all interfaces"), self.__compileAllInterfaces
203 )
204 self.sourceMenu.addSeparator()
205 self.sourceMenu.addAction(
206 self.tr("Configure IDL compiler"), self.__configureIdlCompiler
207 )
208 self.sourceMenu.addSeparator()
209 self.sourceMenu.addAction(self.tr("Open"), self._openItem)
210 self.sourceMenu.addSeparator()
211 act = self.sourceMenu.addAction(self.tr("Rename file"), self._renameFile)
212 self.menuActions.append(act)
213 act = self.sourceMenu.addAction(
214 self.tr("Remove from project"), self._removeFile
215 )
216 self.menuActions.append(act)
217 act = self.sourceMenu.addAction(self.tr("Delete"), self.__deleteFile)
218 self.menuActions.append(act)
219 self.sourceMenu.addSeparator()
220 self.sourceMenu.addAction(
221 self.tr("Add interfaces..."), self.__addInterfaceFiles
222 )
223 self.sourceMenu.addAction(
224 self.tr("Add interfaces directory..."), self.__addInterfacesDirectory
225 )
226 self.sourceMenu.addSeparator()
227 self.sourceMenu.addAction(
228 self.tr("Copy Path to Clipboard"), self._copyToClipboard
229 )
230 self.sourceMenu.addSeparator()
231 self.sourceMenu.addAction(
232 self.tr("Expand all directories"), self._expandAllDirs
233 )
234 self.sourceMenu.addAction(
235 self.tr("Collapse all directories"), self._collapseAllDirs
236 )
237 self.sourceMenu.addSeparator()
238 self.sourceMenu.addAction(self.tr("Configure..."), self._configure)
239 self.sourceMenu.addAction(self.tr("Configure CORBA..."), self.__configureCorba)
240
241 self.menu = QMenu(self)
242 if self.omniidl is not None:
243 self.menu.addAction(self.tr("Compile interface"), self.__compileInterface)
244 self.menu.addAction(
245 self.tr("Compile all interfaces"), self.__compileAllInterfaces
246 )
247 self.menu.addSeparator()
248 self.menu.addAction(
249 self.tr("Configure IDL compiler"), self.__configureIdlCompiler
250 )
251 self.menu.addSeparator()
252 self.menu.addAction(self.tr("Open"), self._openItem)
253 self.menu.addSeparator()
254 self.menu.addAction(self.tr("Add interfaces..."), self.__addInterfaceFiles)
255 self.menu.addAction(
256 self.tr("Add interfaces directory..."), self.__addInterfacesDirectory
257 )
258 self.menu.addSeparator()
259 self.menu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
260 self.menu.addAction(self.tr("Collapse all directories"), self._collapseAllDirs)
261 self.menu.addSeparator()
262 self.menu.addAction(self.tr("Configure..."), self._configure)
263 self.menu.addAction(self.tr("Configure CORBA..."), self.__configureCorba)
264
265 self.backMenu = QMenu(self)
266 if self.omniidl is not None:
267 self.backMenu.addAction(
268 self.tr("Compile all interfaces"), self.__compileAllInterfaces
269 )
270 self.backMenu.addSeparator()
271 self.backMenu.addAction(
272 self.tr("Configure IDL compiler"), self.__configureIdlCompiler
273 )
274 self.backMenu.addSeparator()
275 self.backMenu.addAction(
276 self.tr("Add interfaces..."), lambda: self.project.addFiles("INTERFACES")
277 )
278 self.backMenu.addAction(
279 self.tr("Add interfaces directory..."),
280 lambda: self.project.addDirectory("INTERFACES"),
281 )
282 self.backMenu.addSeparator()
283 self.backMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
284 self.backMenu.addAction(
285 self.tr("Collapse all directories"), self._collapseAllDirs
286 )
287 self.backMenu.addSeparator()
288 self.backMenu.addAction(self.tr("Configure..."), self._configure)
289 self.backMenu.addAction(self.tr("Configure CORBA..."), self.__configureCorba)
290 self.backMenu.setEnabled(False)
291
292 # create the menu for multiple selected files
293 self.multiMenu = QMenu(self)
294 if self.omniidl is not None:
295 self.multiMenu.addAction(
296 self.tr("Compile interfaces"), self.__compileSelectedInterfaces
297 )
298 self.multiMenu.addSeparator()
299 self.multiMenu.addAction(
300 self.tr("Configure IDL compiler"), self.__configureIdlCompiler
301 )
302 self.multiMenu.addSeparator()
303 self.multiMenu.addAction(self.tr("Open"), self._openItem)
304 self.multiMenu.addSeparator()
305 act = self.multiMenu.addAction(self.tr("Remove from project"), self._removeFile)
306 self.multiMenuActions.append(act)
307 act = self.multiMenu.addAction(self.tr("Delete"), self.__deleteFile)
308 self.multiMenuActions.append(act)
309 self.multiMenu.addSeparator()
310 self.multiMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
311 self.multiMenu.addAction(
312 self.tr("Collapse all directories"), self._collapseAllDirs
313 )
314 self.multiMenu.addSeparator()
315 self.multiMenu.addAction(self.tr("Configure..."), self._configure)
316 self.multiMenu.addAction(self.tr("Configure CORBA..."), self.__configureCorba)
317
318 self.dirMenu = QMenu(self)
319 if self.omniidl is not None:
320 self.dirMenu.addAction(
321 self.tr("Compile all interfaces"), self.__compileAllInterfaces
322 )
323 self.dirMenu.addSeparator()
324 self.dirMenu.addAction(
325 self.tr("Configure IDL compiler"), self.__configureIdlCompiler
326 )
327 self.dirMenu.addSeparator()
328 act = self.dirMenu.addAction(self.tr("Remove from project"), self._removeFile)
329 self.dirMenuActions.append(act)
330 act = self.dirMenu.addAction(self.tr("Delete"), self._deleteDirectory)
331 self.dirMenuActions.append(act)
332 self.dirMenu.addSeparator()
333 self.dirMenu.addAction(self.tr("Add interfaces..."), self.__addInterfaceFiles)
334 self.dirMenu.addAction(
335 self.tr("Add interfaces directory..."), self.__addInterfacesDirectory
336 )
337 self.dirMenu.addSeparator()
338 self.dirMenu.addAction(self.tr("Copy Path to Clipboard"), self._copyToClipboard)
339 self.dirMenu.addSeparator()
340 self.dirMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
341 self.dirMenu.addAction(
342 self.tr("Collapse all directories"), self._collapseAllDirs
343 )
344 self.dirMenu.addSeparator()
345 self.dirMenu.addAction(self.tr("Configure..."), self._configure)
346 self.dirMenu.addAction(self.tr("Configure CORBA..."), self.__configureCorba)
347
348 self.dirMultiMenu = QMenu(self)
349 if self.omniidl is not None:
350 self.dirMultiMenu.addAction(
351 self.tr("Compile all interfaces"), self.__compileAllInterfaces
352 )
353 self.dirMultiMenu.addSeparator()
354 self.dirMultiMenu.addAction(
355 self.tr("Configure IDL compiler"), self.__configureIdlCompiler
356 )
357 self.dirMultiMenu.addSeparator()
358 self.dirMultiMenu.addAction(
359 self.tr("Add interfaces..."), lambda: self.project.addFiles("INTERFACES")
360 )
361 self.dirMultiMenu.addAction(
362 self.tr("Add interfaces directory..."),
363 lambda: self.project.addDirectory("INTERFACES"),
364 )
365 self.dirMultiMenu.addSeparator()
366 self.dirMultiMenu.addAction(
367 self.tr("Expand all directories"), self._expandAllDirs
368 )
369 self.dirMultiMenu.addAction(
370 self.tr("Collapse all directories"), self._collapseAllDirs
371 )
372 self.dirMultiMenu.addSeparator()
373 self.dirMultiMenu.addAction(self.tr("Configure..."), self._configure)
374 self.dirMultiMenu.addAction(
375 self.tr("Configure CORBA..."), self.__configureCorba
376 )
377
378 self.sourceMenu.aboutToShow.connect(self.__showContextMenu)
379 self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti)
380 self.dirMenu.aboutToShow.connect(self.__showContextMenuDir)
381 self.dirMultiMenu.aboutToShow.connect(self.__showContextMenuDirMulti)
382 self.backMenu.aboutToShow.connect(self.__showContextMenuBack)
383 self.mainMenu = self.sourceMenu
384
385 def _contextMenuRequested(self, coord):
386 """
387 Protected slot to show the context menu.
388
389 @param coord the position of the mouse pointer (QPoint)
390 """
391 if not self.project.isOpen():
392 return
393
394 with contextlib.suppress(Exception): # secok
395 categories = self.getSelectedItemsCountCategorized(
396 [
397 ProjectBrowserFileItem,
398 BrowserClassItem,
399 BrowserMethodItem,
400 ProjectBrowserSimpleDirectoryItem,
401 ]
402 )
403 cnt = categories["sum"]
404 if cnt <= 1:
405 index = self.indexAt(coord)
406 if index.isValid():
407 self._selectSingleItem(index)
408 categories = self.getSelectedItemsCountCategorized(
409 [
410 ProjectBrowserFileItem,
411 BrowserClassItem,
412 BrowserMethodItem,
413 ProjectBrowserSimpleDirectoryItem,
414 ]
415 )
416 cnt = categories["sum"]
417
418 bfcnt = categories[str(ProjectBrowserFileItem)]
419 cmcnt = (
420 categories[str(BrowserClassItem)] + categories[str(BrowserMethodItem)]
421 )
422 sdcnt = categories[str(ProjectBrowserSimpleDirectoryItem)]
423 if cnt > 1 and cnt == bfcnt:
424 self.multiMenu.popup(self.mapToGlobal(coord))
425 elif cnt > 1 and cnt == sdcnt:
426 self.dirMultiMenu.popup(self.mapToGlobal(coord))
427 else:
428 index = self.indexAt(coord)
429 if cnt == 1 and index.isValid():
430 if bfcnt == 1 or cmcnt == 1:
431 itm = self.model().item(index)
432 if isinstance(itm, ProjectBrowserFileItem):
433 self.sourceMenu.popup(self.mapToGlobal(coord))
434 elif isinstance(itm, (BrowserClassItem, BrowserMethodItem)):
435 self.menu.popup(self.mapToGlobal(coord))
436 else:
437 self.backMenu.popup(self.mapToGlobal(coord))
438 elif sdcnt == 1:
439 self.dirMenu.popup(self.mapToGlobal(coord))
440 else:
441 self.backMenu.popup(self.mapToGlobal(coord))
442 else:
443 self.backMenu.popup(self.mapToGlobal(coord))
444
445 def __showContextMenu(self):
446 """
447 Private slot called by the menu aboutToShow signal.
448 """
449 ProjectBaseBrowser._showContextMenu(self, self.menu)
450
451 self.showMenu.emit("Main", self.menu)
452
453 def __showContextMenuMulti(self):
454 """
455 Private slot called by the multiMenu aboutToShow signal.
456 """
457 ProjectBaseBrowser._showContextMenuMulti(self, self.multiMenu)
458
459 self.showMenu.emit("MainMulti", self.multiMenu)
460
461 def __showContextMenuDir(self):
462 """
463 Private slot called by the dirMenu aboutToShow signal.
464 """
465 ProjectBaseBrowser._showContextMenuDir(self, self.dirMenu)
466
467 self.showMenu.emit("MainDir", self.dirMenu)
468
469 def __showContextMenuDirMulti(self):
470 """
471 Private slot called by the dirMultiMenu aboutToShow signal.
472 """
473 ProjectBaseBrowser._showContextMenuDirMulti(self, self.dirMultiMenu)
474
475 self.showMenu.emit("MainDirMulti", self.dirMultiMenu)
476
477 def __showContextMenuBack(self):
478 """
479 Private slot called by the backMenu aboutToShow signal.
480 """
481 ProjectBaseBrowser._showContextMenuBack(self, self.backMenu)
482
483 self.showMenu.emit("MainBack", self.backMenu)
484
485 def _openItem(self):
486 """
487 Protected slot to handle the open popup menu entry.
488 """
489 itmList = self.getSelectedItems(
490 [
491 BrowserFileItem,
492 BrowserClassItem,
493 BrowserMethodItem,
494 BrowserClassAttributeItem,
495 ]
496 )
497
498 for itm in itmList:
499 if isinstance(itm, BrowserFileItem):
500 self.sourceFile[str].emit(itm.fileName())
501 elif isinstance(itm, BrowserClassItem):
502 self.sourceFile[str, int].emit(itm.fileName(), itm.classObject().lineno)
503 elif isinstance(itm, BrowserMethodItem):
504 self.sourceFile[str, int].emit(
505 itm.fileName(), itm.functionObject().lineno
506 )
507 elif isinstance(itm, BrowserClassAttributeItem):
508 self.sourceFile[str, int].emit(
509 itm.fileName(), itm.attributeObject().lineno
510 )
511
512 def __addInterfaceFiles(self):
513 """
514 Private method to add interface files to the project.
515 """
516 itm = self.model().item(self.currentIndex())
517 if isinstance(
518 itm, (ProjectBrowserFileItem, BrowserClassItem, BrowserMethodItem)
519 ):
520 dn = os.path.dirname(itm.fileName())
521 elif isinstance(
522 itm, (ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem)
523 ):
524 dn = itm.dirName()
525 else:
526 dn = None
527 self.project.addFiles(self.FileFilter, dn)
528
529 def __addInterfacesDirectory(self):
530 """
531 Private method to add interface files of a directory to the project.
532 """
533 itm = self.model().item(self.currentIndex())
534 if isinstance(
535 itm, (ProjectBrowserFileItem, BrowserClassItem, BrowserMethodItem)
536 ):
537 dn = os.path.dirname(itm.fileName())
538 elif isinstance(
539 itm, (ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem)
540 ):
541 dn = itm.dirName()
542 else:
543 dn = None
544 self.project.addDirectory(self.FileFilter, dn)
545
546 def __deleteFile(self):
547 """
548 Private method to delete files from the project.
549 """
550 itmList = self.getSelectedItems()
551
552 files = []
553 fullNames = []
554 for itm in itmList:
555 fn2 = itm.fileName()
556 fullNames.append(fn2)
557 fn = self.project.getRelativePath(fn2)
558 files.append(fn)
559
560 dlg = DeleteFilesConfirmationDialog(
561 self.parent(),
562 self.tr("Delete interfaces"),
563 self.tr(
564 "Do you really want to delete these interfaces from" " the project?"
565 ),
566 files,
567 )
568
569 if dlg.exec() == QDialog.DialogCode.Accepted:
570 for fn2, fn in zip(fullNames, files):
571 self.closeSourceWindow.emit(fn2)
572 self.project.deleteFile(fn)
573
574 ###########################################################################
575 ## Methods to handle the various compile commands
576 ###########################################################################
577
578 def __readStdout(self):
579 """
580 Private slot to handle the readyReadStandardOutput signal of the
581 omniidl process.
582 """
583 if self.compileProc is None:
584 return
585
586 ioEncoding = Preferences.getSystem("IOEncoding")
587
588 self.compileProc.setReadChannel(QProcess.ProcessChannel.StandardOutput)
589 while self.compileProc and self.compileProc.canReadLine():
590 s = "omniidl: "
591 output = str(self.compileProc.readLine(), ioEncoding, "replace")
592 s += output
593 self.appendStdout.emit(s)
594
595 def __readStderr(self):
596 """
597 Private slot to handle the readyReadStandardError signal of the
598 omniidl process.
599 """
600 if self.compileProc is None:
601 return
602
603 ioEncoding = Preferences.getSystem("IOEncoding")
604
605 self.compileProc.setReadChannel(QProcess.ProcessChannel.StandardError)
606 while self.compileProc and self.compileProc.canReadLine():
607 s = "omniidl: "
608 error = str(self.compileProc.readLine(), ioEncoding, "replace")
609 s += error
610 self.appendStderr.emit(s)
611
612 def __compileIDLDone(self, exitCode, exitStatus):
613 """
614 Private slot to handle the finished signal of the omniidl process.
615
616 @param exitCode exit code of the process (integer)
617 @param exitStatus exit status of the process (QProcess.ExitStatus)
618 """
619 pixmapSuffix = "dark" if ericApp().usesDarkPalette() else "light"
620 pixmap = EricPixmapCache.getPixmap(
621 os.path.join(
622 os.path.dirname(__file__),
623 "icons",
624 "corba48-{0}".format(pixmapSuffix),
625 )
626 )
627
628 self.compileRunning = False
629 ui = ericApp().getObject("UserInterface")
630 if exitStatus == QProcess.ExitStatus.NormalExit and exitCode == 0:
631 path = os.path.dirname(self.idlFile)
632 poaList = glob.glob(os.path.join(path, "*__POA"))
633 npoaList = [f.replace("__POA", "") for f in poaList]
634 fileList = glob.glob(os.path.join(path, "*_idl.py"))
635 for directory in poaList + npoaList:
636 fileList += Utilities.direntries(directory, True, "*.py")
637 for file in fileList:
638 self.project.appendFile(file)
639 ui.showNotification(
640 pixmap,
641 self.tr("Interface Compilation"),
642 self.tr("The compilation of the interface file was successful."),
643 )
644 else:
645 ui.showNotification(
646 pixmap,
647 self.tr("Interface Compilation"),
648 self.tr("The compilation of the interface file failed."),
649 kind=NotificationTypes.CRITICAL,
650 timeout=0,
651 )
652 self.compileProc = None
653
654 def __compileIDL(self, fn, noDialog=False, progress=None):
655 """
656 Private method to compile a .idl file to python.
657
658 @param fn filename of the .idl file to be compiled (string)
659 @param noDialog flag indicating silent operations (boolean)
660 @param progress reference to the progress dialog (EricProgressDialog)
661 @return reference to the compile process (QProcess)
662 """
663 params = self.project.getProjectData(dataKey="IDLPARAMS")
664
665 self.compileProc = QProcess()
666 args = []
667
668 args.append("-bpython")
669 args.append("-I.")
670 for directory in params["IncludeDirs"]:
671 args.append(
672 "-I{0}".format(self.project.getAbsoluteUniversalPath(directory))
673 )
674 for name in params["DefinedNames"]:
675 args.append("-D{0}".format(name))
676 for name in params["UndefinedNames"]:
677 args.append("-U{0}".format(name))
678
679 fn = self.project.getAbsoluteUniversalPath(fn)
680 self.idlFile = fn
681 args.append("-C{0}".format(os.path.dirname(fn)))
682 args.append(fn)
683
684 self.compileProc.finished.connect(self.__compileIDLDone)
685 self.compileProc.readyReadStandardOutput.connect(self.__readStdout)
686 self.compileProc.readyReadStandardError.connect(self.__readStderr)
687
688 self.noDialog = noDialog
689 self.compileProc.start(self.omniidl, args)
690 procStarted = self.compileProc.waitForStarted(5000)
691 if procStarted:
692 self.compileRunning = True
693 return self.compileProc
694 else:
695 self.compileRunning = False
696 if progress is not None:
697 progress.cancel()
698 EricMessageBox.critical(
699 self,
700 self.tr("Process Generation Error"),
701 self.tr(
702 "<p>Could not start {0}.<br>"
703 "Ensure that it is in the search path.</p>"
704 ).format(self.omniidl),
705 )
706 return None
707
708 def __compileInterface(self):
709 """
710 Private method to compile an interface to python.
711 """
712 if self.omniidl is not None:
713 itm = self.model().item(self.currentIndex())
714 fn2 = itm.fileName()
715 fn = self.project.getRelativePath(fn2)
716 self.__compileIDL(fn)
717
718 def __compileAllInterfaces(self):
719 """
720 Private method to compile all interfaces to python.
721 """
722 if self.omniidl is not None:
723 numIDLs = len(self.project.getProjectData(dataKey="INTERFACES"))
724 progress = EricProgressDialog(
725 self.tr("Compiling interfaces..."),
726 self.tr("Abort"),
727 0,
728 numIDLs,
729 self.tr("%v/%m Interfaces"),
730 self,
731 )
732 progress.setModal(True)
733 progress.setMinimumDuration(0)
734 progress.setWindowTitle(self.tr("Interfaces"))
735
736 for prog, fn in enumerate(
737 self.project.getProjectData(dataKey="INTERFACES")
738 ):
739 progress.setValue(prog)
740 if progress.wasCanceled():
741 break
742 proc = self.__compileIDL(fn, True, progress)
743 if proc is not None:
744 while proc.state() == QProcess.ProcessState.Running:
745 QThread.msleep(100)
746 QApplication.processEvents()
747 else:
748 break
749 progress.setValue(numIDLs)
750
751 def __compileSelectedInterfaces(self):
752 """
753 Private method to compile selected interfaces to python.
754 """
755 if self.omniidl is not None:
756 items = self.getSelectedItems()
757
758 files = [self.project.getRelativePath(itm.fileName()) for itm in items]
759 numIDLs = len(files)
760 progress = EricProgressDialog(
761 self.tr("Compiling interfaces..."),
762 self.tr("Abort"),
763 0,
764 numIDLs,
765 self.tr("%v/%m Interfaces"),
766 self,
767 )
768 progress.setModal(True)
769 progress.setMinimumDuration(0)
770 progress.setWindowTitle(self.tr("Interfaces"))
771
772 for prog, fn in enumerate(files):
773 progress.setValue(prog)
774 if progress.wasCanceled():
775 break
776 proc = self.__compileIDL(fn, True, progress)
777 if proc is not None:
778 while proc.state() == QProcess.ProcessState.Running:
779 QThread.msleep(100)
780 QApplication.processEvents()
781 else:
782 break
783 progress.setValue(numIDLs)
784
785 def __configureIdlCompiler(self):
786 """
787 Private method to show a dialog to configure some options for the
788 IDL compiler.
789 """
790 from .IdlCompilerOptionsDialog import IdlCompilerOptionsDialog
791
792 params = self.project.getProjectData(dataKey="IDLPARAMS")
793
794 dlg = IdlCompilerOptionsDialog(
795 params["IncludeDirs"][:],
796 params["DefinedNames"][:],
797 params["UndefinedNames"][:],
798 self.project,
799 self,
800 )
801 if dlg.exec() == QDialog.DialogCode.Accepted:
802 include, defined, undefined = dlg.getData()
803 if include != params["IncludeDirs"]:
804 params["IncludeDirs"] = include[:]
805 self.project.setDirty(True)
806 if defined != params["DefinedNames"]:
807 params["DefinedNames"] = defined[:]
808 self.project.setDirty(True)
809 if undefined != params["UndefinedNames"]:
810 params["UndefinedNames"] = undefined[:]
811 self.project.setDirty(True)
812
813 def __configureCorba(self):
814 """
815 Private method to open the configuration dialog.
816 """
817 ericApp().getObject("UserInterface").showPreferences("corbaPage")

eric ide

mercurial