Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c81277f
qt: Send tab - Generalized related CSS and some redesign
xdustinface May 29, 2020
9ba352c
qt: Overview tab - Generalized related CSS and some redesign
xdustinface May 29, 2020
4415e97
qt: Receive tab & QPushButton - Generalized related CSS and some rede…
xdustinface May 29, 2020
8373b32
qt: Transaction tab - Generalized related CSS and some redesign
xdustinface May 29, 2020
3d7956d
qt: Masternode tab - Generalized related CSS and some redesign
xdustinface May 29, 2020
fda98c5
qt: CoinControl dialog - Generalized related CSS and some redesign
xdustinface May 29, 2020
5ec4753
qt: Sync overlay - Generalized related CSS and some redesign
xdustinface May 29, 2020
13df37a
qt: About dialog - Generalized related CSS
xdustinface May 29, 2020
7f85aa9
qt: Edit address dialog - Generalized related CSS
xdustinface May 29, 2020
019823b
qt: Help message dialog - Generalized related CSS
xdustinface May 29, 2020
27e1880
qt: RPC console - Generalized related CSS and some redesign
xdustinface May 29, 2020
8e79a3a
qt: Options dialog - Generalized related CSS
xdustinface May 29, 2020
496c429
qt: Ask passphrase dialog - Generalized related CSS
xdustinface May 30, 2020
43b02b8
qt: Addressbook page - Generalized related CSS
xdustinface May 30, 2020
2cd7afb
qt: Sign/Verify dialog - Generalized related CSS
xdustinface May 30, 2020
a596963
qt: Open URI dialog - Generalized related CSS
xdustinface May 30, 2020
62858cd
qt: Generalized remaining individual Qt classes
xdustinface May 30, 2020
adf2bf1
qt: Fixed indentation in css files
xdustinface Jun 1, 2020
dfce74f
qt: Use newlines for multiple selector entries
xdustinface Jun 2, 2020
e44ac22
qt: Formal cleanups in all css files
xdustinface Jun 2, 2020
b2980a3
qt: Add copyright and file description to all css files
xdustinface Jun 3, 2020
3d63397
qt: Add update_colors.py, prepare css files for scripted color updates
xdustinface Jun 3, 2020
ad0b90d
qt/contrib: Moved update_colors.py to update-css-files.py
xdustinface Jun 4, 2020
bd1e341
build: Remove files in src/qt/res/css/colors when running "make clean"
xdustinface Jun 4, 2020
945c350
git: Add src/qt/res/css/colors/* to gitignore and remove the files fr…
xdustinface Jun 4, 2020
aea40f0
qt: Fix background-color of bgWidget in trad.css
xdustinface Jun 4, 2020
4ad1be2
qt: Run update_colors.py
xdustinface Jun 4, 2020
bf53bcd
path -> css_folder_path
UdjinM6 Jun 4, 2020
f379ef6
Resolve path and fail early
UdjinM6 Jun 4, 2020
54843f1
Create 'colors/' if it doesn't exist and fail if smth went wrong
UdjinM6 Jun 4, 2020
2019349
Run git after all filesystem preparations are done
UdjinM6 Jun 4, 2020
c0026a4
contrib: Use case insensitive regex for color matching
xdustinface Jun 4, 2020
51c96e7
qt: Update colors in css files
xdustinface Jun 4, 2020
ded2872
contrib: Remove obsolete import in update-css-files.py
xdustinface Jun 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ src/dash-tx
src/test/test_dash
src/test/test_dash_fuzzy
src/qt/test/test_dash-qt
src/qt/res/css/colors/*
src/bench/bench_dash

# autoreconf
Expand Down
198 changes: 198 additions & 0 deletions contrib/devtools/update-css-files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
#!/usr/bin/env python3
#
# update-css-files.py creates color analyse files in css/colors and updates the
# `<colors></colors>` section in all css files.
#
# Copyright (c) 2020 The Dash Core developers
# Distributed under the MIT/X11 software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

from pathlib import Path
import re
import subprocess
import sys

MATCH_REPLACE = '<colors>.+?</colors>'
MATCH_COLORS = '#(?:[0-9a-fA-F]{2}){2,4}|#(?:[0-9a-f]{1}){3}'

def error(msg):
exit('\nERROR: {}\n'.format(msg))

def parse_css(file_css):
# Temporarily
state = 0
selectors = []

# Results
by_attribute = {}
by_color = {}

for line in file_css.read_text().splitlines():

if line == '':
continue

# start of a comment
if state == 0 and line.startswith('/*'):
if '*/' in line:
state = 0
else:
state = 1
# we are in a comment section
elif state == 1:
# end of the comment
if '*/' in line:
state = 0
else:
continue
# first line of multiple selector
elif (state == 0 or state == 2) and ',' in line:
state = 2
# first line of single selector or end of multiple
elif (state == 0 or state == 2) and '{' in line:
state = 3
# end of element
elif state == 4 and line == '}':
state = 0

