Skip to content

Commit

Permalink
Merge pull request #111 from davidlatwe/default-themes
Browse files Browse the repository at this point in the history
Default themes
  • Loading branch information
davidlatwe authored Nov 2, 2020
2 parents 405d250 + fab7903 commit 0a3e964
Show file tree
Hide file tree
Showing 62 changed files with 1,788 additions and 324 deletions.
25 changes: 25 additions & 0 deletions allzpark/allzparkconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,28 @@ def metadata_from_package(variant):
"icon": data.get("icon", ""),
"hidden": data.get("hidden", False),
})


def themes():
"""Allzpark GUI theme list provider
This will only be called once on startup.
Each theme in list is a dict object, for example:
{
"name": "theme_name",
"source": "my_style.css",
"keywords": {"base-tone": "red", "res": "path-to-icons"},
}
* `name` is the theme name, this is required.
* `source` can be a file path or plain css code, this is required.
* `keywords` is optional, must be dict type if provided, will be
used to string format the css code.
Returns:
list
"""
return []
19 changes: 10 additions & 9 deletions allzpark/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def main():
with timings("- Loading Qt.. ") as msg:
try:
from .vendor import Qt
msg["success"] = "(%s) - ok {:.2f}\n" % Qt.__binding__
msg["success"] = "(%s - %s) - ok {:.2f}\n"\
% (Qt.__binding__, Qt.__qt_version__)
except ImportError:
msg["failure"] = (
"ERROR: allzpark requires a Python binding for Qt,\n"
Expand Down Expand Up @@ -329,16 +330,16 @@ def excepthook(type, value, traceback):

sys.excepthook = excepthook

with timings("- Loading themes.. "):
resources.load_themes()

window = view.Window(ctrl)
user_css = storage.value("userCss") or ""

with open(resources.find("style.css")) as f:
css = f.read()

# Store for CSS Editor
window._originalcss = css

window.setStyleSheet("\n".join([css, user_css]))
originalcss = resources.load_theme(storage.value("theme", None))
# Store for CSS Editor
window._originalcss = originalcss
window.setStyleSheet("\n".join([originalcss,
resources.format_stylesheet(user_css)]))

window.show()

Expand Down
25 changes: 9 additions & 16 deletions allzpark/dock.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, title, parent=None):
central = QtWidgets.QWidget()

layout = QtWidgets.QVBoxLayout(central)
layout.setContentsMargins(0, 0, 0, 0)
layout.setContentsMargins(4, 4, 4, 4)
layout.setSpacing(px(5))
layout.addWidget(panels["help"])
layout.addWidget(panels["body"])
Expand Down Expand Up @@ -230,6 +230,7 @@ def __init__(self, parent=None):
self.setWidget(panels["central"])

widgets["text"].setReadOnly(True)
widgets["text"].setObjectName("consolelog")

layout = QtWidgets.QVBoxLayout(panels["central"])
layout.setContentsMargins(0, 0, 0, 0)
Expand All @@ -238,12 +239,7 @@ def __init__(self, parent=None):
self._widgets = widgets

def append(self, line, level=logging.INFO):
color = {
logging.DEBUG: "<font color=\"grey\">",
logging.WARNING: "<font color=\"darkorange\">",
logging.ERROR: "<font color=\"red\">",
logging.CRITICAL: "<font color=\"red\">",
}.get(level, "<font color=\"#222\">")
color = "<font color=\"%s\">" % res.log_level_color(level)

line = line.replace(" ", "&nbsp;")
line = line.replace("\n", "<br>")
Expand Down Expand Up @@ -960,13 +956,10 @@ class Preferences(AbstractDockWidget):
"Load this application on startup"
)),

qargparse.Separator("Theme"),
qargparse.Separator("Appearance"),

qargparse.Info("primaryColor", default="white", help=(
"Main color of the GUI"
)),
qargparse.Info("secondaryColor", default="steelblue", help=(
"Secondary color of the GUI"
qargparse.Enum("theme", items=res.theme_names(), help=(
"GUI skin. May need to restart Allzpark after changed."
)),

qargparse.Button("resetLayout", help=(
Expand Down Expand Up @@ -1086,7 +1079,7 @@ def handler(self, argument):
def on_css_applied(self, css):
self._ctrl.state.store("userCss", css)
self._window.setStyleSheet("\n".join([
self._window._originalcss, css]))
self._window._originalcss, res.format_stylesheet(css)]))
self._window.tell("Applying css..")


Expand Down Expand Up @@ -1516,8 +1509,8 @@ def __init__(self, ctrl, parent=None):
version.setToolTip("Click to change profile version")
version.setEnabled(False)

widgets["sep1"].setFrameShape(QtWidgets.QFrame.HLine)
widgets["sep1"].setFrameShadow(QtWidgets.QFrame.Sunken)
widgets["sep1"].setFrameStyle(QtWidgets.QFrame.HLine
| QtWidgets.QFrame.Plain)

# icons
icon_size = QtCore.QSize(14, 14)
Expand Down
156 changes: 156 additions & 0 deletions allzpark/resources.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import os
import logging
from collections import OrderedDict as odict
from . import allzparkconfig
from .vendor.Qt import QtGui

dirname = os.path.dirname(__file__)
_cache = {}
_themes = odict()


def px(value, scale=1.0):
Expand Down Expand Up @@ -34,3 +38,155 @@ def pixmap(*paths):

def icon(*paths):
return QtGui.QIcon(pixmap(*paths))


def load_themes():
_themes.clear()
for theme in default_themes() + allzparkconfig.themes():
_themes[theme["name"]] = theme


def theme_names():
for name in _themes.keys():
yield name


def load_theme(name=None):
if name:
theme = _themes.get(name)
if theme is None:
print("No theme named: %s" % name)
return
else:
theme = next(iter(_themes.values()))

source = theme["source"]
keywords = theme.get("keywords", dict())

if any(source.endswith(ext) for ext in [".css", ".qss"]):
if not os.path.isfile(source):
print("Theme stylesheet file not found: %s" % source)
return
else:
with open(source) as f:
css = f.read()
else:
# plain css code
css = source

_cache["_keywordsCache_"] = keywords
_cache["_logColorCache_"] = {
logging.DEBUG: keywords.get("log.debug", "lightgrey"),
logging.INFO: keywords.get("log.info", "grey"),
logging.WARNING: keywords.get("log.warning", "darkorange"),
logging.ERROR: keywords.get("log.error", "lightcoral"),
logging.CRITICAL: keywords.get("log.critical", "red"),
}

return format_stylesheet(css)


def format_stylesheet(css):
try:
return css % _cache["_keywordsCache_"]
except KeyError as e:
print("Stylesheet format failed: %s" % str(e))
return ""


def log_level_color(level):
log_colors = _cache.get("_logColorCache_", dict())
return log_colors.get(level, "grey")


def default_themes():
_load_fonts()
res_root = os.path.join(dirname, "resources").replace("\\", "/")
return [
{
"name": "default-dark",
"source": find("style-dark.css"),
"keywords": {
"prim": "#2E2C2C",
"brightest": "#403E3D",
"bright": "#383635",
"base": "#2E2C2C",
"dim": "#21201F",
"dimmest": "#141413",
"hover": "rgba(104, 182, 237, 60)",
"highlight": "rgb(110, 191, 245)",
"highlighted": "#111111",
"active": "silver",
"inactive": "dimGray",
"console": "#161616",
"log.debug": "lightgrey",
"log.info": "grey",
"log.warning": "darkorange",
"log.error": "lightcoral",
"log.critical": "red",
"res": res_root,
}
},
{
"name": "default-light",
"source": find("style-light.css"),
"keywords": {
"prim": "#FFFFFF",
"brightest": "#FDFDFD",
"bright": "#F9F9F9",
"base": "#EFEFEF",
"dim": "#DFDFDF",
"dimmest": "#CFCFCF",
"hover": "rgba(122, 194, 245, 60)",
"highlight": "rgb(136, 194, 235)",
"highlighted": "#111111",
"active": "black",
"inactive": "gray",
"console": "#363636",
"log.debug": "lightgrey",
"log.info": "grey",
"log.warning": "darkorange",
"log.error": "lightcoral",
"log.critical": "red",
"res": res_root,
}
},
]


def _load_fonts():
"""Load default fonts from resources"""
_res_root = os.path.join(dirname, "resources").replace("\\", "/")

font_root = os.path.join(_res_root, "fonts")
fonts = [
"opensans/OpenSans-Bold.ttf",
"opensans/OpenSans-BoldItalic.ttf",
"opensans/OpenSans-ExtraBold.ttf",
"opensans/OpenSans-ExtraBoldItalic.ttf",
"opensans/OpenSans-Italic.ttf",
"opensans/OpenSans-Light.ttf",
"opensans/OpenSans-LightItalic.ttf",
"opensans/OpenSans-Regular.ttf",
"opensans/OpenSans-Semibold.ttf",
"opensans/OpenSans-SemiboldItalic.ttf",

"jetbrainsmono/JetBrainsMono-Bold.ttf"
"jetbrainsmono/JetBrainsMono-Bold-Italic.ttf"
"jetbrainsmono/JetBrainsMono-ExtraBold.ttf"
"jetbrainsmono/JetBrainsMono-ExtraBold-Italic.ttf"
"jetbrainsmono/JetBrainsMono-ExtraLight.ttf"
"jetbrainsmono/JetBrainsMono-ExtraLight-Italic.ttf"
"jetbrainsmono/JetBrainsMono-Italic.ttf"
"jetbrainsmono/JetBrainsMono-Light.ttf"
"jetbrainsmono/JetBrainsMono-Light-Italic.ttf"
"jetbrainsmono/JetBrainsMono-Medium.ttf"
"jetbrainsmono/JetBrainsMono-Medium-Italic.ttf"
"jetbrainsmono/JetBrainsMono-Regular.ttf"
"jetbrainsmono/JetBrainsMono-SemiLight.ttf"
"jetbrainsmono/JetBrainsMono-SemiLight-Italic.ttf"
]

for font in fonts:
path = os.path.join(font_root, font)
QtGui.QFontDatabase.addApplicationFont(path)
Binary file added allzpark/resources/branch_closed-on-dim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/branch_closed-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/branch_closed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/branch_open-on-dim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/branch_open-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/branch_open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/checkbox_checked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/checkbox_checked_bright.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/checkbox_checked_dim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/checkbox_unchecked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/checkbox_unchecked_bright.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/checkbox_unchecked_dim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion allzpark/resources/collapse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/down_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/down_arrow_dim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added allzpark/resources/down_arrow_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion allzpark/resources/expand.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion allzpark/resources/filter_off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion allzpark/resources/filter_on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 0a3e964

Please sign in to comment.