Browse Source

fix some lint

Daniel Sheffield 1 year ago
parent
commit
3b48369ddf

+ 1 - 1
app/__init__.py

@@ -1,5 +1,5 @@
 #
-# Copyright (c) Daniel Sheffield 2022
+# Copyright (c) Daniel Sheffield 2022 - 2023
 #
 # All rights reserved
 #

+ 61 - 0
app/activities/ActivityManager.py

@@ -0,0 +1,61 @@
+#
+# Copyright (c) Daniel Sheffield 2021 - 2023
+#
+# All rights reserved
+#
+# THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
+from typing import Iterator
+import urwid
+from urwid.display_common import BaseScreen
+
+def show_or_exit(key,
+    screen: BaseScreen = None, palettes: Iterator = None
+):
+
+    if isinstance(key, tuple):
+        return
+    
+    if key == 'ctrl home':
+        
+        if screen is None or palettes is None:
+            return
+        
+        p = next(palettes)
+        screen.register_palette(p)
+        screen.clear()
+
+    if key in ('esc',):
+        raise urwid.ExitMainLoop()
+
+class ActivityManager():
+
+    def __init__(self):
+        self.widgets = dict()
+        self.app = None
+    
+    def add(self, widget, name):
+        self.widgets[name] = widget
+        return widget
+    
+    def get(self, name):
+        if name in self.widgets:
+            return self.widgets[name]
+        return None
+    
+    def create(self, cls, name, *args, **kwargs):
+        widget = cls(*args, **kwargs)
+        if name is not None:
+            self.add(widget, name)
+        return widget
+    
+    def show(self, widget):
+        if self.app is not None:
+            self.app.original_widget = widget
+            return
+        self.app = widget
+
+    def current(self):
+        if self.app is None:
+            return None
+        return self.app.original_widget
+

+ 9 - 3
app/activities/PriceCheck.py

@@ -7,7 +7,6 @@
 import itertools
 from decimal import Decimal, InvalidOperation
 from itertools import chain