if state == 0 and len(selectors):
selectors = []

if state == 2:
selector = line.split(",")[0].strip(' ')
selectors.append(selector)

if state == 3:
selector = line.split("{")[0].strip(' ')
selectors.append(selector)
state = 4
continue

if state == 4:
matched_colors = re.findall(MATCH_COLORS, line)

if len(matched_colors) > 1:
error("Multiple colors in a line.\n\n {}\n\nSeems to be an invalid file!".format(line))
elif len(matched_colors) == 1:
matched_color = matched_colors[0]
element = line.split(":")[0].strip(' ')

if not matched_color in by_color:
by_color[matched_color] = []

by_color[matched_color].append(element)

entry = element + " " + matched_color

if not entry in by_attribute:
by_attribute[entry] = []

by_attribute[entry].extend(selectors)

def sort_color(color):
tmp = color[0].replace('#', '0x')
return int(tmp, 0)

def remove_duplicates(l):
no_duplicates = []
[no_duplicates.append(i) for i in l if not no_duplicates.count(i)]
return no_duplicates

colors = []

# sort colors just by hex value
if len(by_color):
colors = sorted(by_color.items(), key=lambda x: sort_color(x))

for k, l in by_attribute.items():
by_attribute[k] = remove_duplicates(l)

for k, l in by_color.items():
by_color[k] = remove_duplicates(l)

return {'fileName': file_css.stem, 'byAttribute': by_attribute, 'byColor': by_color, 'colors': colors}


def create_color_file(content, commit):

str_result = "Color analyse of " +\
content['fileName'] + ".css " + \
"by " + \
Path(__file__).name + \
" for commit " + \
commit + \
"\n\n"

if not len(content['colors']):
return None

str_result += "# Used colors\n\n"
for c in content['colors']:
str_result += c[0] + '\n'

str_result += "\n# Grouped by attribute\n"

for k, v in content['byAttribute'].items():
str_result += '\n' + k + '\n'
for val in v:
str_result += ' ' + val + '\n'

str_result += "\n# Grouped by color\n"

for k, v in content['byColor'].items():
str_result += '\n' + k + '\n'
for val in v:
str_result += ' ' + val + '\n'

return str_result

if __name__ == '__main__':

if len(sys.argv) > 1:
error('No argument required!')

try:
css_folder_path = Path(__file__).parent.absolute() / Path('../../src/qt/res/css/')
css_folder_path = css_folder_path.resolve(strict=True)
except Exception:
error("Path doesn't exist: {}".format(css_folder_path))

if not len(list(css_folder_path.glob('*.css'))):
error("No .css files found in {}".format(css_folder_path))

results = [parse_css(x) for x in css_folder_path.glob('*.css') if x.is_file()]

colors_folder_path = css_folder_path / Path('colors/')
if not colors_folder_path.is_dir():
try:
colors_folder_path.mkdir()
except Exception:
error("Can't create new folder: {}".format(colors_folder_path))

commit = subprocess.check_output(['git', '-C', css_folder_path, 'rev-parse', '--short', 'HEAD']).decode("utf-8")

for r in results:

# Update the css file
css_file = css_folder_path / Path(r['fileName'] + '.css')
css_content = css_file.read_text()
to_replace = re.findall(MATCH_REPLACE, css_content, re.DOTALL)

str_result = "\n# Used colors in {}.css for commit {}\n".format(r['fileName'], commit)
for c in r['colors']:
str_result += c[0] + '\n'

str_replace = "<colors>\n{}\n</colors>".format(str_result)
css_content = css_content.replace(to_replace[0], str_replace)
css_file.write_text(css_content)

# Write the <css>_color.txt files
str_result = create_color_file(r, commit)

if str_result is not None:
color_file = colors_folder_path / Path(r['fileName'] + '_css_colors.txt')
color_file.write_text(str_result)

print('\n{}.css -> {} created!'.format(r['fileName'], color_file))
else:
print('\n{}.css -> No colors found..'.format(r['fileName'] + ".css"))
2 changes: 1 addition & 1 deletion src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ $(QT_QRC_CPP): $(QT_QRC) $(QT_FORMS_H) $(RES_ICONS) $(RES_IMAGES) $(RES_CSS) $(R
$(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(RCC) $(RCCFLAGS) -name dash $< | \
$(SED) -e '/^\*\*.*Created:/d' -e '/^\*\*.*by:/d' > $@

CLEAN_QT = $(nodist_qt_libdashqt_a_SOURCES) $(QT_QM) $(QT_FORMS_H) qt/*.gcda qt/*.gcno qt/temp_dash_locale.qrc
CLEAN_QT = $(nodist_qt_libdashqt_a_SOURCES) $(QT_QM) $(QT_FORMS_H) qt/*.gcda qt/*.gcno qt/temp_dash_locale.qrc qt/res/css/colors/*

CLEANFILES += $(CLEAN_QT)

Expand Down
Loading