Resize everything with HiDPI scaling on
parent
bceeaa56ff
commit
e524ee9045
|
@ -29,7 +29,7 @@ class PriceAxis(pg.AxisItem):
|
||||||
})
|
})
|
||||||
self.setLabel(**{'font-size': '10pt'})
|
self.setLabel(**{'font-size': '10pt'})
|
||||||
self.setTickFont(_font)
|
self.setTickFont(_font)
|
||||||
self.setWidth(125)
|
self.setWidth(50)
|
||||||
|
|
||||||
# XXX: drop for now since it just eats up h space
|
# XXX: drop for now since it just eats up h space
|
||||||
|
|
||||||
|
@ -61,12 +61,12 @@ class DynamicDateAxis(pg.AxisItem):
|
||||||
|
|
||||||
# default styling
|
# default styling
|
||||||
self.setStyle(
|
self.setStyle(
|
||||||
tickTextOffset=7,
|
tickTextOffset=4,
|
||||||
textFillLimits=[(0, 0.70)],
|
textFillLimits=[(0, 0.70)],
|
||||||
# TODO: doesn't seem to work -> bug in pyqtgraph?
|
# TODO: doesn't seem to work -> bug in pyqtgraph?
|
||||||
# tickTextHeight=2,
|
# tickTextHeight=11,
|
||||||
)
|
)
|
||||||
# self.setHeight(35)
|
self.setHeight(10)
|
||||||
|
|
||||||
def _indexes_to_timestrs(
|
def _indexes_to_timestrs(
|
||||||
self,
|
self,
|
||||||
|
@ -175,7 +175,7 @@ class XAxisLabel(AxisLabel):
|
||||||
# TODO: we need to get the parent axe's dimensions transformed
|
# TODO: we need to get the parent axe's dimensions transformed
|
||||||
# to abs coords to be 100% correct here:
|
# to abs coords to be 100% correct here:
|
||||||
# self.parent.boundingRect()
|
# self.parent.boundingRect()
|
||||||
return QtCore.QRectF(0, 0, 100, 31)
|
return QtCore.QRectF(0, 2, 40, 10)
|
||||||
|
|
||||||
def update_label(
|
def update_label(
|
||||||
self,
|
self,
|
||||||
|
@ -206,7 +206,7 @@ class YAxisLabel(AxisLabel):
|
||||||
return ('{: ,.%df}' % self.digits).format(tick_pos).replace(',', ' ')
|
return ('{: ,.%df}' % self.digits).format(tick_pos).replace(',', ' ')
|
||||||
|
|
||||||
def boundingRect(self): # noqa
|
def boundingRect(self): # noqa
|
||||||
return QtCore.QRectF(0, 0, 120, 30)
|
return QtCore.QRectF(0, 0, 50, 11)
|
||||||
|
|
||||||
def update_label(
|
def update_label(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -8,16 +8,29 @@ from functools import partial
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Tuple, Callable, Dict, Any
|
from typing import Tuple, Callable, Dict, Any
|
||||||
|
|
||||||
|
# Qt specific
|
||||||
import PyQt5 # noqa
|
import PyQt5 # noqa
|
||||||
from pyqtgraph import QtGui
|
from pyqtgraph import QtGui
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
from PyQt5.QtCore import pyqtRemoveInputHook
|
from PyQt5.QtCore import (
|
||||||
|
pyqtRemoveInputHook, Qt, QCoreApplication
|
||||||
|
)
|
||||||
import qdarkstyle
|
import qdarkstyle
|
||||||
|
|
||||||
import trio
|
import trio
|
||||||
import tractor
|
import tractor
|
||||||
from outcome import Error
|
from outcome import Error
|
||||||
|
|
||||||
|
|
||||||
|
# Proper high DPI scaling is available in Qt >= 5.6.0. This attibute
|
||||||
|
# must be set before creating the application
|
||||||
|
if hasattr(Qt, 'AA_EnableHighDpiScaling'):
|
||||||
|
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
|
||||||
|
|
||||||
|
# if hasattr(Qt, 'AA_UseHighDpiPixmaps'):
|
||||||
|
# QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtGui.QMainWindow):
|
class MainWindow(QtGui.QMainWindow):
|
||||||
|
|
||||||
size = (800, 500)
|
size = (800, 500)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import pyqtgraph as pg
|
||||||
from PyQt5 import QtCore, QtGui
|
from PyQt5 import QtCore, QtGui
|
||||||
from PyQt5.QtCore import QLineF
|
from PyQt5.QtCore import QLineF
|
||||||
|
|
||||||
from .quantdom.utils import timeit
|
# from .quantdom.utils import timeit
|
||||||
from ._style import _xaxis_at, hcolor
|
from ._style import _xaxis_at, hcolor
|
||||||
from ._axes import YAxisLabel, XAxisLabel
|
from ._axes import YAxisLabel, XAxisLabel
|
||||||
|
|
||||||
|
@ -286,7 +286,6 @@ class BarItems(pg.GraphicsObject):
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.last = QtGui.QPicture()
|
self.last = QtGui.QPicture()
|
||||||
# self.buffer = QtGui.QPicture()
|
|
||||||
self.history = QtGui.QPicture()
|
self.history = QtGui.QPicture()
|
||||||
# TODO: implement updateable pixmap solution
|
# TODO: implement updateable pixmap solution
|
||||||
self._pi = plotitem
|
self._pi = plotitem
|
||||||
|
@ -307,10 +306,12 @@ class BarItems(pg.GraphicsObject):
|
||||||
# @timeit
|
# @timeit
|
||||||
def draw_from_data(
|
def draw_from_data(
|
||||||
self,
|
self,
|
||||||
data: np.recarray,
|
data: np.ndarray,
|
||||||
start: int = 0,
|
start: int = 0,
|
||||||
):
|
):
|
||||||
"""Draw OHLC datum graphics from a ``np.recarray``.
|
"""Draw OHLC datum graphics from a ``np.ndarray``.
|
||||||
|
|
||||||
|
This routine is usually only called to draw the initial history.
|
||||||
"""
|
"""
|
||||||
lines = bars_from_ohlc(data, self.w, start=start)
|
lines = bars_from_ohlc(data, self.w, start=start)
|
||||||
|
|
||||||
|
@ -332,20 +333,16 @@ class BarItems(pg.GraphicsObject):
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Draw the current line set using the painter.
|
"""Draw the current line set using the painter.
|
||||||
"""
|
"""
|
||||||
# start = time.time()
|
|
||||||
|
|
||||||
if just_history:
|
if just_history:
|
||||||
istart = 0
|
# draw bars for the "history" picture
|
||||||
iend = iend or self.index - 1
|
iend = iend or self.index - 1
|
||||||
pic = self.history
|
pic = self.history
|
||||||
else:
|
else:
|
||||||
|
# draw the last bar
|
||||||
istart = self.index - 1
|
istart = self.index - 1
|
||||||
iend = self.index
|
iend = iend or self.index
|
||||||
pic = self.last
|
pic = self.last
|
||||||
|
|
||||||
if iend is not None:
|
|
||||||
iend = iend
|
|
||||||
|
|
||||||
# use 2d array of lines objects, see conlusion on speed:
|
# use 2d array of lines objects, see conlusion on speed:
|
||||||
# https://stackoverflow.com/a/60089929
|
# https://stackoverflow.com/a/60089929
|
||||||
to_draw = np.ravel(self.lines[istart:iend])
|
to_draw = np.ravel(self.lines[istart:iend])
|
||||||
|
@ -370,9 +367,6 @@ class BarItems(pg.GraphicsObject):
|
||||||
# https://doc.qt.io/qt-5/qgraphicsitem.html#update
|
# https://doc.qt.io/qt-5/qgraphicsitem.html#update
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
# diff = time.time() - start
|
|
||||||
# print(f'{len(to_draw)} lines update took {diff}')
|
|
||||||
|
|
||||||
def update_from_array(
|
def update_from_array(
|
||||||
self,
|
self,
|
||||||
array: np.ndarray,
|
array: np.ndarray,
|
||||||
|
@ -407,9 +401,7 @@ class BarItems(pg.GraphicsObject):
|
||||||
return
|
return
|
||||||
|
|
||||||
# current bar update
|
# current bar update
|
||||||
i, open, close, = array[-1][['index', 'open', 'close']]
|
i, open, last, = array[-1][['index', 'open', 'close']]
|
||||||
last = close
|
|
||||||
# i, body, larm, rarm = self.lines[index-1]
|
|
||||||
body, larm, rarm = self.lines[index-1]
|
body, larm, rarm = self.lines[index-1]
|
||||||
|
|
||||||
# XXX: is there a faster way to modify this?
|
# XXX: is there a faster way to modify this?
|
||||||
|
@ -443,13 +435,18 @@ class BarItems(pg.GraphicsObject):
|
||||||
# The only required methods are paint() and boundingRect()
|
# The only required methods are paint() and boundingRect()
|
||||||
# @timeit
|
# @timeit
|
||||||
def paint(self, p, opt, widget):
|
def paint(self, p, opt, widget):
|
||||||
# start = time.time()
|
|
||||||
|
|
||||||
# TODO: use to avoid drawing artefacts?
|
# TODO: use to avoid drawing artefacts?
|
||||||
# self.prepareGeometryChange()
|
# self.prepareGeometryChange()
|
||||||
|
|
||||||
# p.setCompositionMode(0)
|
# p.setCompositionMode(0)
|
||||||
|
|
||||||
|
# TODO: one thing we could try here is pictures being drawn of
|
||||||
|
# a fixed count of bars such that based on the viewbox indices we
|
||||||
|
# only draw the "rounded up" number of "pictures worth" of bars
|
||||||
|
# as is necesarry for what's in "view". Not sure if this will
|
||||||
|
# lead to any perf gains other then when zoomed in to less bars
|
||||||
|
# in view.
|
||||||
p.drawPicture(0, 0, self.history)
|
p.drawPicture(0, 0, self.history)
|
||||||
p.drawPicture(0, 0, self.last)
|
p.drawPicture(0, 0, self.last)
|
||||||
|
|
||||||
|
@ -458,9 +455,6 @@ class BarItems(pg.GraphicsObject):
|
||||||
# self._pmi.setPixmap(self.picture)
|
# self._pmi.setPixmap(self.picture)
|
||||||
# print(self.scene())
|
# print(self.scene())
|
||||||
|
|
||||||
# diff = time.time() - start
|
|
||||||
# print(f'draw time {diff}')
|
|
||||||
|
|
||||||
def boundingRect(self):
|
def boundingRect(self):
|
||||||
# TODO: can we do rect caching to make this faster?
|
# TODO: can we do rect caching to make this faster?
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,14 @@ from qdarkstyle.palette import DarkPalette
|
||||||
_font = QtGui.QFont("Hack", 4)
|
_font = QtGui.QFont("Hack", 4)
|
||||||
_i3_rgba = QtGui.QColor.fromRgbF(*[0.14]*3 + [1])
|
_i3_rgba = QtGui.QColor.fromRgbF(*[0.14]*3 + [1])
|
||||||
|
|
||||||
|
|
||||||
# splitter widget config
|
# splitter widget config
|
||||||
_xaxis_at = 'bottom'
|
_xaxis_at = 'bottom'
|
||||||
|
|
||||||
|
|
||||||
# charting config
|
# charting config
|
||||||
_min_points_to_show = 3
|
_min_points_to_show = 3
|
||||||
|
CHART_MARGINS = (0, 0, 2, 2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_tina_mode = False
|
_tina_mode = False
|
||||||
|
|
Loading…
Reference in New Issue