Fix bug in reset of mode filters. Make forecast labels theme-dependent.

This commit is contained in:
alessandro90
2019-04-14 15:57:18 +02:00
parent 7625016b56
commit 91bfcde7cc
10 changed files with 771 additions and 703 deletions

View File

@@ -1,5 +1,4 @@
from collections import namedtuple from collections import namedtuple
from itertools import chain
from functools import partial from functools import partial
import webbrowser import webbrowser
import os import os
@@ -31,8 +30,7 @@ from constants import (Constants,
Database, Database,
ChecksumWhat, ChecksumWhat,
Messages, Messages,
Signal, Signal,)
Colors,)
from themes import Theme from themes import Theme
from utilities import (checksum_ok, from utilities import (checksum_ok,
uncheck_and_emit, uncheck_and_emit,
@@ -64,6 +62,66 @@ class Artemis(QMainWindow, Ui_MainWindow):
self.current_signal_name = '' self.current_signal_name = ''
self.signal_names = [] self.signal_names = []
self.total_signals = 0 self.total_signals = 0
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)
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)
self.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 lab in self.forecast_labels:
lab.set_default_stylesheet()
self.forecast_label_container.labels = self.forecast_labels
self.theme = Theme(self) self.theme = Theme(self)
# Manage frequency filters. # Manage frequency filters.
@@ -377,92 +435,6 @@ class Artemis(QMainWindow, Ui_MainWindow):
self.update_now_bar.set_idle() self.update_now_bar.set_idle()
self.space_weather_data = SpaceWeatherData() self.space_weather_data = SpaceWeatherData()
self.space_weather_data.update_complete.connect(self.update_space_weather) 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(None, None)
k_storms_colors = [[Colors.RED_LIGHT, Colors.RED_DARK],
[Colors.RED2_LIGHT, Colors.RED2_DARK],
[Colors.RED3_LIGHT, Colors.RED3_DARK],
[Colors.ORANGE2_LIGHT, Colors.ORANGE2_DARK],
[Colors.ORANGE_LIGHT, Colors.ORANGE_DARK],
[Colors.YELLOW_LIGHT, Colors.YELLOW_DARK],
[Colors.GREEN2_LIGHT, Colors.GREEN2_DARK],
[Colors.GREEN3_LIGHT, Colors.GREEN3_DARK],
[Colors.GREEN_LIGHT, Colors.GREEN_DARK],
[Colors.BLUE_LIGHT, Colors.BLUE_DARK]]
a_storm_colors = [[Colors.RED_LIGHT, Colors.RED_DARK],
[Colors.ORANGE2_LIGHT, Colors.ORANGE2_DARK],
[Colors.ORANGE_LIGHT, Colors.ORANGE_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(None, None)
self.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)
self.forecast_label_container.labels = self.forecast_labels
# Final operations. # Final operations.
self.theme.initialize() self.theme.initialize()
@@ -580,37 +552,35 @@ 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)") 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)") 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)") 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)") 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)") 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)") 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)") 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)") 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)") 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.setText(" S30+ (>>-60 dBm) ")
self.expected_noise_lbl.setStyleSheet(f""" self.expected_noise_lbl.switch_on()
color:#ffffff;
background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #4776e6 ,stop: 1 #8e54e9);""")
val = int(self.space_weather_data.ak_index[7][2].replace('.', '')) val = int(self.space_weather_data.ak_index[7][2].replace('.', ''))
self.sfi_lbl.setText(f"{val}") self.sfi_lbl.setText(f"{val}")
@@ -618,10 +588,9 @@ class Artemis(QMainWindow, Ui_MainWindow):
self.sn_lbl.setText(f"{val:d}") self.sn_lbl.setText(f"{val:d}")
for label, pixmap in zip(self.forecast_labels, self.space_weather_data.images): for label, pixmap in zip(self.forecast_labels, self.space_weather_data.images):
label.setText('')
label.pixmap = pixmap label.pixmap = pixmap
label.setPixmap(pixmap.scaled(label.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation)) label.make_transparent()
label.setStyleSheet("background-color: transparent;") label.apply_pixmap()
else: else:
pop_up(self, title = Messages.BAD_DOWNLOAD, pop_up(self, title = Messages.BAD_DOWNLOAD,
text = Messages.BAD_DOWNLOAD_MSG).show() text = Messages.BAD_DOWNLOAD_MSG).show()
@@ -998,8 +967,15 @@ class Artemis(QMainWindow, Ui_MainWindow):
@pyqtSlot() @pyqtSlot()
def reset_mode_filters(self): def reset_mode_filters(self):
uncheck_and_emit(self.apply_remove_mode_filter_btn) uncheck_and_emit(self.apply_remove_mode_filter_btn)
parents = Constants.MODES.keys()
selected_children = []
for item in self.mode_tree_widget.selectedItems(): for item in self.mode_tree_widget.selectedItems():
item.setSelected(False) if item.text(0) in parents:
item.setSelected(False)
else:
selected_children.append(item)
for children in selected_children:
children.setSelected(False)
if self.include_unknown_modes_btn.isChecked(): if self.include_unknown_modes_btn.isChecked():
self.include_unknown_modes_btn.setChecked(False) self.include_unknown_modes_btn.setChecked(False)

