Exemplo n.º 1
0
    def __init__(self, webTab):
        '''
        @param: webTab WebTab
        '''
        super(TabbedWebView, self).__init__(webTab)
        self._window = None  # BrowserWindow
        self._webTab = webTab  # WebTab
        self._menu = Menu(self)  # Menu

        self._currentIp = ''

        self._menu.setCloseOnMiddleClick(True)

        self.loadStarted.connect(self._slotLoadStarted)
        self.loadProgress.connect(self._slotLoadProgress)
        self.loadFinished.connect(self._slotLoadFinished)
Exemplo n.º 2
0
    def _init(self):
        self.setTitle('Hi&story')

        icon = IconProvider.standardIcon(QStyle.SP_ArrowBack)
        act = self.addAction(icon, '&Back', self._goBack)
        act.setShortcut(
            gVar.appTools.actionShortcut(QKeySequence.Back,
                                         Qt.ALT + Qt.Key_Left,
                                         QKeySequence.Forward,
                                         Qt.ALT + Qt.Key_Right))

        icon = IconProvider.standardIcon(QStyle.SP_ArrowForward)
        act = self.addAction(icon, '&Forward', self._goForward)
        act.setShortcut(
            gVar.appTools.actionShortcut(QKeySequence.Forward,
                                         Qt.ALT + Qt.Key_Right,
                                         QKeySequence.Back,
                                         Qt.ALT + Qt.Key_Left))

        act = self.addAction(QIcon.fromTheme('go-home'), '&Home', self._goHome)
        act.setShortcut(QKeySequence(Qt.ALT + Qt.Key_Home))

        icon = QIcon.fromTheme('deep-history',
                               QIcon(':/icons/menu/history.svg'))
        act = self.addAction(icon, 'Show &All History')
        act.triggered.connect(self._showHistoryManager)
        act.setShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_H))

        self.addSeparator()

        self.aboutToShow.connect(self._aboutToHide)
        self.aboutToHide.connect(self._aboutToShow)

        self._menuMostVisited = Menu('Most Visited', self)
        self._menuMostVisited.aboutToShow.connect(self._aboutToShowMostVisited)

        self._menuClosedTabs = Menu('Closed Tabs')
        self._menuClosedTabs.aboutToShow.connect(self._aboutToShowClosedTabs)

        self._menuClosedWindows = Menu('Closed Windows')
        self._menuClosedWindows.aboutToShow.connect(
            self._aboutToShowClosedWindows)

        self.addMenu(self._menuMostVisited)
        self.addMenu(self._menuClosedTabs)
        self.addMenu(self._menuClosedWindows)
    def _init(self):
        assert (self._bookmark)

        self.setFocusPolicy(Qt.NoFocus)
        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred)
        self.setToolTip(self._createTooltip())

        if self._bookmark.isFolder():
            menu = Menu(self)
            self.setMenu(menu)
            self._createMenu()
Exemplo n.º 4
0
    def _createSelectedTextContextMenu(self, menu, hitTest):
        '''
        @param: menu QMenu
        @param: hitTest WebHitTestResult
        '''
        selectedText = self.page().selectedText()

        menu.addSeparator()
        if self.pageAction(QWebEnginePage.Copy) not in menu.actions():
            menu.addAction(self.pageAction(QWebEnginePage.Copy))
        menu.addAction(QIcon.fromTheme('mail-message-new'), _('Send text...'),
                self._sendTextByMail).setData(selectedText)
        menu.addSeparator()

        # 379: Remove newlines
        selectedString = selectedText.strip()
        if '.' not in selectedString:
            # Try to add .com
            selectedString += '.com'
        guessedUrl = QUrl.fromUserInput(selectedString)
        if self.isUrlValid(guessedUrl):
            act = Action(QIcon.fromTheme('document-open-remote'), _('Go to &web address'), menu)
            act.setData(guessedUrl)

            act.triggered.connect(self._openActionUrl)
            act.ctrlTriggered.connect(lambda: self.userDefinedOpenUrlInNewTab())
            menu.addAction(act)

        menu.addSeparator()
        selectedText = selectedText[:20]
        # KDE is displaying newlines in menu actions ... weird
        selectedText = selectedText.replace('\n', ' ').replace('\t', ' ')

        engine = gVar.app.searchEnginesManager().defaultEngine()
        act = Action(engine.icon, _('Search "%s .." with %s') % (selectedText, engine.name), menu)
        act.triggered.connect(self._searchSelectedText)
        act.ctrlTriggered.connect(self._searchSelectedTextInBackgroundTab)
        menu.addAction(act)

        # Search with ...
        swMenu = Menu(_('Search with...'), menu)
        swMenu.setCloseOnMiddleClick(True)
        searchManager = gVar.app.searchEnginesManager()
        for en in searchManager.allEngines():
            act = Action(en.icon, en.name, swMenu)
            act.setData(en)

            act.triggered.connect(self._searchSelectedText)
            act.ctrlTriggered.connect(self._searchSelectedTextInBackgroundTab)
            swMenu.addAction(act)

        menu.addMenu(swMenu)
