Ejemplo n.º 1
0
    Author: YingzhiGou
    Date: 20/06/2017
"""

import abc
import inspect
import traceback

import matplotlib
import matplotlib.pyplot as plt
from qtpy import QtCore, QT_VERSION
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QWidget, QVBoxLayout
from matplotlib.figure import Figure

if QT_VERSION.startswith('4'):
    from matplotlib.backends.backend_qt4agg import FigureCanvas
    from matplotlib.backends.backend_qt4 import NavigationToolbar2QT as NavigationToolbar
else:
    from matplotlib.backends.backend_qt5agg import FigureCanvas
    from matplotlib.backends.backend_qt5 import NavigationToolbar2QT as NavigationToolbar

from mtpy.gui.SmartMT.Components.plot_parameter import PlotParameter
from mtpy.utils.mtpylog import MtPyLog


class VisualizationBase(QtCore.QThread):
    """
    plugin base for data visualization
    """
Ejemplo n.º 2
0
# syntax_style for the console must be one of the supported styles from
# pygments - see here for examples https://help.farbox.com/pygments.html
import re
from ast import literal_eval

try:
    from qtpy import QT_VERSION

    major, minor, *rest = QT_VERSION.split('.')
    use_gradients = (int(major) >= 5) and (int(minor) >= 12)
except Exception:
    use_gradients = False

palettes = {
    'dark': {
        'folder': 'dark',
        'background': 'rgb(38, 41, 48)',
        'foreground': 'rgb(65, 72, 81)',
        'primary': 'rgb(90, 98, 108)',
        'secondary': 'rgb(134, 142, 147)',
        'highlight': 'rgb(106, 115, 128)',
        'text': 'rgb(240, 241, 242)',
        'icon': 'rgb(209, 210, 212)',
        'warning': 'rgb(153, 18, 31)',
        'current': 'rgb(0, 122, 204)',
        'syntax_style': 'native',
        'console': 'rgb(0, 0, 0)',
        'canvas': 'black',
    },
    'light': {
        'folder': 'light',
Ejemplo n.º 3
0
try:
    import msgpack
    MSGPACK_SUPPORT = True
except ImportError:
    MSGPACK_SUPPORT = False

try:
    import cbor
    CBOR_SUPPORT = True
except ImportError:
    CBOR_SUPPORT = False


# @Future: when Qt 5.6 becomes standard, remove this:
QT_VER = QT_VERSION.split('.')
if QT_VER[0] == '5' and int(QT_VER[1]) < 6:
    QT55_COMPAT = True
else:
    QT55_COMPAT = False


# Maybe there should be one common enum with all options instead of
# one enum for each thing? I guess I'll decide when there will be
# more than one thing in total.
class Exc_Indication(enum.IntEnum):
    RED_BG = 0
    MSG_ICON = 1
    ICON_AND_RED_BG = 2

Ejemplo n.º 4
0
_thread_lock.acquire()

_GUI_RESOURCE_BUILT = False

if not _GUI_RESOURCE_BUILT:
    logger = MtPyLog.get_mtpy_logger(__name__)

    from qtpy.uic import compileUiDir
    from qtpy import QT_VERSION

    if getattr(sys, 'frozen', False):
        # running in a pyinstaller bundle
        _dir = os.path.join(sys._MEIPASS, "mtpy/gui/SmartMT/ui_asset")
        sys.path.append(sys._MEIPASS)
    else:
        _dir = os.path.dirname(__file__)

    if QT_VERSION.startswith("4"):
        _resource_suffix = "_py{python_version}_qt4_rc".format(python_version=sys.version_info[0])
    else:
        _resource_suffix = "_qt5_rc"

    logger.debug("Setting PyQt resource suffix to {}".format(_resource_suffix))
    logger.debug("compiling Qt .ui designer files ...")
    compileUiDir(_dir, recurse=True, resource_suffix=_resource_suffix)
    del _dir, _resource_suffix
    _GUI_RESOURCE_BUILT = True

_thread_lock.release()
del _thread_lock
Ejemplo n.º 5
0
    Date: 20/06/2017
"""
import inspect
import os
import sys
import webbrowser

import sip
from qtpy import QtCore
from qtpy.QtWidgets import QMainWindow, QWidget, qApp, QMessageBox, QFileDialog, QDialog, QWizard, QMdiArea, QAction, \
    QMdiSubWindow, QApplication

from qtpy import QT_VERSION
import matplotlib

if QT_VERSION.startswith("4"):
    matplotlib.use("Qt4Agg")
elif QT_VERSION.startswith("5"):
    matplotlib.use("Qt5Agg")

from mtpy.core.edi_collection import EdiCollection
from mtpy.gui.SmartMT.gui.busy_indicators import ProgressBar
from mtpy.gui.SmartMT.gui.export_dialog import ExportDialog
from mtpy.gui.SmartMT.gui.export_dialog_modem import ExportDialogModEm
from mtpy.gui.SmartMT.gui.plot_option import PlotOption
from mtpy.gui.SmartMT.gui.station_summary import StationSummary
from mtpy.gui.SmartMT.gui.station_viewer import StationViewer
from mtpy.gui.SmartMT.ui_asset.main_window import Ui_SmartMT_MainWindow
from mtpy.gui.SmartMT.utils.file_handler import FileHandler, FileHandlingException
from mtpy.gui.SmartMT.visualization.visualization_base import MPLCanvasWidget
from mtpy.utils.decorator import deprecated
Ejemplo n.º 6
0
from qtpy import QT_VERSION
from qtpy.QtWidgets import QSlider  # noqa
from superqt import QDoubleSlider

