From 5b95d19d7c77712ba9fe7fc72e78c0f4b0a200d4 Mon Sep 17 00:00:00 2001 From: alessandro90 Date: Mon, 1 Apr 2019 22:53:54 +0200 Subject: [PATCH] Update left half of space weather with colored labels. Also apply minor modifications --- artemis.py | 217 +++++++++- artemis.ui | 951 ++++++++++++++++++++++++++---------------- constants.py | 24 ++ download_window.py | 6 +- space_weather_data.py | 12 +- switchable_label.py | 12 +- themes.py | 4 +- threads.py | 10 +- utilities.py | 11 +- 9 files changed, 854 insertions(+), 393 deletions(-) diff --git a/artemis.py b/artemis.py index d2589e9..1cbceca 100644 --- a/artemis.py +++ b/artemis.py @@ -1,4 +1,5 @@ from collections import namedtuple +from itertools import chain from functools import partial from glob import glob import webbrowser @@ -26,14 +27,15 @@ from audio_player import AudioPlayer from space_weather_data import SpaceWeatherData from double_text_button import DoubleTextButton from download_window import DownloadWindow -from switchable_label import SwitchableLabel, SwitchableLabelIterable +from switchable_label import SwitchableLabel, SwitchableLabelsIterable from constants import (Constants, Ftype, GfdType, Database, ChecksumWhat, Messages, - Signal,) + Signal, + Colors,) from themes import Theme from utilities import (checksum_ok, uncheck_and_emit, @@ -377,6 +379,81 @@ class Artemis(QMainWindow, Ui_MainWindow): self.update_now_btn.clicked.connect(self.start_update_space_weather) self.space_weather_data = SpaceWeatherData() self.space_weather_data.update_complete.connect(self.update_space_weather) + self.switchable_r_labels = SwitchableLabelsIterable(self.r0_now_lbl, + self.r1_now_lbl, + self.r2_now_lbl, + self.r3_now_lbl, + self.r4_now_lbl, + self.r5_now_lbl,) + self.switchable_s_labels = SwitchableLabelsIterable(self.s0_now_lbl, + self.s1_now_lbl, + self.s2_now_lbl, + self.s3_now_lbl, + self.s4_now_lbl, + self.s5_now_lbl,) + self.switchable_g_now_labels = SwitchableLabelsIterable(self.g0_now_lbl, + self.g1_now_lbl, + self.g2_now_lbl, + self.g3_now_lbl, + self.g4_now_lbl, + self.g5_now_lbl) + self.switchable_g_today_labels = SwitchableLabelsIterable(self.g0_today_lbl, + self.g1_today_lbl, + self.g2_today_lbl, + self.g3_today_lbl, + self.g4_today_lbl, + self.g5_today_lbl) + colors_array = [[Colors.WHITE_LIGHT, Colors.WHITE_DARK], + [Colors.BLUE_LIGHT, Colors.BLUE_DARK], + [Colors.GREEN_LIGHT, Colors.GREEN_DARK], + [Colors.YELLOW_LIGHT, Colors.YELLOW_DARK], + [Colors.ORANGE_LIGHT, Colors.ORANGE_DARK], + [Colors.RED_LIGHT, Colors.RED_DARK]] + + for lab, [light_color, dark_color] in zip(chain(self.switchable_r_labels, + self.switchable_s_labels, + self.switchable_g_now_labels, + self.switchable_g_today_labels), + colors_array * 4): + lab.set_colors(light_color, dark_color) + + k_storms_colors = [[Colors.RED_LIGHT, Colors.RED_DARK], + [Colors.RED2_LIGHT, Colors.RED2_DARK], + [Colors.RED3_LIGHT, Colors.RED3_DARK], + [Colors.ORANGE_LIGHT, Colors.ORANGE_DARK], + [Colors.ORANGE2_LIGHT, Colors.ORANGE2_DARK], + [Colors.YELLOW_LIGHT, Colors.YELLOW_DARK], + [Colors.GREEN3_LIGHT, Colors.GREEN3_DARK], + [Colors.GREEN2_LIGHT, Colors.GREEN2_DARK], + [Colors.GREEN_LIGHT, Colors.GREEN_DARK], + [Colors.BLUE_LIGHT, Colors.BLUE_DARK]] + a_storm_colors = [[Colors.RED_LIGHT, Colors.RED_DARK], + [Colors.ORANGE_LIGHT, Colors.ORANGE_DARK], + [Colors.ORANGE2_LIGHT, Colors.ORANGE2_DARK], + [Colors.YELLOW_LIGHT, Colors.YELLOW_DARK], + [Colors.GREEN_LIGHT, Colors.GREEN_DARK], + [Colors.BLUE_LIGHT, Colors.BLUE_DARK]] + + self.k_storm_labels = SwitchableLabelsIterable(self.k_ex_sev_storm_lbl, + self.k_very_sev_storm_lbl, + self.k_sev_storm_lbl, + self.k_maj_storm_lbl, + self.k_min_storm_lbl, + self.k_active_lbl, + self.k_unsettled_lbl, + self.k_quiet_lbl, + self.k_very_quiet_lbl, + self.k_inactive_lbl) + self.a_storm_labels = SwitchableLabelsIterable(self.a_sev_storm_lbl, + self.a_maj_storm_lbl, + self.a_min_storm_lbl, + self.a_active_lbl, + self.a_unsettled_lbl, + self.a_quiet_lbl) + + for lab, [light_color, dark_color] in zip(chain(self.k_storm_labels, self.a_storm_labels), + chain(k_storms_colors, a_storm_colors)): + lab.set_colors(light_color, dark_color) # Final operations. self.theme.initialize() @@ -393,7 +470,129 @@ class Artemis(QMainWindow, Ui_MainWindow): def update_space_weather(self, status_ok): self.update_now_bar.setMaximum(self.update_now_bar.minimum() + 1) if status_ok: - print('ok') # Insert labels values and colors here. + xray_long = float(self.space_weather_data.xray[-1][7]) + format_text = lambda letter, power : letter + f"{xray_long * 10**power:.1f}" + if xray_long < 1e-8 and xray_long != -1.00e+05: + self.peak_flux_lbl.setText(format_text("= 1e-8 and xray_long < 1e-7: + self.peak_flux_lbl.setText(format_text("A", 8)) + elif xray_long >= 1e-7 and xray_long < 1e-6: + self.peak_flux_lbl.setText(format_text("B", 7)) + elif xray_long >= 1e-6 and xray_long < 1e-5: + self.peak_flux_lbl.setText(format_text("C", 6)) + elif xray_long >= 1e-5 and xray_long < 1e-4: + self.peak_flux_lbl.setText(format_text("M", 5)) + elif xray_long >= 1e-4: + self.peak_flux_lbl.setText(format_text("X", 4)) + elif xray_long == -1.00e+05: + self.peak_flux_lbl.setText("No Data") + + if xray_long < 1e-5 and xray_long != -1.00e+05: + self.switchable_r_labels.switch_on(self.r0_now_lbl) + elif xray_long >= 1e-5 and xray_long < 5e-5: + self.switchable_r_labels.switch_on(self.r1_now_lbl) + elif xray_long >= 5e-5 and xray_long < 1e-4: + self.switchable_r_labels.switch_on(self.r2_now_lbl) + elif xray_long >= 1e-4 and xray_long < 1e-3: + self.switchable_r_labels.switch_on(self.r3_now_lbl) + elif xray_long >= 1e-3 and xray_long < 2e-3: + self.switchable_r_labels.switch_on(self.r4_now_lbl) + elif xray_long >= 2e-3: + self.switchable_r_labels.switch_on(self.r5_now_lbl) + elif xray_long == -1.00e+05: + self.switchable_r_labels.switch_off_all() + + pro10 = float(self.space_weather_data.prot_el[-1][8]) + if pro10 < 10 and pro10 != -1.00e+05: + self.switchable_s_labels.switch_on(self.s0_now_lbl) + elif pro10 >= 10 and pro10 < 100: + self.switchable_s_labels.switch_on(self.s1_now_lbl) + elif pro10 >= 100 and pro10 < 1000: + self.switchable_s_labels.switch_on(self.s2_now_lbl) + elif pro10 >= 1000 and pro10 < 10000: + self.switchable_s_labels.switch_on(self.s3_now_lbl) + elif pro10 >= 10000 and pro10 < 100000: + self.switchable_s_labels.switch_on(self.s4_now_lbl) + elif pro10 >= 100000: + self.switchable_s_labels.switch_on(self.s5_now_lbl) + elif pro10 == -1.00e+05: + self.switchable_s_labels.switch_off_all() + + k_index = int(self.space_weather_data.ak_index[8][11].replace('.', '')) + self.k_index_lbl.setText(str(k_index)) + a_index = int(self.space_weather_data.ak_index[7][7].replace('.', '')) + self.a_index_lbl.setText(str(a_index)) + + if k_index == 0: + self.switchable_g_now_labels.switch_on(self.g0_now_lbl) + self.k_storm_labels.switch_on(self.k_inactive_lbl) + elif k_index == 1: + self.switchable_g_now_labels.switch_on(self.g0_now_lbl) + self.k_storm_labels.switch_on(self.k_very_quiet_lbl) + elif k_index == 2: + self.switchable_g_now_labels.switch_on(self.g0_now_lbl) + self.k_storm_labels.switch_on(self.k_quiet_lbl) + elif k_index == 3: + self.switchable_g_now_labels.switch_on(self.g0_now_lbl) + self.k_storm_labels.switch_on(self.k_unsettled_lbl) + elif k_index == 4: + self.switchable_g_now_labels.switch_on(self.g0_now_lbl) + self.k_storm_labels.switch_on(self.k_active_lbl) + elif k_index == 5: + self.switchable_g_now_labels.switch_on(self.g1_now_lbl) + self.k_storm_labels.switch_on(self.k_min_storm_lbl) + elif k_index == 6: + self.switchable_g_now_labels.switch_on(self.g2_now_lbl) + self.k_storm_labels.switch_on(self.k_maj_storm_lbl) + elif k_index == 7: + self.switchable_g_now_labels.switch_on(self.g3_now_lbl) + self.k_storm_labels.switch_on(self.k_sev_storm_lbl) + elif k_index == 8: + self.switchable_g_now_labels.switch_on(self.g4_now_lbl) + self.k_storm_labels.switch_on(self.k_very_sev_storm_lbl) + elif k_index == 9: + self.switchable_g_now_labels.switch_on(self.g5_now_lbl) + self.k_storm_labels.switch_on(self.k_ex_sev_storm_lbl) + + if a_index >= 0 and a_index < 8: + self.a_storm_labels.switch_on(self.a_quiet_lbl) + elif a_index >= 8 and a_index < 16: + self.a_storm_labels.switch_on(self.a_unsettled_lbl) + elif a_index >= 16 and a_index < 30: + self.a_storm_labels.switch_on(self.a_active_lbl) + elif a_index >= 30 and a_index < 50: + self.a_storm_labels.switch_on(self.a_min_storm_lbl) + elif a_index >= 50 and a_index < 100: + self.a_storm_labels.switch_on(self.a_maj_storm_lbl) + elif a_index >= 100 and a_index < 400: + self.a_storm_labels.switch_on(self.a_sev_storm_lbl) + + index = self.space_weather_data.geo_storm[6].index("was") + 1 + k_index_24_hmax = int(self.space_weather_data.geo_storm[6][index]) + if k_index_24_hmax == 0: + self.switchable_g_today_labels.switch_on(self.g0_today_lbl) + elif k_index_24_hmax == 1: + self.switchable_g_today_labels.switch_on(self.g0_today_lbl) + elif k_index_24_hmax == 2: + self.switchable_g_today_labels.switch_on(self.g0_today_lbl) + elif k_index_24_hmax == 3: + self.switchable_g_today_labels.switch_on(self.g0_today_lbl) + elif k_index_24_hmax == 4: + self.switchable_g_today_labels.switch_on(self.g0_today_lbl) + elif k_index_24_hmax == 5: + self.switchable_g_today_labels.switch_on(self.g1_today_lbl) + elif k_index_24_hmax == 6: + self.switchable_g_today_labels.switch_on(self.g2_today_lbl) + elif k_index_24_hmax == 7: + self.switchable_g_today_labels.switch_on(self.g3_today_lbl) + elif k_index_24_hmax == 8: + self.switchable_g_today_labels.switch_on(self.g4_today_lbl) + elif k_index_24_hmax == 9: + self.switchable_g_today_labels.switch_on(self.g5_today_lbl) + + self.sfi_lbl.setText(self.space_weather_data.ak_index[7][2].replace('.', '').lstrip('0')) + self.sn_lbl.setText([x[4] for i, x in enumerate(self.space_weather_data.sgas) if "SSN" in x][0].lstrip('0')) + else: pop_up(self, title = Messages.BAD_DOWNLOAD, text = Messages.BAD_DOWNLOAD_MSG).show() @@ -402,10 +601,10 @@ class Artemis(QMainWindow, Ui_MainWindow): @pyqtSlot() def go_to_gfd(self, by): query = "/?q=" - if by == GfdType.FREQ: + if by is GfdType.FREQ: value_in_mhz = self.freq_gfd.value() * Constants.CONVERSION_FACTORS[self.unit_freq_gfd.currentText()] / Constants.CONVERSION_FACTORS["MHz"] query += str(value_in_mhz) - elif by == GfdType.LOC: + elif by is GfdType.LOC: query += self.gfd_line_edit.text() try: webbrowser.open(Constants.GFD_SITE + query.lower()) @@ -1060,9 +1259,9 @@ if __name__ == '__main__': my_app = QApplication(sys.argv) img = QPixmap(":/icons/Artemis3.500px.png") # img = img.scaled(600, 600, aspectRatioMode = Qt.KeepAspectRatio) - splash = QSplashScreen(img) - splash.show() - sleep(2) + # splash = QSplashScreen(img) + # splash.show() + # sleep(2) w = Artemis() - splash.finish(w) + # splash.finish(w) sys.exit(my_app.exec_()) diff --git a/artemis.ui b/artemis.ui index 61e4b3d..920bdb3 100644 --- a/artemis.ui +++ b/artemis.ui @@ -6,8 +6,8 @@ 0 0 - 1206 - 674 + 1387 + 761 @@ -4604,7 +4604,7 @@ www.qrg.globaltuners.com Now - + @@ -4613,7 +4613,7 @@ www.qrg.globaltuners.com - 9 + 11 75 true true @@ -4624,106 +4624,11 @@ www.qrg.globaltuners.com - - - - - - Radio Blackout - - - - - - - - - - - 75 - true - - - - R0 - - - - - - - - 75 - true - - - - R1 - - - - - - - - 75 - true - - - - R2 - - - - - - - - 75 - true - - - - R3 - - - - - - - - 75 - true - - - - R4 - - - - - - - - 75 - true - - - - R5 - - - - - - - - - + - 9 + 11 75 true true @@ -4734,10 +4639,15 @@ www.qrg.globaltuners.com - + + + + 9 + + Solar Radiation Storm @@ -4757,6 +4667,9 @@ www.qrg.globaltuners.com S0 + + Qt::AlignCenter + @@ -4770,6 +4683,9 @@ www.qrg.globaltuners.com S1 + + Qt::AlignCenter + @@ -4783,6 +4699,9 @@ www.qrg.globaltuners.com S2 + + Qt::AlignCenter + @@ -4796,6 +4715,9 @@ www.qrg.globaltuners.com S3 + + Qt::AlignCenter + @@ -4809,6 +4731,9 @@ www.qrg.globaltuners.com S4 + + Qt::AlignCenter + @@ -4822,6 +4747,9 @@ www.qrg.globaltuners.com S5 + + Qt::AlignCenter + @@ -4833,7 +4761,7 @@ www.qrg.globaltuners.com - 9 + 11 75 true true @@ -4848,6 +4776,13 @@ www.qrg.globaltuners.com + + + 9 + 75 + true + + K-Index @@ -4855,6 +4790,11 @@ www.qrg.globaltuners.com + + + 9 + + - @@ -4862,10 +4802,17 @@ www.qrg.globaltuners.com - + + + + 9 + 75 + true + + A-Index @@ -4873,6 +4820,11 @@ www.qrg.globaltuners.com + + + 9 + + - @@ -4884,202 +4836,282 @@ www.qrg.globaltuners.com - + - 7 + 9 + 75 + true EXTREMELY SEVERE STORM + + Qt::AlignCenter + - + - 7 + 9 + 75 + true VERY SEVERE STORM + + Qt::AlignCenter + - + - 7 + 9 + 75 + true SEVERE STORM + + Qt::AlignCenter + - + - 7 + 9 + 75 + true MAJOR STORM + + Qt::AlignCenter + - + - 7 + 9 + 75 + true MINOR STORM + + Qt::AlignCenter + - + - 7 + 9 + 75 + true ACTIVE + + Qt::AlignCenter + - + - 7 + 9 + 75 + true UNSETTLED + + Qt::AlignCenter + - + - 7 + 9 + 75 + true QUIET + + Qt::AlignCenter + - + - 7 + 9 + 75 + true VERY QUIET + + Qt::AlignCenter + - + - 7 + 9 + 75 + true INACTIVE + + Qt::AlignCenter + - + - + - 7 + 9 + 75 + true SEVERE STORM + + Qt::AlignCenter + - + - 7 + 9 + 75 + true MAJOR STORM + + Qt::AlignCenter + - + - 7 + 9 + 75 + true MINOR STORM + + Qt::AlignCenter + - + - 7 + 9 + 75 + true ACTIVE + + Qt::AlignCenter + - + - 7 + 9 + 75 + true UNSETTLED + + Qt::AlignCenter + - + - 7 + 9 + 75 + true QUIET + + Qt::AlignCenter + @@ -5089,6 +5121,13 @@ STORM + + + 9 + 75 + true + + SFI @@ -5096,6 +5135,11 @@ STORM + + + 9 + + - @@ -5103,10 +5147,17 @@ STORM - + + + + 9 + 75 + true + + SN @@ -5114,6 +5165,11 @@ STORM + + + 9 + + - @@ -5121,192 +5177,251 @@ STORM - - - - Geomagnetic Storm (now) - - - - - - - - - - - 75 - true - - - - G0 - - - - - - - - 75 - true - - - - G1 - - - - - - - - 75 - true - - - - G2 - - - - - - - - 75 - true - - - - G3 - - - - - - - - 75 - true - - - - G4 - - - - - - - - 75 - true - - - - G5 - - - - - - - - - Geomagnetic Storm (MAX 24 hrs) - - + + + + + + 9 + + + + Geomagnetic Storm (MAX 24 hrs) + + + + + + + + + + + 75 + true + + + + G0 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + G1 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + G2 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + G3 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + G4 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + G5 + + + Qt::AlignCenter + + + + + + + - - - - - - - - 75 - true - - - - G0 - - - - - - - - 75 - true - - - - G1 - - - - - - - - 75 - true - - - - G2 - - - - - - - - 75 - true - - - - G3 - - - - - - - - 75 - true - - - - G4 - - - - - - - - 75 - true - - - - G5 - - - - - + + + + + + + 9 + + + + Geomagnetic Storm (now) + + + + + + + + + + + 75 + true + + + + G0 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + G1 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + G2 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + G3 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + G4 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + G5 + + + Qt::AlignCenter + + + + + + + - + + + + 9 + + Peak Flux Class @@ -5314,6 +5429,11 @@ STORM + + + 9 + + - @@ -5324,6 +5444,124 @@ STORM + + + + + + + 9 + + + + Radio Blackout + + + + + + + + + + + 75 + true + + + + R0 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + R1 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + R2 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + R3 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + R4 + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + R5 + + + Qt::AlignCenter + + + + + + + + @@ -5331,17 +5569,47 @@ STORM - - - - 15 - 75 - true - true - + + + + 0 + 0 + - Protons-Electrons Flux + Info + + + + + + + + 0 + 0 + + + + Update + + + + + + + + 0 + 0 + + + + 1 + + + -1 + + + false @@ -5350,33 +5618,6 @@ STORM - - - - Info - - - - - - - Update - - - - - - - 1 - - - -1 - - - false - - - @@ -5645,7 +5886,7 @@ QSlider::handle:horizontal { 0 0 - 1206 + 1387 21 diff --git a/constants.py b/constants.py index 904d340..b4c6ec7 100644 --- a/constants.py +++ b/constants.py @@ -66,6 +66,30 @@ class Database(object): Signal.SUP_BAND, Signal.CATEGORY_CODE,) +class Colors(object): + RED_DARK = "#4d0000" + RED_LIGHT = "#ff0000" + RED2_DARK = "#4c0c00" + RED2_LIGHT = "#ff2700" + RED3_DARK = "#4b1100" + RED3_LIGHT = "#ff3a00" + ORANGE_DARK = "#4d2e00" + ORANGE_LIGHT = "#ffad33" + ORANGE2_DARK = "#4c2000" + ORANGE2_LIGHT = "#ff6c00" + GREEN_DARK = "#003300" + GREEN_LIGHT = "#33ff33" + GREEN2_DARK = "#424d00" + GREEN2_LIGHT = "#dcff00" + GREEN3_DARK = "#344d00" + GREEN3_LIGHT = "#aeff00" + BLUE_DARK = "#000033" + BLUE_LIGHT = "#3333ff" + WHITE_DARK = "#333333" + WHITE_LIGHT = "#d9b3ff" + YELLOW_DARK = "#333300" + YELLOW_LIGHT = "#ffff33" + class Constants(object): ACF_DOCS = "https://aresvalley.com/documentation/" FORECAST_XRAY = "https://services.swpc.noaa.gov/text/goes-xray-flux-primary.txt" diff --git a/download_window.py b/download_window.py index 8b0df8e..47907e2 100644 --- a/download_window.py +++ b/download_window.py @@ -50,11 +50,11 @@ class DownloadWindow(QWidget, Ui_Download_window): @pyqtSlot() def wait_close(self): - if self.download_thread.status == ThreadStatus.OK: + if self.download_thread.status is ThreadStatus.OK: self.close() - elif self.download_thread.status == ThreadStatus.NO_CONNECTION_ERR: + elif self.download_thread.status is ThreadStatus.NO_CONNECTION_ERR: self.show_no_connection_warning() - elif self.download_thread.status == ThreadStatus.BAD_DOWNLOAD_ERR: + elif self.download_thread.status is ThreadStatus.BAD_DOWNLOAD_ERR: self.show_bad_download_warning() else: self.close() diff --git a/space_weather_data.py b/space_weather_data.py index e33f1bd..694c4c8 100644 --- a/space_weather_data.py +++ b/space_weather_data.py @@ -1,7 +1,6 @@ from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject from threads import UpadteSpaceWeatherThread, ThreadStatus -from utilities import double_split class SpaceWeatherData(QObject): update_complete = pyqtSignal(bool) @@ -21,10 +20,11 @@ class SpaceWeatherData(QObject): self.__update_thread.start() def __parse_data(self): - self.xray = double_split(self.xray) - self.prot_el = double_split(self.prot_el) - self.ak_index = double_split(self.ak_index) - self.sgas = double_split(self.sgas) + double_split = lambda string : [i.split() for i in string.splitlines()] + self.xray = double_split(self.xray) + self.prot_el = double_split(self.prot_el) + self.ak_index = double_split(self.ak_index) + self.sgas = double_split(self.sgas) self.geo_storm = double_split(self.geo_storm) def remove_data(self): @@ -36,7 +36,7 @@ class SpaceWeatherData(QObject): @pyqtSlot() def __parse_and_emit_signal(self): - if self.__update_thread.status != ThreadStatus.OK: + if self.__update_thread.status is not ThreadStatus.OK: status_ok = False else: status_ok = True diff --git a/switchable_label.py b/switchable_label.py index 44b9207..68639b6 100644 --- a/switchable_label.py +++ b/switchable_label.py @@ -11,13 +11,15 @@ class SwitchableLabel(QLabel): self.switch_off_color = off def switch_on(self): - self.setStyleSheet(f"background-color: {self.switch_on_color}") + self.setStyleSheet(f"""background-color: {self.switch_on_color}; + color:#000000;""") def switch_off(self): - self.setStyleSheet(f"background-color: {self.switch_off_color}") + self.setStyleSheet(f"""background-color: {self.switch_off_color}; + color:#000000;""") -class SwitchableLabelIterable(object): +class SwitchableLabelsIterable(object): def __init__(self, *labels): self.labels = labels @@ -25,9 +27,9 @@ class SwitchableLabelIterable(object): for lab in self.labels: yield lab - def switch_on(label): + def switch_on(self, label): for lab in self.labels: - if lab == label: + if lab is label: lab.switch_on() else: lab.switch_off() diff --git a/themes.py b/themes.py index a1603c4..db2cb69 100644 --- a/themes.py +++ b/themes.py @@ -1,10 +1,11 @@ from functools import partial import os +import re from PyQt5.QtWidgets import QAction from PyQt5.QtCore import pyqtSlot from PyQt5.QtGui import QPixmap from constants import Constants -from utilities import pop_up, is_valid_html_color +from utilities import pop_up class ThemeConstants(object): FOLDER = "themes" @@ -138,6 +139,7 @@ class Theme(object): valid_format = True quality, color = line.split(ThemeConstants.COLOR_SEPARATOR) color = color.rstrip() + is_valid_html_color = lambda color : bool(re.match("#([a-zA-Z0-9]){6}", color)) if quality.lower() == Constants.ACTIVE and is_valid_html_color(color): self.__parent.active_color = color active_color_ok = True diff --git a/threads.py b/threads.py index dcb6310..8ea2cbb 100644 --- a/threads.py +++ b/threads.py @@ -73,10 +73,10 @@ class UpadteSpaceWeatherThread(QThread): def run(self): try: - self.__space_weather_data.xray = str(urllib3.PoolManager().request('GET', Constants.FORECAST_XRAY).data) - self.__space_weather_data.prot_el = str(urllib3.PoolManager().request('GET', Constants.FORECAST_PROT).data) - self.__space_weather_data.ak_index = str(urllib3.PoolManager().request('GET', Constants.FORECAST_AK_IND).data) - self.__space_weather_data.sgas = str(urllib3.PoolManager().request('GET', Constants.FORECAST_SGAS).data) - self.__space_weather_data.geo_storm = str(urllib3.PoolManager().request('GET', Constants.FORECAST_G).data) + self.__space_weather_data.xray = str(urllib3.PoolManager().request('GET', Constants.FORECAST_XRAY).data, 'utf-8') + self.__space_weather_data.prot_el = str(urllib3.PoolManager().request('GET', Constants.FORECAST_PROT).data, 'utf-8') + self.__space_weather_data.ak_index = str(urllib3.PoolManager().request('GET', Constants.FORECAST_AK_IND).data, 'utf-8') + self.__space_weather_data.sgas = str(urllib3.PoolManager().request('GET', Constants.FORECAST_SGAS).data, 'utf-8') + self.__space_weather_data.geo_storm = str(urllib3.PoolManager().request('GET', Constants.FORECAST_G).data, 'utf-8') except: self.__status = ThreadStatus.UNKNOWN_ERR diff --git a/utilities.py b/utilities.py index e79ff95..51d7c66 100644 --- a/utilities.py +++ b/utilities.py @@ -1,6 +1,5 @@ from functools import partial import hashlib -import re import sys import os from pandas import read_csv @@ -42,9 +41,9 @@ def pop_up(cls, title, text, def checksum_ok(data, what): code = hashlib.sha256() code.update(data) - if what == ChecksumWhat.FOLDER: + if what is ChecksumWhat.FOLDER: n = 0 - elif what == ChecksumWhat.DB: + elif what is ChecksumWhat.DB: n = 1 else: raise ValueError("Wrong entry name.") @@ -55,9 +54,6 @@ def checksum_ok(data, what): raise return code.hexdigest() == reference -def is_valid_html_color(color): - return bool(re.match("#([a-zA-Z0-9]){6}", color)) - def connect_to(events_to_connect, fun_to_connect, fun_args): if fun_args: for event in events_to_connect: @@ -107,6 +103,3 @@ def format_numbers(lower, upper): return f"{lower:,} {units[lower_factor]} - {upper:,} {units[upper_factor]}" else: return f"{lower:,} {units[lower_factor]}" - -def double_split(string): - return [i.split() for i in string.splitlines()]