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)
from PyQt4.QtGui import QDialog, QVBoxLayout, QGridLayout, \ QLabel, QComboBox, QHBoxLayout, QRadioButton, \ QPushButton, QApplication, QColorDialog, QMainWindow, \ QWidget, QTreeWidgetItem, QButtonGroup, QTreeWidget, \ QSplitter, QTabWidget, QMenuBar, QMessageBox, QSpacerItem, \ QLineEdit, QHeaderView, QSpinBox, QTextBrowser, \ QMenu, QAction, QTabBar, QStackedWidget, QFileDialog, \ QScrollArea, QProgressBar, QStyleOptionSlider, QGroupBox, \ QAbstractItemView, QSizePolicy, QFrame, QStyle, QScrollBar, QToolBar, \ QDialogButtonBox, QToolButton, QCheckBox, QLayout from PyQt4.QtGui import QFont, QIcon, QFontMetrics, QPen, QColor, QPainter, \ QPixmap, QBrush, QPainterPath , QDesktopServices from PyQt4.QtCore import QObject, QTimer, QProcess, QEvent, QSize, \ QLine, QRect, QPoint, QRectF, QUrl, QCoreApplication, \ pyqtSignal from PyQt4.QtGui import QPrinter, QPrintDialog, qApp from PyQt4.QtCore import QT_VERSION_STR def getQApp(): return qApp g_rc.qt_imported = True g_rc.qt_variant = 'PyQt4' g_rc.qt_version = map(int, QT_VERSION_STR.split(".")) except: pass
customWidgets={'Line': QtGui.QFrame}) sys.modules["PySide.uic"] = uic matplotlib.rcParams['backend.qt4'] = 'PySide' Qt_version = QtCore.__version_info__ else: try: from PyQt4 import QtGui, QtCore, uic, QtWebKit from PyQt4.QtCore import SIGNAL, pyqtSignal as Signal except ImportError: has_Qt = False from PyQt4.QtCore import QT_VERSION_STR from PyQt4.Qt import PYQT_VERSION_STR from sip import SIP_VERSION_STR Qt_version = tuple(int(i) for i in QT_VERSION_STR.split(".")[:3]) SIP_version = tuple(int(i) for i in SIP_VERSION_STR.split(".")[:3]) PyQt_version = tuple(int(i) for i in PYQT_VERSION_STR.split(".")[:3]) if has_Qt: matplotlib.rcParams['backend'] = 'Qt4Agg' import matplotlib.pyplot matplotlib.pyplot.switch_backend('Qt4Agg') # Dear reader, I apologize for something that ugly ! # Any cleaner version would be appreciated # matplotlib.use('Qt4Agg') from matplotlib.backends import backend_qt4 as backend from matplotlib import pyplot from matplotlib import pylab else:
QTreeView, QTreeWidget, QTreeWidgetItem, QTreeWidgetItemIterator, QValidator, QVBoxLayout, QWidget, ) from PyQt4.uic import loadUi def getQApp(): return qApp qt_imported = True qt_variant = "PyQt4" qt_version_no = list(map(int, QT_VERSION_STR.split("."))) _ver = PYQT_VERSION_STR.split(".") ver = _ver + ["0"] * (3 - len(_ver)) pyqt_version_no = list(map(int, ver))[:3] except BaseException: pass try: from PyQt4.QtWebKit import QWebPage except ImportError: pass # # PySide # if (qt_variant == "PySide") or (qt_variant is None and not qt_imported):
customWidgets={'Line': QtGui.QFrame}) sys.modules["PySide.uic"] = uic matplotlib.rcParams['backend.qt4'] = 'PySide' Qt_version = QtCore.__version_info__ else: try: from PyQt4 import QtGui, QtCore, uic, QtWebKit from PyQt4.QtCore import SIGNAL, pyqtSignal as Signal except ImportError: has_Qt = False else: from PyQt4.QtCore import QT_VERSION_STR from PyQt4.Qt import PYQT_VERSION_STR from sip import SIP_VERSION_STR Qt_version = tuple(int(i) for i in QT_VERSION_STR.split(".")[:3]) SIP_version = tuple(int(i) for i in SIP_VERSION_STR.split(".")[:3]) PyQt_version = tuple(int(i) for i in PYQT_VERSION_STR.split(".")[:3]) if has_Qt: matplotlib.rcParams['backend'] = 'Qt4Agg' import matplotlib.pyplot matplotlib.pyplot.switch_backend('Qt4Agg') # Dear reader, I apologize for something that ugly ! # Any cleaner version would be appreciated # matplotlib.use('Qt4Agg') from matplotlib.backends import backend_qt4 as backend from matplotlib import pyplot from matplotlib import pylab else: