From d18a2bbe323edb575ca5822090bb735328d98150 Mon Sep 17 00:00:00 2001 From: max Date: Wed, 18 Dec 2024 15:24:24 +1100 Subject: [PATCH] updating formatting --- src/accessvis/widgets/__init__.py | 2 +- src/accessvis/widgets/calendar_widget.py | 36 +++++++++++++----------- src/accessvis/widgets/clock_widget.py | 10 ++++--- src/accessvis/widgets/image_widget.py | 1 + src/accessvis/widgets/season_widget.py | 36 +++++++++++++----------- src/accessvis/widgets/text_widget.py | 9 +++--- src/accessvis/widgets/widget_base.py | 10 +++---- 7 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/accessvis/widgets/__init__.py b/src/accessvis/widgets/__init__.py index b83385a..f989330 100644 --- a/src/accessvis/widgets/__init__.py +++ b/src/accessvis/widgets/__init__.py @@ -3,4 +3,4 @@ from .calendar_widget import CalendarWidget from .clock_widget import ClockWidget from .image_widget import ImageWidget -from .text_widget import TextWidget \ No newline at end of file +from .text_widget import TextWidget diff --git a/src/accessvis/widgets/calendar_widget.py b/src/accessvis/widgets/calendar_widget.py index 65c21f3..2278b6f 100644 --- a/src/accessvis/widgets/calendar_widget.py +++ b/src/accessvis/widgets/calendar_widget.py @@ -1,27 +1,30 @@ -import numpy as np -import matplotlib.pyplot as plt import calendar import datetime + +import numpy as np +import matplotlib.pyplot as plt + from .widget_base import WidgetMPL + class CalendarWidget(WidgetMPL): - def __init__(self,lv, text_colour='black', **kwargs): + def __init__(self, lv, text_colour="black", **kwargs): super().__init__(lv=lv, **kwargs) self.text_colour = text_colour self.arrow = None def _make_mpl(self): - plt.rc('axes', linewidth=4) - plt.rc('font', weight='bold') - fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}, figsize=(5, 5)) + plt.rc("axes", linewidth=4) + plt.rc("font", weight="bold") + fig, ax = plt.subplots(subplot_kw={"projection": "polar"}, figsize=(5, 5)) fig.patch.set_facecolor((0, 0, 0, 0)) # make background transparent - ax.set_facecolor('white') # adds a white ring around edge + ax.set_facecolor("white") # adds a white ring around edge # Setting up grid ax.set_rticks([]) ax.grid(False) - ax.set_theta_zero_location('NW') + ax.set_theta_zero_location("NW") ax.set_theta_direction(-1) # Label Angles @@ -30,36 +33,35 @@ def _make_mpl(self): MONTH.append(calendar.month_name[i][0]) MONTH = np.roll(MONTH, 2) ANGLES = np.linspace(0.0, 2 * np.pi, 12, endpoint=False) - ax.tick_params(axis='x', which='major', pad=12, labelcolor=self.text_colour) + ax.tick_params(axis="x", which="major", pad=12, labelcolor=self.text_colour) ax.set_xticks(ANGLES) ax.set_xticklabels(MONTH, size=20) - ax.spines['polar'].set_color(self.text_colour) + ax.spines["polar"].set_color(self.text_colour) # Make Colours: - ax.bar(x=0, height=10, width=np.pi * 2, color='black') + ax.bar(x=0, height=10, width=np.pi * 2, color="black") for i in range(12): - c = 'darkorange' if i % 2 else 'darkcyan' + c = "darkorange" if i % 2 else "darkcyan" ax.bar(x=i * np.pi / 6, height=10, width=np.pi / 6, color=c) return fig, ax - def _update_mpl(self, fig, ax, date: datetime.datetime = None, show_year=True): if show_year and date is not None: title = str(date.year) else: - title = '' - fig.suptitle(title, fontsize=20, fontweight='bold', y=0.08, color=self.text_colour) + title = "" + fig.suptitle(title, fontsize=20, fontweight="bold", y=0.08, color=self.text_colour) if date is None: return else: day_of_year = date.timetuple().tm_yday - 1 position = day_of_year / 365. * np.pi * 2.0 - self.arrow = ax.arrow(position, 0, 0, 8.5, facecolor='#fff', width=0.1, head_length=2, + self.arrow = ax.arrow(position, 0, 0, 8.5, facecolor="#fff", width=0.1, head_length=2, edgecolor="black") # , zorder=11, width=1) def _reset_mpl(self, fig, ax, **kwargs): - fig.suptitle('') + fig.suptitle("") if self.arrow is not None: self.arrow.remove() diff --git a/src/accessvis/widgets/clock_widget.py b/src/accessvis/widgets/clock_widget.py index b40cd7b..819d1c2 100644 --- a/src/accessvis/widgets/clock_widget.py +++ b/src/accessvis/widgets/clock_widget.py @@ -1,11 +1,13 @@ import datetime -from .widget_base import WidgetMPL + import matplotlib.pyplot as plt import numpy as np +from .widget_base import WidgetMPL + class ClockWidget(WidgetMPL): - def __init__(self, lv, text_colour='white', background='black', + def __init__(self, lv, text_colour="white", background="black", show_seconds=False, show_minutes=True, show_hours=True, **kwargs): super().__init__(lv=lv, **kwargs) self.text_colour = text_colour @@ -23,14 +25,14 @@ def _make_mpl(self): plt.setp(ax.get_yticklabels(), visible=False) ax.set_xticks(np.linspace(0, 2 * np.pi, 12, endpoint=False)) ax.set_xticklabels(range(1, 13)) - ax.tick_params(axis='x', which='major', labelcolor=self.text_colour) + ax.tick_params(axis="x", which="major", labelcolor=self.text_colour) ax.set_theta_direction(-1) ax.set_theta_offset(np.pi / 3.0) ax.grid(False) plt.ylim(0, 1) ax.set_facecolor(self.background) - ax.spines['polar'].set_color(self.text_colour) + ax.spines["polar"].set_color(self.text_colour) return fig, ax diff --git a/src/accessvis/widgets/image_widget.py b/src/accessvis/widgets/image_widget.py index 1a9a7f5..bfeb002 100644 --- a/src/accessvis/widgets/image_widget.py +++ b/src/accessvis/widgets/image_widget.py @@ -1,4 +1,5 @@ import matplotlib.pyplot as plt + from .widget_base import Widget diff --git a/src/accessvis/widgets/season_widget.py b/src/accessvis/widgets/season_widget.py index 8fa726d..4e9e3a8 100644 --- a/src/accessvis/widgets/season_widget.py +++ b/src/accessvis/widgets/season_widget.py @@ -1,49 +1,51 @@ +import datetime + import numpy as np import matplotlib.pyplot as plt -import datetime from matplotlib.colors import LinearSegmentedColormap + from .widget_base import WidgetMPL class SeasonWidget(WidgetMPL): - def __init__(self, lv, text_colour='black', hemisphere='south', **kwargs): + def __init__(self, lv, text_colour="black", hemisphere="south", **kwargs): super().__init__(lv=lv, **kwargs) self.text_colour = text_colour self.hemisphere = hemisphere self.arrow = None def _make_mpl(self): - plt.rc('axes', linewidth=4) - plt.rc('font', weight='bold') - fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}, figsize=(5, 5)) + plt.rc("axes", linewidth=4) + plt.rc("font", weight="bold") + fig, ax = plt.subplots(subplot_kw={"projection": "polar"}, figsize=(5, 5)) fig.patch.set_facecolor((0, 0, 0, 0)) # make background transparent - ax.set_facecolor('white') # adds a white ring around edge + ax.set_facecolor("white") # adds a white ring around edge # Setting up grid ax.set_rticks([]) ax.grid(False) - ax.set_theta_zero_location('N') + ax.set_theta_zero_location("N") ax.set_theta_direction(-1) # Label Angles - if self.hemisphere == 'south': - MONTH = ['Sum', 'Aut', 'Win', 'Spr'] + if self.hemisphere == "south": + MONTH = ["Sum", "Aut", "Win", "Spr"] cmap = LinearSegmentedColormap.from_list("custom_gradient", ["orange", "black", "blue", "black", "orange"]) else: - MONTH = ['Win', 'Spr', 'Sum', 'Aut'] + MONTH = ["Win", "Spr", "Sum", "Aut"] cmap = LinearSegmentedColormap.from_list("custom_gradient", ["blue", "black", "orange", "black", "blue"]) ANGLES = np.linspace(np.pi / 4, 2 * np.pi + np.pi / 4, 4, endpoint=False) - ax.tick_params(axis='x', which='major', pad=12, labelcolor=self.text_colour) + ax.tick_params(axis="x", which="major", pad=12, labelcolor=self.text_colour) ax.set_xticks(ANGLES) ax.set_xticklabels(MONTH, size=20) - ax.spines['polar'].set_color(self.text_colour) + ax.spines["polar"].set_color(self.text_colour) # Colour background based on time of year: dec22 = np.pi * 2.0 * (datetime.date(2001, 12, 22).timetuple().tm_yday - 1) / 365 # summer solstice r = np.linspace(0, 10, 5) theta = np.linspace(dec22, dec22 + 2 * np.pi, 500) R, T = np.meshgrid(r, theta) - ax.pcolormesh(T, R, T, cmap=cmap, shading='gouraud') + ax.pcolormesh(T, R, T, cmap=cmap, shading="gouraud") return fig, ax @@ -51,18 +53,18 @@ def _update_mpl(self, fig, ax, date: datetime.datetime = None, show_year=True): if show_year and date is not None: title = str(date.year) else: - title = '' - fig.suptitle(title, fontsize=20, fontweight='bold', y=0.08, color=self.text_colour) + title = "" + fig.suptitle(title, fontsize=20, fontweight="bold", y=0.08, color=self.text_colour) if date is None: return else: day_of_year = date.timetuple().tm_yday - 1 position = day_of_year / 365. * np.pi * 2.0 - self.arrow = ax.arrow(position, 0, 0, 8.5, facecolor='#fff', width=0.1, head_length=2, + self.arrow = ax.arrow(position, 0, 0, 8.5, facecolor="#fff", width=0.1, head_length=2, edgecolor="black") # , zorder=11, width=1) def _reset_mpl(self, fig, ax, **kwargs): - fig.suptitle('') + fig.suptitle("") if self.arrow is not None: self.arrow.remove() diff --git a/src/accessvis/widgets/text_widget.py b/src/accessvis/widgets/text_widget.py index 2694e3c..b236a57 100644 --- a/src/accessvis/widgets/text_widget.py +++ b/src/accessvis/widgets/text_widget.py @@ -1,9 +1,10 @@ import matplotlib.pyplot as plt + from .widget_base import WidgetMPL class TextWidget(WidgetMPL): - def __init__(self, lv, width=300, height=50, text_colour='black', background=(0, 0, 0, 0), **kwargs): + def __init__(self, lv, width=300, height=50, text_colour="black", background=(0, 0, 0, 0), **kwargs): super().__init__(lv, **kwargs) self.width = width self.height = height @@ -16,13 +17,13 @@ def _make_mpl(self): fig.subplots_adjust(left=0, right=1, top=1, bottom=0) ax.set_axis_off() fig.patch.set_facecolor(self.background) - self.text = ax.text(0.5, 0.5, '', ha='center', va='center', fontsize=20, color=self.text_colour) + self.text = ax.text(0.5, 0.5, "", ha="center", va="center", fontsize=20, color=self.text_colour) return fig, ax - def _update_mpl(self, fig, ax, text='', **kwargs): + def _update_mpl(self, fig, ax, text="", **kwargs): self.text.set_text(text) def _reset_mpl(self, fig, ax, **kwargs): - self.text.set_text('') + self.text.set_text("") diff --git a/src/accessvis/widgets/widget_base.py b/src/accessvis/widgets/widget_base.py index 6ab94a1..0f22d94 100644 --- a/src/accessvis/widgets/widget_base.py +++ b/src/accessvis/widgets/widget_base.py @@ -1,9 +1,9 @@ from abc import ABC, abstractmethod from functools import cached_property +import os import matplotlib.pyplot as plt import numpy as np -import os from ..earth import Settings @@ -22,12 +22,12 @@ def make_overlay(self): pixels[::, ::, ::] = 0 y, x, c = np.shape(pixels) - vert_path = os.path.join(Settings.INSTALL_PATH, 'widgets', 'screen.vert') - frag_path = os.path.join(Settings.INSTALL_PATH, 'widgets', 'screen.frag') + vert_path = os.path.join(Settings.INSTALL_PATH, "widgets", "screen.vert") + frag_path = os.path.join(Settings.INSTALL_PATH, "widgets", "screen.frag") self.overlay = self.lv.screen(shaders=[vert_path, frag_path], vertices=[[0, 0, 0]], texture="blank.png") - self.lv.set_uniforms(self.overlay['name'], scale=self.scale, offset=self.offset, widthToHeight=x / y) + self.lv.set_uniforms(self.overlay["name"], scale=self.scale, offset=self.offset, widthToHeight=x / y) self.overlay.texture(pixels) # Clear texture with transparent image @abstractmethod @@ -43,7 +43,7 @@ def update_widget(self, **kwargs): def remove(self): if self.overlay is not None: - self.lv.delete(self.overlay['name']) + self.lv.delete(self.overlay["name"]) self.overlay = None self.lv = None