1091
artemis.ui

File diff suppressed because it is too large Load Diff

View File

@@ -66,30 +66,6 @@ class Database(object):
Signal.SUP_BAND, Signal.SUP_BAND,
Signal.CATEGORY_CODE,) 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): class Constants(object):
CLICK_TO_UPDATE_STR = "Click to update" CLICK_TO_UPDATE_STR = "Click to update"
UPDATING_STR = "Updating..." UPDATING_STR = "Updating..."
@@ -117,6 +93,9 @@ class Constants(object):
AUDIO_FOLDER = "Audio" AUDIO_FOLDER = "Audio"
ACTIVE = "active" ACTIVE = "active"
INACTIVE = "inactive" INACTIVE = "inactive"
LABEL_ON_COLOR = "on"
LABEL_OFF_COLOR = "off"
TEXT_COLOR = "text"
NOT_AVAILABLE = "spectrumnotavailable.png" NOT_AVAILABLE = "spectrumnotavailable.png"
NOT_SELECTED = "nosignalselected.png" NOT_SELECTED = "nosignalselected.png"
__Band = namedtuple("Band", ["lower", "upper"]) __Band = namedtuple("Band", ["lower", "upper"])

View File

@@ -1,14 +1,27 @@
from PyQt5.QtWidgets import QLabel from PyQt5.QtWidgets import QLabel
from PyQt5.QtCore import QSize, Qt from PyQt5.QtCore import Qt
class FixedAspectRatioLabel(QLabel): class FixedAspectRatioLabel(QLabel):
def __init__(self, parent = None): def __init__(self, parent = None):
super().__init__(parent) super().__init__(parent)
self.pixmap = None self.pixmap = None
def rescale(self, w, h): def set_default_stylesheet(self):
self.resize(QSize(w, h)) self.setStyleSheet("""
color: #ffffff;
background-color: #666666;
""")
def make_transparent(self):
self.setText('')
self.setStyleSheet("background-color: transparent;")
def apply_pixmap(self):
if self.pixmap: if self.pixmap:
self.setPixmap( self.setPixmap(
self.pixmap.scaled( self.pixmap.scaled(
self.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation)) self.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation))
def rescale(self, size):
self.resize(size)
self.apply_pixmap()

View File

@@ -1,4 +1,5 @@
from PyQt5.QtWidgets import QWidget from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import QSize
class FixedAspectRatioWidget(QWidget): class FixedAspectRatioWidget(QWidget):
space = 10 space = 10
@@ -16,4 +17,4 @@ class FixedAspectRatioWidget(QWidget):
h_lbl = h / 9 - self.space h_lbl = h / 9 - self.space
for label in self.labels: for label in self.labels:
label.rescale(w_lbl, h_lbl) label.rescale(QSize(w_lbl, h_lbl))

View File

