eric6/UI/UserInterface.py

branch
multi_processing
changeset 7646
39e3db2b4936
parent 7627
812ee8c0a91a
parent 7635
0cdead130a81
child 7802
eefe954f01e8
equal deleted inserted replaced
7627:812ee8c0a91a 7646:39e3db2b4936
1213 @param icon icon to be used 1213 @param icon icon to be used
1214 @type QIcon 1214 @type QIcon
1215 @param label label text to be shown 1215 @param label label text to be shown
1216 @type str 1216 @type str
1217 """ 1217 """
1218 assert side in [UserInterface.LeftSide, UserInterface.BottomSide, 1218 if side in [UserInterface.LeftSide, UserInterface.BottomSide,
1219 UserInterface.RightSide] 1219 UserInterface.RightSide]:
1220 1220 if self.__layoutType == "Toolboxes":
1221 if self.__layoutType == "Toolboxes": 1221 if side == UserInterface.LeftSide:
1222 if side == UserInterface.LeftSide: 1222 self.lToolbox.addItem(widget, icon, label)
1223 self.lToolbox.addItem(widget, icon, label) 1223 elif side == UserInterface.BottomSide:
1224 elif side == UserInterface.BottomSide: 1224 self.hToolbox.addItem(widget, icon, label)
1225 self.hToolbox.addItem(widget, icon, label) 1225 elif side == UserInterface.RightSide:
1226 elif side == UserInterface.RightSide: 1226 self.rToolbox.addItem(widget, icon, label)
1227 self.rToolbox.addItem(widget, icon, label) 1227 elif self.__layoutType == "Sidebars":
1228 elif self.__layoutType == "Sidebars": 1228 if side == UserInterface.LeftSide:
1229 if side == UserInterface.LeftSide: 1229 self.leftSidebar.addTab(widget, icon, label)
1230 self.leftSidebar.addTab(widget, icon, label) 1230 elif side == UserInterface.BottomSide:
1231 elif side == UserInterface.BottomSide: 1231 self.bottomSidebar.addTab(widget, icon, label)
1232 self.bottomSidebar.addTab(widget, icon, label) 1232 elif side == UserInterface.RightSide:
1233 elif side == UserInterface.RightSide: 1233 self.rightSidebar.addTab(widget, icon, label)
1234 self.rightSidebar.addTab(widget, icon, label)
1235 1234
1236 def removeSideWidget(self, widget): 1235 def removeSideWidget(self, widget):
1237 """ 1236 """
1238 Public method to remove a widget added using addSideWidget(). 1237 Public method to remove a widget added using addSideWidget().
1239 1238
2185 )) 2184 ))
2186 self.utProjectAct.triggered.connect(self.__unittestProject) 2185 self.utProjectAct.triggered.connect(self.__unittestProject)
2187 self.utProjectAct.setEnabled(False) 2186 self.utProjectAct.setEnabled(False)
2188 self.actions.append(self.utProjectAct) 2187 self.actions.append(self.utProjectAct)
2189 2188
2190 # check for Qt4/Qt5 designer and linguist 2189 # check for Qt5 designer and linguist
2191 if Utilities.isWindowsPlatform(): 2190 if Utilities.isWindowsPlatform():
2192 designerExe = os.path.join( 2191 designerExe = os.path.join(
2193 Utilities.getQtBinariesPath(), 2192 Utilities.getQtBinariesPath(),
2194 "{0}.exe".format(Utilities.generateQtToolName("designer"))) 2193 "{0}.exe".format(Utilities.generateQtToolName("designer")))
2195 elif Utilities.isMacPlatform(): 2194 elif Utilities.isMacPlatform():
2719 2718
2720 def __initQtDocActions(self): 2719 def __initQtDocActions(self):
2721 """ 2720 """
2722 Private slot to initialize the action to show the Qt documentation. 2721 Private slot to initialize the action to show the Qt documentation.
2723 """ 2722 """
2724 self.qt4DocAct = E5Action(
2725 self.tr('Qt4 Documentation'),
2726 self.tr('Qt&4 Documentation'),
2727 0, 0, self, 'qt4_documentation')
2728 self.qt4DocAct.setStatusTip(self.tr('Open Qt4 Documentation'))
2729 self.qt4DocAct.setWhatsThis(self.tr(
2730 """<b>Qt4 Documentation</b>"""
2731 """<p>Display the Qt4 Documentation. Dependent upon your"""
2732 """ settings, this will either show the help in Eric's internal"""
2733 """ help viewer/web browser, or execute a web browser or Qt"""
2734 """ Assistant. </p>"""
2735 ))
2736 self.qt4DocAct.triggered.connect(self.__showQt4Doc)
2737 self.actions.append(self.qt4DocAct)
2738
2739 self.qt5DocAct = E5Action( 2723 self.qt5DocAct = E5Action(
2740 self.tr('Qt5 Documentation'), 2724 self.tr('Qt5 Documentation'),
2741 self.tr('Qt&5 Documentation'), 2725 self.tr('Qt&5 Documentation'),
2742 0, 0, self, 'qt5_documentation') 2726 0, 0, self, 'qt5_documentation')
2743 self.qt5DocAct.setStatusTip(self.tr('Open Qt5 Documentation')) 2727 self.qt5DocAct.setStatusTip(self.tr('Open Qt5 Documentation'))
2749 """ Assistant. </p>""" 2733 """ Assistant. </p>"""
2750 )) 2734 ))
2751 self.qt5DocAct.triggered.connect(self.__showQt5Doc) 2735 self.qt5DocAct.triggered.connect(self.__showQt5Doc)
2752 self.actions.append(self.qt5DocAct) 2736 self.actions.append(self.qt5DocAct)
2753 2737
2754 try:
2755 import PyQt4 # __IGNORE_WARNING__
2756 self.pyqt4DocAct = E5Action(
2757 self.tr('PyQt4 Documentation'),
2758 self.tr('PyQt&4 Documentation'),
2759 0, 0, self, 'pyqt4_documentation')
2760 self.pyqt4DocAct.setStatusTip(self.tr('Open PyQt4 Documentation'))
2761 self.pyqt4DocAct.setWhatsThis(self.tr(
2762 """<b>PyQt4 Documentation</b>"""
2763 """<p>Display the PyQt4 Documentation. Dependent upon your"""
2764 """ settings, this will either show the help in Eric's"""
2765 """ internal help viewer/web browser, or execute a web"""
2766 """ browser or Qt Assistant. </p>"""
2767 ))
2768 self.pyqt4DocAct.triggered.connect(self.__showPyQt4Doc)
2769 self.actions.append(self.pyqt4DocAct)
2770 except ImportError:
2771 self.pyqt4DocAct = None
2772
2773 self.pyqt5DocAct = E5Action( 2738 self.pyqt5DocAct = E5Action(
2774 self.tr('PyQt5 Documentation'), 2739 self.tr('PyQt5 Documentation'),
2775 self.tr('PyQt&5 Documentation'), 2740 self.tr('PyQt&5 Documentation'),
2776 0, 0, self, 'pyqt5_documentation') 2741 0, 0, self, 'pyqt5_documentation')
2777 self.pyqt5DocAct.setStatusTip(self.tr( 2742 self.pyqt5DocAct.setStatusTip(self.tr(
2806 """ <i>/usr/share/doc/packages/python/html</i> on Unix. Set""" 2771 """ <i>/usr/share/doc/packages/python/html</i> on Unix. Set"""
2807 """ PYTHON3DOCDIR in your environment to override this.</p>""" 2772 """ PYTHON3DOCDIR in your environment to override this.</p>"""
2808 )) 2773 ))
2809 self.pythonDocAct.triggered.connect(self.__showPythonDoc) 2774 self.pythonDocAct.triggered.connect(self.__showPythonDoc)
2810 self.actions.append(self.pythonDocAct) 2775 self.actions.append(self.pythonDocAct)
2811 2776
2812 self.python2DocAct = E5Action(
2813 self.tr('Python 2 Documentation'),
2814 self.tr('Python &2 Documentation'),
2815 0, 0, self, 'python2_documentation')
2816 self.python2DocAct.setStatusTip(self.tr(
2817 'Open Python 2 Documentation'))
2818 self.python2DocAct.setWhatsThis(self.tr(
2819 """<b>Python 2 Documentation</b>"""
2820 """<p>Display the Python 2 documentation. If no documentation"""
2821 """ directory is configured, the location of the Python 2"""
2822 """ documentation is assumed to be the doc directory underneath"""
2823 """ the location of the configured Python 2 executable on"""
2824 """ Windows and"""
2825 """ <i>/usr/share/doc/packages/python/html/python-docs-html</i>"""
2826 """ on Unix. Set PYTHON2DOCDIR in your environment to override"""
2827 """ this. </p>"""
2828 ))
2829 self.python2DocAct.triggered.connect(self.__showPython2Doc)
2830 self.actions.append(self.python2DocAct)
2831
2832 def __initEricDocAction(self): 2777 def __initEricDocAction(self):
2833 """ 2778 """
2834 Private slot to initialize the action to show the eric6 documentation. 2779 Private slot to initialize the action to show the eric6 documentation.
2835 """ 2780 """
2836 self.ericDocAct = E5Action( 2781 self.ericDocAct = E5Action(
2851 def __initPySideDocActions(self): 2796 def __initPySideDocActions(self):
2852 """ 2797 """
2853 Private slot to initialize the actions to show the PySide 2798 Private slot to initialize the actions to show the PySide
2854 documentation. 2799 documentation.
2855 """ 2800 """
2856 pyside_py2, pyside_py3 = Utilities.checkPyside("1") 2801 if Utilities.checkPyside():
2857 if pyside_py2 or pyside_py3:
2858 self.pysideDocAct = E5Action(
2859 self.tr('PySide Documentation'),
2860 self.tr('Py&Side Documentation'),
2861 0, 0, self, 'pyside_documentation')
2862 self.pysideDocAct.setStatusTip(self.tr(
2863 'Open PySide Documentation'))
2864 self.pysideDocAct.setWhatsThis(self.tr(
2865 """<b>PySide Documentation</b>"""
2866 """<p>Display the PySide Documentation. Dependent upon your"""
2867 """ settings, this will either show the help in Eric's"""
2868 """ internal help viewer/web browser, or execute a web"""
2869 """ browser or Qt Assistant. </p>"""
2870 ))
2871 self.pysideDocAct.triggered.connect(
2872 lambda: self.__showPySideDoc("1"))
2873 self.actions.append(self.pysideDocAct)
2874 else:
2875 self.pysideDocAct = None
2876
2877 pyside2_py2, pyside2_py3 = Utilities.checkPyside("2")
2878 if pyside2_py2 or pyside2_py3:
2879 self.pyside2DocAct = E5Action( 2802 self.pyside2DocAct = E5Action(
2880 self.tr('PySide2 Documentation'), 2803 self.tr('PySide2 Documentation'),
2881 self.tr('PySide&2 Documentation'), 2804 self.tr('PySide&2 Documentation'),
2882 0, 0, self, 'pyside2_documentation') 2805 0, 0, self, 'pyside2_documentation')
2883 self.pyside2DocAct.setStatusTip(self.tr( 2806 self.pyside2DocAct.setStatusTip(self.tr(
3179 if self.helpviewerAct: 3102 if self.helpviewerAct:
3180 self.__menus["help"].addAction(self.helpviewerAct) 3103 self.__menus["help"].addAction(self.helpviewerAct)
3181 self.__menus["help"].addSeparator() 3104 self.__menus["help"].addSeparator()
3182 self.__menus["help"].addAction(self.ericDocAct) 3105 self.__menus["help"].addAction(self.ericDocAct)
3183 self.__menus["help"].addAction(self.pythonDocAct) 3106 self.__menus["help"].addAction(self.pythonDocAct)
3184 self.__menus["help"].addAction(self.python2DocAct)
3185 self.__menus["help"].addAction(self.qt4DocAct)
3186 self.__menus["help"].addAction(self.qt5DocAct) 3107 self.__menus["help"].addAction(self.qt5DocAct)
3187 if self.pyqt4DocAct is not None:
3188 self.__menus["help"].addAction(self.pyqt4DocAct)
3189 if self.pyqt5DocAct is not None: 3108 if self.pyqt5DocAct is not None:
3190 self.__menus["help"].addAction(self.pyqt5DocAct) 3109 self.__menus["help"].addAction(self.pyqt5DocAct)
3191 if self.pysideDocAct is not None:
3192 self.__menus["help"].addAction(self.pysideDocAct)
3193 if self.pyside2DocAct is not None: 3110 if self.pyside2DocAct is not None:
3194 self.__menus["help"].addAction(self.pyside2DocAct) 3111 self.__menus["help"].addAction(self.pyside2DocAct)
3195 self.__menus["help"].addSeparator() 3112 self.__menus["help"].addSeparator()
3196 self.__menus["help"].addAction(self.versionAct) 3113 self.__menus["help"].addAction(self.versionAct)
3197 self.__menus["help"].addSeparator() 3114 self.__menus["help"].addSeparator()
5539 elif hvType == 3: 5456 elif hvType == 3:
5540 self.__webBrowser(home) 5457 self.__webBrowser(home)
5541 else: 5458 else:
5542 self.__customViewer(home) 5459 self.__customViewer(home)
5543 5460
5544 def __showPython2Doc(self):
5545 """
5546 Private slot to show the Python 2 documentation.
5547 """
5548 pythonDocDir = Preferences.getHelp("Python2DocDir")
5549 if not pythonDocDir:
5550 if Utilities.isWindowsPlatform():
5551 venvName = Preferences.getDebugger("Python2VirtualEnv")
5552 interpreter = (
5553 e5App().getObject("VirtualEnvManager")
5554 .getVirtualenvInterpreter(venvName)
5555 )
5556 if interpreter:
5557 default = os.path.join(os.path.dirname(interpreter), "doc")
5558 else:
5559 default = ""
5560 pythonDocDir = Utilities.getEnvironmentEntry(
5561 "PYTHON2DOCDIR", default)
5562 else:
5563 pythonDocDir = Utilities.getEnvironmentEntry(
5564 "PYTHON2DOCDIR",
5565 '/usr/share/doc/packages/python/html')
5566 if not pythonDocDir.startswith(("http://", "https://", "qthelp://")):
5567 if pythonDocDir.startswith("file://"):
5568 pythonDocDir = pythonDocDir[7:]
5569 if not os.path.splitext(pythonDocDir)[1]:
5570 home = Utilities.normjoinpath(pythonDocDir, 'index.html')
5571 else:
5572 home = pythonDocDir
5573
5574 if not os.path.exists(home):
5575 E5MessageBox.warning(
5576 self,
5577 self.tr("Documentation Missing"),
5578 self.tr("""<p>The documentation starting point"""
5579 """ "<b>{0}</b>" could not be found.</p>""")
5580 .format(home))
5581 return
5582
5583 if not home.endswith(".chm"):
5584 if Utilities.isWindowsPlatform():
5585 home = "file:///" + Utilities.fromNativeSeparators(home)
5586 else:
5587 home = "file://" + home
5588 else:
5589 home = pythonDocDir
5590
5591 if home.endswith(".chm"):
5592 self.__chmViewer(home)
5593 else:
5594 hvType = Preferences.getWebBrowser("HelpViewerType")
5595 if hvType == 1:
5596 self.launchHelpViewer(home)
5597 elif hvType == 2:
5598 if home.startswith("qthelp://"):
5599 self.__assistant(home)
5600 else:
5601 self.__webBrowser(home)
5602 elif hvType == 3:
5603 self.__webBrowser(home)
5604 else:
5605 self.__customViewer(home)
5606
5607 def __showQt4Doc(self):
5608 """
5609 Private slot to show the Qt4 documentation.
5610 """
5611 self.__showQtDoc(4)
5612
5613 def __showQt5Doc(self): 5461 def __showQt5Doc(self):
5614 """ 5462 """
5615 Private slot to show the Qt5 documentation. 5463 Private slot to show the Qt5 documentation.
5616 """ 5464 """
5617 self.__showQtDoc(5) 5465 self.__showQtDoc(5)
5620 """ 5468 """
5621 Private method to show the Qt documentation. 5469 Private method to show the Qt documentation.
5622 5470
5623 @param version Qt version to show documentation for (integer) 5471 @param version Qt version to show documentation for (integer)
5624 """ 5472 """
5625 assert version in [4, 5] 5473 if version == 5:
5626 if version == 4:
5627 qtDocDir = Preferences.getQt4DocDir()
5628 elif version == 5:
5629 qtDocDir = Preferences.getQt5DocDir() 5474 qtDocDir = Preferences.getQt5DocDir()
5630 5475
5631 if qtDocDir.startswith("qthelp://"): 5476 if qtDocDir.startswith("qthelp://"):
5632 if not os.path.splitext(qtDocDir)[1]: 5477 if not os.path.splitext(qtDocDir)[1]:
5633 home = qtDocDir + "/index.html" 5478 home = qtDocDir + "/index.html"
5654 5499
5655 if Utilities.isWindowsPlatform(): 5500 if Utilities.isWindowsPlatform():
5656 home = "file:///" + Utilities.fromNativeSeparators(home) 5501 home = "file:///" + Utilities.fromNativeSeparators(home)
5657 else: 5502 else:
5658 home = "file://" + home 5503 home = "file://" + home
5659
5660 hvType = Preferences.getWebBrowser("HelpViewerType")
5661 if hvType == 1:
5662 self.launchHelpViewer(home)
5663 elif hvType == 2:
5664 if home.startswith("qthelp://"):
5665 self.__assistant(home)
5666 else:
5667 self.__webBrowser(home)
5668 elif hvType == 3:
5669 self.__webBrowser(home)
5670 else:
5671 self.__customViewer(home)
5672
5673 def __showPyQt4Doc(self):
5674 """
5675 Private slot to show the PyQt4 documentation.
5676 """
5677 pyqt4DocDir = Preferences.getHelp("PyQt4DocDir")
5678 if not pyqt4DocDir:
5679 pyqt4DocDir = Utilities.getEnvironmentEntry("PYQT4DOCDIR", None)
5680
5681 if not pyqt4DocDir:
5682 E5MessageBox.warning(
5683 self,
5684 self.tr("Documentation"),
5685 self.tr("""<p>The PyQt4 documentation starting point"""
5686 """ has not been configured.</p>"""))
5687 return
5688
5689 if not pyqt4DocDir.startswith(("http://", "https://", "qthelp://")):
5690 home = ""
5691 if pyqt4DocDir:
5692 if pyqt4DocDir.startswith("file://"):
5693 pyqt4DocDir = pyqt4DocDir[7:]
5694 if not os.path.splitext(pyqt4DocDir)[1]:
5695 possibleHomes = [
5696 Utilities.normjoinpath(pyqt4DocDir, 'index.html'),
5697 Utilities.normjoinpath(pyqt4DocDir, 'classes.html'),
5698 ]
5699 for possibleHome in possibleHomes:
5700 if os.path.exists(possibleHome):
5701 home = possibleHome
5702 break
5703 else:
5704 home = pyqt4DocDir
5705
5706 if not home or not os.path.exists(home):
5707 E5MessageBox.warning(
5708 self,
5709 self.tr("Documentation Missing"),
5710 self.tr("""<p>The documentation starting point"""
5711 """ "<b>{0}</b>" could not be found.</p>""")
5712 .format(home))
5713 return
5714
5715 if Utilities.isWindowsPlatform():
5716 home = "file:///" + Utilities.fromNativeSeparators(home)
5717 else:
5718 home = "file://" + home
5719 else:
5720 home = pyqt4DocDir
5721 5504
5722 hvType = Preferences.getWebBrowser("HelpViewerType") 5505 hvType = Preferences.getWebBrowser("HelpViewerType")
5723 if hvType == 1: 5506 if hvType == 1:
5724 self.launchHelpViewer(home) 5507 self.launchHelpViewer(home)
5725 elif hvType == 2: 5508 elif hvType == 2:
5830 self.__webBrowser(home) 5613 self.__webBrowser(home)
5831 elif hvType == 3: 5614 elif hvType == 3:
5832 self.__webBrowser(home) 5615 self.__webBrowser(home)
5833 else: 5616 else:
5834 self.__customViewer(home) 5617 self.__customViewer(home)
5835 5618
5836 def __showPySideDoc(self, variant): 5619 def __showPySideDoc(self, variant="2"):
5837 """ 5620 """
5838 Private slot to show the PySide/PySide2 documentation. 5621 Private slot to show the PySide2 documentation.
5839 5622
5840 @param variant PySide variant (1 or 2) 5623 @param variant PySide variant (2)
5841 @type str 5624 @type str
5842 """ 5625 """
5843 assert variant in ("1", "2") 5626 pysideDocDir = Preferences.getHelp("PySide2DocDir")
5844 5627 if not pysideDocDir:
5845 if variant == "1": 5628 pysideDocDir = Utilities.getEnvironmentEntry(
5846 pysideDocDir = Preferences.getHelp("PySideDocDir") 5629 "PYSIDE2DOCDIR", None)
5847 if not pysideDocDir:
5848 pysideDocDir = Utilities.getEnvironmentEntry(
5849 "PYSIDEDOCDIR", None)
5850 else:
5851 pysideDocDir = Preferences.getHelp("PySide2DocDir")
5852 if not pysideDocDir:
5853 pysideDocDir = Utilities.getEnvironmentEntry(
5854 "PYSIDE2DOCDIR", None)
5855 5630
5856 if not pysideDocDir: 5631 if not pysideDocDir:
5857 E5MessageBox.warning( 5632 E5MessageBox.warning(
5858 self, 5633 self,
5859 self.tr("Documentation"), 5634 self.tr("Documentation"),
5860 self.tr("""<p>The PySide{0} documentation starting point""" 5635 self.tr("""<p>The PySide{0} documentation starting point"""
5861 """ has not been configured.</p>""").format( 5636 """ has not been configured.</p>""").format(
5862 "" if variant == "1" else variant) 5637 variant)
5863 ) 5638 )
5864 return 5639 return
5865 5640
5866 if not pysideDocDir.startswith(("http://", "https://", "qthelp://")): 5641 if not pysideDocDir.startswith(("http://", "https://", "qthelp://")):
5867 if pysideDocDir.startswith("file://"): 5642 if pysideDocDir.startswith("file://"):

eric ide

mercurial