Exemplo n.º 5
0
    def addFolderToMenu(cls, receiver, menu, folder):
        '''
        @param: receiver QObject
        @param: menu Menu
        @param: folder BookmarkItem
        '''
        assert(menu)
        assert(folder)
        assert(folder.isFolder())

        subMenu = Menu(menu)
        title = QFontMetrics(subMenu.font()).elidedText(folder.title(), Qt.ElideRight, 250)
        subMenu.setTitle(title)
        subMenu.setIcon(folder.icon())

        cls.addFolderContentsToMenu(receiver, subMenu, folder)

        # QAction
        act = menu.addMenu(subMenu)
        act.setData(folder)
        act.setIconVisibleInMenu(True)
Exemplo n.º 6
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self._menu = Menu()  # Menu
        self._inspector = None  # QPoint<WebInspector>

        self._menu.setCloseOnMiddleClick(True)
Exemplo n.º 7
0
class PopupWebView(WebView):
    def __init__(self, parent=None):
        super().__init__(parent)
        self._menu = Menu()  # Menu
        self._inspector = None  # QPoint<WebInspector>

        self._menu.setCloseOnMiddleClick(True)

    # override
    def overlayWidget(self):
        '''
        @return: QWidget
        '''
        return self.parentWidget()

    # override
    def loadInNewTab(self, req, position):
        '''
        @param: req LoadRequest
        @param: position Qz::NewTabPositionFlags
        '''
        window = gVar.app.getWindow()

        if window:
            index = window.tabWidget().addView(QUrl(), const.NT_SelectedTab)
            window.weView(index).loadByReq(req)
            window.raise_()

    # override
    def closeView(self):
        self.window().close()

    # override
    def isFullScreen(self):
        return self.parentWidget().isFullScreen()

    # override
    def requestFullScreen(self, enable):
        if enable:
            self.parentWidget().showFullScreen()
        else:
            self.parentWidget().showNormal()

    # public Q_SLOTS:
    def inspectElement(self):
        if not WebInspector.isEnabled():
            return

        if self._inspector:
            self.triggerPageAction(QWebEnginePage.InspectElement)
            return

        self._inspector = WebInspector()
        self._inspector.setView(self)
        self._inspector.inspectElement()
        self._inspector.show()

    # private:
    # override
    def _contextMenuEvent(self, event):
        '''
        @param: event QContextMenuEvent
        '''
        self._menu.clear()

        # WebHitTestResult
        hitTest = self.page().hitTestContent(event.pos())
        self.createContextMenu(self._menu, hitTest)

        if WebInspector.isEnabled():
            self._menu.addSeparator()
            self._menu.addAction('Inspect Element', self.inspectElement)

        if not self._menu.isEmpty():
            # Prevent choosing first option with double rightclick
            pos = event.globalPos()
            p = QPoint(pos.x(), pos.y() + 1)

            self._menu.popup(p)
            return

        super()._contextMenuEvent(event)