-from typing import Callable, Union
 from urwid import (
     connect_signal,
     AttrMap,
@@ -32,9 +31,16 @@ from ..widgets import (
     FlowBarGraphWithVScale,
 )
 from ..data.QueryManager import QueryManager
-from . import ActivityManager, show_or_exit
+from .ActivityManager import ActivityManager, show_or_exit
 from .Rating import Rating
 
+def get_historic_prices(df):
+    return df.drop(labels=[
+        'id', 'last', 'avg', 'min', 'max', 'price', 'quantity', 'ts_raw', 'product', 'category', 'group'
+    ], axis=1).to_string(header=[
+        'Date', 'Store', '$/unit', 'Org',
+    ], justify='justify-all', max_colwidth=16, index=False)
+
 class PriceCheck(FocusWidget):
 
     def keypress(self, size, key):
@@ -172,7 +178,7 @@ class PriceCheck(FocusWidget):
         self.rating.update_rating(_avg, _min, _max, unit, price=price, quantity=quantity)
 
         self.text_fields['dbview'].set_text(
-            self.rating.get_historic_prices(df)
+            get_historic_prices(df)
         )
         self.update_graph(df)
 

+ 5 - 15
app/activities/Rating.py

@@ -1,24 +1,14 @@
 #
-# Copyright (c) Daniel Sheffield 2021 - 2022
+# Copyright (c) Daniel Sheffield 2021 - 2023
 #
 # All rights reserved
 #
 # THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
 import numpy as np
-class Rating(object):
+class Rating():
     def __init__(self, text_fields):
         self.text_fields = text_fields
-
-    def get_historic_prices(self, df):
-        if df.empty:
-            self.update_rating(None, None, None)
-            return ''
-
-        return df.drop(labels=[
-            'id', 'last', 'avg', 'min', 'max', 'price', 'quantity', 'ts_raw', 'product', 'category', 'group'
-        ], axis=1).to_string(header=[
-            'Date', 'Store', '$/unit', 'Org',
-        ], justify='justify-all', max_colwidth=16, index=False)
+        self.size = 14
 
     def update_rating(self, _avg, _min, _max, unit, price=None, quantity=None):
         if None in (_avg, _min, _max):
@@ -27,8 +17,8 @@ class Rating(object):
             self.text_fields['marker'].set_text('')
             return
         current = None if None in (price, quantity or None) else float(price/quantity)
-        size = 14
-        chars = ['|', *['-']*(size - 2), '|' ]
+        
+        chars = ['|', *['-']*(self.size - 2), '|' ]
         rating = [' ']*len(chars)
         _min, _max = min(_min, current or _min), max(_max, current or _max)
         ls = np.linspace(_min, _max, len(chars))

+ 1 - 4
app/activities/RecipeEditor.py

@@ -29,15 +29,12 @@ from urwid.numedit import FloatEdit
 from .. import COPYRIGHT
 from ..widgets import (
     AutoCompleteEdit,
-    AutoCompleteFloatEdit,
     FocusWidget,
     AutoCompletePopUp,
     NoTabCheckBox,
-    FlowBarGraphWithVScale,
 )
 from ..data.QueryManager import QueryManager
-from . import ActivityManager, show_or_exit
-from .Rating import Rating
+from .ActivityManager import ActivityManager, show_or_exit
 import yaml
 def change_style(style, representer):
     def new_representer(dumper, data):

+ 1 - 61
app/activities/__init__.py

@@ -1,66 +1,6 @@
 #
-# Copyright (c) Daniel Sheffield 2021
+# Copyright (c) Daniel Sheffield 2021 - 2023
 #
 # All rights reserved
 #
 # THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
-from typing import Iterator
-import urwid
-from urwid.display_common import BaseScreen
-
-def show_or_exit(key,
-    screen: BaseScreen = None, palettes: Iterator = None
-):
-
-    if isinstance(key, tuple):
-        return
-    
-    if key == 'ctrl home':
-        
-        if screen is None or palettes is None:
-            return
-        else:
-            try:
-                p = next(palettes)
-                screen.register_palette(p)
-                screen.clear()
-            except StopIteration:
-                pass
-            finally:
-                return
-
-    if key in ('esc',):
-        raise urwid.ExitMainLoop()
-
-class ActivityManager(object):
-
-    def __init__(self):
-        self.widgets = dict()
-        self.app = None
-    
-    def add(self, widget, name):
-        self.widgets[name] = widget
-        return widget
-    
-    def get(self, name):
-        if name in self.widgets:
-            return self.widgets[name]
-        return None
-    
-    def create(self, cls, name, *args, **kwargs):
-        widget = cls(*args, **kwargs)
-        if name is not None:
-            self.add(widget, name)
-        return widget
-    
-    def show(self, widget):
-        if self.app is not None:
-            self.app.original_widget = widget
-            return
-        self.app = widget
-
-    def current(self):
-        if self.app is None:
-            return None
-        return self.app.original_widget
-

+ 1 - 1
grocery_transactions.py

@@ -8,7 +8,7 @@
 import sys
 from psycopg import Cursor
 from urwid import raw_display, WidgetPlaceholder, SolidFill, MainLoop
-from app.activities import ActivityManager, show_or_exit
+from app.activities.ActivityManager import ActivityManager, show_or_exit
 from app.activities.TransactionEditor import TransactionEditor
 from app.data.QueryManager import QueryManager, display_mapper
 from app.palette import solarized

+ 1 - 1
price_check.py

@@ -7,7 +7,7 @@
 # THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
 from psycopg import Cursor
 from urwid import raw_display, WidgetPlaceholder, SolidFill, MainLoop
-from app.activities import ActivityManager, show_or_exit
+from app.activities.ActivityManager import ActivityManager, show_or_exit
 from app.activities.PriceCheck import PriceCheck
 from app.data.QueryManager import QueryManager, display_mapper
 from app.palette import high_contrast

+ 1 - 1
recipe.py

@@ -7,7 +7,7 @@
 # THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
 from psycopg import Cursor
 from urwid import raw_display, WidgetPlaceholder, SolidFill, MainLoop
-from app.activities import ActivityManager, show_or_exit
+from app.activities.ActivityManager import ActivityManager, show_or_exit
 from app.activities.RecipeEditor import RecipeEditor
 from app.data.QueryManager import QueryManager, display_mapper
 from app.palette import high_contrast