@@ -3,32 +3,26 @@ from PyQt5.QtWidgets import QLabel
class SwitchableLabel(QLabel): class SwitchableLabel(QLabel):
def __init__(self, parent = None): def __init__(self, parent = None):
super().__init__(parent) super().__init__(parent)
self.switch_on_color = None self.switch_on_colors = ()
self.switch_off_color = None self.switch_off_colors = ()
self.text_color = ''
def set_colors(self, on, off): self.is_on = False
self.switch_on_color = on
self.switch_off_color = off
def switch_on(self): def switch_on(self):
if self.switch_on_color and self.switch_off_color: self.is_on = True
self.setStyleSheet(f"""background-color: {self.switch_on_color}; self.__apply_colors(*self.switch_on_colors)
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.is_on = False
self.setStyleSheet(f"""background-color: {self.switch_off_color}; self.__apply_colors(*self.switch_off_colors)
color:#000000;""")
else: def __apply_colors(self, start, end):
self.setStyleSheet(""" self.setStyleSheet(
color:#ffffff; f"""
background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 #283048 ,stop: 1 #859398); color:{self.text_color};
""") background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop:0 {start} ,stop: 1 {end});
"""
)
class SwitchableLabelsIterable(object): class SwitchableLabelsIterable(object):
@@ -49,3 +43,14 @@ class SwitchableLabelsIterable(object):
def switch_off_all(self): def switch_off_all(self):
for lab in self.labels: for lab in self.labels:
lab.switch_off() lab.switch_off()
def set(self, attr, value):
for lab in self.labels:
setattr(lab, attr, value)
def refresh(self):
for lab in self.labels:
if lab.is_on:
lab.switch_on()
else:
lab.switch_off()

View File

@@ -1,10 +1,12 @@
from functools import partial from functools import partial
from itertools import chain
import os import os
import re import re
from PyQt5.QtWidgets import QAction, QActionGroup 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
from switchable_label import SwitchableLabelsIterable
from utilities import pop_up from utilities import pop_up
class ThemeConstants(object): class ThemeConstants(object):
@@ -15,8 +17,11 @@ class ThemeConstants(object):
CURRENT = ".current_theme" CURRENT = ".current_theme"
COLORS = "colors.txt" COLORS = "colors.txt"
COLOR_SEPARATOR = "=" COLOR_SEPARATOR = "="
DEFAULT_ACTIVE_COLOR = "#39eaff" DEFAULT_ACTIVE_COLOR = "#000000"
DEFAULT_INACTIVE_COLOR = "#9f9f9f" DEFAULT_INACTIVE_COLOR = "#9f9f9f"
DEFAULT_OFF_COLORS = "#000000", "#434343"
DEFAULT_ON_COLORS = "#4b79a1", "#283e51"
DEFAULT_TEXT_COLOR = "#ffffff"
THEME_NOT_FOUND = "Theme not found" THEME_NOT_FOUND = "Theme not found"
MISSING_THEME = "Missing theme in '" + FOLDER + "' folder." MISSING_THEME = "Missing theme in '" + FOLDER + "' folder."
@@ -25,10 +30,25 @@ class Theme(object):
self.__parent = parent self.__parent = parent
self.__parent.active_color = ThemeConstants.DEFAULT_ACTIVE_COLOR self.__parent.active_color = ThemeConstants.DEFAULT_ACTIVE_COLOR
self.__parent.inactive_color = ThemeConstants.DEFAULT_INACTIVE_COLOR self.__parent.inactive_color = ThemeConstants.DEFAULT_INACTIVE_COLOR
self.__theme_path = ThemeConstants.DEFAULT
self.__theme_path = ""
self.__current_theme = ""
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.__forecast_labels = SwitchableLabelsIterable(*list(chain(self.__parent.switchable_r_labels,
self.__parent.switchable_s_labels,
self.__parent.switchable_g_now_labels,
self.__parent.switchable_g_today_labels,
self.__parent.k_storm_labels,
self.__parent.a_storm_labels,
[self.__parent.expected_noise_lbl])))
self.__forecast_labels.set("switch_on_colors", ThemeConstants.DEFAULT_ON_COLORS)
self.__forecast_labels.set("switch_off_colors", ThemeConstants.DEFAULT_OFF_COLORS)
self.__theme_names = {} self.__theme_names = {}
self.__detect_themes() self.__detect_themes()
@@ -43,6 +63,7 @@ class Theme(object):
self.__parent.upper_band_filter_unit, self.__parent.upper_band_filter_unit,
self.__parent.upper_band_confidence, self.__parent.upper_band_confidence,
self.__parent.band_range_lbl) self.__parent.band_range_lbl)
self.__parent.set_band_filter_label(self.__parent.activate_low_freq_filter_btn, self.__parent.set_band_filter_label(self.__parent.activate_low_freq_filter_btn,
self.__parent.lower_freq_spinbox, self.__parent.lower_freq_spinbox,
self.__parent.lower_freq_filter_unit, self.__parent.lower_freq_filter_unit,
@@ -56,10 +77,12 @@ class Theme(object):
@pyqtSlot() @pyqtSlot()
def __apply(self, theme_path): def __apply(self, theme_path):
self.__theme_path = theme_path self.__theme_path = theme_path
self.__change() if self.__theme_path != self.__current_theme:
self.__parent.display_specs(self.__parent.result_list.currentItem(), None) self.__change()
self.__refresh_range_labels() self.__parent.display_specs(self.__parent.result_list.currentItem(), None)
self.__parent.audio_widget.refresh_btns_colors(self.__parent.active_color, self.__parent.inactive_color) self.__refresh_range_labels()
self.__parent.audio_widget.refresh_btns_colors(self.__parent.active_color, self.__parent.inactive_color)
self.__forecast_labels.refresh()
def __pretty_name(self, bad_name): def __pretty_name(self, bad_name):
return ' '.join( return ' '.join(
@@ -135,28 +158,53 @@ class Theme(object):
path_to_colors = os.path.join(self.__theme_path, ThemeConstants.COLORS) path_to_colors = os.path.join(self.__theme_path, ThemeConstants.COLORS)
active_color_ok = False active_color_ok = False
inactive_color_ok = False inactive_color_ok = False
valid_format = False switch_on_color_ok = False
valid_file = False switch_off_color_ok = False
text_color_ok = False
if os.path.exists(path_to_colors): if os.path.exists(path_to_colors):
valid_file = True is_valid_html_color = lambda colors : all([bool(re.match("#([a-zA-Z0-9]){6}", color)) for color in colors])
with open(path_to_colors, "r") as colors_file: with open(path_to_colors, "r") as colors_file:
for line in colors_file: for line in colors_file:
if ThemeConstants.COLOR_SEPARATOR in line: if ThemeConstants.COLOR_SEPARATOR in line:
valid_format = True
quality, color = line.split(ThemeConstants.COLOR_SEPARATOR) quality, color = line.split(ThemeConstants.COLOR_SEPARATOR)
color = color.rstrip() color = color.rstrip()
is_valid_html_color = lambda color : bool(re.match("#([a-zA-Z0-9]){6}", color)) if ',' in color:
if quality.lower() == Constants.ACTIVE and is_valid_html_color(color): color = [c.rstrip().lstrip() for c in color.split(',')]
self.__parent.active_color = color else:
active_color_ok = True color = [color]
if quality.lower() == Constants.INACTIVE and is_valid_html_color(color): if len(color) > 2:
self.__parent.inactive_color = color break
inactive_color_ok = True if is_valid_html_color(color):
if quality.lower() == Constants.ACTIVE:
self.__parent.active_color = color[0]
active_color_ok = True
if quality.lower() == Constants.INACTIVE:
self.__parent.inactive_color = color[0]
inactive_color_ok = True
if quality.lower() == Constants.LABEL_ON_COLOR:
switch_on_color_ok = True
self.__forecast_labels.set("switch_on_colors", color)
if quality.lower() == Constants.LABEL_OFF_COLOR:
switch_off_color_ok = True
self.__forecast_labels.set("switch_off_colors", color)
if quality.lower() == Constants.TEXT_COLOR:
text_color_ok = True
self.__forecast_labels.set("text_color", color[0])
if not all([valid_file, valid_format, active_color_ok, inactive_color_ok]): if not (active_color_ok and inactive_color_ok):
self.__parent.active_color = ThemeConstants.DEFAULT_ACTIVE_COLOR self.__parent.active_color = ThemeConstants.DEFAULT_ACTIVE_COLOR
self.__parent.inactive_color = ThemeConstants.DEFAULT_INACTIVE_COLOR self.__parent.inactive_color = ThemeConstants.DEFAULT_INACTIVE_COLOR
if not (switch_on_color_ok and switch_off_color_ok):
for label in self.__forecast_labels:
label.switch_on_colors = ThemeConstants.DEFAULT_ON_COLORS
label.switch_off_colors = ThemeConstants.DEFAULT_OFF_COLORS
if not text_color_ok:
self.__forecast_labels.set("text_color", ThemeConstants.DEFAULT_TEXT_COLOR)
self.__current_theme = self.__theme_path
try: try:
with open(os.path.join(ThemeConstants.FOLDER, with open(os.path.join(ThemeConstants.FOLDER,
ThemeConstants.CURRENT), "w") as current_theme: ThemeConstants.CURRENT), "w") as current_theme:
@@ -171,7 +219,7 @@ class Theme(object):
theme_path = current_theme_path.read() theme_path = current_theme_path.read()
theme_name = self.__pretty_name(os.path.basename(theme_path)) theme_name = self.__pretty_name(os.path.basename(theme_path))
self.__theme_names[theme_name].setChecked(True) self.__theme_names[theme_name].setChecked(True)
if theme_path != ThemeConstants.DEFAULT: self.__apply(theme_path)
self.__apply(theme_path)
else: else:
self.__theme_names[self.__pretty_name(ThemeConstants.DEFAULT)].setChecked(True) self.__theme_names[self.__pretty_name(ThemeConstants.DEFAULT)].setChecked(True)
self.__apply(os.path.join(ThemeConstants.FOLDER, ThemeConstants.DEFAULT))

View File

@@ -1,2 +1,5 @@
active=#4da6ff active=#4545e5
inactive=#546E7A inactive=#546E7A
off=#283048,#859398
on=#4776e6, #8e54e9
text=#ffffff

View File

@@ -1,2 +1,4 @@
active=#88cc00 active=#88cc00
inactive=#546E7A inactive=#546E7A
off=#304352,#d7d2cc
on=#3ca55c,#b5ac49

View File

@@ -1,2 +1,4 @@
active=#6ECE12 active=#6ECE12
inactive=#b3b3cc inactive=#b3b3cc
off=#948e99,#2e1437
on=#b993d6,#8ca6db