Python qtpy.PYQT5 Examples

The following are 7 code examples of qtpy.PYQT5(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module qtpy , or try the search function .
Example #1
Source File: test_macos_checks.py    From qtpy with MIT License 6 votes vote down vote up
def test_qt511_exception(mac_ver, monkeypatch):
    # Remove qtpy to reimport it again
    try:
        del sys.modules["qtpy"]
    except KeyError:
        pass

    # Patch stdlib to emulate a macOS system
    monkeypatch.setattr("sys.platform", 'darwin')
    mac_ver.return_value = ('10.10.3',)

    # Patch Qt version
    if PYQT5:
        monkeypatch.setattr("PyQt5.QtCore.QT_VERSION_STR", '5.11.1')
    else:
        monkeypatch.setattr("PySide2.QtCore.__version__", '5.11.1')

    # This should raise an Exception
    with pytest.raises(Exception) as e:
        import qtpy

    assert '10.11' in str(e.value)
    assert '5.11' in str(e.value) 
Example #2
Source File: test_macos_checks.py    From qtpy with MIT License 6 votes vote down vote up
def test_qt511_no_exception(mac_ver, monkeypatch):
    # Remove qtpy to reimport it again
    try:
        del sys.modules["qtpy"]
    except KeyError:
        pass

    # Patch stdlib to emulate a macOS system
    monkeypatch.setattr("sys.platform", 'darwin')
    mac_ver.return_value = ('10.13.2',)

    # Patch Qt version
    if PYQT5:
        monkeypatch.setattr("PyQt5.QtCore.QT_VERSION_STR", '5.11.1')
    else:
        monkeypatch.setattr("PySide2.QtCore.__version__", '5.11.1')

   # This should not raise an Exception
    try:
        import qtpy
    except Exception:
        pytest.fail("Error!") 
Example #3
Source File: graph_view.py    From pyflowgraph with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def wheelEvent(self, event):

        (xfo, invRes) = self.transform().inverted()
        topLeft = xfo.map(self.rect().topLeft())
        bottomRight = xfo.map(self.rect().bottomRight())
        center = ( topLeft + bottomRight ) * 0.5

        if PYQT5:
            zoomFactor = 1.0 + event.angleDelta().y() * self._mouseWheelZoomRate
        else:
             zoomFactor = 1.0 + event.delta() * self._mouseWheelZoomRate

        transform = self.transform()

        # Limit zoom to 3x
        if transform.m22() * zoomFactor >= 2.0:
            return

        self.scale(zoomFactor, zoomFactor)

        # Call udpate to redraw background
        self.update()


    ################################################
    ## Painting 
Example #4
Source File: mainwindow.py    From tellurium with Apache License 2.0 4 votes vote down vote up
def initialize():
    """Initialize Qt, patching sys.exit and eventually setting up ETS"""
    # This doesn't create our QApplication, just holds a reference to
    # MAIN_APP, created above to show our splash screen as early as
    # possible
    app = qapplication()

    # --- Set application icon
    app.setWindowIcon(APP_ICON)

    #----Monkey patching QApplication
    class FakeQApplication(QApplication):
        """Spyder's fake QApplication"""
        def __init__(self, args):
            self = app  # analysis:ignore
        @staticmethod
        def exec_():
            """Do nothing because the Qt mainloop is already running"""
            pass
    from qtpy import QtWidgets
    QtWidgets.QApplication = FakeQApplication

    # ----Monkey patching sys.exit
    def fake_sys_exit(arg=[]):
        pass
    sys.exit = fake_sys_exit

    # ----Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+
    if PYQT5:
        def spy_excepthook(type_, value, tback):
            sys.__excepthook__(type_, value, tback)
        sys.excepthook = spy_excepthook

    # Removing arguments from sys.argv as in standard Python interpreter
    sys.argv = ['']

    # Selecting Qt4 backend for Enthought Tool Suite (if installed)
    try:
        from enthought.etsconfig.api import ETSConfig
        ETSConfig.toolkit = 'qt4'
    except ImportError:
        pass

    return app 
Example #5
Source File: mainwindow.py    From tellurium with Apache License 2.0 4 votes vote down vote up
def report_issue(self, traceback=""):
        if PY3:
            from urllib.parse import quote
        else:
            from urllib import quote     # analysis:ignore
        versions = get_versions()
        # Get git revision for development version
        revision = ''
        if versions['revision']:
            revision = versions['revision']
        issue_template = """\
## Description

**What steps will reproduce the problem?**

1. 
2. 
3. 

**What is the expected output? What do you see instead?**


**Please provide any additional information below**

%s

## Version and main components

* Spyder Version: %s %s
* Python Version: %s
* Qt Versions: %s, %s %s on %s

## Dependencies
```
%s
```
""" % (traceback,
       versions['spyder'],
       revision,
       versions['python'],
       versions['qt'],
       versions['qt_api'],
       versions['qt_api_ver'],
       versions['system'],
       dependencies.status())

        url = QUrl("https://github.com/spyder-ide/spyder/issues/new")
        if PYQT5:
            from qtpy.QtCore import QUrlQuery
            query = QUrlQuery()
            query.addQueryItem("body", quote(issue_template))
            url.setQuery(query)
        else:
            url.addEncodedQueryItem("body", quote(issue_template))
            
        QDesktopServices.openUrl(url) 
Example #6
Source File: mainwindow.py    From tellurium with Apache License 2.0 4 votes vote down vote up
def initialize():
    """Initialize Qt, patching sys.exit and eventually setting up ETS"""
    # This doesn't create our QApplication, just holds a reference to
    # MAIN_APP, created above to show our splash screen as early as
    # possible
    app = qapplication()

    # --- Set application icon
    app.setWindowIcon(APP_ICON)

    #----Monkey patching QApplication
    class FakeQApplication(QApplication):
        """Spyder's fake QApplication"""
        def __init__(self, args):
            self = app  # analysis:ignore
        @staticmethod
        def exec_():
            """Do nothing because the Qt mainloop is already running"""
            pass
    from qtpy import QtWidgets
    QtWidgets.QApplication = FakeQApplication

    # ----Monkey patching sys.exit
    def fake_sys_exit(arg=[]):
        pass
    sys.exit = fake_sys_exit

    # ----Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+
    if PYQT5:
        def spy_excepthook(type_, value, tback):
            sys.__excepthook__(type_, value, tback)
        sys.excepthook = spy_excepthook

    # Removing arguments from sys.argv as in standard Python interpreter
    sys.argv = ['']

    # Selecting Qt4 backend for Enthought Tool Suite (if installed)
    try:
        from enthought.etsconfig.api import ETSConfig
        ETSConfig.toolkit = 'qt4'
    except ImportError:
        pass

    return app 
Example #7
Source File: table.py    From conda-manager with MIT License 4 votes vote down vote up
def __init__(self, parent):
        super(TableCondaPackages, self).__init__(parent)
        self._parent = parent
        self._searchbox = u''
        self._filterbox = const.ALL
        self._delegate = CustomDelegate(self)
        self.row_count = None
        self._advanced_mode = True
        self._current_hover_row = None
        self._menu = None
        self._palette = {}

        # To manage icon states
        self._model_index_clicked = None
        self.valid = False
        self.column_ = None
        self.current_index = None

        # To prevent triggering the keyrelease after closing a dialog
        # but hititng enter on it
        self.pressed_here = False

        self.source_model = None
        self.proxy_model = None

        self.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.setSelectionMode(QAbstractItemView.SingleSelection)
        self.verticalHeader().hide()
        self.setSortingEnabled(True)
        self.setMouseTracking(True)

        self.setAlternatingRowColors(True)
        self._delegate.current_row = self.current_row
        self._delegate.current_hover_row = self.current_hover_row
        self._delegate.update_index = self.update
        self._delegate.has_focus_or_context = self.has_focus_or_context
        self.setItemDelegate(self._delegate)
        self.setShowGrid(False)
        self.setWordWrap(True)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.horizontalHeader().setStretchLastSection(True)

        # Header setup
        self._hheader = self.horizontalHeader()
        if PYQT5:
            self._hheader.setSectionResizeMode(self._hheader.Fixed)
        else:
            self._hheader.setResizeMode(self._hheader.Fixed)
#        self._hheader.setStyleSheet("""QHeaderView {border: 0px;
#                                                    border-radius: 0px;};
#                                                    """)
        self.sortByColumn(const.COL_NAME, Qt.AscendingOrder)
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.hide_columns()