# here until we can debug why labeled sliders render differently on 5.12
if tuple(int(x) for x in QT_VERSION.split(".")) >= (5, 14):
    from superqt import QLabeledDoubleSlider as QDoubleSlider  # noqa
    from superqt import QLabeledSlider as QSlider  # noqa
Ejemplo n.º 7
0
#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from qtpy import QT_VERSION
from . import QT_API, PYQT4_API, PYQT5_API

__version__ = QT_VERSION
__version_info__ = tuple(map(int, QT_VERSION.split('.')))
from qtpy.QtCore import *

if QT_API in PYQT4_API or QT_API in PYQT5_API:
    QDateTime.toPython = QDateTime.__dict__['toPyDateTime']
    QDate.toPython = QDate.__dict__['toPyDate']
    QTime.toPython = QTime.__dict__['toPyTime']
    # Remove the input hook or pdb.set_trace() will infinitely recurse
    pyqtRemoveInputHook()
Ejemplo n.º 8
0
    expected_column -= 3
    qtbot.keyPress(editor, Qt.Key_Delete)
    assert editor.textCursor().columnNumber() == expected_column
    qtbot.keyPress(editor, Qt.Key_Down)
    assert editor.textCursor().columnNumber() == expected_column

    # However, this second subtest does trigger the original bug
    for press in range(3):
        qtbot.keyPress(editor, Qt.Key_Right, Qt.ShiftModifier)
    qtbot.keyPress(editor, Qt.Key_Delete)
    assert editor.textCursor().columnNumber() == expected_column
    qtbot.keyPress(editor, Qt.Key_Up)
    assert editor.textCursor().columnNumber() == expected_column


@pytest.mark.skipif(QT_VERSION.startswith('5.15'), reason='Fixed on Qt 5.15')
def test_qtbug35861(qtbot):
    """This test will detect if upstream QTBUG-35861 is fixed.
    If that happens, then the workarounds for spyder-ide/spyder#12663
    can be removed. Such a fix would probably only happen in the most
    recent Qt version however...
    See also https://bugreports.qt.io/browse/QTBUG-35861
    """
    widget = QTextEdit(None)
    qtbot.addWidget(widget)
    widget.show()

    cursor = widget.textCursor()
    cursor.setPosition(0)
    # Build the text from a single character since a non-fixed width
    # font is used by default.
Ejemplo n.º 9
0
from typing import Optional, Any, Union, Type

from qtpy.QtCore import Qt, QObject, QRegExp
from qtpy.QtGui import QPainter, QPixmap, QIcon
from qtpy.QtWidgets import QApplication
from qtpy import QT_VERSION
# if needed, you can import specific boolean API variables from this module
# when implementing API code elsewhere
from qtpy import API, PYQT4, PYQT5, PYSIDE, PYSIDE2

from .dock_splitter import DockSplitter

DEBUG_LEVEL = 0
QT_VERSION_TUPLE = tuple(int(i) for i in QT_VERSION.split('.')[:3])
del QT_VERSION


def emit_top_level_event_for_widget(widget: Optional['DockWidget'],
                                    floating: bool):
    '''
    Call this function to emit a topLevelChanged() signal and to update the
    dock area tool bar visibility

    Parameters
    ----------
    widget : DockWidget
        The top-level dock widget
    floating : bool
    '''
    if widget is None:
        return
from qtpy import PYQT6, PYSIDE2, PYSIDE6, QT_VERSION
from qtpy.QtWidgets import QApplication
from qtpy.QtWidgets import QHeaderView
from qtpy.QtCore import Qt
from qtpy.QtCore import QAbstractListModel


def get_qapp(icon_path=None):
    qapp = QApplication.instance()
    if qapp is None:
        qapp = QApplication([''])
    return qapp


@pytest.mark.skipif(
    QT_VERSION.startswith('5.15') or PYSIDE6 or PYQT6 or
    ((PYSIDE2) and sys.version_info.major == 3 and sys.version_info.minor >= 8
     and (sys.platform == 'darwin' or sys.platform.startswith('linux'))
    ),
    reason="Segfaults with Qt 5.15; and PySide2/Python 3.8+ on Mac and Linux")
def test_patched_qheaderview():
    """
    This will test whether QHeaderView has the new methods introduced in Qt5.
    It will then create an instance of QHeaderView and test that no exceptions
    are raised and that some basic behaviour works.
    """
    assert QHeaderView.sectionsClickable is not None
    assert QHeaderView.sectionsMovable is not None
    assert QHeaderView.sectionResizeMode is not None
    assert QHeaderView.setSectionsClickable is not None
    assert QHeaderView.setSectionsMovable is not None
Ejemplo n.º 11
0
#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from qtpy import QT_VERSION
from . import QT_API, PYQT4_API, PYQT5_API

__version__ = QT_VERSION
__version_info__ = tuple(map(int, QT_VERSION.split('.')))
from qtpy.QtCore import *

if QT_API in PYQT4_API or QT_API in PYQT5_API:
    QDateTime.toPython = QDateTime.__dict__['toPyDateTime']
    QDate.toPython = QDate.__dict__['toPyDate']
    QTime.toPython = QTime.__dict__['toPyTime']
    # Remove the input hook or pdb.set_trace() will infinitely recurse
    pyqtRemoveInputHook()
Ejemplo n.º 12
0
 def qt_version(self):
     return tuple(int(v) for v in QT_VERSION.split('.'))