Example #1
0
    def __init__(self, *args, **kwargs):
        super(EventRecordingApp, self).__init__(*args, **kwargs)
        self._notify = functools.partial(QApplication.notify,
                                         QApplication.instance())

        # Since playback speed can be laggy (especially if running from a VM),
        #  we want to give a generous double-click timeout.
        # Unfortunately, this API is NOT supported in Qt5!
        # When we upgrade from Qt4, we'll have to find some alternative solution...
        assert QT_VERSION_STR.startswith(
            '4'
        ), "Qt5 does not allow use to use setDoubleClickInterval().  Recordings may not playback well."
        self.setDoubleClickInterval(1000)
        self.setStartDragTime(1000)

        # Lazy import here because there can be subtle problems
        #  if this is imported BEFORE the app is created.
        from eventcapture.eventRecorderGui import EventRecorderGui

        # We keep the recorder control window as a member of the app
        # to ensure that it isn't deleted while the app is alive
        # (It does not belong to the MainWindow.)
        self.recorder_control_window = EventRecorderGui()
    def onFinishLoading(self):
        """
        On finish loading
        """
        self.webTitle.setText("Title: %s" % self.webView.title())

        # need complete refonte with qt5
        if QT_VERSION_STR.startswith("5."):
            return

        frame = self.webView.page().mainFrame()
        document = frame.documentElement()

        elements = []
        self.examineChildElements(document, elements)

        tagList = {}
        idList = {}
        classList = {}
        nameList = {}
        linkList = {}
        cssList = {}

        for el in elements:
            # by tagname
            if 'tagname' in el:
                if el['tagname'] not in tagList: tagList[el['tagname']] = ''

            # by id
            if 'id' in el:
                if el['id'] not in idList: idList[el['id']] = ''

            # by name
            if 'name' in el:
                if el['name'] not in nameList: nameList[el['name']] = ''

            # by class
            if 'class' in el:
                if el['class'] not in classList:
                    classList[el['class'].replace(" ", ".")] = ''

            # by link text
            if 'text' in el:
                if 'tagname' in el:
                    if sys.version_info > (3, ):
                        if el['tagname'].lower() == 'a':
                            if el['text'] not in linkList:
                                linkList[el['text']] = ''
                    else:
                        if str(el['tagname']).lower() == 'a':
                            if el['text'] not in linkList:
                                linkList[el['text']] = ''

            # by css selector
            if 'tagname' in el:
                if sys.version_info > (3, ):
                    cssSelector = "%s" % el['tagname'].lower()
                else:
                    cssSelector = "%s" % str(el['tagname']).lower()
                if 'id' in el:
                    cssSelector += "#%s" % el['id']
                if 'class' in el:
                    cssSelector += ".%s" % el['class'].replace(" ", ".")
                cssList[cssSelector] = ''

        self.TagsHtml.emit(tagList, idList, classList, nameList, linkList,
                           cssList)
    def createWidgets(self):
        """
        Create all qt widgets
        """
        self.setWindowTitle(self.tr("Extensive Testing Client - Web Browser"))
        self.setWindowIcon(QIcon(":/main.png"))

        self.dockToolbarWebBrowser = QToolBar(self)
        self.dockToolbarWebBrowser.setToolButtonStyle(
            Qt.ToolButtonTextBesideIcon)

        browserLayoutGroup = QVBoxLayout()
        browserLayoutGroup.addWidget(self.dockToolbarWebBrowser)

        toolbarBrowserLayoutGroup = QHBoxLayout()

        self.locationEdit = QLineEdit(self)
        self.locationEdit.setSizePolicy(
            QSizePolicy.Expanding,
            self.locationEdit.sizePolicy().verticalPolicy())

        self.webCounter = QLabel("(0%)")

        toolbarBrowserLayoutGroup.addWidget(QLabel("Load URL:"))
        toolbarBrowserLayoutGroup.addWidget(self.webCounter)
        toolbarBrowserLayoutGroup.addWidget(self.locationEdit)

        self.webTitle = QLabel("Title:")

        self.webView = QWebView()

        if QtHelper.str2bool(
                Settings.instance().readValue(key='Server/proxy-web-active')):

            proxy = QNetworkProxy()
            proxy.setType(3)
            # http
            proxy.setHostName(
                Settings.instance().readValue(key='Server/addr-proxy-http'))
            proxy.setPort(
                int(Settings.instance().readValue(
                    key='Server/port-proxy-http')))
            self.webView.page().networkAccessManager().setProxy(proxy)

        if QT_VERSION_STR.startswith("4."):
            self.webInspector = QWebInspector()
            self.webView.settings().setAttribute(
                QWebSettings.DeveloperExtrasEnabled, True)
            self.webInspector.setPage(self.webView.page())

        self.webView.setHtml(
            '<html><head></head><body>No content loaded</body></html>')
        self.webView.settings().setAttribute(QWebSettings.PluginsEnabled, True)
        self.webView.settings().setAttribute(
            QWebSettings.JavascriptCanOpenWindows, True)

        browserLayoutGroup.addLayout(toolbarBrowserLayoutGroup)
        browserLayoutGroup.addWidget(self.webTitle)

        self.webTab = QTabWidget()
        self.webTab.addTab(self.webView, "Web Page")
        if QT_VERSION_STR.startswith("4."):
            self.webTab.addTab(self.webInspector, "Source Inspector")

        browserLayoutGroup.addWidget(self.webTab)

        self.setLayout(browserLayoutGroup)