Helpviewer/HelpWindow.py

changeset 5224
7454861e4106
parent 5196
e7490a5e7549
child 5226
7d8cee42ab86
equal deleted inserted replaced
5223:4c0b3ee7d2d8 5224:7454861e4106
70 privacyChanged = pyqtSignal(bool) 70 privacyChanged = pyqtSignal(bool)
71 71
72 helpwindows = [] 72 helpwindows = []
73 73
74 _fromEric = False 74 _fromEric = False
75 useQtHelp = QTHELP_AVAILABLE 75 _useQtHelp = QTHELP_AVAILABLE
76 76
77 _networkAccessManager = None 77 _networkAccessManager = None
78 _cookieJar = None 78 _cookieJar = None
79 _helpEngine = None 79 _helpEngine = None
80 _bookmarksManager = None 80 _bookmarksManager = None
144 144
145 # initialize some SSL stuff 145 # initialize some SSL stuff
146 from E5Network.E5SslUtilities import initSSL 146 from E5Network.E5SslUtilities import initSSL
147 initSSL() 147 initSSL()
148 148
149 if self.useQtHelp: 149 if HelpWindow._useQtHelp:
150 self.__helpEngine = \ 150 self.__helpEngine = QHelpEngine(
151 QHelpEngine(os.path.join(Utilities.getConfigDir(), 151 HelpWindow.getQtHelpCollectionFileName(),
152 "browser", "eric6help.qhc"), self) 152 self)
153 self.__removeOldDocumentation() 153 self.__removeOldDocumentation()
154 self.__helpEngine.warning.connect(self.__warning) 154 self.__helpEngine.warning.connect(self.__warning)
155 else: 155 else:
156 self.__helpEngine = None 156 self.__helpEngine = None
157 self.__helpInstaller = None 157 self.__helpInstaller = None
182 QSizePolicy.Preferred, QSizePolicy.Expanding) 182 QSizePolicy.Preferred, QSizePolicy.Expanding)
183 centralWidget.setLayout(layout) 183 centralWidget.setLayout(layout)
184 self.setCentralWidget(centralWidget) 184 self.setCentralWidget(centralWidget)
185 self.findDlg.hide() 185 self.findDlg.hide()
186 186
187 if self.useQtHelp: 187 if HelpWindow._useQtHelp:
188 # setup the TOC widget 188 # setup the TOC widget
189 self.__tocWindow = HelpTocWidget(self.__helpEngine, self) 189 self.__tocWindow = HelpTocWidget(self.__helpEngine, self)
190 self.__tocDock = QDockWidget(self.tr("Contents"), self) 190 self.__tocDock = QDockWidget(self.tr("Contents"), self)
191 self.__tocDock.setObjectName("TocWindow") 191 self.__tocDock.setObjectName("TocWindow")
192 self.__tocDock.setWidget(self.__tocWindow) 192 self.__tocDock.setWidget(self.__tocWindow)
258 QDesktopServices.setUrlHandler("http", self.__linkActivated) 258 QDesktopServices.setUrlHandler("http", self.__linkActivated)
259 QDesktopServices.setUrlHandler("https", self.__linkActivated) 259 QDesktopServices.setUrlHandler("https", self.__linkActivated)
260 260
261 # setup connections 261 # setup connections
262 self.__activating = False 262 self.__activating = False
263 if self.useQtHelp: 263 if HelpWindow._useQtHelp:
264 # TOC window 264 # TOC window
265 self.__tocWindow.linkActivated.connect(self.__linkActivated) 265 self.__tocWindow.linkActivated.connect(self.__linkActivated)
266 self.__tocWindow.escapePressed.connect( 266 self.__tocWindow.escapePressed.connect(
267 self.__activateCurrentBrowser) 267 self.__activateCurrentBrowser)
268 # index window 268 # index window
292 292
293 self.__shutdownCalled = False 293 self.__shutdownCalled = False
294 294
295 self.flashCookieManager() 295 self.flashCookieManager()
296 296
297 if self.useQtHelp: 297 if HelpWindow._useQtHelp:
298 QTimer.singleShot(0, self.__lookForNewDocumentation) 298 QTimer.singleShot(0, self.__lookForNewDocumentation)
299 if self.__searchWord is not None: 299 if self.__searchWord is not None:
300 QTimer.singleShot(0, self.__searchForWord) 300 QTimer.singleShot(0, self.__searchForWord)
301 301
302 e5App().focusChanged.connect(self.__appFocusChanged) 302 e5App().focusChanged.connect(self.__appFocusChanged)
1238 if not self.initShortcutsOnly: 1238 if not self.initShortcutsOnly:
1239 self.featurePermissionAct.triggered.connect( 1239 self.featurePermissionAct.triggered.connect(
1240 self.__showFeaturePermissionDialog) 1240 self.__showFeaturePermissionDialog)
1241 self.__actions.append(self.featurePermissionAct) 1241 self.__actions.append(self.featurePermissionAct)
1242 1242
1243 if self.useQtHelp or self.initShortcutsOnly: 1243 if HelpWindow._useQtHelp or self.initShortcutsOnly:
1244 self.syncTocAct = E5Action( 1244 self.syncTocAct = E5Action(
1245 self.tr('Sync with Table of Contents'), 1245 self.tr('Sync with Table of Contents'),
1246 UI.PixmapCache.getIcon("syncToc.png"), 1246 UI.PixmapCache.getIcon("syncToc.png"),
1247 self.tr('Sync with Table of Contents'), 1247 self.tr('Sync with Table of Contents'),
1248 0, 0, self, 'help_sync_toc') 1248 0, 0, self, 'help_sync_toc')
1655 menu.addAction(self.forwardAct) 1655 menu.addAction(self.forwardAct)
1656 menu.addAction(self.homeAct) 1656 menu.addAction(self.homeAct)
1657 menu.addSeparator() 1657 menu.addSeparator()
1658 menu.addAction(self.stopAct) 1658 menu.addAction(self.stopAct)
1659 menu.addAction(self.reloadAct) 1659 menu.addAction(self.reloadAct)
1660 if self.useQtHelp: 1660 if HelpWindow._useQtHelp:
1661 menu.addSeparator() 1661 menu.addSeparator()
1662 menu.addAction(self.syncTocAct) 1662 menu.addAction(self.syncTocAct)
1663 1663
1664 from .History.HistoryMenu import HistoryMenu 1664 from .History.HistoryMenu import HistoryMenu
1665 self.historyMenu = HistoryMenu(self, self.tabWidget) 1665 self.historyMenu = HistoryMenu(self, self.tabWidget)
1719 self.__userAgentMenu = UserAgentMenu(self.tr("Global User Agent")) 1719 self.__userAgentMenu = UserAgentMenu(self.tr("Global User Agent"))
1720 menu.addMenu(self.__userAgentMenu) 1720 menu.addMenu(self.__userAgentMenu)
1721 menu.addAction(self.userAgentManagerAct) 1721 menu.addAction(self.userAgentManagerAct)
1722 menu.addSeparator() 1722 menu.addSeparator()
1723 1723
1724 if self.useQtHelp: 1724 if HelpWindow._useQtHelp:
1725 menu.addAction(self.manageQtHelpDocsAct) 1725 menu.addAction(self.manageQtHelpDocsAct)
1726 menu.addAction(self.manageQtHelpFiltersAct) 1726 menu.addAction(self.manageQtHelpFiltersAct)
1727 menu.addAction(self.reindexDocumentationAct) 1727 menu.addAction(self.reindexDocumentationAct)
1728 menu.addSeparator() 1728 menu.addSeparator()
1729 menu.addAction(self.clearPrivateDataAct) 1729 menu.addAction(self.clearPrivateDataAct)
1739 menu.addAction(self.toolsMonitorAct) 1739 menu.addAction(self.toolsMonitorAct)
1740 1740
1741 menu = mb.addMenu(self.tr("&Window")) 1741 menu = mb.addMenu(self.tr("&Window"))
1742 menu.setTearOffEnabled(True) 1742 menu.setTearOffEnabled(True)
1743 menu.addAction(self.showDownloadManagerAct) 1743 menu.addAction(self.showDownloadManagerAct)
1744 if self.useQtHelp: 1744 if HelpWindow._useQtHelp:
1745 menu.addSeparator() 1745 menu.addSeparator()
1746 menu.addAction(self.showTocAct) 1746 menu.addAction(self.showTocAct)
1747 menu.addAction(self.showIndexAct) 1747 menu.addAction(self.showIndexAct)
1748 menu.addAction(self.showSearchAct) 1748 menu.addAction(self.showSearchAct)
1749 1749
1805 findtb.setIconSize(UI.Config.ToolBarIconSize) 1805 findtb.setIconSize(UI.Config.ToolBarIconSize)
1806 findtb.addAction(self.findAct) 1806 findtb.addAction(self.findAct)
1807 findtb.addAction(self.findNextAct) 1807 findtb.addAction(self.findNextAct)
1808 findtb.addAction(self.findPrevAct) 1808 findtb.addAction(self.findPrevAct)
1809 1809
1810 if self.useQtHelp: 1810 if HelpWindow._useQtHelp:
1811 filtertb = self.addToolBar(self.tr("Filter")) 1811 filtertb = self.addToolBar(self.tr("Filter"))
1812 filtertb.setObjectName("FilterToolBar") 1812 filtertb.setObjectName("FilterToolBar")
1813 self.filterCombo = QComboBox() 1813 self.filterCombo = QComboBox()
1814 self.filterCombo.setMinimumWidth( 1814 self.filterCombo.setMinimumWidth(
1815 QFontMetrics(QFont()).width("ComboBoxWithEnoughWidth")) 1815 QFontMetrics(QFont()).width("ComboBoxWithEnoughWidth"))
2260 2260
2261 self.flashCookieManager().shutdown() 2261 self.flashCookieManager().shutdown()
2262 2262
2263 self.searchEdit.openSearchManager().close() 2263 self.searchEdit.openSearchManager().close()
2264 2264
2265 if self.useQtHelp: 2265 if HelpWindow._useQtHelp:
2266 self.__searchEngine.cancelIndexing() 2266 self.__searchEngine.cancelIndexing()
2267 self.__searchEngine.cancelSearching() 2267 self.__searchEngine.cancelSearching()
2268 2268
2269 if self.__helpInstaller: 2269 if self.__helpInstaller:
2270 self.__helpInstaller.stop() 2270 self.__helpInstaller.stop()
2585 Class method to set the QtHelp usage. 2585 Class method to set the QtHelp usage.
2586 2586
2587 @param use flag indicating usage (boolean) 2587 @param use flag indicating usage (boolean)
2588 """ 2588 """
2589 if use: 2589 if use:
2590 cls.useQtHelp = use and QTHELP_AVAILABLE 2590 cls._useQtHelp = use and QTHELP_AVAILABLE
2591 else: 2591 else:
2592 cls.useQtHelp = False 2592 cls._useQtHelp = False
2593 2593
2594 @classmethod 2594 @classmethod
2595 def helpEngine(cls): 2595 def helpEngine(cls):
2596 """ 2596 """
2597 Class method to get a reference to the help engine. 2597 Class method to get a reference to the help engine.
2598 2598
2599 @return reference to the help engine (QHelpEngine) 2599 @return reference to the help engine (QHelpEngine)
2600 """ 2600 """
2601 if cls.useQtHelp: 2601 if cls.useQtHelp:
2602 if cls._helpEngine is None: 2602 if cls._helpEngine is None:
2603 cls._helpEngine = \ 2603 cls._helpEngine = QHelpEngine(
2604 QHelpEngine(os.path.join(Utilities.getConfigDir(), 2604 HelpWindow.getQtHelpCollectionFileName())
2605 "browser", "eric6help.qhc"))
2606 return cls._helpEngine 2605 return cls._helpEngine
2607 else: 2606 else:
2608 return None 2607 return None
2609 2608
2609 @classmethod
2610 def getQtHelpCollectionFileName(cls):
2611 """
2612 Class method to determine the name of the QtHelp collection file.
2613
2614 @return path of the QtHelp collection file
2615 @rtype str
2616 """
2617 qthelpDir = os.path.join(Utilities.getConfigDir(), "qthelp")
2618 if not os.path.exists(qthelpDir):
2619 os.makedirs(qthelpDir)
2620 return os.path.join(qthelpDir, "eric6help.qhc")
2621
2610 @classmethod 2622 @classmethod
2611 def networkAccessManager(cls): 2623 def networkAccessManager(cls):
2612 """ 2624 """
2613 Class method to get a reference to the network access manager. 2625 Class method to get a reference to the network access manager.
2614 2626
2678 2690
2679 def __syncTOC(self): 2691 def __syncTOC(self):
2680 """ 2692 """
2681 Private slot to synchronize the TOC with the currently shown page. 2693 Private slot to synchronize the TOC with the currently shown page.
2682 """ 2694 """
2683 if self.useQtHelp: 2695 if HelpWindow._useQtHelp:
2684 QApplication.setOverrideCursor(Qt.WaitCursor) 2696 QApplication.setOverrideCursor(Qt.WaitCursor)
2685 url = self.currentBrowser().source() 2697 url = self.currentBrowser().source()
2686 self.__showTocWindow() 2698 self.__showTocWindow()
2687 if not self.__tocWindow.syncToContent(url): 2699 if not self.__tocWindow.syncToContent(url):
2688 self.statusBar().showMessage( 2700 self.statusBar().showMessage(
2691 2703
2692 def __showTocWindow(self): 2704 def __showTocWindow(self):
2693 """ 2705 """
2694 Private method to show the table of contents window. 2706 Private method to show the table of contents window.
2695 """ 2707 """
2696 if self.useQtHelp: 2708 if HelpWindow._useQtHelp:
2697 self.__activateDock(self.__tocWindow) 2709 self.__activateDock(self.__tocWindow)
2698 2710
2699 def __hideTocWindow(self): 2711 def __hideTocWindow(self):
2700 """ 2712 """
2701 Private method to hide the table of contents window. 2713 Private method to hide the table of contents window.
2702 """ 2714 """
2703 if self.useQtHelp: 2715 if HelpWindow._useQtHelp:
2704 self.__tocDock.hide() 2716 self.__tocDock.hide()
2705 2717
2706 def __showIndexWindow(self): 2718 def __showIndexWindow(self):
2707 """ 2719 """
2708 Private method to show the index window. 2720 Private method to show the index window.
2709 """ 2721 """
2710 if self.useQtHelp: 2722 if HelpWindow._useQtHelp:
2711 self.__activateDock(self.__indexWindow) 2723 self.__activateDock(self.__indexWindow)
2712 2724
2713 def __hideIndexWindow(self): 2725 def __hideIndexWindow(self):
2714 """ 2726 """
2715 Private method to hide the index window. 2727 Private method to hide the index window.
2716 """ 2728 """
2717 if self.useQtHelp: 2729 if HelpWindow._useQtHelp:
2718 self.__indexDock.hide() 2730 self.__indexDock.hide()
2719 2731
2720 def __showSearchWindow(self): 2732 def __showSearchWindow(self):
2721 """ 2733 """
2722 Private method to show the search window. 2734 Private method to show the search window.
2723 """ 2735 """
2724 if self.useQtHelp: 2736 if HelpWindow._useQtHelp:
2725 self.__activateDock(self.__searchWindow) 2737 self.__activateDock(self.__searchWindow)
2726 2738
2727 def __hideSearchWindow(self): 2739 def __hideSearchWindow(self):
2728 """ 2740 """
2729 Private method to hide the search window. 2741 Private method to hide the search window.
2730 """ 2742 """
2731 if self.useQtHelp: 2743 if HelpWindow._useQtHelp:
2732 self.__searchDock.hide() 2744 self.__searchDock.hide()
2733 2745
2734 def __activateDock(self, widget): 2746 def __activateDock(self, widget):
2735 """ 2747 """
2736 Private method to activate the dock widget of the given widget. 2748 Private method to activate the dock widget of the given widget.
2743 2755
2744 def __setupFilterCombo(self): 2756 def __setupFilterCombo(self):
2745 """ 2757 """
2746 Private slot to setup the filter combo box. 2758 Private slot to setup the filter combo box.
2747 """ 2759 """
2748 if self.useQtHelp: 2760 if HelpWindow._useQtHelp:
2749 curFilter = self.filterCombo.currentText() 2761 curFilter = self.filterCombo.currentText()
2750 if not curFilter: 2762 if not curFilter:
2751 curFilter = self.__helpEngine.currentFilter() 2763 curFilter = self.__helpEngine.currentFilter()
2752 self.filterCombo.clear() 2764 self.filterCombo.clear()
2753 self.filterCombo.addItems(self.__helpEngine.customFilters()) 2765 self.filterCombo.addItems(self.__helpEngine.customFilters())
2767 2779
2768 def __manageQtHelpDocumentation(self): 2780 def __manageQtHelpDocumentation(self):
2769 """ 2781 """
2770 Private slot to manage the QtHelp documentation database. 2782 Private slot to manage the QtHelp documentation database.
2771 """ 2783 """
2772 if self.useQtHelp: 2784 if HelpWindow._useQtHelp:
2773 from .QtHelpDocumentationDialog import QtHelpDocumentationDialog 2785 from .QtHelpDocumentationDialog import QtHelpDocumentationDialog
2774 dlg = QtHelpDocumentationDialog(self.__helpEngine, self) 2786 dlg = QtHelpDocumentationDialog(self.__helpEngine, self)
2775 dlg.exec_() 2787 dlg.exec_()
2776 if dlg.hasChanges(): 2788 if dlg.hasChanges():
2777 for i in sorted(dlg.getTabsToClose(), reverse=True): 2789 for i in sorted(dlg.getTabsToClose(), reverse=True):
2788 2800
2789 def __manageQtHelpFilters(self): 2801 def __manageQtHelpFilters(self):
2790 """ 2802 """
2791 Private slot to manage the QtHelp filters. 2803 Private slot to manage the QtHelp filters.
2792 """ 2804 """
2793 if self.useQtHelp: 2805 if HelpWindow._useQtHelp:
2794 from .QtHelpFiltersDialog import QtHelpFiltersDialog 2806 from .QtHelpFiltersDialog import QtHelpFiltersDialog
2795 dlg = QtHelpFiltersDialog(self.__helpEngine, self) 2807 dlg = QtHelpFiltersDialog(self.__helpEngine, self)
2796 dlg.exec_() 2808 dlg.exec_()
2797 2809
2798 def __indexingStarted(self): 2810 def __indexingStarted(self):
2799 """ 2811 """
2800 Private slot to handle the start of the indexing process. 2812 Private slot to handle the start of the indexing process.
2801 """ 2813 """
2802 if self.useQtHelp: 2814 if HelpWindow._useQtHelp:
2803 self.__indexing = True 2815 self.__indexing = True
2804 if self.__indexingProgress is None: 2816 if self.__indexingProgress is None:
2805 self.__indexingProgress = QWidget() 2817 self.__indexingProgress = QWidget()
2806 layout = QHBoxLayout(self.__indexingProgress) 2818 layout = QHBoxLayout(self.__indexingProgress)
2807 layout.setContentsMargins(0, 0, 0, 0) 2819 layout.setContentsMargins(0, 0, 0, 0)
2824 2836
2825 def __indexingFinished(self): 2837 def __indexingFinished(self):
2826 """ 2838 """
2827 Private slot to handle the start of the indexing process. 2839 Private slot to handle the start of the indexing process.
2828 """ 2840 """
2829 if self.useQtHelp: 2841 if HelpWindow._useQtHelp:
2830 self.statusBar().removeWidget(self.__indexingProgress) 2842 self.statusBar().removeWidget(self.__indexingProgress)
2831 self.__indexingProgress = None 2843 self.__indexingProgress = None
2832 self.__indexing = False 2844 self.__indexing = False
2833 if self.__searchWord is not None: 2845 if self.__searchWord is not None:
2834 self.__searchForWord() 2846 self.__searchForWord()
2835 2847
2836 def __searchForWord(self): 2848 def __searchForWord(self):
2837 """ 2849 """
2838 Private slot to search for a word. 2850 Private slot to search for a word.
2839 """ 2851 """
2840 if self.useQtHelp and not self.__indexing and \ 2852 if HelpWindow._useQtHelp and not self.__indexing and \
2841 self.__searchWord is not None: 2853 self.__searchWord is not None:
2842 self.__searchDock.show() 2854 self.__searchDock.show()
2843 self.__searchDock.raise_() 2855 self.__searchDock.raise_()
2844 query = QHelpSearchQuery(QHelpSearchQuery.DEFAULT, 2856 query = QHelpSearchQuery(QHelpSearchQuery.DEFAULT,
2845 [self.__searchWord]) 2857 [self.__searchWord])
2850 """ 2862 """
2851 Public method to search for a word. 2863 Public method to search for a word.
2852 2864
2853 @param word word to search for (string) 2865 @param word word to search for (string)
2854 """ 2866 """
2855 if self.useQtHelp: 2867 if HelpWindow._useQtHelp:
2856 self.__searchWord = word 2868 self.__searchWord = word
2857 self.__searchForWord() 2869 self.__searchForWord()
2858 2870
2859 def __removeOldDocumentation(self): 2871 def __removeOldDocumentation(self):
2860 """ 2872 """
2868 def __lookForNewDocumentation(self): 2880 def __lookForNewDocumentation(self):
2869 """ 2881 """
2870 Private slot to look for new documentation to be loaded into the 2882 Private slot to look for new documentation to be loaded into the
2871 help database. 2883 help database.
2872 """ 2884 """
2873 if self.useQtHelp: 2885 if HelpWindow._useQtHelp:
2874 from .HelpDocsInstaller import HelpDocsInstaller 2886 from .HelpDocsInstaller import HelpDocsInstaller
2875 self.__helpInstaller = HelpDocsInstaller( 2887 self.__helpInstaller = HelpDocsInstaller(
2876 self.__helpEngine.collectionFile()) 2888 self.__helpEngine.collectionFile())
2877 self.__helpInstaller.errorMessage.connect( 2889 self.__helpInstaller.errorMessage.connect(
2878 self.__showInstallationError) 2890 self.__showInstallationError)
2898 Private slot handling the end of documentation installation. 2910 Private slot handling the end of documentation installation.
2899 2911
2900 @param installed flag indicating that documents were installed 2912 @param installed flag indicating that documents were installed
2901 (boolean) 2913 (boolean)
2902 """ 2914 """
2903 if self.useQtHelp: 2915 if HelpWindow._useQtHelp:
2904 if installed: 2916 if installed:
2905 self.__helpEngine.setupData() 2917 self.__helpEngine.setupData()
2906 self.statusBar().clearMessage() 2918 self.statusBar().clearMessage()
2907 2919
2908 def __initHelpDb(self): 2920 def __initHelpDb(self):
2909 """ 2921 """
2910 Private slot to initialize the documentation database. 2922 Private slot to initialize the documentation database.
2911 """ 2923 """
2912 if self.useQtHelp: 2924 if HelpWindow._useQtHelp:
2913 if not self.__helpEngine.setupData(): 2925 if not self.__helpEngine.setupData():
2914 return 2926 return
2915 2927
2916 unfiltered = self.tr("Unfiltered") 2928 unfiltered = self.tr("Unfiltered")
2917 if unfiltered not in self.__helpEngine.customFilters(): 2929 if unfiltered not in self.__helpEngine.customFilters():

eric ide

mercurial