Close #14 Make font customizable. Also manage user settings via a settings.json

file. Also improve 'dark' and 'elegant_dark' themes.
Finally improve 'Signal's wiki' button behaviour.
Also fix a bug in forecast/now view which caused a crash if solar activity
was inactive
This commit is contained in:
Alessandro
2019-11-29 20:17:07 +01:00
parent 5908110a43
commit bcd24cc035
12 changed files with 339 additions and 80 deletions

80
src/urlbutton.py Normal file
View File

@@ -0,0 +1,80 @@
from PyQt5.QtWidgets import QPushButton
from collections import namedtuple
from enum import Enum, auto
class UrlButton(QPushButton):
"""Define the behaviour of the wiki button."""
class State(Enum):
"""Possible states of the button."""
ACTIVE = auto()
INACTIVE = auto()
CLICKED = auto()
_UrlColors = namedtuple(
"UrlColors",
[
"INACTIVE",
"ACTIVE",
"CLICKED",
"ACTIVE_HOVER",
"CLICKED_HOVER",
]
)
_COLORS = _UrlColors(
"#9f9f9f",
"#4c75ff",
"#942ccc",
"#808FFF",
"#DE78FF",
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def set_enabled(self, state):
"""Enable the button and set the stylesheet."""
super().setEnabled(True)
if state is self.State.ACTIVE:
color = self._COLORS.ACTIVE
else:
color = self._COLORS.CLICKED
self.setStyleSheet(f"""
QPushButton {{
border: 0px;
background-color: transparent;
color: {color};
}}
QPushButton::hover {{
border: 0px;
background-color: transparent;
color: {self._COLORS.ACTIVE_HOVER};
}}
""")
def set_disabled(self):
"""Disable the button and set the stylesheet."""
super().setEnabled(False)
self.setStyleSheet(f"""
QPushButton:disabled {{
border: 0px;
background-color: transparent;
color: {self._COLORS.INACTIVE};
}}
""")
def set_clicked(self):
"""Apply the stylesheet for the clicked state."""
self.setStyleSheet(f"""
QPushButton {{
border: 0px;
background-color: transparent;
color: {self._COLORS.CLICKED};
}}
QPushButton::hover {{
border: 0px;
background-color: transparent;
color: {self._COLORS.CLICKED_HOVER};
}}
""")