WebBrowser/WebBrowserWindow.py

changeset 5224
7454861e4106
parent 5200
0f0efb52fda6
child 5341
d874aeb629dc
equal deleted inserted replaced
5223:4c0b3ee7d2d8 5224:7454861e4106
81 webBrowserClosed = pyqtSignal(QWidget) 81 webBrowserClosed = pyqtSignal(QWidget)
82 82
83 BrowserWindows = [] 83 BrowserWindows = []
84 84
85 _fromEric = False 85 _fromEric = False
86 UseQtHelp = QTHELP_AVAILABLE 86 _useQtHelp = QTHELP_AVAILABLE
87 _isPrivate = False 87 _isPrivate = False
88 88
89 _webProfile = None 89 _webProfile = None
90 _networkManager = None 90 _networkManager = None
91 _cookieJar = None 91 _cookieJar = None
185 185
186 # initialize some SSL stuff 186 # initialize some SSL stuff
187 from E5Network.E5SslUtilities import initSSL 187 from E5Network.E5SslUtilities import initSSL
188 initSSL() 188 initSSL()
189 189
190 if WebBrowserWindow.useQtHelp: 190 if WebBrowserWindow._useQtHelp:
191 self.__helpEngine = QHelpEngine( 191 self.__helpEngine = QHelpEngine(
192 os.path.join(Utilities.getConfigDir(), 192 WebBrowserWindow.getQtHelpCollectionFileName(),
193 "web_browser", "eric6help.qhc"),
194 self) 193 self)
195 self.__removeOldDocumentation() 194 self.__removeOldDocumentation()
196 self.__helpEngine.warning.connect(self.__warning) 195 self.__helpEngine.warning.connect(self.__warning)
197 else: 196 else:
198 self.__helpEngine = None 197 self.__helpEngine = None
226 QSizePolicy.Preferred, QSizePolicy.Expanding) 225 QSizePolicy.Preferred, QSizePolicy.Expanding)
227 centralWidget.setLayout(layout) 226 centralWidget.setLayout(layout)
228 self.setCentralWidget(centralWidget) 227 self.setCentralWidget(centralWidget)
229 self.__searchWidget.hide() 228 self.__searchWidget.hide()
230 229
231 if WebBrowserWindow.useQtHelp: 230 if WebBrowserWindow._useQtHelp:
232 # setup the TOC widget 231 # setup the TOC widget
233 self.__tocWindow = HelpTocWidget(self.__helpEngine) 232 self.__tocWindow = HelpTocWidget(self.__helpEngine)
234 self.__tocDock = QDockWidget(self.tr("Contents"), self) 233 self.__tocDock = QDockWidget(self.tr("Contents"), self)
235 self.__tocDock.setObjectName("TocWindow") 234 self.__tocDock.setObjectName("TocWindow")
236 self.__tocDock.setWidget(self.__tocWindow) 235 self.__tocDock.setWidget(self.__tocWindow)
325 QDesktopServices.setUrlHandler("http", self.__linkActivated) 324 QDesktopServices.setUrlHandler("http", self.__linkActivated)
326 QDesktopServices.setUrlHandler("https", self.__linkActivated) 325 QDesktopServices.setUrlHandler("https", self.__linkActivated)
327 326
328 # setup connections 327 # setup connections
329 self.__activating = False 328 self.__activating = False
330 if WebBrowserWindow.useQtHelp: 329 if WebBrowserWindow._useQtHelp:
331 # TOC window 330 # TOC window
332 self.__tocWindow.escapePressed.connect( 331 self.__tocWindow.escapePressed.connect(
333 self.__activateCurrentBrowser) 332 self.__activateCurrentBrowser)
334 self.__tocWindow.openUrl.connect(self.openUrl) 333 self.__tocWindow.openUrl.connect(self.openUrl)
335 self.__tocWindow.newTab.connect(self.openUrlNewTab) 334 self.__tocWindow.newTab.connect(self.openUrlNewTab)
370 369
371 self.__shutdownCalled = False 370 self.__shutdownCalled = False
372 371
373 self.flashCookieManager() 372 self.flashCookieManager()
374 373
375 if WebBrowserWindow.useQtHelp: 374 if WebBrowserWindow._useQtHelp:
376 QTimer.singleShot(0, self.__lookForNewDocumentation) 375 QTimer.singleShot(0, self.__lookForNewDocumentation)
377 if self.__searchWord is not None: 376 if self.__searchWord is not None:
378 QTimer.singleShot(0, self.__searchForWord) 377 QTimer.singleShot(0, self.__searchForWord)
379 378
380 e5App().focusChanged.connect(self.__appFocusChanged) 379 e5App().focusChanged.connect(self.__appFocusChanged)
1390 if not self.__initShortcutsOnly: 1389 if not self.__initShortcutsOnly:
1391 self.featurePermissionAct.triggered.connect( 1390 self.featurePermissionAct.triggered.connect(
1392 self.__showFeaturePermissionDialog) 1391 self.__showFeaturePermissionDialog)
1393 self.__actions.append(self.featurePermissionAct) 1392 self.__actions.append(self.featurePermissionAct)
1394 1393
1395 if WebBrowserWindow.useQtHelp or self.__initShortcutsOnly: 1394 if WebBrowserWindow._useQtHelp or self.__initShortcutsOnly:
1396 self.syncTocAct = E5Action( 1395 self.syncTocAct = E5Action(
1397 self.tr('Sync with Table of Contents'), 1396 self.tr('Sync with Table of Contents'),
1398 UI.PixmapCache.getIcon("syncToc.png"), 1397 UI.PixmapCache.getIcon("syncToc.png"),
1399 self.tr('Sync with Table of Contents'), 1398 self.tr('Sync with Table of Contents'),
1400 0, 0, self, 'webbrowser_sync_toc') 1399 0, 0, self, 'webbrowser_sync_toc')
1826 menu.addAction(self.forwardAct) 1825 menu.addAction(self.forwardAct)
1827 menu.addAction(self.homeAct) 1826 menu.addAction(self.homeAct)
1828 menu.addSeparator() 1827 menu.addSeparator()
1829 menu.addAction(self.stopAct) 1828 menu.addAction(self.stopAct)
1830 menu.addAction(self.reloadAct) 1829 menu.addAction(self.reloadAct)
1831 if WebBrowserWindow.useQtHelp: 1830 if WebBrowserWindow._useQtHelp:
1832 menu.addSeparator() 1831 menu.addSeparator()
1833 menu.addAction(self.syncTocAct) 1832 menu.addAction(self.syncTocAct)
1834 1833
1835 from .History.HistoryMenu import HistoryMenu 1834 from .History.HistoryMenu import HistoryMenu
1836 self.historyMenu = HistoryMenu(self, self.__tabWidget) 1835 self.historyMenu = HistoryMenu(self, self.__tabWidget)
1892 self.__userAgentMenu = UserAgentMenu(self.tr("Global User Agent")) 1891 self.__userAgentMenu = UserAgentMenu(self.tr("Global User Agent"))
1893 menu.addMenu(self.__userAgentMenu) 1892 menu.addMenu(self.__userAgentMenu)
1894 menu.addAction(self.userAgentManagerAct) 1893 menu.addAction(self.userAgentManagerAct)
1895 menu.addSeparator() 1894 menu.addSeparator()
1896 1895
1897 if WebBrowserWindow.useQtHelp: 1896 if WebBrowserWindow._useQtHelp:
1898 menu.addAction(self.manageQtHelpDocsAct) 1897 menu.addAction(self.manageQtHelpDocsAct)
1899 menu.addAction(self.manageQtHelpFiltersAct) 1898 menu.addAction(self.manageQtHelpFiltersAct)
1900 menu.addAction(self.reindexDocumentationAct) 1899 menu.addAction(self.reindexDocumentationAct)
1901 menu.addSeparator() 1900 menu.addSeparator()
1902 menu.addAction(self.clearPrivateDataAct) 1901 menu.addAction(self.clearPrivateDataAct)
1912 menu = mb.addMenu(self.tr("&Window")) 1911 menu = mb.addMenu(self.tr("&Window"))
1913 menu.setTearOffEnabled(True) 1912 menu.setTearOffEnabled(True)
1914 menu.addAction(self.showDownloadManagerAct) 1913 menu.addAction(self.showDownloadManagerAct)
1915 menu.addAction(self.showJavaScriptConsoleAct) 1914 menu.addAction(self.showJavaScriptConsoleAct)
1916 menu.addAction(self.showTabManagerAct) 1915 menu.addAction(self.showTabManagerAct)
1917 if WebBrowserWindow.useQtHelp: 1916 if WebBrowserWindow._useQtHelp:
1918 menu.addSeparator() 1917 menu.addSeparator()
1919 menu.addAction(self.showTocAct) 1918 menu.addAction(self.showTocAct)
1920 menu.addAction(self.showIndexAct) 1919 menu.addAction(self.showIndexAct)
1921 menu.addAction(self.showSearchAct) 1920 menu.addAction(self.showSearchAct)
1922 1921
1990 findtb.setIconSize(UI.Config.ToolBarIconSize) 1989 findtb.setIconSize(UI.Config.ToolBarIconSize)
1991 findtb.addAction(self.findAct) 1990 findtb.addAction(self.findAct)
1992 findtb.addAction(self.findNextAct) 1991 findtb.addAction(self.findNextAct)
1993 findtb.addAction(self.findPrevAct) 1992 findtb.addAction(self.findPrevAct)
1994 1993
1995 if WebBrowserWindow.useQtHelp: 1994 if WebBrowserWindow._useQtHelp:
1996 filtertb = self.addToolBar(self.tr("Filter")) 1995 filtertb = self.addToolBar(self.tr("Filter"))
1997 filtertb.setObjectName("FilterToolBar") 1996 filtertb.setObjectName("FilterToolBar")
1998 self.filterCombo = QComboBox() 1997 self.filterCombo = QComboBox()
1999 self.filterCombo.setMinimumWidth( 1998 self.filterCombo.setMinimumWidth(
2000 QFontMetrics(QFont()).width("ComboBoxWithEnoughWidth")) 1999 QFontMetrics(QFont()).width("ComboBoxWithEnoughWidth"))
2551 2550
2552 if len(WebBrowserWindow.BrowserWindows) == 1: 2551 if len(WebBrowserWindow.BrowserWindows) == 1:
2553 # it is the last window 2552 # it is the last window
2554 self.tabManager().close() 2553 self.tabManager().close()
2555 2554
2556 if WebBrowserWindow.useQtHelp: 2555 if WebBrowserWindow._useQtHelp:
2557 self.__searchEngine.cancelIndexing() 2556 self.__searchEngine.cancelIndexing()
2558 self.__searchEngine.cancelSearching() 2557 self.__searchEngine.cancelSearching()
2559 2558
2560 if self.__helpInstaller: 2559 if self.__helpInstaller:
2561 self.__helpInstaller.stop() 2560 self.__helpInstaller.stop()
2884 Class method to set the QtHelp usage. 2883 Class method to set the QtHelp usage.
2885 2884
2886 @param use flag indicating usage (boolean) 2885 @param use flag indicating usage (boolean)
2887 """ 2886 """
2888 if use: 2887 if use:
2889 cls.useQtHelp = use and QTHELP_AVAILABLE 2888 cls._useQtHelp = use and QTHELP_AVAILABLE
2890 else: 2889 else:
2891 cls.useQtHelp = False 2890 cls._useQtHelp = False
2892 2891
2893 @classmethod 2892 @classmethod
2894 def helpEngine(cls): 2893 def helpEngine(cls):
2895 """ 2894 """
2896 Class method to get a reference to the help engine. 2895 Class method to get a reference to the help engine.
2897 2896
2898 @return reference to the help engine (QHelpEngine) 2897 @return reference to the help engine (QHelpEngine)
2899 """ 2898 """
2900 if cls.useQtHelp: 2899 if cls._useQtHelp:
2901 if cls._helpEngine is None: 2900 if cls._helpEngine is None:
2902 cls._helpEngine = \ 2901 cls._helpEngine = QHelpEngine(
2903 QHelpEngine(os.path.join(Utilities.getConfigDir(), 2902 WebBrowserWindow.getQtHelpCollectionFileName())
2904 "web_browser", "eric6help.qhc"))
2905 return cls._helpEngine 2903 return cls._helpEngine
2906 else: 2904 else:
2907 return None 2905 return None
2908 2906
2907 @classmethod
2908 def getQtHelpCollectionFileName(cls):
2909 """
2910 Class method to determine the name of the QtHelp collection file.
2911
2912 @return path of the QtHelp collection file
2913 @rtype str
2914 """
2915 qthelpDir = os.path.join(Utilities.getConfigDir(), "qthelp")
2916 if not os.path.exists(qthelpDir):
2917 os.makedirs(qthelpDir)
2918 return os.path.join(qthelpDir, "eric6help.qhc")
2919
2909 @classmethod 2920 @classmethod
2910 def networkManager(cls): 2921 def networkManager(cls):
2911 """ 2922 """
2912 Class method to get a reference to the network manager object. 2923 Class method to get a reference to the network manager object.
2913 2924
2964 2975
2965 def __syncTOC(self): 2976 def __syncTOC(self):
2966 """ 2977 """
2967 Private slot to synchronize the TOC with the currently shown page. 2978 Private slot to synchronize the TOC with the currently shown page.
2968 """ 2979 """
2969 if WebBrowserWindow.UseQtHelp: 2980 if WebBrowserWindow._useQtHelp:
2970 QApplication.setOverrideCursor(Qt.WaitCursor) 2981 QApplication.setOverrideCursor(Qt.WaitCursor)
2971 url = self.currentBrowser().source() 2982 url = self.currentBrowser().source()
2972 self.__showTocWindow() 2983 self.__showTocWindow()
2973 if not self.__tocWindow.syncToContent(url): 2984 if not self.__tocWindow.syncToContent(url):
2974 self.statusBar().showMessage( 2985 self.statusBar().showMessage(
2977 2988
2978 def __showTocWindow(self): 2989 def __showTocWindow(self):
2979 """ 2990 """
2980 Private method to show the table of contents window. 2991 Private method to show the table of contents window.
2981 """ 2992 """
2982 if WebBrowserWindow.useQtHelp: 2993 if WebBrowserWindow._useQtHelp:
2983 self.__activateDock(self.__tocWindow) 2994 self.__activateDock(self.__tocWindow)
2984 2995
2985 def __showIndexWindow(self): 2996 def __showIndexWindow(self):
2986 """ 2997 """
2987 Private method to show the index window. 2998 Private method to show the index window.
2988 """ 2999 """
2989 if WebBrowserWindow.useQtHelp: 3000 if WebBrowserWindow._useQtHelp:
2990 self.__activateDock(self.__indexWindow) 3001 self.__activateDock(self.__indexWindow)
2991 3002
2992 def __showSearchWindow(self): 3003 def __showSearchWindow(self):
2993 """ 3004 """
2994 Private method to show the search window. 3005 Private method to show the search window.
2995 """ 3006 """
2996 if WebBrowserWindow.useQtHelp: 3007 if WebBrowserWindow._useQtHelp:
2997 self.__activateDock(self.__searchWindow) 3008 self.__activateDock(self.__searchWindow)
2998 3009
2999 def __activateDock(self, widget): 3010 def __activateDock(self, widget):
3000 """ 3011 """
3001 Private method to activate the dock widget of the given widget. 3012 Private method to activate the dock widget of the given widget.
3008 3019
3009 def __setupFilterCombo(self): 3020 def __setupFilterCombo(self):
3010 """ 3021 """
3011 Private slot to setup the filter combo box. 3022 Private slot to setup the filter combo box.
3012 """ 3023 """
3013 if WebBrowserWindow.useQtHelp: 3024 if WebBrowserWindow._useQtHelp:
3014 curFilter = self.filterCombo.currentText() 3025 curFilter = self.filterCombo.currentText()
3015 if not curFilter: 3026 if not curFilter:
3016 curFilter = self.__helpEngine.currentFilter() 3027 curFilter = self.__helpEngine.currentFilter()
3017 self.filterCombo.clear() 3028 self.filterCombo.clear()
3018 self.filterCombo.addItems(self.__helpEngine.customFilters()) 3029 self.filterCombo.addItems(self.__helpEngine.customFilters())
3032 3043
3033 def __manageQtHelpDocumentation(self): 3044 def __manageQtHelpDocumentation(self):
3034 """ 3045 """
3035 Private slot to manage the QtHelp documentation database. 3046 Private slot to manage the QtHelp documentation database.
3036 """ 3047 """
3037 if WebBrowserWindow.useQtHelp: 3048 if WebBrowserWindow._useQtHelp:
3038 from .QtHelp.QtHelpDocumentationDialog import \ 3049 from .QtHelp.QtHelpDocumentationDialog import \
3039 QtHelpDocumentationDialog 3050 QtHelpDocumentationDialog
3040 dlg = QtHelpDocumentationDialog(self.__helpEngine, self) 3051 dlg = QtHelpDocumentationDialog(self.__helpEngine, self)
3041 dlg.exec_() 3052 dlg.exec_()
3042 if dlg.hasChanges(): 3053 if dlg.hasChanges():
3054 3065
3055 def __manageQtHelpFilters(self): 3066 def __manageQtHelpFilters(self):
3056 """ 3067 """
3057 Private slot to manage the QtHelp filters. 3068 Private slot to manage the QtHelp filters.
3058 """ 3069 """
3059 if WebBrowserWindow.useQtHelp: 3070 if WebBrowserWindow._useQtHelp:
3060 from .QtHelp.QtHelpFiltersDialog import QtHelpFiltersDialog 3071 from .QtHelp.QtHelpFiltersDialog import QtHelpFiltersDialog
3061 dlg = QtHelpFiltersDialog(self.__helpEngine, self) 3072 dlg = QtHelpFiltersDialog(self.__helpEngine, self)
3062 dlg.exec_() 3073 dlg.exec_()
3063 3074
3064 def __indexingStarted(self): 3075 def __indexingStarted(self):
3065 """ 3076 """
3066 Private slot to handle the start of the indexing process. 3077 Private slot to handle the start of the indexing process.
3067 """ 3078 """
3068 if WebBrowserWindow.useQtHelp: 3079 if WebBrowserWindow._useQtHelp:
3069 self.__indexing = True 3080 self.__indexing = True
3070 if self.__indexingProgress is None: 3081 if self.__indexingProgress is None:
3071 self.__indexingProgress = QWidget() 3082 self.__indexingProgress = QWidget()
3072 layout = QHBoxLayout(self.__indexingProgress) 3083 layout = QHBoxLayout(self.__indexingProgress)
3073 layout.setContentsMargins(0, 0, 0, 0) 3084 layout.setContentsMargins(0, 0, 0, 0)
3090 3101
3091 def __indexingFinished(self): 3102 def __indexingFinished(self):
3092 """ 3103 """
3093 Private slot to handle the start of the indexing process. 3104 Private slot to handle the start of the indexing process.
3094 """ 3105 """
3095 if WebBrowserWindow.useQtHelp: 3106 if WebBrowserWindow._useQtHelp:
3096 self.statusBar().removeWidget(self.__indexingProgress) 3107 self.statusBar().removeWidget(self.__indexingProgress)
3097 self.__indexingProgress = None 3108 self.__indexingProgress = None
3098 self.__indexing = False 3109 self.__indexing = False
3099 if self.__searchWord is not None: 3110 if self.__searchWord is not None:
3100 self.__searchForWord() 3111 self.__searchForWord()
3101 3112
3102 def __searchForWord(self): 3113 def __searchForWord(self):
3103 """ 3114 """
3104 Private slot to search for a word. 3115 Private slot to search for a word.
3105 """ 3116 """
3106 if WebBrowserWindow.useQtHelp and not self.__indexing and \ 3117 if WebBrowserWindow._useQtHelp and not self.__indexing and \
3107 self.__searchWord is not None: 3118 self.__searchWord is not None:
3108 self.__searchDock.show() 3119 self.__searchDock.show()
3109 self.__searchDock.raise_() 3120 self.__searchDock.raise_()
3110 query = QHelpSearchQuery(QHelpSearchQuery.DEFAULT, 3121 query = QHelpSearchQuery(QHelpSearchQuery.DEFAULT,
3111 [self.__searchWord]) 3122 [self.__searchWord])
3116 """ 3127 """
3117 Public method to search for a word. 3128 Public method to search for a word.
3118 3129
3119 @param word word to search for (string) 3130 @param word word to search for (string)
3120 """ 3131 """
3121 if WebBrowserWindow.useQtHelp: 3132 if WebBrowserWindow._useQtHelp:
3122 self.__searchWord = word 3133 self.__searchWord = word
3123 self.__searchForWord() 3134 self.__searchForWord()
3124 3135
3125 def __removeOldDocumentation(self): 3136 def __removeOldDocumentation(self):
3126 """ 3137 """
3134 def __lookForNewDocumentation(self): 3145 def __lookForNewDocumentation(self):
3135 """ 3146 """
3136 Private slot to look for new documentation to be loaded into the 3147 Private slot to look for new documentation to be loaded into the
3137 help database. 3148 help database.
3138 """ 3149 """
3139 if WebBrowserWindow.useQtHelp: 3150 if WebBrowserWindow._useQtHelp:
3140 from .QtHelp.HelpDocsInstaller import HelpDocsInstaller 3151 from .QtHelp.HelpDocsInstaller import HelpDocsInstaller
3141 self.__helpInstaller = HelpDocsInstaller( 3152 self.__helpInstaller = HelpDocsInstaller(
3142 self.__helpEngine.collectionFile()) 3153 self.__helpEngine.collectionFile())
3143 self.__helpInstaller.errorMessage.connect( 3154 self.__helpInstaller.errorMessage.connect(
3144 self.__showInstallationError) 3155 self.__showInstallationError)
3164 Private slot handling the end of documentation installation. 3175 Private slot handling the end of documentation installation.
3165 3176
3166 @param installed flag indicating that documents were installed 3177 @param installed flag indicating that documents were installed
3167 (boolean) 3178 (boolean)
3168 """ 3179 """
3169 if WebBrowserWindow.useQtHelp: 3180 if WebBrowserWindow._useQtHelp:
3170 if installed: 3181 if installed:
3171 self.__helpEngine.setupData() 3182 self.__helpEngine.setupData()
3172 self.statusBar().clearMessage() 3183 self.statusBar().clearMessage()
3173 3184
3174 def __initHelpDb(self): 3185 def __initHelpDb(self):
3175 """ 3186 """
3176 Private slot to initialize the documentation database. 3187 Private slot to initialize the documentation database.
3177 """ 3188 """
3178 if WebBrowserWindow.useQtHelp: 3189 if WebBrowserWindow._useQtHelp:
3179 if not self.__helpEngine.setupData(): 3190 if not self.__helpEngine.setupData():
3180 return 3191 return
3181 3192
3182 unfiltered = self.tr("Unfiltered") 3193 unfiltered = self.tr("Unfiltered")
3183 if unfiltered not in self.__helpEngine.customFilters(): 3194 if unfiltered not in self.__helpEngine.customFilters():

eric ide

mercurial