From 2ebdf008da2517c602d5e07082034bc87a4c4556 Mon Sep 17 00:00:00 2001 From: wattygetlood <61716739+wattygetlood@users.noreply.github.com> Date: Thu, 16 Sep 2021 16:33:48 -0400 Subject: [PATCH 01/18] Configure window size based on screen dims on windows --- piker/ui/_exec.py | 4 ++++ piker/ui/_window.py | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/piker/ui/_exec.py b/piker/ui/_exec.py index 284ddd9b..7b69acef 100644 --- a/piker/ui/_exec.py +++ b/piker/ui/_exec.py @@ -61,7 +61,9 @@ _do_overrides() # XXX: pretty sure none of this shit works on linux as per: # https://bugreports.qt.io/browse/QTBUG-53022 # it seems to work on windows.. no idea wtf is up. +is_windows = False if platform.system() == "Windows": + is_windows = True # Proper high DPI scaling is available in Qt >= 5.6.0. This attibute # must be set before creating the application @@ -182,6 +184,8 @@ def run_qtractor( window.main_widget = main_widget window.setCentralWidget(instance) + if is_windows: + window.configure_to_desktop() # actually render to screen window.show() diff --git a/piker/ui/_window.py b/piker/ui/_window.py index 6a0c1d8b..da9dd305 100644 --- a/piker/ui/_window.py +++ b/piker/ui/_window.py @@ -153,8 +153,8 @@ class MainWindow(QtGui.QMainWindow): # XXX: for tiling wms this should scale # with the alloted window size. # TODO: detect for tiling and if untrue set some size? - # size = (300, 500) - size = (0, 0) + size = (300, 500) + #size = (0, 0) title = 'piker chart (ur symbol is loading bby)' @@ -165,7 +165,7 @@ class MainWindow(QtGui.QMainWindow): self._status_bar: QStatusBar = None self._status_label: QLabel = None - + @property def mode_label(self) -> QtGui.QLabel: @@ -269,6 +269,16 @@ class MainWindow(QtGui.QMainWindow): assert screen, "Wow Qt is dumb as shit and has no screen..." return screen + def configure_to_desktop( + self, + ) -> None: + # https://stackoverflow.com/a/18975846 + app = QtGui.QApplication.instance() + geo = self.current_screen().geometry() + h, w = geo.height(), geo.width() + self.resize(round(w * .375), round(h * 3/8)) + + # singleton app per actor _qt_win: QtGui.QMainWindow = None From c0082e15bca4fbe7c5975036ee47a97e16f66395 Mon Sep 17 00:00:00 2001 From: wattygetlood <61716739+wattygetlood@users.noreply.github.com> Date: Thu, 16 Sep 2021 16:34:43 -0400 Subject: [PATCH 02/18] Fix default `brokers.toml` copying since module move --- piker/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/piker/config.py b/piker/config.py index 70d9c9c5..93a47378 100644 --- a/piker/config.py +++ b/piker/config.py @@ -60,7 +60,7 @@ def repodir(): """ dirpath = os.path.abspath( # we're 3 levels down in **this** module file - dirname(dirname(dirname(os.path.realpath(__file__)))) + dirname(dirname(os.path.realpath(__file__))) ) return dirpath @@ -73,7 +73,7 @@ def load( path = path or get_broker_conf_path() if not os.path.isfile(path): shutil.copyfile( - os.path.join(repodir(), 'data/brokers.toml'), + os.path.join(repodir(), 'config', 'brokers.toml'), path, ) From 15556e40f0c9442aa7b47c8f0adb4fbff25bbcf4 Mon Sep 17 00:00:00 2001 From: wattygetlood <61716739+wattygetlood@users.noreply.github.com> Date: Thu, 16 Sep 2021 16:46:44 -0400 Subject: [PATCH 03/18] No support for notifications (yet) on windows --- piker/ui/order_mode.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/piker/ui/order_mode.py b/piker/ui/order_mode.py index 755e72f3..437e4ca5 100644 --- a/piker/ui/order_mode.py +++ b/piker/ui/order_mode.py @@ -22,6 +22,7 @@ from contextlib import asynccontextmanager from dataclasses import dataclass, field from functools import partial from pprint import pformat +import platform import time from typing import Optional, Dict, Callable, Any import uuid @@ -429,6 +430,9 @@ class OrderMode: # TODO: make this not trash. # XXX: linux only for now + if platform.system() == "Windows": + return + result = await trio.run_process( [ 'notify-send', From c411a244f646399a748f345c4b470a37111c9880 Mon Sep 17 00:00:00 2001 From: wattygetlood <61716739+wattygetlood@users.noreply.github.com> Date: Sun, 19 Sep 2021 18:34:17 -0400 Subject: [PATCH 04/18] Size the window to aproximately 1/3 the screen space --- piker/ui/_window.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/piker/ui/_window.py b/piker/ui/_window.py index da9dd305..be43a261 100644 --- a/piker/ui/_window.py +++ b/piker/ui/_window.py @@ -165,6 +165,7 @@ class MainWindow(QtGui.QMainWindow): self._status_bar: QStatusBar = None self._status_label: QLabel = None + self._size: Optional[tuple[int, int]] = None @property def mode_label(self) -> QtGui.QLabel: @@ -271,12 +272,18 @@ class MainWindow(QtGui.QMainWindow): def configure_to_desktop( self, + size: Optional[tuple[int, int]] = None, ) -> None: # https://stackoverflow.com/a/18975846 - app = QtGui.QApplication.instance() - geo = self.current_screen().geometry() - h, w = geo.height(), geo.width() - self.resize(round(w * .375), round(h * 3/8)) + if not size and not self._size: + app = QtGui.QApplication.instance() + geo = self.current_screen().geometry() + h, w = geo.height(), geo.width() + self.setMaximumSize(w, h) + # use approx 1/3 of the area of the screen by default + self._size = round(w * .666), round(h * .666) + + self.resize(*size or self._size) From d069481f1d7fdf6772e0e57f27d0bb954b4ea7cb Mon Sep 17 00:00:00 2001 From: wattygetlood <61716739+wattygetlood@users.noreply.github.com> Date: Sun, 19 Sep 2021 18:37:46 -0400 Subject: [PATCH 05/18] Hack search view on windows to 1/2 window height; needs a better solution --- piker/ui/_search.py | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/piker/ui/_search.py b/piker/ui/_search.py index f1fc1f4e..4e9d6184 100644 --- a/piker/ui/_search.py +++ b/piker/ui/_search.py @@ -49,7 +49,7 @@ from PyQt5 import QtCore from PyQt5 import QtWidgets from PyQt5.QtCore import ( Qt, - # QSize, + QSize, QModelIndex, QItemSelectionModel, ) @@ -112,6 +112,7 @@ class CompleterView(QTreeView): model = QStandardItemModel(self) self.labels = labels + self._last_window_h: Optional[int] = None # a std "tabular" config self.setItemDelegate(FontScaledDelegate(self)) @@ -126,6 +127,10 @@ class CompleterView(QTreeView): # self.setSizeAdjustPolicy(QAbstractScrollArea.AdjustIgnored) # ux settings + self.setSizePolicy( + QtWidgets.QSizePolicy.Expanding, + QtWidgets.QSizePolicy.Expanding, + ) self.setItemsExpandable(True) self.setExpandsOnDoubleClick(False) self.setAnimated(False) @@ -152,24 +157,41 @@ class CompleterView(QTreeView): self._font_size = size self.setStyleSheet(f"font: {size}px") + + #def resizeEvent(self, event: 'QEvent') -> None: + # self.resize_to_results() + # super().resizeEvent(event) - def resize(self): + def resize_to_results(self): model = self.model() cols = model.columnCount() for i in range(cols): self.resizeColumnToContents(i) - # inclusive of search bar and header "rows" in pixel terms - rows = 100 - # max_rows = 8 # 6 + search and headers row_px = self.rowHeight(self.currentIndex()) - # print(f'font_h: {font_h}\n px_height: {px_height}') # TODO: probably make this more general / less hacky - self.setMinimumSize(self.width(), rows * row_px) - self.setMaximumSize(self.width() + 10, rows * row_px) + # we should figure out the exact number of rows to allow + # inclusive of search bar and header "rows", in pixel terms. + window_h = self.window().height() + rows = round(window_h * 0.5 / row_px) - 4 + + # TODO: the problem here is that this view widget is **not** resizing/scaling + # when the parent layout is adjusted, not sure what exactly is up... + # only "scale up" the results view when the window size has increased/ + if not self._last_window_h or self._last_window_h < window_h: + self.setMaximumSize(self.width(), rows * row_px) + self.setMinimumSize(self.width(), rows * row_px) + + #elif not self._last_window_h or self._last_window_h > window_h: + # self.setMinimumSize(self.width(), rows * row_px) + # self.setMaximumSize(self.width(), rows * row_px) + + self.resize(self.width(), rows * row_px) + self._last_window_h = window_h self.setFixedWidth(333) + self.update() def is_selecting_d1(self) -> bool: cidx = self.selectionModel().currentIndex() @@ -334,7 +356,7 @@ class CompleterView(QTreeView): else: model.setItem(idx.row(), 1, QStandardItem()) - self.resize() + self.resize_to_results() return idx else: @@ -405,7 +427,7 @@ class CompleterView(QTreeView): def show_matches(self) -> None: self.show() - self.resize() + self.resize_to_results() class SearchBar(Edit): @@ -459,7 +481,7 @@ class SearchWidget(QtWidgets.QWidget): # size it as we specify self.setSizePolicy( QtWidgets.QSizePolicy.Fixed, - QtWidgets.QSizePolicy.Fixed, + QtWidgets.QSizePolicy.Expanding, ) self.godwidget = godwidget From cc87508fd9c036d55c23f5c2c8671c5f43cb28d9 Mon Sep 17 00:00:00 2001 From: wattygetlood <61716739+wattygetlood@users.noreply.github.com> Date: Tue, 28 Sep 2021 18:40:56 -0400 Subject: [PATCH 06/18] Only load 4 ib requests worth of bars on windows... --- piker/brokers/ib.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/piker/brokers/ib.py b/piker/brokers/ib.py index 4139d60d..788bc829 100644 --- a/piker/brokers/ib.py +++ b/piker/brokers/ib.py @@ -1204,6 +1204,11 @@ async def backfill_bars( https://github.com/pikers/piker/issues/128 """ + if platform.system() == 'Windows': + log.warning( + 'Decreasing history query count to 4 since, windows...') + count = 4 + out, fails = await get_bars(sym) if out is None: From fc3c0741b892446b894290f3aca2453f71eb4033 Mon Sep 17 00:00:00 2001 From: wattygetlood <61716739+wattygetlood@users.noreply.github.com> Date: Tue, 28 Sep 2021 18:42:23 -0400 Subject: [PATCH 07/18] Set isn't serializable on std msgpack --- piker/clearing/_ems.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piker/clearing/_ems.py b/piker/clearing/_ems.py index 3756daf4..1567f795 100644 --- a/piker/clearing/_ems.py +++ b/piker/clearing/_ems.py @@ -1054,7 +1054,7 @@ async def _emsd_main( # signal to client that we're started and deliver # all known pps and accounts for this ``brokerd``. - await ems_ctx.started((pp_msgs, relay.accounts)) + await ems_ctx.started((pp_msgs, list(relay.accounts))) # establish 2-way stream with requesting order-client and # begin handling inbound order requests and updates From a0034e2948b533b5a507dfff23f3e20d8aac5d1f Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 7 Feb 2022 17:28:16 -0500 Subject: [PATCH 08/18] If the DE (like windohz) already scales DPI, just use that scale for font size --- piker/ui/_style.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/piker/ui/_style.py b/piker/ui/_style.py index b51331ab..d751efcb 100644 --- a/piker/ui/_style.py +++ b/piker/ui/_style.py @@ -22,6 +22,7 @@ import math import pyqtgraph as pg from PyQt5 import QtCore, QtGui +from PyQt5.QtCore import Qt, QCoreApplication from qdarkstyle import DarkPalette from ..log import get_logger @@ -121,19 +122,29 @@ class DpiAwareFont: dpi = mn_dpi mult = 1.0 - # dpi is likely somewhat scaled down so use slightly larger font size - if scale >= 1.1 and self._font_size: - # no idea why - if 1.2 <= scale: - mult = 1.0375 + if ( + hasattr(Qt, 'AA_EnableHighDpiScaling') + and QCoreApplication.testAttribute(Qt.AA_EnableHighDpiScaling) + ): + inches *= scale - if scale >= 1.5: - mult = 1.375 + # No implicit DPI scaling was done by the DE so let's engage + # some hackery ad-hoc scaling shiat. + else: + # dpi is likely somewhat scaled down so use slightly larger font size + if scale >= 1.1 and self._font_size: - # TODO: this multiplier should probably be determined from - # relative aspect ratios or something? - inches *= mult + # no idea why + if 1.2 <= scale: + mult = 1.0375 + + if scale >= 1.5: + mult = 1.375 + + # TODO: this multiplier should probably be determined from + # relative aspect ratios or something? + inches *= mult # TODO: we might want to fiddle with incrementing font size by # +1 for the edge cases above. it seems doing it via scaling is @@ -142,7 +153,7 @@ class DpiAwareFont: self._font_inches = inches font_size = math.floor(inches * dpi) - log.debug( + log.info( f"screen:{screen.name()}\n" f"pDPI: {pdpi}, lDPI: {ldpi}, scale: {scale}\n" f"\nOur best guess font size is {font_size}\n" From a5ad24f7709e2ea252dd3038b8f508cbdfe45ac9 Mon Sep 17 00:00:00 2001 From: wattygetlood Date: Tue, 8 Feb 2022 09:41:20 -0500 Subject: [PATCH 09/18] Additionally apply DPI scaling to font size if detected --- piker/ui/_style.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/piker/ui/_style.py b/piker/ui/_style.py index d751efcb..21f003d8 100644 --- a/piker/ui/_style.py +++ b/piker/ui/_style.py @@ -123,28 +123,27 @@ class DpiAwareFont: mult = 1.0 + # No implicit DPI scaling was done by the DE so let's engage + # some hackery ad-hoc scaling shiat. + # dpi is likely somewhat scaled down so use slightly larger font size + if scale >= 1.1 and self._font_size: + + # no idea why + if 1.2 <= scale: + mult = 1.0375 + + if scale >= 1.5: + mult = 1.375 + + # TODO: this multiplier should probably be determined from + # relative aspect ratios or something? + inches *= mult + #inches = inches*2 if ( hasattr(Qt, 'AA_EnableHighDpiScaling') and QCoreApplication.testAttribute(Qt.AA_EnableHighDpiScaling) ): - inches *= scale - - # No implicit DPI scaling was done by the DE so let's engage - # some hackery ad-hoc scaling shiat. - else: - # dpi is likely somewhat scaled down so use slightly larger font size - if scale >= 1.1 and self._font_size: - - # no idea why - if 1.2 <= scale: - mult = 1.0375 - - if scale >= 1.5: - mult = 1.375 - - # TODO: this multiplier should probably be determined from - # relative aspect ratios or something? - inches *= mult + inches *= round(scale) # TODO: we might want to fiddle with incrementing font size by # +1 for the edge cases above. it seems doing it via scaling is From 5a4c1557982fefd74ae418d6e01f211aa183d828 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 10 Feb 2022 13:04:13 -0500 Subject: [PATCH 10/18] Add detailed comment around DE scaling --- piker/ui/_style.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/piker/ui/_style.py b/piker/ui/_style.py index 21f003d8..c60cb077 100644 --- a/piker/ui/_style.py +++ b/piker/ui/_style.py @@ -138,7 +138,11 @@ class DpiAwareFont: # TODO: this multiplier should probably be determined from # relative aspect ratios or something? inches *= mult - #inches = inches*2 + + # XXX: if additionally we detect a known DE scaling factor we + # also scale *up* our font size on top of the existing + # heuristical (aka no clue why it works) scaling from the block + # above XD if ( hasattr(Qt, 'AA_EnableHighDpiScaling') and QCoreApplication.testAttribute(Qt.AA_EnableHighDpiScaling) @@ -152,7 +156,7 @@ class DpiAwareFont: self._font_inches = inches font_size = math.floor(inches * dpi) - log.info( + log.debug( f"screen:{screen.name()}\n" f"pDPI: {pdpi}, lDPI: {ldpi}, scale: {scale}\n" f"\nOur best guess font size is {font_size}\n" From c54c9ae3d3fa95f836bda580c14908dfc5f301ae Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 10 Feb 2022 14:20:15 -0500 Subject: [PATCH 11/18] Add doc string to DE sizing method --- piker/ui/_window.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/piker/ui/_window.py b/piker/ui/_window.py index be43a261..9dbe6704 100644 --- a/piker/ui/_window.py +++ b/piker/ui/_window.py @@ -273,7 +273,16 @@ class MainWindow(QtGui.QMainWindow): def configure_to_desktop( self, size: Optional[tuple[int, int]] = None, + ) -> None: + ''' + Explicitly size the window dimensions (for stacked window + managers). + + For tina systems (like windoze) try to do a sane window size on + startup. + + ''' # https://stackoverflow.com/a/18975846 if not size and not self._size: app = QtGui.QApplication.instance() @@ -282,7 +291,7 @@ class MainWindow(QtGui.QMainWindow): self.setMaximumSize(w, h) # use approx 1/3 of the area of the screen by default self._size = round(w * .666), round(h * .666) - + self.resize(*size or self._size) From 51d94a301a07f7b2e388d1b21981ab53d9e4e045 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 10 Feb 2022 14:21:17 -0500 Subject: [PATCH 12/18] Support resize event relaying from the god widget --- piker/ui/_chart.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/piker/ui/_chart.py b/piker/ui/_chart.py index a9350d97..6048ca42 100644 --- a/piker/ui/_chart.py +++ b/piker/ui/_chart.py @@ -112,6 +112,9 @@ class GodWidget(QWidget): # assigned in the startup func `_async_main()` self._root_n: trio.Nursery = None + self._widgets: dict[str, QWidget] = {} + self._resizing: bool = False + # def init_timeframes_ui(self): # self.tf_layout = QHBoxLayout() # self.tf_layout.setSpacing(0) @@ -259,7 +262,16 @@ class GodWidget(QWidget): Where we do UX magic to make things not suck B) ''' - log.debug('god widget resize') + if self._resizing: + return + + self._resizing = True + + log.info('God widget resize') + for name, widget in self._widgets.items(): + widget.on_resize() + + self._resizing = False class ChartnPane(QFrame): From 890ffc76cfd75486b871d9dc772c4308d5ee7152 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 10 Feb 2022 14:22:46 -0500 Subject: [PATCH 13/18] Dynamically re-size the search results view --- piker/ui/_search.py | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/piker/ui/_search.py b/piker/ui/_search.py index 4e9d6184..fcb5bba5 100644 --- a/piker/ui/_search.py +++ b/piker/ui/_search.py @@ -39,6 +39,7 @@ from typing import ( Awaitable, Sequence, Any, AsyncIterator ) +from math import ceil import time # from pprint import pformat @@ -49,7 +50,6 @@ from PyQt5 import QtCore from PyQt5 import QtWidgets from PyQt5.QtCore import ( Qt, - QSize, QModelIndex, QItemSelectionModel, ) @@ -157,17 +157,26 @@ class CompleterView(QTreeView): self._font_size = size self.setStyleSheet(f"font: {size}px") - - #def resizeEvent(self, event: 'QEvent') -> None: - # self.resize_to_results() - # super().resizeEvent(event) + + # def resizeEvent(self, event: 'QEvent') -> None: + # self.resize_to_results() + # super().resizeEvent(event) + + def on_resize(self) -> None: + ''' + Resize relay event from god. + + ''' + self.resize_to_results() def resize_to_results(self): model = self.model() cols = model.columnCount() + col_w_tot = 0 for i in range(cols): self.resizeColumnToContents(i) + col_w_tot += self.columnWidth(i) row_px = self.rowHeight(self.currentIndex()) @@ -175,22 +184,25 @@ class CompleterView(QTreeView): # we should figure out the exact number of rows to allow # inclusive of search bar and header "rows", in pixel terms. window_h = self.window().height() - rows = round(window_h * 0.5 / row_px) - 4 + rows = ceil(window_h / row_px) - 2 - # TODO: the problem here is that this view widget is **not** resizing/scaling - # when the parent layout is adjusted, not sure what exactly is up... - # only "scale up" the results view when the window size has increased/ + # TODO: the problem here is that this view widget is **not** + # resizing/scaling when the parent layout is adjusted, not sure + # what exactly is up... only "scale up" the results view + # when the window size has increased/ if not self._last_window_h or self._last_window_h < window_h: self.setMaximumSize(self.width(), rows * row_px) self.setMinimumSize(self.width(), rows * row_px) - - #elif not self._last_window_h or self._last_window_h > window_h: - # self.setMinimumSize(self.width(), rows * row_px) - # self.setMaximumSize(self.width(), rows * row_px) - + + # self.resize(self.width(), rows * row_px) self.resize(self.width(), rows * row_px) self._last_window_h = window_h - self.setFixedWidth(333) + + # size to width of longest result seen thus far + # TODO: should we always dynamically scale to longest result? + if self.width() < col_w_tot: + self.setFixedWidth(col_w_tot) + self.update() def is_selecting_d1(self) -> bool: @@ -447,6 +459,7 @@ class SearchBar(Edit): self.godwidget = godwidget super().__init__(parent, **kwargs) self.view: CompleterView = view + godwidget._widgets[view.mode_name] = view def show(self) -> None: super().show() From 86b131669136c882e60b6b296d0047302a7b1536 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 10 Feb 2022 14:35:11 -0500 Subject: [PATCH 14/18] Handle no-rows-yet case --- piker/ui/_search.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/piker/ui/_search.py b/piker/ui/_search.py index fcb5bba5..739a29ab 100644 --- a/piker/ui/_search.py +++ b/piker/ui/_search.py @@ -183,8 +183,11 @@ class CompleterView(QTreeView): # TODO: probably make this more general / less hacky # we should figure out the exact number of rows to allow # inclusive of search bar and header "rows", in pixel terms. - window_h = self.window().height() - rows = ceil(window_h / row_px) - 2 + if row_px > 0: + window_h = self.window().height() + rows = ceil(window_h / row_px) - 2 + else: + rows = 16 # TODO: the problem here is that this view widget is **not** # resizing/scaling when the parent layout is adjusted, not sure From 68e1db27f895444c005dcd5e0b6315af1a4e16bc Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 10 Feb 2022 14:35:28 -0500 Subject: [PATCH 15/18] Drop old null window size --- piker/ui/_window.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/piker/ui/_window.py b/piker/ui/_window.py index 9dbe6704..46c35e52 100644 --- a/piker/ui/_window.py +++ b/piker/ui/_window.py @@ -154,7 +154,6 @@ class MainWindow(QtGui.QMainWindow): # with the alloted window size. # TODO: detect for tiling and if untrue set some size? size = (300, 500) - #size = (0, 0) title = 'piker chart (ur symbol is loading bby)' @@ -166,7 +165,7 @@ class MainWindow(QtGui.QMainWindow): self._status_bar: QStatusBar = None self._status_label: QLabel = None self._size: Optional[tuple[int, int]] = None - + @property def mode_label(self) -> QtGui.QLabel: @@ -295,7 +294,6 @@ class MainWindow(QtGui.QMainWindow): self.resize(*size or self._size) - # singleton app per actor _qt_win: QtGui.QMainWindow = None From 412c34eba0f9e795b3220db2f636008ef8a35a0c Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 11 Feb 2022 08:32:28 -0500 Subject: [PATCH 16/18] Drop width check logic; only do height --- piker/ui/_search.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/piker/ui/_search.py b/piker/ui/_search.py index 739a29ab..1a74f59d 100644 --- a/piker/ui/_search.py +++ b/piker/ui/_search.py @@ -112,7 +112,6 @@ class CompleterView(QTreeView): model = QStandardItemModel(self) self.labels = labels - self._last_window_h: Optional[int] = None # a std "tabular" config self.setItemDelegate(FontScaledDelegate(self)) @@ -185,21 +184,14 @@ class CompleterView(QTreeView): # inclusive of search bar and header "rows", in pixel terms. if row_px > 0: window_h = self.window().height() - rows = ceil(window_h / row_px) - 2 + rows = ceil(window_h / row_px) - 6 else: rows = 16 - # TODO: the problem here is that this view widget is **not** - # resizing/scaling when the parent layout is adjusted, not sure - # what exactly is up... only "scale up" the results view - # when the window size has increased/ - if not self._last_window_h or self._last_window_h < window_h: - self.setMaximumSize(self.width(), rows * row_px) - self.setMinimumSize(self.width(), rows * row_px) + self.setFixedHeight(rows * row_px) # self.resize(self.width(), rows * row_px) self.resize(self.width(), rows * row_px) - self._last_window_h = window_h # size to width of longest result seen thus far # TODO: should we always dynamically scale to longest result? @@ -255,7 +247,8 @@ class CompleterView(QTreeView): idx: QModelIndex, ) -> QStandardItem: - '''Select and return the item at index ``idx``. + ''' + Select and return the item at index ``idx``. ''' sel = self.selectionModel() @@ -270,7 +263,8 @@ class CompleterView(QTreeView): return model.itemFromIndex(idx) def select_first(self) -> QStandardItem: - '''Select the first depth >= 2 entry from the completer tree and + ''' + Select the first depth >= 2 entry from the completer tree and return it's item. ''' @@ -333,7 +327,8 @@ class CompleterView(QTreeView): section: str, ) -> Optional[QModelIndex]: - '''Find the *first* depth = 1 section matching ``section`` in + ''' + Find the *first* depth = 1 section matching ``section`` in the tree and return its index. ''' From 9ed153bcb62a9384eec4af94abb4ead19c10803d Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 11 Feb 2022 08:45:57 -0500 Subject: [PATCH 17/18] Less gap below results view --- piker/ui/_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piker/ui/_search.py b/piker/ui/_search.py index 1a74f59d..dc86816e 100644 --- a/piker/ui/_search.py +++ b/piker/ui/_search.py @@ -184,7 +184,7 @@ class CompleterView(QTreeView): # inclusive of search bar and header "rows", in pixel terms. if row_px > 0: window_h = self.window().height() - rows = ceil(window_h / row_px) - 6 + rows = ceil(window_h / row_px) - 3 else: rows = 16 From 92c63988bc843e8e52fcd71e8f9745ba1ed236de Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 11 Feb 2022 10:07:43 -0500 Subject: [PATCH 18/18] Bleh, just fill the available window space --- piker/ui/_search.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/piker/ui/_search.py b/piker/ui/_search.py index dc86816e..8cac6b1a 100644 --- a/piker/ui/_search.py +++ b/piker/ui/_search.py @@ -39,7 +39,6 @@ from typing import ( Awaitable, Sequence, Any, AsyncIterator ) -from math import ceil import time # from pprint import pformat @@ -158,7 +157,7 @@ class CompleterView(QTreeView): self.setStyleSheet(f"font: {size}px") # def resizeEvent(self, event: 'QEvent') -> None: - # self.resize_to_results() + # event.accept() # super().resizeEvent(event) def on_resize(self) -> None: @@ -171,27 +170,37 @@ class CompleterView(QTreeView): def resize_to_results(self): model = self.model() cols = model.columnCount() + # rows = model.rowCount() col_w_tot = 0 for i in range(cols): self.resizeColumnToContents(i) col_w_tot += self.columnWidth(i) - row_px = self.rowHeight(self.currentIndex()) + win = self.window() + win_h = win.height() + edit_h = self.parent().bar.height() + sb_h = win.statusBar().height() # TODO: probably make this more general / less hacky # we should figure out the exact number of rows to allow # inclusive of search bar and header "rows", in pixel terms. - if row_px > 0: - window_h = self.window().height() - rows = ceil(window_h / row_px) - 3 - else: - rows = 16 - - self.setFixedHeight(rows * row_px) - + # Eventually when we have an "info" widget below the results we + # will want space for it and likely terminating the results-view + # space **exactly on a row** would be ideal. + # if row_px > 0: + # rows = ceil(window_h / row_px) - 4 + # else: + # rows = 16 + # self.setFixedHeight(rows * row_px) # self.resize(self.width(), rows * row_px) - self.resize(self.width(), rows * row_px) + + # NOTE: if the heigh set here is **too large** then the resize + # event will perpetually trigger as the window causes some kind + # of recompute of callbacks.. so we have to ensure it's limited. + h = win_h - (edit_h + 1.666*sb_h) + assert h > 0 + self.setFixedHeight(round(h)) # size to width of longest result seen thus far # TODO: should we always dynamically scale to longest result?