From ea93e96d884717410b8a72ae19ba8e126d5a5584 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 17 Jun 2020 14:51:29 -0400 Subject: [PATCH] Move all kivy ui components to subpackage --- piker/brokers/questrade.py | 8 +++++++- piker/ui/cli.py | 6 +++--- piker/ui/{ => kivy}/monitor.py | 4 ++-- piker/ui/kivy/mouse_over.py | 4 ++-- piker/ui/{ => kivy}/option_chain.py | 7 +++---- piker/ui/{ => kivy}/pager.py | 4 ++-- piker/ui/{ => kivy}/tabular.py | 4 ++-- 7 files changed, 21 insertions(+), 16 deletions(-) rename piker/ui/{ => kivy}/monitor.py (99%) rename piker/ui/{ => kivy}/option_chain.py (99%) rename piker/ui/{ => kivy}/pager.py (99%) rename piker/ui/{ => kivy}/tabular.py (99%) diff --git a/piker/brokers/questrade.py b/piker/brokers/questrade.py index 73ad2984..b69eb53f 100644 --- a/piker/brokers/questrade.py +++ b/piker/brokers/questrade.py @@ -964,13 +964,19 @@ def format_option_quote( # change = percent_change(previous, last) computed = { # why QT do you have to be an asshole shipping null values!!! - '$ vol': round((quote['VWAP'] or 0) * (quote['volume'] or 0), 3), + # '$ vol': round((quote['VWAP'] or 0) * (quote['volume'] or 0), 3), # '%': round(change, 3), # 'close': previous, } new = {} displayable = {} + vwap = quote.get('VWAP') + volume = quote.get('volume') + if volume is not None: # could be 0 + # why questrade do you have to be an asshole shipping null values!!! + computed['$ vol'] = round((vwap or 0) * (volume or 0), 3) + # structuring and normalization for key, new_key in keymap.items(): display_value = value = computed.get(key) or quote.get(key) diff --git a/piker/ui/cli.py b/piker/ui/cli.py index f9b693a0..e572d1d8 100644 --- a/piker/ui/cli.py +++ b/piker/ui/cli.py @@ -45,7 +45,7 @@ def monitor(config, rate, name, dhost, test, tl): return _kivy_import_hack() - from .monitor import _async_main + from .kivy.monitor import _async_main async def main(tries): async with maybe_spawn_brokerd_as_subactor( @@ -61,7 +61,7 @@ def monitor(config, rate, name, dhost, test, tl): partial(main, tries=1), name='monitor', loglevel=loglevel if tl else None, - rpc_module_paths=['piker.ui.monitor'], + rpc_module_paths=['piker.ui.kivy.monitor'], start_method='forkserver', ) @@ -81,7 +81,7 @@ def optschain(config, symbol, date, tl, rate, test): brokername = config['broker'] _kivy_import_hack() - from .option_chain import _async_main + from .kivy.option_chain import _async_main async def main(tries): async with maybe_spawn_brokerd_as_subactor( diff --git a/piker/ui/monitor.py b/piker/ui/kivy/monitor.py similarity index 99% rename from piker/ui/monitor.py rename to piker/ui/kivy/monitor.py index cd73c3fa..932b581e 100644 --- a/piker/ui/monitor.py +++ b/piker/ui/kivy/monitor.py @@ -15,11 +15,11 @@ from kivy.lang import Builder from kivy.app import async_runTouchApp from kivy.core.window import Window -from ..brokers.data import DataFeed +from ...brokers.data import DataFeed from .tabular import ( Row, TickerTable, _kv, _black_rgba, colorcode, ) -from ..log import get_logger +from ...log import get_logger from .pager import PagerView diff --git a/piker/ui/kivy/mouse_over.py b/piker/ui/kivy/mouse_over.py index c9ad149b..766371cd 100644 --- a/piker/ui/kivy/mouse_over.py +++ b/piker/ui/kivy/mouse_over.py @@ -11,7 +11,6 @@ from kivy.properties import BooleanProperty, ObjectProperty from kivy.core.window import Window from kivy.clock import Clock - from ...log import get_logger @@ -100,7 +99,8 @@ class MouseOverBehavior(object): # throttle at 10ms latency @triggered(timeout=0.01, interval=False) def _on_mouse_pos(cls, *args): - log.debug(f"{cls} time since last call: {time.time() - cls._last_time}") + log.debug( + f"{cls} time since last call: {time.time() - cls._last_time}") cls._last_time = time.time() # XXX: how to still do this at the class level? # don't proceed if I'm not displayed <=> If have no parent diff --git a/piker/ui/option_chain.py b/piker/ui/kivy/option_chain.py similarity index 99% rename from piker/ui/option_chain.py rename to piker/ui/kivy/option_chain.py index e2421103..cfa0e665 100644 --- a/piker/ui/option_chain.py +++ b/piker/ui/kivy/option_chain.py @@ -15,11 +15,10 @@ from kivy.app import async_runTouchApp from kivy.core.window import Window from kivy.uix.label import Label -from ..log import get_logger, get_console_log -from ..brokers.data import DataFeed -from ..brokers import get_brokermod +from ...log import get_logger, get_console_log +from ...brokers.data import DataFeed +from ...brokers import get_brokermod from .pager import PagerView - from .tabular import Row, HeaderCell, Cell, TickerTable from .monitor import update_quotes diff --git a/piker/ui/pager.py b/piker/ui/kivy/pager.py similarity index 99% rename from piker/ui/pager.py rename to piker/ui/kivy/pager.py index ca17935b..20a8baef 100644 --- a/piker/ui/pager.py +++ b/piker/ui/kivy/pager.py @@ -9,8 +9,8 @@ from kivy.uix.widget import Widget from kivy.uix.textinput import TextInput from kivy.uix.scrollview import ScrollView -from ..log import get_logger -from .kivy.utils_async import async_bind +from ...log import get_logger +from .utils_async import async_bind log = get_logger('keyboard') diff --git a/piker/ui/tabular.py b/piker/ui/kivy/tabular.py similarity index 99% rename from piker/ui/tabular.py rename to piker/ui/kivy/tabular.py index 27c1e091..5a5a6b3a 100644 --- a/piker/ui/tabular.py +++ b/piker/ui/kivy/tabular.py @@ -12,8 +12,8 @@ from kivy.uix.button import Button from kivy import utils from kivy.properties import BooleanProperty -from ..log import get_logger -from .kivy.mouse_over import new_mouse_over_group +from ...log import get_logger +from .mouse_over import new_mouse_over_group HoverBehavior = new_mouse_over_group()