`PyQt5` + `pyqtgraph` import updates (`QtGui -> `QtWidgets`)

pg_exts_fork
Tyler Goodlet 2022-10-30 21:11:14 -04:00
parent 11ecf9cb09
commit 5976acbe76
5 changed files with 56 additions and 28 deletions

View File

@ -111,7 +111,8 @@ class LevelMarker(QGraphicsPathItem):
# get polygon and scale # get polygon and scale
super().__init__() super().__init__()
self.scale(size, size) # self.setScale(size, size)
self.setScale(size)
# interally generates path # interally generates path
self._style = None self._style = None

View File

@ -26,7 +26,19 @@ from typing import (
) )
import pyqtgraph as pg import pyqtgraph as pg
from pyqtgraph import ViewBox, Point, QtCore, QtGui from pyqtgraph import (
ViewBox,
Point,
QtCore,
QtWidgets,
)
from PyQt5.QtGui import (
QColor,
)
from PyQt5.QtWidgets import (
QLabel,
)
from pyqtgraph import functions as fn from pyqtgraph import functions as fn
from PyQt5.QtCore import QPointF from PyQt5.QtCore import QPointF
import numpy as np import numpy as np
@ -240,7 +252,7 @@ class LineEditor(Struct):
return lines return lines
class SelectRect(QtGui.QGraphicsRectItem): class SelectRect(QtWidgets.QGraphicsRectItem):
def __init__( def __init__(
self, self,
@ -249,12 +261,12 @@ class SelectRect(QtGui.QGraphicsRectItem):
) -> None: ) -> None:
super().__init__(0, 0, 1, 1) super().__init__(0, 0, 1, 1)
# self.rbScaleBox = QtGui.QGraphicsRectItem(0, 0, 1, 1) # self.rbScaleBox = QGraphicsRectItem(0, 0, 1, 1)
self.vb = viewbox self.vb = viewbox
self._chart: 'ChartPlotWidget' = None # noqa self._chart: 'ChartPlotWidget' = None # noqa
# override selection box color # override selection box color
color = QtGui.QColor(hcolor(color)) color = QColor(hcolor(color))
self.setPen(fn.mkPen(color, width=1)) self.setPen(fn.mkPen(color, width=1))
color.setAlpha(66) color.setAlpha(66)
self.setBrush(fn.mkBrush(color)) self.setBrush(fn.mkBrush(color))
@ -262,7 +274,7 @@ class SelectRect(QtGui.QGraphicsRectItem):
self.hide() self.hide()
self._label = None self._label = None
label = self._label = QtGui.QLabel() label = self._label = QLabel()
label.setTextFormat(0) # markdown label.setTextFormat(0) # markdown
label.setFont(_font.font) label.setFont(_font.font)
label.setMargin(0) label.setMargin(0)
@ -299,8 +311,8 @@ class SelectRect(QtGui.QGraphicsRectItem):
# TODO: get bg color working # TODO: get bg color working
palette.setColor( palette.setColor(
self._label.backgroundRole(), self._label.backgroundRole(),
# QtGui.QColor(chart.backgroundBrush()), # QColor(chart.backgroundBrush()),
QtGui.QColor(hcolor('papas_special')), QColor(hcolor('papas_special')),
) )
def update_on_resize(self, vr, r): def update_on_resize(self, vr, r):

View File

@ -20,19 +20,24 @@ Trio - Qt integration
Run ``trio`` in guest mode on top of the Qt event loop. Run ``trio`` in guest mode on top of the Qt event loop.
All global Qt runtime settings are mostly defined here. All global Qt runtime settings are mostly defined here.
""" """
from __future__ import annotations
from typing import ( from typing import (
Callable, Callable,
Any, Any,
Type, Type,
TYPE_CHECKING,
) )
import platform import platform
import traceback import traceback
# Qt specific # Qt specific
import PyQt5 # noqa import PyQt5 # noqa
from pyqtgraph import QtGui from PyQt5.QtWidgets import (
QWidget,
QMainWindow,
QApplication,
)
from PyQt5 import QtCore from PyQt5 import QtCore
# from PyQt5.QtGui import QLabel, QStatusBar
from PyQt5.QtCore import ( from PyQt5.QtCore import (
pyqtRemoveInputHook, pyqtRemoveInputHook,
Qt, Qt,
@ -49,6 +54,7 @@ from ..log import get_logger
from ._pg_overrides import _do_overrides from ._pg_overrides import _do_overrides
from . import _style from . import _style
log = get_logger(__name__) log = get_logger(__name__)
# pyqtgraph global config # pyqtgraph global config
@ -76,17 +82,17 @@ if platform.system() == "Windows":
def run_qtractor( def run_qtractor(
func: Callable, func: Callable,
args: tuple, args: tuple,
main_widget_type: Type[QtGui.QWidget], main_widget_type: Type[QWidget],
tractor_kwargs: dict[str, Any] = {}, tractor_kwargs: dict[str, Any] = {},
window_type: QtGui.QMainWindow = None, window_type: QMainWindow = None,
) -> None: ) -> None:
# avoids annoying message when entering debugger from qt loop # avoids annoying message when entering debugger from qt loop
pyqtRemoveInputHook() pyqtRemoveInputHook()
app = QtGui.QApplication.instance() app = QApplication.instance()
if app is None: if app is None:
app = PyQt5.QtWidgets.QApplication([]) app = QApplication([])
# TODO: we might not need this if it's desired # TODO: we might not need this if it's desired
# to cancel the tractor machinery on Qt loop # to cancel the tractor machinery on Qt loop

View File

@ -32,6 +32,7 @@ from PyQt5.QtGui import QPainterPath
from .._profile import pg_profile_enabled, ms_slower_then from .._profile import pg_profile_enabled, ms_slower_then
from ._style import hcolor from ._style import hcolor
from ..log import get_logger from ..log import get_logger
from .._profile import Profiler
if TYPE_CHECKING: if TYPE_CHECKING:
from ._chart import LinkedSplits from ._chart import LinkedSplits
@ -170,7 +171,7 @@ class BarItems(pg.GraphicsObject):
) -> None: ) -> None:
profiler = pg.debug.Profiler( profiler = Profiler(
disabled=not pg_profile_enabled(), disabled=not pg_profile_enabled(),
ms_threshold=ms_slower_then, ms_threshold=ms_slower_then,
) )

View File

@ -28,10 +28,19 @@ from typing import (
) )
import uuid import uuid
from pyqtgraph import QtGui
from PyQt5 import QtCore from PyQt5 import QtCore
from PyQt5.QtWidgets import QLabel, QStatusBar from PyQt5.QtWidgets import (
QWidget,
QMainWindow,
QApplication,
QLabel,
QStatusBar,
)
from PyQt5.QtGui import (
QScreen,
QCloseEvent,
)
from ..log import get_logger from ..log import get_logger
from ._style import _font_small, hcolor from ._style import _font_small, hcolor
from ._chart import GodWidget from ._chart import GodWidget
@ -153,7 +162,7 @@ class MultiStatus:
self.bar.clearMessage() self.bar.clearMessage()
class MainWindow(QtGui.QMainWindow): class MainWindow(QMainWindow):
# XXX: for tiling wms this should scale # XXX: for tiling wms this should scale
# with the alloted window size. # with the alloted window size.
@ -176,12 +185,12 @@ class MainWindow(QtGui.QMainWindow):
self._size: Optional[tuple[int, int]] = None self._size: Optional[tuple[int, int]] = None
@property @property
def mode_label(self) -> QtGui.QLabel: def mode_label(self) -> QLabel:
# init mode label # init mode label
if not self._status_label: if not self._status_label:
self._status_label = label = QtGui.QLabel() self._status_label = label = QLabel()
label.setStyleSheet( label.setStyleSheet(
f"""QLabel {{ f"""QLabel {{
color : {hcolor('gunmetal')}; color : {hcolor('gunmetal')};
@ -203,8 +212,7 @@ class MainWindow(QtGui.QMainWindow):
def closeEvent( def closeEvent(
self, self,
event: QCloseEvent,
event: QtGui.QCloseEvent,
) -> None: ) -> None:
'''Cancel the root actor asap. '''Cancel the root actor asap.
@ -244,8 +252,8 @@ class MainWindow(QtGui.QMainWindow):
def on_focus_change( def on_focus_change(
self, self,
last: QtGui.QWidget, last: QWidget,
current: QtGui.QWidget, current: QWidget,
) -> None: ) -> None:
@ -256,12 +264,12 @@ class MainWindow(QtGui.QMainWindow):
name = getattr(current, 'mode_name', '') name = getattr(current, 'mode_name', '')
self.set_mode_name(name) self.set_mode_name(name)
def current_screen(self) -> QtGui.QScreen: def current_screen(self) -> QScreen:
''' '''
Get a frickin screen (if we can, gawd). Get a frickin screen (if we can, gawd).
''' '''
app = QtGui.QApplication.instance() app = QApplication.instance()
for _ in range(3): for _ in range(3):
screen = app.screenAt(self.pos()) screen = app.screenAt(self.pos())
@ -294,7 +302,7 @@ class MainWindow(QtGui.QMainWindow):
''' '''
# https://stackoverflow.com/a/18975846 # https://stackoverflow.com/a/18975846
if not size and not self._size: if not size and not self._size:
# app = QtGui.QApplication.instance() # app = QApplication.instance()
geo = self.current_screen().geometry() geo = self.current_screen().geometry()
h, w = geo.height(), geo.width() h, w = geo.height(), geo.width()
# use approx 1/3 of the area of the screen by default # use approx 1/3 of the area of the screen by default
@ -331,7 +339,7 @@ class MainWindow(QtGui.QMainWindow):
# singleton app per actor # singleton app per actor
_qt_win: QtGui.QMainWindow = None _qt_win: QMainWindow = None
def main_window() -> MainWindow: def main_window() -> MainWindow: