Completes first forecast screen (experimental colors). Adds checkable theme in action bar. Fixes bug in show_matching_strings function

This commit is contained in:
alessandro90
2019-04-06 18:54:33 +02:00
parent 5b95d19d7c
commit d626475ace
7 changed files with 1920 additions and 856 deletions

View File

@@ -415,21 +415,21 @@ class Artemis(QMainWindow, Ui_MainWindow):
self.switchable_g_now_labels, self.switchable_g_now_labels,
self.switchable_g_today_labels), self.switchable_g_today_labels),
colors_array * 4): colors_array * 4):
lab.set_colors(light_color, dark_color) lab.set_colors(None, None)
k_storms_colors = [[Colors.RED_LIGHT, Colors.RED_DARK], k_storms_colors = [[Colors.RED_LIGHT, Colors.RED_DARK],
[Colors.RED2_LIGHT, Colors.RED2_DARK], [Colors.RED2_LIGHT, Colors.RED2_DARK],
[Colors.RED3_LIGHT, Colors.RED3_DARK], [Colors.RED3_LIGHT, Colors.RED3_DARK],
[Colors.ORANGE_LIGHT, Colors.ORANGE_DARK],
[Colors.ORANGE2_LIGHT, Colors.ORANGE2_DARK], [Colors.ORANGE2_LIGHT, Colors.ORANGE2_DARK],
[Colors.ORANGE_LIGHT, Colors.ORANGE_DARK],
[Colors.YELLOW_LIGHT, Colors.YELLOW_DARK], [Colors.YELLOW_LIGHT, Colors.YELLOW_DARK],
[Colors.GREEN3_LIGHT, Colors.GREEN3_DARK],
[Colors.GREEN2_LIGHT, Colors.GREEN2_DARK], [Colors.GREEN2_LIGHT, Colors.GREEN2_DARK],
[Colors.GREEN3_LIGHT, Colors.GREEN3_DARK],
[Colors.GREEN_LIGHT, Colors.GREEN_DARK], [Colors.GREEN_LIGHT, Colors.GREEN_DARK],
[Colors.BLUE_LIGHT, Colors.BLUE_DARK]] [Colors.BLUE_LIGHT, Colors.BLUE_DARK]]
a_storm_colors = [[Colors.RED_LIGHT, Colors.RED_DARK], a_storm_colors = [[Colors.RED_LIGHT, Colors.RED_DARK],
[Colors.ORANGE_LIGHT, Colors.ORANGE_DARK],
[Colors.ORANGE2_LIGHT, Colors.ORANGE2_DARK], [Colors.ORANGE2_LIGHT, Colors.ORANGE2_DARK],
[Colors.ORANGE_LIGHT, Colors.ORANGE_DARK],
[Colors.YELLOW_LIGHT, Colors.YELLOW_DARK], [Colors.YELLOW_LIGHT, Colors.YELLOW_DARK],
[Colors.GREEN_LIGHT, Colors.GREEN_DARK], [Colors.GREEN_LIGHT, Colors.GREEN_DARK],
[Colors.BLUE_LIGHT, Colors.BLUE_DARK]] [Colors.BLUE_LIGHT, Colors.BLUE_DARK]]
@@ -453,7 +453,7 @@ class Artemis(QMainWindow, Ui_MainWindow):
for lab, [light_color, dark_color] in zip(chain(self.k_storm_labels, self.a_storm_labels), for lab, [light_color, dark_color] in zip(chain(self.k_storm_labels, self.a_storm_labels),
chain(k_storms_colors, a_storm_colors)): chain(k_storms_colors, a_storm_colors)):
lab.set_colors(light_color, dark_color) lab.set_colors(None, None)
# Final operations. # Final operations.
self.theme.initialize() self.theme.initialize()
@@ -571,27 +571,56 @@ class Artemis(QMainWindow, Ui_MainWindow):
k_index_24_hmax = int(self.space_weather_data.geo_storm[6][index]) k_index_24_hmax = int(self.space_weather_data.geo_storm[6][index])
if k_index_24_hmax == 0: if k_index_24_hmax == 0:
self.switchable_g_today_labels.switch_on(self.g0_today_lbl) self.switchable_g_today_labels.switch_on(self.g0_today_lbl)
self.expected_noise_lbl.setText("S0 - S1 (<-120 dBm)")
elif k_index_24_hmax == 1: elif k_index_24_hmax == 1:
self.switchable_g_today_labels.switch_on(self.g0_today_lbl) self.switchable_g_today_labels.switch_on(self.g0_today_lbl)
self.expected_noise_lbl.setText("S0 - S1 (<-120 dBm)")
elif k_index_24_hmax == 2: elif k_index_24_hmax == 2:
self.switchable_g_today_labels.switch_on(self.g0_today_lbl) self.switchable_g_today_labels.switch_on(self.g0_today_lbl)
self.expected_noise_lbl.setText("S1 - S2 (-115 dBm)")
elif k_index_24_hmax == 3: elif k_index_24_hmax == 3:
self.switchable_g_today_labels.switch_on(self.g0_today_lbl) self.switchable_g_today_labels.switch_on(self.g0_today_lbl)
self.expected_noise_lbl.setText("S2 - S3 (-110 dBm)")
elif k_index_24_hmax == 4: elif k_index_24_hmax == 4:
self.switchable_g_today_labels.switch_on(self.g0_today_lbl) self.switchable_g_today_labels.switch_on(self.g0_today_lbl)
self.expected_noise_lbl.setText("S3 - S4 (-100 dBm)")
elif k_index_24_hmax == 5: elif k_index_24_hmax == 5:
self.switchable_g_today_labels.switch_on(self.g1_today_lbl) self.switchable_g_today_labels.switch_on(self.g1_today_lbl)
self.expected_noise_lbl.setText("S4 - S6 (-90 dBm)")
elif k_index_24_hmax == 6: elif k_index_24_hmax == 6:
self.switchable_g_today_labels.switch_on(self.g2_today_lbl) self.switchable_g_today_labels.switch_on(self.g2_today_lbl)
self.expected_noise_lbl.setText("S6 - S9 (-80 dBm)")
elif k_index_24_hmax == 7: elif k_index_24_hmax == 7:
self.switchable_g_today_labels.switch_on(self.g3_today_lbl) self.switchable_g_today_labels.switch_on(self.g3_today_lbl)
self.expected_noise_lbl.setText("S9 - S20 (>-60 dBm)")
elif k_index_24_hmax == 8: elif k_index_24_hmax == 8:
self.switchable_g_today_labels.switch_on(self.g4_today_lbl) self.switchable_g_today_labels.switch_on(self.g4_today_lbl)
self.expected_noise_lbl.setText("S20 - S30 (>-60 dBm)")
elif k_index_24_hmax == 9: elif k_index_24_hmax == 9:
self.switchable_g_today_labels.switch_on(self.g5_today_lbl) self.switchable_g_today_labels.switch_on(self.g5_today_lbl)
self.expected_noise_lbl.setText("S30+ (>>-60 dBm)")
self.expected_noise_lbl.setStyleSheet(f"""
color:#ffffff;
background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #4776e6 ,stop: 1 #8e54e9);""")
self.sfi_lbl.setText(self.space_weather_data.ak_index[7][2].replace('.', '').lstrip('0')) val = int(self.space_weather_data.ak_index[7][2].replace('.', ''))
self.sn_lbl.setText([x[4] for i, x in enumerate(self.space_weather_data.sgas) if "SSN" in x][0].lstrip('0')) self.sfi_lbl.setText(f"{val}")
val = int([x[4] for x in self.space_weather_data.sgas if "SSN" in x][0])
self.sn_lbl.setText(f"{val:d}")
forecast_labels = (self.forecast_lbl_0,
self.forecast_lbl_1,
self.forecast_lbl_2,
self.forecast_lbl_3,
self.forecast_lbl_4,
self.forecast_lbl_5,
self.forecast_lbl_6,
self.forecast_lbl_7,
self.forecast_lbl_8)
for label, pixmap in zip(forecast_labels, self.space_weather_data.images):
label.setText('')
label.setPixmap(pixmap)
label.setScaledContents(True)
else: else:
pop_up(self, title = Messages.BAD_DOWNLOAD, pop_up(self, title = Messages.BAD_DOWNLOAD,
@@ -632,7 +661,7 @@ class Artemis(QMainWindow, Ui_MainWindow):
def show_matching_strings(self, list_elements, text): def show_matching_strings(self, list_elements, text):
for index in range(list_elements.count()): for index in range(list_elements.count()):
item = list_elements.item(index) item = list_elements.item(index)
if text.upper() in item.text() or item.isSelected(): if text.lower() in item.text().lower() or item.isSelected():
item.setHidden(False) item.setHidden(False)
else: else:
item.setHidden(True) item.setHidden(True)

1504
artemis.ui

File diff suppressed because it is too large Load Diff

View File

@@ -98,6 +98,15 @@ class Constants(object):
FORECAST_SGAS = "https://services.swpc.noaa.gov/text/sgas.txt" FORECAST_SGAS = "https://services.swpc.noaa.gov/text/sgas.txt"
FORECAST_G = "https://services.swpc.noaa.gov/text/3-day-forecast.txt" FORECAST_G = "https://services.swpc.noaa.gov/text/3-day-forecast.txt"
FORECAST_INFO = "https://www.swpc.noaa.gov/sites/default/files/images/NOAAscales.pdf" FORECAST_INFO = "https://www.swpc.noaa.gov/sites/default/files/images/NOAAscales.pdf"
FORECAST_IMG_0 = "http://www.mmmonvhf.de/eme/eme.png"
FORECAST_IMG_1 = "http://www.mmmonvhf.de/ms/ms.png"
FORECAST_IMG_2 = "http://www.mmmonvhf.de/es/es.png"
FORECAST_IMG_3 = "http://www.mmmonvhf.de/solar/solar.png"
FORECAST_IMG_4 = "http://amunters.home.xs4all.nl/eskipstatusNA.gif"
FORECAST_IMG_5 = "http://amunters.home.xs4all.nl/aurorastatus.gif"
FORECAST_IMG_6 = "http://amunters.home.xs4all.nl/eskip50status.gif"
FORECAST_IMG_7 = "http://amunters.home.xs4all.nl/eskip70status.gif"
FORECAST_IMG_8 = "http://amunters.home.xs4all.nl/eskipstatus.gif"
SEARCH_LABEL_IMG = "search_icon.png" SEARCH_LABEL_IMG = "search_icon.png"
VOLUME_LABEL_IMG = "volume.png" VOLUME_LABEL_IMG = "volume.png"
DATA_FOLDER = "Data" DATA_FOLDER = "Data"

View File

@@ -1,5 +1,5 @@
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject
from threads import UpadteSpaceWeatherThread, ThreadStatus from threads import UpadteSpaceWeatherThread, ThreadStatus
class SpaceWeatherData(QObject): class SpaceWeatherData(QObject):
@@ -12,6 +12,15 @@ class SpaceWeatherData(QObject):
self.ak_index = '' self.ak_index = ''
self.sgas = '' self.sgas = ''
self.geo_storm = '' self.geo_storm = ''
self.images = [QPixmap(),
QPixmap(),
QPixmap(),
QPixmap(),
QPixmap(),
QPixmap(),
QPixmap(),
QPixmap(),
QPixmap()]
self.__update_thread = UpadteSpaceWeatherThread(self) self.__update_thread = UpadteSpaceWeatherThread(self)
self.__update_thread.finished.connect(self.__parse_and_emit_signal) self.__update_thread.finished.connect(self.__parse_and_emit_signal)

View File

@@ -11,12 +11,24 @@ class SwitchableLabel(QLabel):
self.switch_off_color = off self.switch_off_color = off
def switch_on(self): def switch_on(self):
if self.switch_on_color and self.switch_off_color:
self.setStyleSheet(f"""background-color: {self.switch_on_color}; self.setStyleSheet(f"""background-color: {self.switch_on_color};
color:#000000;""") color:#000000;""")
else:
self.setStyleSheet("""
color:#ffffff;
background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #4776e6 ,stop: 1 #8e54e9);
""")
def switch_off(self): def switch_off(self):
if self.switch_on_color and self.switch_off_color:
self.setStyleSheet(f"""background-color: {self.switch_off_color}; self.setStyleSheet(f"""background-color: {self.switch_off_color};
color:#000000;""") color:#000000;""")
else:
self.setStyleSheet("""
color:#ffffff;
background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398);
""")
class SwitchableLabelsIterable(object): class SwitchableLabelsIterable(object):

View File

@@ -1,7 +1,7 @@
from functools import partial from functools import partial
import os import os
import re import re
from PyQt5.QtWidgets import QAction from PyQt5.QtWidgets import QAction, QActionGroup
from PyQt5.QtCore import pyqtSlot from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import QPixmap from PyQt5.QtGui import QPixmap
from constants import Constants from constants import Constants
@@ -29,6 +29,7 @@ class Theme(object):
self.__parent.default_images_folder = os.path.join(ThemeConstants.FOLDER, self.__parent.default_images_folder = os.path.join(ThemeConstants.FOLDER,
ThemeConstants.DEFAULT, ThemeConstants.DEFAULT,
ThemeConstants.ICONS_FOLDER) ThemeConstants.ICONS_FOLDER)
self.__theme_names = {}
self.__detect_themes() self.__detect_themes()
def __refresh_range_labels(self): def __refresh_range_labels(self):
@@ -60,21 +61,26 @@ class Theme(object):
self.__refresh_range_labels() self.__refresh_range_labels()
self.__parent.audio_widget.refresh_btns_colors(self.__parent.active_color, self.__parent.inactive_color) self.__parent.audio_widget.refresh_btns_colors(self.__parent.active_color, self.__parent.inactive_color)
def __pretty_name(self, bad_name):
return ' '.join(
map(lambda s: s.capitalize(),
bad_name.split('-')[1].split('_')
)
)
def __detect_themes(self): def __detect_themes(self):
themes = [] themes = []
ag = QActionGroup(self.__parent, exclusive = True)
for theme_folder in os.listdir(ThemeConstants.FOLDER): for theme_folder in os.listdir(ThemeConstants.FOLDER):
relative_folder = os.path.join(ThemeConstants.FOLDER, theme_folder) relative_folder = os.path.join(ThemeConstants.FOLDER, theme_folder)
if os.path.isdir(os.path.abspath(relative_folder)): if os.path.isdir(os.path.abspath(relative_folder)):
relative_folder = os.path.join(ThemeConstants.FOLDER, theme_folder) relative_folder = os.path.join(ThemeConstants.FOLDER, theme_folder)
themes.append(relative_folder) themes.append(relative_folder)
for theme_path in themes: for theme_path in themes:
theme_name = '&' + ' '.join( theme_name = '&' + self.__pretty_name(os.path.basename(theme_path))
map(lambda s: s.capitalize(), new_theme = ag.addAction(QAction(theme_name, self.__parent, checkable = True))
os.path.basename(theme_path).split('-')[1].split('_')
)
)
new_theme = QAction(theme_name, self.__parent)
self.__parent.menu_themes.addAction(new_theme) self.__parent.menu_themes.addAction(new_theme)
self.__theme_names[theme_name.lstrip('&')] = new_theme
new_theme.triggered.connect(partial(self.__apply, theme_path)) new_theme.triggered.connect(partial(self.__apply, theme_path))
def __change(self): def __change(self):
@@ -163,5 +169,9 @@ class Theme(object):
if os.path.exists(current_theme_file): if os.path.exists(current_theme_file):
with open(current_theme_file, "r") as current_theme_path: with open(current_theme_file, "r") as current_theme_path:
theme_path = current_theme_path.read() theme_path = current_theme_path.read()
theme_name = self.__pretty_name(os.path.basename(theme_path))
self.__theme_names[theme_name].setChecked(True)
if theme_path != ThemeConstants.DEFAULT: if theme_path != ThemeConstants.DEFAULT:
self.__apply(theme_path) self.__apply(theme_path)
else:
self.__theme_names[self.__pretty_name(ThemeConstants.DEFAULT)].setChecked(True)

View File

@@ -78,5 +78,14 @@ class UpadteSpaceWeatherThread(QThread):
self.__space_weather_data.ak_index = str(urllib3.PoolManager().request('GET', Constants.FORECAST_AK_IND).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.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') self.__space_weather_data.geo_storm = str(urllib3.PoolManager().request('GET', Constants.FORECAST_G).data, 'utf-8')
self.__space_weather_data.images[0].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_0).data)
self.__space_weather_data.images[1].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_1).data)
self.__space_weather_data.images[2].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_2).data)
self.__space_weather_data.images[3].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_3).data)
self.__space_weather_data.images[4].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_4).data)
self.__space_weather_data.images[5].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_5).data)
self.__space_weather_data.images[6].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_6).data)
self.__space_weather_data.images[7].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_7).data)
self.__space_weather_data.images[8].loadFromData(urllib3.PoolManager().request('GET', Constants.FORECAST_IMG_8).data)
except: except:
self.__status = ThreadStatus.UNKNOWN_ERR self.__status = ThreadStatus.UNKNOWN_ERR