Compare commits

..

No commits in common. "1fd8654ca5bbbd2bb43bc8ca65c60a934c953403" and "3d03781810707520a82278ea541f80c6178b7074" have entirely different histories.

28 changed files with 220 additions and 440 deletions

View File

@ -14,8 +14,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
UI components built using `Qt` with major versions swapped in via
the import indirection in the `.qt` sub-mod.
"""
Stuff for your eyes, aka super hawt Qt UI components.
'''
Currently we only support PyQt5 due to this issue in Pyside2:
https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1313
"""

View File

@ -21,10 +21,8 @@ Anchor funtions for UI placement of annotions.
from __future__ import annotations
from typing import Callable, TYPE_CHECKING
from piker.ui.qt import (
QPointF,
QGraphicsPathItem,
)
from PyQt5.QtCore import QPointF
from PyQt5.QtWidgets import QGraphicsPathItem
if TYPE_CHECKING:
from ._chart import ChartPlotWidget

View File

@ -20,22 +20,12 @@ Annotations for ur faces.
"""
from typing import Callable
from pyqtgraph import (
Point,
functions as fn,
Color,
)
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QPointF, QRectF
from PyQt5.QtWidgets import QGraphicsPathItem
from pyqtgraph import Point, functions as fn, Color
import numpy as np
from piker.ui.qt import (
QtCore,
QtGui,
QtWidgets,
QPointF,
QRectF,
QGraphicsPathItem,
)
def mk_marker_path(

View File

@ -21,11 +21,9 @@ Main app startup and run.
from functools import partial
from types import ModuleType
from PyQt5.QtCore import QEvent
import trio
from piker.ui.qt import (
QEvent,
)
from ..service import maybe_spawn_brokerd
from . import _event
from ._exec import run_qtractor

View File

@ -25,16 +25,9 @@ from math import floor
import polars as pl
import pyqtgraph as pg
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QPointF
from piker.ui.qt import (
QtCore,
QtGui,
QtWidgets,
QPointF,
txt_flag,
align_flag,
px_cache_mode,
)
from . import _pg_overrides as pgo
from ..accounting._mktinfo import float_digits
from ._label import Label
@ -421,15 +414,11 @@ class AxisLabel(pg.GraphicsObject):
super().__init__()
self.setParentItem(parent)
self.setFlag(
self.GraphicsItemFlag.ItemIgnoresTransformations
)
self.setFlag(self.ItemIgnoresTransformations)
self.setZValue(100)
# XXX: pretty sure this is faster
self.setCacheMode(
px_cache_mode.DeviceCoordinateCache
)
self.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache)
self._parent = parent
@ -566,14 +555,21 @@ class AxisLabel(pg.GraphicsObject):
return (self.rect.width(), self.rect.height())
# _common_text_flags = (
# QtCore.Qt.TextDontClip |
# QtCore.Qt.AlignCenter |
# QtCore.Qt.AlignTop |
# QtCore.Qt.AlignHCenter |
# QtCore.Qt.AlignVCenter
# )
class XAxisLabel(AxisLabel):
_x_margin = 8
text_flags = (
align_flag.AlignCenter
| txt_flag.TextDontClip
QtCore.Qt.TextDontClip
| QtCore.Qt.AlignCenter
)
def size_hint(self) -> tuple[float, float]:
@ -630,10 +626,10 @@ class YAxisLabel(AxisLabel):
_y_margin: int = 4
text_flags = (
align_flag.AlignLeft
| align_flag.AlignVCenter
# | align_flag.AlignHCenter
| txt_flag.TextDontClip
QtCore.Qt.AlignLeft
# QtCore.Qt.AlignHCenter
| QtCore.Qt.AlignVCenter
| QtCore.Qt.TextDontClip
)
def __init__(

View File

@ -28,20 +28,22 @@ from typing import (
TYPE_CHECKING,
)
import pyqtgraph as pg
import trio
from piker.ui.qt import (
QtCore,
QtWidgets,
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import (
Qt,
QLineF,
# QPointF,
)
from PyQt5.QtWidgets import (
QFrame,
QWidget,
QHBoxLayout,
QVBoxLayout,
QSplitter,
)
import pyqtgraph as pg
import trio
from ._axes import (
DynamicDateAxis,
PriceAxis,
@ -568,8 +570,8 @@ class LinkedSplits(QWidget):
# style?
self.chart.setFrameStyle(
QFrame.Shape.StyledPanel |
QFrame.Shadow.Plain
QFrame.StyledPanel |
QFrame.Plain
)
return self.chart
@ -687,8 +689,8 @@ class LinkedSplits(QWidget):
cpw.plotItem.vb.linked = self
cpw.setFrameStyle(
QFrame.Shape.StyledPanel
# | QFrame.Shadow.Plain
QtWidgets.QFrame.StyledPanel
# | QtWidgets.QFrame.Plain
)
# don't show the little "autoscale" A label.

View File

@ -28,14 +28,9 @@ from typing import (
import inspect
import numpy as np
import pyqtgraph as pg
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import QPointF, QRectF
from piker.ui.qt import (
QPointF,
QRectF,
QtCore,
QtWidgets,
px_cache_mode,
)
from ._style import (
_xaxis_at,
hcolor,
@ -109,9 +104,7 @@ class LineDot(pg.CurvePoint):
dot.setParentItem(self)
# keep a static size
self.setFlag(
self.GraphicsItemFlag.ItemIgnoresTransformations
)
self.setFlag(self.ItemIgnoresTransformations)
def event(
self,
@ -431,10 +424,10 @@ class Cursor(pg.GraphicsObject):
# vertical and horizonal lines and a y-axis label
vl = plot.addLine(x=0, pen=self.lines_pen, movable=False)
vl.setCacheMode(px_cache_mode.DeviceCoordinateCache)
vl.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache)
hl = plot.addLine(y=0, pen=self.lines_pen, movable=False)
hl.setCacheMode(px_cache_mode.DeviceCoordinateCache)
hl.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache)
hl.hide()
yl = YAxisLabel(
@ -518,10 +511,7 @@ class Cursor(pg.GraphicsObject):
plot=chart
)
chart.addItem(cursor)
self.graphics[chart].setdefault(
'cursors',
[],
).append(cursor)
self.graphics[chart].setdefault('cursors', []).append(cursor)
return cursor
def mouseAction(

View File

@ -19,21 +19,20 @@ Fast, smooth, sexy curves.
"""
from contextlib import contextmanager as cm
from enum import EnumType
from typing import Callable
import numpy as np
import pyqtgraph as pg
from piker.ui.qt import (
QtWidgets,
QGraphicsItem,
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QGraphicsItem
from PyQt5.QtCore import (
Qt,
QLineF,
QRectF,
)
from PyQt5.QtGui import (
QPainter,
QPainterPath,
px_cache_mode,
)
from ._style import hcolor
from ..log import get_logger
@ -43,16 +42,15 @@ from ..toolz.profile import (
ms_slower_then,
)
log = get_logger(__name__)
pen_style: EnumType = Qt.PenStyle
_line_styles: dict[str, int] = {
'solid': pen_style.SolidLine,
'dash': pen_style.DashLine,
'dot': pen_style.DotLine,
'dashdot': pen_style.DashDotLine,
'solid': Qt.PenStyle.SolidLine,
'dash': Qt.PenStyle.DashLine,
'dot': Qt.PenStyle.DotLine,
'dashdot': Qt.PenStyle.DashDotLine,
}
@ -71,12 +69,12 @@ class FlowGraphic(pg.GraphicsObject):
# XXX-NOTE-XXX: graphics caching B)
# see explanation for different caching modes:
# https://stackoverflow.com/a/39410081
cache_mode: int = px_cache_mode.DeviceCoordinateCache
cache_mode: int = QGraphicsItem.DeviceCoordinateCache
# XXX: WARNING item caching seems to only be useful
# if we don't re-generate the entire QPainterPath every time
# don't ever use this - it's a colossal nightmare of artefacts
# and is disastrous for performance.
# cache_mode.ItemCoordinateCache
# QGraphicsItem.ItemCoordinateCache
# TODO: still questions todo with coord-cacheing that we should
# probably talk to a core dev about:
# - if this makes trasform interactions slower (such as zooming)
@ -178,7 +176,7 @@ class FlowGraphic(pg.GraphicsObject):
@cm
def reset_cache(self) -> None:
try:
none = px_cache_mode.NoCache
none = QGraphicsItem.NoCache
log.debug(
f'{self._name} -> CACHE DISABLE: {none}'
)

View File

@ -40,8 +40,8 @@ from numpy import (
ndarray,
)
import pyqtgraph as pg
from PyQt5.QtCore import QLineF
from piker.ui.qt import QLineF
from ..data._sharedmem import (
ShmArray,
)

View File

@ -57,7 +57,6 @@ from piker.toolz import (
Profiler,
)
from piker.log import get_logger
from piker import config
# from ..data._source import tf_in_1s
from ._axes import YAxisLabel
from ._chart import (
@ -1232,8 +1231,6 @@ async def link_views_with_region(
# region.sigRegionChangeFinished.connect(update_pi_from_region)
# NOTE: default is set to 60 FPS until the runtime delivers the
# discoverd hw value below.
_quote_throttle_rate: int = 60 - 6
@ -1275,54 +1272,26 @@ async def display_symbol_data(
# TODO: ctl over update loop's maximum frequency.
# - load this from a config.toml!
# - allow dyanmic configuration from chart UI?
(
conf,
path,
) = config.load()
ui_conf: dict = conf['ui']
global _quote_throttle_rate
from ._window import main_window
display_rate: int = floor(
main_window().current_screen().refreshRate()
) - 6
mx_redraw_rate: int = ui_conf.get(
'max_redraw_rate',
_quote_throttle_rate,
)
if mx_redraw_rate < display_rate:
log.info(
'Down-throttling redraw rate to config setting\n'
f'display FPS: {display_rate}\n'
'max_redraw_rate: {max_redraw_rate}\n'
)
else:
_quote_throttle_rate = display_rate
display_rate = main_window().current_screen().refreshRate()
_quote_throttle_rate = floor(display_rate) - 6
# TODO: we should be able to increase this if we use some
# `mypyc` speedups elsewhere? 22ish seems to be the sweet
# spot for single-feed chart.
num_of_feeds = len(fqmes)
# if num_of_feeds > 1:
mx: int = 22
if num_of_feeds > 1:
# there will be more ctx switches with more than 1 feed so we
# max throttle down a bit more.
mx_per_feed: int = (
ui_conf.get(
'per_feed_redraw_rate',
mx_redraw_rate,
)
or 16
)
mx = 16
# limit to at least display's FPS
# avoiding needless Qt-in-guest-mode context switches
cycles_per_feed = min(
round(_quote_throttle_rate/num_of_feeds),
mx_per_feed,
mx,
)
feed: Feed

View File

@ -32,21 +32,24 @@ from pyqtgraph import (
QtCore,
QtWidgets,
)
from PyQt5.QtCore import (
QPointF,
QRectF,
)
from PyQt5.QtGui import (
QColor,
QTransform,
)
from PyQt5.QtWidgets import (
QGraphicsProxyWidget,
QGraphicsScene,
QLabel,
)
from pyqtgraph import functions as fn
import numpy as np
from piker.types import Struct
from piker.ui.qt import (
Qt,
QPointF,
QRectF,
QGraphicsProxyWidget,
QGraphicsScene,
QLabel,
QColor,
QTransform,
)
from ._style import (
hcolor,
_font,
@ -313,9 +316,7 @@ class SelectRect(QtWidgets.QGraphicsRectItem):
self.setZValue(1e9)
label = self._label = QLabel()
label.setTextFormat(
Qt.TextFormat.MarkdownText
)
label.setTextFormat(0) # markdown
label.setFont(_font.font)
label.setMargin(0)
label.setAlignment(

View File

@ -23,29 +23,28 @@ from typing import Callable
import trio
from tractor.trionics import gather_contexts
from piker.ui.qt import (
QtCore,
QWidget,
QEvent,
keys,
gs_keys,
pyqtBoundSignal,
from PyQt5 import QtCore
from PyQt5.QtCore import QEvent, pyqtBoundSignal
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import (
QGraphicsSceneMouseEvent as gs_mouse,
)
from piker.types import Struct
MOUSE_EVENTS = {
gs_keys.GraphicsSceneMousePress,
gs_keys.GraphicsSceneMouseRelease,
keys.MouseButtonPress,
keys.MouseButtonRelease,
gs_mouse.GraphicsSceneMousePress,
gs_mouse.GraphicsSceneMouseRelease,
QEvent.MouseButtonPress,
QEvent.MouseButtonRelease,
# QtGui.QMouseEvent,
}
# TODO: maybe consider some constrained ints down the road?
# https://pydantic-docs.helpmanual.io/usage/types/#constrained-types
class KeyboardMsg(Struct):
'''Unpacked Qt keyboard event data.
@ -115,10 +114,7 @@ class EventRelay(QtCore.QObject):
# something to do with Qt internals and calling the
# parent handler?
if etype in {
QEvent.Type.KeyPress,
QEvent.Type.KeyRelease,
}:
if etype in {QEvent.KeyPress, QEvent.KeyRelease}:
msg = KeyboardMsg(
event=ev,
@ -164,9 +160,7 @@ class EventRelay(QtCore.QObject):
async def open_event_stream(
source_widget: QWidget,
event_types: set[QEvent] = {
QEvent.Type.KeyPress,
},
event_types: set[QEvent] = {QEvent.KeyPress},
filter_auto_repeats: bool = True,
) -> trio.abc.ReceiveChannel:

View File

@ -30,22 +30,25 @@ from typing import (
import platform
import traceback
# Qt specific
import PyQt5 # noqa
from PyQt5.QtWidgets import (
QWidget,
QMainWindow,
QApplication,
)
from PyQt5 import QtCore
from PyQt5.QtCore import (
pyqtRemoveInputHook,
Qt,
QCoreApplication,
)
import qdarkstyle
from qdarkstyle import DarkPalette
# import qdarkgraystyle # TODO: play with it
import trio
from outcome import Error
# Qt version-agnostic
from .qt import (
QWidget,
QMainWindow,
QApplication,
QtCore,
pyqtRemoveInputHook,
Qt,
QCoreApplication,
)
from ..service import (
maybe_open_pikerd,
get_runtime_vars,
@ -147,7 +150,7 @@ def run_qtractor(
# load dark theme
stylesheet = qdarkstyle.load_stylesheet(
qt_api='pyqt6',
qt_api='pyqt5',
palette=DarkPalette,
)
app.setStyleSheet(stylesheet)

View File

@ -28,15 +28,9 @@ from typing import (
)
import trio
from piker.ui.qt import (
keys,
size_policy,
QtGui,
QSize,
QModelIndex,
Qt,
QEvent,
from PyQt5 import QtGui
from PyQt5.QtCore import QSize, QModelIndex, Qt, QEvent
from PyQt5.QtWidgets import (
QWidget,
QLabel,
QComboBox,
@ -45,6 +39,7 @@ from piker.ui.qt import (
QVBoxLayout,
QFormLayout,
QProgressBar,
QSizePolicy,
QStyledItemDelegate,
QStyleOptionViewItem,
)
@ -76,14 +71,14 @@ class Edit(QLineEdit):
if width_in_chars:
self._chars = int(width_in_chars)
x_size_policy = size_policy.Fixed
x_size_policy = QSizePolicy.Fixed
else:
# chart count which will be used to calculate
# width of input field.
self._chars: int = 6
# fit to surroundingn frame width
x_size_policy = size_policy.Expanding
x_size_policy = QSizePolicy.Expanding
super().__init__(parent)
@ -91,7 +86,7 @@ class Edit(QLineEdit):
# https://doc.qt.io/qt-5/qsizepolicy.html#Policy-enum
self.setSizePolicy(
x_size_policy,
size_policy.Fixed,
QSizePolicy.Fixed,
)
self.setFont(font.font)
@ -185,13 +180,11 @@ class Selection(QComboBox):
self._items: dict[str, int] = {}
super().__init__(parent=parent)
self.setSizeAdjustPolicy(
QComboBox.SizeAdjustPolicy.AdjustToContents,
)
self.setSizeAdjustPolicy(QComboBox.AdjustToContents)
# make line edit expand to surrounding frame
self.setSizePolicy(
size_policy.Expanding,
size_policy.Fixed,
QSizePolicy.Expanding,
QSizePolicy.Fixed,
)
view = self.view()
view.setUniformItemSizes(True)
@ -315,8 +308,8 @@ class FieldsForm(QWidget):
# size it as we specify
self.setSizePolicy(
size_policy.Expanding,
size_policy.Expanding,
QSizePolicy.Expanding,
QSizePolicy.Expanding,
)
# XXX: not sure why we have to create this here exactly
@ -423,8 +416,8 @@ class FieldsForm(QWidget):
select.set_items(values)
self.setSizePolicy(
size_policy.Fixed,
size_policy.Fixed,
QSizePolicy.Fixed,
QSizePolicy.Fixed,
)
select.show()
self.form.addRow(label, select)
@ -444,10 +437,7 @@ async def handle_field_input(
async for kbmsg in recv_chan:
if kbmsg.etype in {
keys.KeyPress,
keys.KeyRelease,
}:
if kbmsg.etype in {QEvent.KeyPress, QEvent.KeyRelease}:
event, etype, key, mods, txt = kbmsg.to_tuple()
print(f'key: {kbmsg.key}, mods: {kbmsg.mods}, txt: {kbmsg.txt}')
@ -713,8 +703,7 @@ def mk_fill_status_bar(
)
bottom_label = form.add_field_label(
# 'x: {step_size}',
'{unit_prefix}: {step_size}',
'x: {step_size}',
font_size=bar_label_font_size,
font_color='gunmetal',
)

View File

@ -15,18 +15,15 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
`QIcon` hackery.
Mostly dynamically loading pixmaps for use with `QGraphicsScene`.
``QIcon`` hackery.
'''
from piker.ui.qt import (
QSize,
QStyle,
QIcon,
QPixmap,
QColor,
from PyQt5.QtWidgets import QStyle
from PyQt5.QtGui import (
QIcon, QPixmap, QColor
)
from PyQt5.QtCore import QSize
from ._style import hcolor
# https://www.pythonguis.com/faq/built-in-qicons-pyqt/
@ -47,8 +44,7 @@ def mk_icons(
size: QSize,
) -> dict[str, QIcon]:
'''
This helper is indempotent.
'''This helper is indempotent.
'''
global _icons, _icon_names
@ -60,11 +56,7 @@ def mk_icons(
# load account selection using current style
for name, icon_name in _icon_names.items():
stdpixmap = getattr(
# https://www.pythonguis.com/faq/built-in-qicons-pyqt/
QStyle.StandardPixmap, # pyqt/pyside6
icon_name,
)
stdpixmap = getattr(QStyle, icon_name)
stdicon = style.standardIcon(stdpixmap)
pixmap = stdicon.pixmap(size)

View File

@ -36,21 +36,23 @@ import pyqtgraph as pg
# this down the road.. Bo
from pyqtgraph.GraphicsScene import mouseEvents as mevs
# from pyqtgraph.GraphicsScene.mouseEvents import MouseDragEvent
from PyQt5.QtWidgets import QGraphicsSceneMouseEvent as gs_mouse
from PyQt5.QtGui import (
QWheelEvent,
)
from PyQt5.QtCore import (
Qt,
QEvent,
)
from pyqtgraph import (
ViewBox,
Point,
QtCore,
functions as fn,
)
from pyqtgraph import functions as fn
import numpy as np
import trio
from piker.ui.qt import (
QWheelEvent,
QGraphicsSceneMouseEvent as gs_mouse,
Qt,
QEvent,
)
from ..log import get_logger
from ..toolz import (
Profiler,
@ -79,22 +81,22 @@ if TYPE_CHECKING:
log = get_logger(__name__)
NUMBER_LINE = {
Qt.Key.Key_1,
Qt.Key.Key_2,
Qt.Key.Key_3,
Qt.Key.Key_4,
Qt.Key.Key_5,
Qt.Key.Key_6,
Qt.Key.Key_7,
Qt.Key.Key_8,
Qt.Key.Key_9,
Qt.Key.Key_0,
Qt.Key_1,
Qt.Key_2,
Qt.Key_3,
Qt.Key_4,
Qt.Key_5,
Qt.Key_6,
Qt.Key_7,
Qt.Key_8,
Qt.Key_9,
Qt.Key_0,
}
ORDER_MODE = {
Qt.Key.Key_A,
Qt.Key.Key_F,
Qt.Key.Key_D,
Qt.Key_A,
Qt.Key_F,
Qt.Key_D,
}

View File

@ -21,12 +21,9 @@ Double auction top-of-book (L1) graphics.
from typing import Tuple
import pyqtgraph as pg
from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import QPointF
from piker.ui.qt import (
QPointF,
QtCore,
QtGui,
)
from ._axes import YAxisLabel
from ._style import hcolor
from ._pg_overrides import PlotItem

View File

@ -25,17 +25,10 @@ from typing import (
)
import pyqtgraph as pg
from PyQt5 import QtGui, QtWidgets
from PyQt5.QtWidgets import QLabel, QSizePolicy
from PyQt5.QtCore import QPointF, QRectF, Qt
from piker.ui.qt import (
px_cache_mode,
QtGui,
QtWidgets,
QLabel,
size_policy,
QPointF,
QRectF,
Qt,
)
from ._style import (
DpiAwareFont,
hcolor,
@ -85,7 +78,7 @@ class Label:
self._x_offset = x_offset
txt = self.txt = QtWidgets.QGraphicsTextItem(parent=parent)
txt.setCacheMode(px_cache_mode.DeviceCoordinateCache)
txt.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache)
vb.scene().addItem(txt)
@ -110,7 +103,7 @@ class Label:
self._anchor_func = self.txt.pos().x
# not sure if this makes a diff
self.txt.setCacheMode(px_cache_mode.DeviceCoordinateCache)
self.txt.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache)
# TODO: edit and selection support
# https://doc.qt.io/qt-5/qt.html#TextInteractionFlag-enum
@ -306,14 +299,12 @@ class FormatLabel(QLabel):
"""
)
self.setFont(_font.font)
self.setTextFormat(
Qt.TextFormat.MarkdownText
)
self.setTextFormat(Qt.MarkdownText) # markdown
self.setMargin(0)
self.setSizePolicy(
size_policy.Expanding,
size_policy.Expanding,
QSizePolicy.Expanding,
QSizePolicy.Expanding,
)
self.setAlignment(
Qt.AlignVCenter | Qt.AlignLeft

View File

@ -27,22 +27,20 @@ from typing import (
)
import pyqtgraph as pg
from pyqtgraph import (
Point,
functions as fn,
)
from piker.ui.qt import (
px_cache_mode,
from pyqtgraph import Point, functions as fn
from PyQt5 import (
QtCore,
QtGui,
)
from PyQt5.QtWidgets import (
QGraphicsPathItem,
QStyleOptionGraphicsItem,
QGraphicsItem,
QGraphicsScene,
QWidget,
QPointF,
)
from PyQt5.QtCore import QPointF
from ._annotate import LevelMarker
from ._anchors import (
vbr_left,
@ -142,9 +140,7 @@ class LevelLine(pg.InfiniteLine):
self._right_end_sc: float = 0
# use px caching
self.setCacheMode(
px_cache_mode.DeviceCoordinateCache
)
self.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
def txt_offsets(self) -> tuple[int, int]:
return 0, 0
@ -215,7 +211,7 @@ class LevelLine(pg.InfiniteLine):
) -> None:
if not called_from_on_pos_change:
last: float = self.value()
last = self.value()
# if the position hasn't changed then ``.update_labels()``
# will not be called by a non-triggered `.on_pos_change()`,

View File

@ -20,14 +20,16 @@ Super fast OHLC sampling graphics types.
from __future__ import annotations
import numpy as np
from piker.ui.qt import (
from PyQt5 import (
QtGui,
QtWidgets,
QPainterPath,
)
from PyQt5.QtCore import (
QLineF,
QRectF,
)
from PyQt5.QtGui import QPainterPath
from ._curve import FlowGraphic
from ..toolz import (
Profiler,

View File

@ -344,10 +344,7 @@ class SettingsPane:
dsize = tracker.live_pp.dsize
# READ out settings and update the status UI / settings widgets
unit_char: str = {
'currency': '$',
'units': 'u',
}[alloc.size_unit]
suffix = {'currency': ' $', 'units': ' u'}[alloc.size_unit]
size_unit, limit = alloc.limit_info()
step_size, currency_per_slot = alloc.step_sizes()
@ -361,11 +358,10 @@ class SettingsPane:
self.apply_setting('limit', limit)
self.step_label.format(
unit_prefix=unit_char,
step_size=str(humanize(step_size))
step_size=str(humanize(step_size)) + suffix
)
self.limit_label.format(
limit=f'{unit_char}: {str(humanize(limit))}'
limit=str(humanize(limit)) + suffix
)
# update size unit in UI

View File

@ -38,14 +38,14 @@ from tractor import (
Context,
MsgStream,
)
from PyQt5.QtWidgets import (
QGraphicsItem,
)
from piker.log import get_logger
from piker.types import Struct
from piker.service import find_service
from piker.brokers import SymbolNotFound
from piker.ui.qt import (
QGraphicsItem,
)
from ._display import DisplayState
from ._interaction import ChartView
from ._editors import SelectRect

View File

@ -30,8 +30,8 @@ from typing import (
import msgspec
import numpy as np
import pyqtgraph as pg
from PyQt5.QtGui import QPainterPath
from piker.ui.qt import QPainterPath
from ..data._formatters import (
IncrementalFormatter,
)

View File

@ -48,24 +48,27 @@ from pprint import pformat
from rapidfuzz import process as fuzzy
import trio
from trio_typing import TaskStatus
from piker.ui.qt import (
size_policy,
align_flag,
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5.QtCore import (
Qt,
QtCore,
QtWidgets,
QModelIndex,
QItemSelectionModel,
)
from PyQt5.QtGui import (
# QLayout,
QStandardItem,
QStandardItemModel,
)
from PyQt5.QtWidgets import (
QWidget,
QTreeView,
# QListWidgetItem,
# QAbstractScrollArea,
# QStyledItemDelegate,
)
from ..log import get_logger
from ._style import (
_font,
@ -126,8 +129,8 @@ class CompleterView(QTreeView):
# ux settings
self.setSizePolicy(
size_policy.Expanding,
size_policy.Expanding,
QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding,
)
self.setItemsExpandable(True)
self.setExpandsOnDoubleClick(False)
@ -564,8 +567,8 @@ class SearchWidget(QtWidgets.QWidget):
# size it as we specify
self.setSizePolicy(
size_policy.Fixed,
size_policy.Fixed,
QtWidgets.QSizePolicy.Fixed,
QtWidgets.QSizePolicy.Fixed,
)
self.godwidget = godwidget
@ -589,16 +592,14 @@ class SearchWidget(QtWidgets.QWidget):
}}
"""
)
label.setTextFormat(
Qt.TextFormat.MarkdownText
)
label.setTextFormat(3) # markdown
label.setFont(_font.font)
label.setMargin(4)
label.setText("search:")
label.show()
label.setAlignment(
align_flag.AlignVCenter
| align_flag.AlignLeft
QtCore.Qt.AlignVCenter
| QtCore.Qt.AlignLeft
)
self.bar_hbox.addWidget(label)
@ -616,17 +617,9 @@ class SearchWidget(QtWidgets.QWidget):
self.vbox.addLayout(self.bar_hbox)
self.vbox.setAlignment(
self.bar,
align_flag.AlignTop
| align_flag.AlignRight,
)
self.vbox.setAlignment(self.bar, Qt.AlignTop | Qt.AlignRight)
self.vbox.addWidget(self.bar.view)
self.vbox.setAlignment(
self.view,
align_flag.AlignTop
| align_flag.AlignLeft,
)
self.vbox.setAlignment(self.view, Qt.AlignTop | Qt.AlignLeft)
def focus(self) -> None:
self.show()

View File

@ -22,14 +22,10 @@ from typing import Dict
import math
import pyqtgraph as pg
from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import Qt, QCoreApplication
from qdarkstyle import DarkPalette
from .qt import (
QtCore,
QtGui,
Qt,
QCoreApplication,
)
from ..log import get_logger
from .. import config

View File

@ -27,14 +27,16 @@ from typing import (
)
import uuid
from piker.ui.qt import (
Qt,
QtCore,
from PyQt5 import QtCore
from PyQt5.QtWidgets import (
QWidget,
QMainWindow,
QApplication,
QLabel,
QStatusBar,
)
from PyQt5.QtGui import (
QScreen,
QCloseEvent,
)
@ -195,9 +197,7 @@ class MainWindow(QMainWindow):
"""
# font-size : {font_size}px;
)
label.setTextFormat(
Qt.TextFormat.MarkdownText
)
label.setTextFormat(3) # markdown
label.setFont(_font_small.font)
label.setMargin(2)
label.setAlignment(

View File

@ -34,6 +34,7 @@ import uuid
from bidict import bidict
import tractor
import trio
from PyQt5.QtCore import Qt
from piker import config
from piker.accounting import (
@ -58,7 +59,6 @@ from piker.data import (
)
from piker.types import Struct
from piker.log import get_logger
from piker.ui.qt import Qt
from ._editors import LineEditor, ArrowEditor
from ._lines import order_line, LevelLine
from ._position import (
@ -494,7 +494,7 @@ class OrderMode:
uuid: str,
order: Order | None = None,
) -> Dialog | None:
) -> Dialog:
'''
Order submitted status event handler.
@ -515,11 +515,6 @@ class OrderMode:
# if an order msg is provided update the line
# **from** that msg.
if order:
if order.price <= 0:
log.error(f'Order has 0 price, cancelling..\n{order}')
self.cancel_orders([order.oid])
return None
line.set_level(order.price)
self.on_level_change_update_next_order_info(
level=order.price,
@ -1018,13 +1013,8 @@ async def process_trade_msg(
) -> tuple[Dialog, Status]:
# TODO: obvi once we're parsing to native struct instances we can
# drop the `pformat()` call Bo
fmtmsg: Struct | dict = msg
if not isinstance(msg, Struct):
fmtmsg: str = pformat(msg)
log.debug(f'Received order msg:\n{fmtmsg}')
fmsg = pformat(msg)
log.debug(f'Received order msg:\n{fmsg}')
name = msg['name']
if name in (
@ -1040,7 +1030,7 @@ async def process_trade_msg(
):
log.info(
f'Loading position for `{fqme}`:\n'
f'{fmtmsg}'
f'{fmsg}'
)
tracker = mode.trackers[msg['account']]
tracker.live_pp.update_from_msg(msg)
@ -1082,7 +1072,7 @@ async def process_trade_msg(
elif order.action != 'cancel':
log.warning(
f'received msg for untracked dialog:\n{fmtmsg}'
f'received msg for untracked dialog:\n{fmsg}'
)
assert msg.resp in ('open', 'dark_open'), f'Unknown msg: {msg}'
@ -1149,7 +1139,7 @@ async def process_trade_msg(
req={'exec_mode': 'dark'},
):
# TODO: UX for a "pending" clear/live order
log.info(f'Dark order triggered for {fmtmsg}')
log.info(f'Dark order triggered for {fmsg}')
case Status(
resp='triggered',

View File

@ -1,104 +0,0 @@
# piker: trading gear for hackers
# Copyright (C) Tyler Goodlet (in stewardship for pikers)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
Qt UI framework version shimming.
Allow importing sub-pkgs from this module instead of worrying about
major version specifics, any enum moves or component renames.
Code in `piker.ui.*` should always explicitlyimport directly from
this module like `from piker.ui.qt import ( ..`
'''
from enum import EnumType
from PyQt6 import (
QtCore,
QtGui,
QtWidgets,
)
from PyQt6.QtCore import (
Qt,
QCoreApplication,
QLineF,
QRectF,
# NOTE: for enums use the `.Type` subattr-space
QEvent,
QPointF,
QSize,
QModelIndex,
QItemSelectionModel,
pyqtBoundSignal,
pyqtRemoveInputHook,
)
align_flag: EnumType = Qt.AlignmentFlag
txt_flag: EnumType = Qt.TextFlag
keys: EnumType = QEvent.Type
scrollbar_policy: EnumType = Qt.ScrollBarPolicy
# ^-NOTE-^: handy snippet to discover enums:
# import enum
# [attr for attr_name in dir(QFrame)
# if (attr := getattr(QFrame, attr_name))
# and isinstance(attr, enum.EnumType)]
from PyQt6.QtGui import (
QPainter,
QPainterPath,
QIcon,
QPixmap,
QColor,
QTransform,
QStandardItem,
QStandardItemModel,
QWheelEvent,
QScreen,
QCloseEvent,
)
from PyQt6.QtWidgets import (
QMainWindow,
QApplication,
QLabel,
QStatusBar,
QLineEdit,
QHBoxLayout,
QVBoxLayout,
QFormLayout,
QProgressBar,
QSizePolicy,
QStyledItemDelegate,
QStyleOptionViewItem,
QComboBox,
QWidget,
QFrame,
QSplitter,
QTreeView,
QStyle,
QGraphicsItem,
QGraphicsPathItem,
# QGraphicsView,
QStyleOptionGraphicsItem,
QGraphicsScene,
QGraphicsSceneMouseEvent,
QGraphicsProxyWidget,
)
gs_keys: EnumType = QGraphicsSceneMouseEvent.Type
size_policy: EnumType = QtWidgets.QSizePolicy.Policy
px_cache_mode: EnumType = QGraphicsItem.CacheMode