Exemplo n.º 8
0
class TabbedWebView(WebView):
    def __init__(self, webTab):
        '''
        @param: webTab WebTab
        '''
        super(TabbedWebView, self).__init__(webTab)
        self._window = None  # BrowserWindow
        self._webTab = webTab  # WebTab
        self._menu = Menu(self)  # Menu

        self._currentIp = ''

        self._menu.setCloseOnMiddleClick(True)

        self.loadStarted.connect(self._slotLoadStarted)
        self.loadProgress.connect(self._slotLoadProgress)
        self.loadFinished.connect(self._slotLoadFinished)

    def setPage(self, page):
        '''
        @param: page WebPage
        '''
        super(TabbedWebView, self).setPage(page)
        page.linkHovered.connect(self._linkHovered)

    def browserWindow(self):
        '''
        @note: BrowserWindow can be null!
        @return: BrowserWindow
        '''
        return self._window

    def setBrowserWindow(self, window):
        self._window = window

    def webTab(self):
        '''
        @return: WebTab
        '''
        return self._webTab

    def getIp(self):
        '''
        @return: QString
        '''
        return self._currentIp

    def tabIndex(self):
        '''
        @return int
        '''
        return self._webTab.tabIndex()

    # override
    def overlayWidget(self):
        '''
        @return: QWidget
        '''
        return self._webTab

    # override
    def closeView(self):
        self.wantsCloseTab.emit(self.tabIndex())

    # override
    def loadInNewTab(self, req, position):
        '''
        @param: req LoadRequest
        @param: position Qz::NewTabPositionFlags
        '''
        if self._window:
            index = self._window.tabWidget().addViewByUrl(QUrl(), position)
            view = self._window.weView(index)
            self.webTab().addChildTab(view.webTab())
            view.webTab().locationBar().showUrl(req.url())
            view.loadByReq(req)

    # override
    def isFullScreen(self):
        return self._window and self._window.isFullScreen()

    # override
    def requestFullScreen(self, enable):
        if not self._window:
            return

        self._window.requestHtmlFullScreen(self, enable)

    # Q_SIGNALS
    wantsCloseTab = pyqtSignal(int)
    ipChanged = pyqtSignal(str)

    # public Q_SLOTS
    def setAsCurrentTab(self):
        if self._window:
            self._window.tabWidget().setCurrentWidget(self._webTab)

    def userLoadAction(self, req):
        '''
        @param: req LoadRequest
        '''
        self.loadByReq(req)

    # private Q_SLOTS
    def _slotLoadStarted(self):
        self._currentIp = ''

    def _slotLoadFinished(self, ok):
        QHostInfo.lookupHost(self.url().host(), self._setIp)

        if self._webTab.isCurrentTab() and self._window:
            self._window.updateLoadingActions()

    def _slotLoadProgress(self, prog):
        '''
        @param: prog int
        '''
        if self._webTab.isCurrentTab() and self._window:
            self._window.updateLoadingActions()

    def _linkHovered(self, link):
        '''
        @param: QString
        '''
        if self._webTab.isCurrentTab() and self._window:
            if not link:
                self._window.statusBar().clearMessage()
            else:
                self._window.statusBar().showMessage(link)

    def _setIp(self, info):
        '''
        @param: info QHostInfo
        '''
        if not info.addresses():
            return

        self._currentIp = '%s (%s)' % (info.hostName(), info.addresses()[0].toString())

        if self._webTab.isCurrentTab():
            self.ipChanged.emit(self._currentIp)

    def _inspectElement(self):
        if self._webTab.haveInspector():
            self.triggerPageAction(QWebEnginePage.InspectElement)
        else:
            self._webTab.showWebInspector(True)

    # private:
    # override
    def _contextMenuEvent(self, event):
        '''
        @param: QContextMenuEvent
        '''
        self._menu.clear()

        # WebHitTestResult
        # TODO: check block execJavaScript?
        hitTest = self.page().hitTestContent(event.pos())
        self._createContextMenu(self._menu, hitTest)

        if WebInspector.isEnabled():
            self._menu.addSeparator()
            self._menu.addAction(_('Inspect Element'), self._inspectElement)

        if not self._menu.isEmpty():
            # Prevent choosing first option with double rightclick
            pos = event.globalPos()
            p = QPoint(pos.x(), pos.y() + 1)
            self._menu.popup(p)
            return

        super()._contextMenuEvent(event)

    # override
    def _mouseMoveEvent(self, event):
        '''
        @param: QMouseEvent
        '''
        if self._window and self._window.isFullScreen():
            if self._window.fullScreenNavigationVisible():
                self._window.hideNavigationWithFullScreen()
            elif event.y() < 5:
                self._window.showNavigationWithFullScreen()
        super()._mouseMoveEvent(event)