From 2a11adc8acb58684fdd54516f84bbe57857acc4e Mon Sep 17 00:00:00 2001 From: Nathan Isom Date: Fri, 16 Oct 2015 10:52:02 -0500 Subject: [PATCH 1/8] initial replace pass. --- qutebrowser/browser/downloadview.py | 2 +- qutebrowser/completion/completiondelegate.py | 2 +- qutebrowser/completion/completionwidget.py | 6 ++-- qutebrowser/mainwindow/statusbar/bar.py | 30 ++++++++++---------- qutebrowser/mainwindow/statusbar/progress.py | 2 +- qutebrowser/mainwindow/statusbar/url.py | 12 ++++---- tests/unit/config/test_style.py | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/qutebrowser/browser/downloadview.py b/qutebrowser/browser/downloadview.py index 0e21d1fb4..b03c893f0 100644 --- a/qutebrowser/browser/downloadview.py +++ b/qutebrowser/browser/downloadview.py @@ -64,7 +64,7 @@ class DownloadView(QListView): STYLESHEET = """ QListView { - {{ color['downloads.bg.bar'] }} + background-color: {{ color['downloads.bg.bar'] }}; {{ font['downloads'] }} } diff --git a/qutebrowser/completion/completiondelegate.py b/qutebrowser/completion/completiondelegate.py index f2f256a40..d07e7da16 100644 --- a/qutebrowser/completion/completiondelegate.py +++ b/qutebrowser/completion/completiondelegate.py @@ -188,7 +188,7 @@ class CompletionItemDelegate(QStyledItemDelegate): self._doc.setDefaultTextOption(text_option) self._doc.setDefaultStyleSheet(style.get_stylesheet(""" .highlight { - {{ color['completion.match.fg'] }} + color: {{ color['completion.match.fg'] }}; } """)) self._doc.setDocumentMargin(2) diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py index 9281a053a..888cea4c6 100644 --- a/qutebrowser/completion/completionwidget.py +++ b/qutebrowser/completion/completionwidget.py @@ -56,14 +56,14 @@ class CompletionView(QTreeView): STYLESHEET = """ QTreeView { {{ font['completion'] }} - {{ color['completion.bg'] }} + background-color: {{ color['completion.bg'] }}; alternate-background-color: {{ color['completion.alternate-bg'] }}; outline: 0; border: 0px; } QTreeView::item:disabled { - {{ color['completion.category.bg'] }} + background-color: {{ color['completion.category.bg'] }}; border-top: 1px solid {{ color['completion.category.border.top'] }}; border-bottom: 1px solid @@ -75,7 +75,7 @@ class CompletionView(QTreeView): {{ color['completion.item.selected.border.top'] }}; border-bottom: 1px solid {{ color['completion.item.selected.border.bottom'] }}; - {{ color['completion.item.selected.bg'] }} + background-color: {{ color['completion.item.selected.bg'] }}; } QTreeView:item::hover { diff --git a/qutebrowser/mainwindow/statusbar/bar.py b/qutebrowser/mainwindow/statusbar/bar.py index b4066060d..809a989f5 100644 --- a/qutebrowser/mainwindow/statusbar/bar.py +++ b/qutebrowser/mainwindow/statusbar/bar.py @@ -112,56 +112,56 @@ class StatusBar(QWidget): QWidget#StatusBar QLineEdit { {{ font['statusbar'] }} {{ color['statusbar.bg'] }} - {{ color['statusbar.fg'] }} + color: {{ color['statusbar.fg'] }}; } QWidget#StatusBar[caret_mode="on"], QWidget#StatusBar[caret_mode="on"] QLabel, QWidget#StatusBar[caret_mode="on"] QLineEdit { - {{ color['statusbar.fg.caret'] }} - {{ color['statusbar.bg.caret'] }} + color: {{ color['statusbar.fg.caret'] }}; + background-color: {{ color['statusbar.bg.caret'] }}; } QWidget#StatusBar[caret_mode="selection"], QWidget#StatusBar[caret_mode="selection"] QLabel, QWidget#StatusBar[caret_mode="selection"] QLineEdit { - {{ color['statusbar.fg.caret-selection'] }} - {{ color['statusbar.bg.caret-selection'] }} + color: {{ color['statusbar.fg.caret-selection'] }}; + background-color: {{ color['statusbar.bg.caret-selection'] }}; } QWidget#StatusBar[severity="error"], QWidget#StatusBar[severity="error"] QLabel, QWidget#StatusBar[severity="error"] QLineEdit { - {{ color['statusbar.fg.error'] }} - {{ color['statusbar.bg.error'] }} + color: {{ color['statusbar.fg.error'] }}; + background-color: {{ color['statusbar.bg.error'] }}; } QWidget#StatusBar[severity="warning"], QWidget#StatusBar[severity="warning"] QLabel, QWidget#StatusBar[severity="warning"] QLineEdit { - {{ color['statusbar.fg.warning'] }} - {{ color['statusbar.bg.warning'] }} + color: {{ color['statusbar.fg.warning'] }}; + background-color: {{ color['statusbar.bg.warning'] }}; } QWidget#StatusBar[prompt_active="true"], QWidget#StatusBar[prompt_active="true"] QLabel, QWidget#StatusBar[prompt_active="true"] QLineEdit { - {{ color['statusbar.fg.prompt'] }} - {{ color['statusbar.bg.prompt'] }} + color: {{ color['statusbar.fg.prompt'] }}; + background-color: {{ color['statusbar.bg.prompt'] }}; } QWidget#StatusBar[insert_active="true"], QWidget#StatusBar[insert_active="true"] QLabel, QWidget#StatusBar[insert_active="true"] QLineEdit { - {{ color['statusbar.fg.insert'] }} - {{ color['statusbar.bg.insert'] }} + color: {{ color['statusbar.fg.insert'] }}; + background-color: {{ color['statusbar.bg.insert'] }}; } QWidget#StatusBar[command_active="true"], QWidget#StatusBar[command_active="true"] QLabel, QWidget#StatusBar[command_active="true"] QLineEdit { - {{ color['statusbar.fg.command'] }} - {{ color['statusbar.bg.command'] }} + color: {{ color['statusbar.fg.command'] }}; + background-color: {{ color['statusbar.bg.command'] }}; } """ diff --git a/qutebrowser/mainwindow/statusbar/progress.py b/qutebrowser/mainwindow/statusbar/progress.py index 2d2747431..3f8f0b1c3 100644 --- a/qutebrowser/mainwindow/statusbar/progress.py +++ b/qutebrowser/mainwindow/statusbar/progress.py @@ -39,7 +39,7 @@ class Progress(QProgressBar): } QProgressBar::chunk { - {{ color['statusbar.progress.bg'] }} + background-color: {{ color['statusbar.progress.bg'] }}; } """ diff --git a/qutebrowser/mainwindow/statusbar/url.py b/qutebrowser/mainwindow/statusbar/url.py index b368be54f..f3b829f68 100644 --- a/qutebrowser/mainwindow/statusbar/url.py +++ b/qutebrowser/mainwindow/statusbar/url.py @@ -54,27 +54,27 @@ class UrlText(textbase.TextBase): STYLESHEET = """ QLabel#UrlText[urltype="normal"] { - {{ color['statusbar.url.fg'] }} + color: {{ color['statusbar.url.fg'] }}; } QLabel#UrlText[urltype="success"] { - {{ color['statusbar.url.fg.success'] }} + color: {{ color['statusbar.url.fg.success'] }}; } QLabel#UrlText[urltype="success_https"] { - {{ color['statusbar.url.fg.success.https'] }} + color: {{ color['statusbar.url.fg.success.https'] }}; } QLabel#UrlText[urltype="error"] { - {{ color['statusbar.url.fg.error'] }} + color: {{ color['statusbar.url.fg.error'] }}; } QLabel#UrlText[urltype="warn"] { - {{ color['statusbar.url.fg.warn'] }} + color: {{ color['statusbar.url.fg.warn'] }}; } QLabel#UrlText[urltype="hover"] { - {{ color['statusbar.url.fg.hover'] }} + color: {{ color['statusbar.url.fg.hover'] }}; } """ diff --git a/tests/unit/config/test_style.py b/tests/unit/config/test_style.py index 53cce823a..8fe443c13 100644 --- a/tests/unit/config/test_style.py +++ b/tests/unit/config/test_style.py @@ -35,7 +35,7 @@ def test_get_stylesheet(config_stub): } template = "{{ color['completion.bg'] }}\n{{ font['completion'] }}" rendered = style.get_stylesheet(template) - assert rendered == 'background-color: black;\nfont: foo;' + assert rendered == 'black\nfont: foo;' class Obj(QObject): From 09b18fbc68ebbd38c0a4f5e1014ea14d4b5b4c95 Mon Sep 17 00:00:00 2001 From: Nathan Isom Date: Fri, 16 Oct 2015 10:55:17 -0500 Subject: [PATCH 2/8] edit colordict to match. --- qutebrowser/config/style.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/qutebrowser/config/style.py b/qutebrowser/config/style.py index 2b109e72b..bb7782af1 100644 --- a/qutebrowser/config/style.py +++ b/qutebrowser/config/style.py @@ -83,10 +83,7 @@ class ColorDict(collections.UserDict): If a value wasn't found, return an empty string. (Color not defined, so no output in the stylesheet) - If the key has a .fg. element in it, return color: X;. - If the key has a .bg. element in it, return background-color: X;. - - In all other cases, return the plain value. + else, return the plain value. """ try: val = self.data[key] @@ -98,10 +95,6 @@ class ColorDict(collections.UserDict): # QtColor instead of Color in the config, and it'd go unnoticed as # the CSS is invalid then. raise TypeError("QColor passed to ColorDict!") - if 'fg' in key.split('.'): - return 'color: {};'.format(val) - elif 'bg' in key.split('.'): - return 'background-color: {};'.format(val) else: return val From 9b8b2130efcf2a8b0e5dbe4302f56cee0db5cf3c Mon Sep 17 00:00:00 2001 From: Nathan Isom Date: Fri, 16 Oct 2015 10:59:02 -0500 Subject: [PATCH 3/8] remove deprecated test. --- tests/unit/config/test_style.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/unit/config/test_style.py b/tests/unit/config/test_style.py index 8fe443c13..673bc0134 100644 --- a/tests/unit/config/test_style.py +++ b/tests/unit/config/test_style.py @@ -82,14 +82,10 @@ class TestColorDict: @pytest.mark.parametrize('key, expected', [ ('foo', 'one'), - ('foo.fg', 'color: two;'), - ('foo.bg', 'background-color: three;'), ]) def test_values(self, key, expected): d = style.ColorDict() d['foo'] = 'one' - d['foo.fg'] = 'two' - d['foo.bg'] = 'three' assert d[key] == expected def test_key_error(self, caplog): From 869e2d91279624be5730e59bd47a6bf4049dff7e Mon Sep 17 00:00:00 2001 From: Nathan Isom Date: Fri, 16 Oct 2015 11:18:25 -0500 Subject: [PATCH 4/8] missed one. --- qutebrowser/mainwindow/statusbar/bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/statusbar/bar.py b/qutebrowser/mainwindow/statusbar/bar.py index 809a989f5..2fc42881a 100644 --- a/qutebrowser/mainwindow/statusbar/bar.py +++ b/qutebrowser/mainwindow/statusbar/bar.py @@ -111,7 +111,7 @@ class StatusBar(QWidget): QWidget#StatusBar QLabel, QWidget#StatusBar QLineEdit { {{ font['statusbar'] }} - {{ color['statusbar.bg'] }} + background-color: {{ color['statusbar.bg'] }}; color: {{ color['statusbar.fg'] }}; } From b18549bbeda75af45591870cb3281c7c5100ea6b Mon Sep 17 00:00:00 2001 From: Nathan Isom Date: Fri, 16 Oct 2015 11:42:46 -0500 Subject: [PATCH 5/8] Remove fontdict wrapper --- qutebrowser/config/style.py | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/qutebrowser/config/style.py b/qutebrowser/config/style.py index bb7782af1..55d63e923 100644 --- a/qutebrowser/config/style.py +++ b/qutebrowser/config/style.py @@ -41,9 +41,8 @@ def get_stylesheet(template_str): The formatted template as string. """ colordict = ColorDict(config.section('colors')) - fontdict = FontDict(config.section('fonts')) template = jinja2.Template(template_str) - return template.render(color=colordict, font=fontdict) + return template.render(color=colordict, font=config.section('fonts')) def set_register_stylesheet(obj): @@ -97,27 +96,3 @@ class ColorDict(collections.UserDict): raise TypeError("QColor passed to ColorDict!") else: return val - - -class FontDict(collections.UserDict): - - """A dict aimed at Qt stylesheet fonts.""" - - def __getitem__(self, key): - """Override dict __getitem__. - - Args: - key: The key to get from the dict. - - Return: - If a value wasn't found, return an empty string. - (Color not defined, so no output in the stylesheet) - - In all other cases, return font: . - """ - try: - val = self.data[key] - except KeyError: - return '' - else: - return 'font: {};'.format(val) From 6391da4f6f924c97575141b864c3a8ca9f8c9d27 Mon Sep 17 00:00:00 2001 From: Nathan Isom Date: Fri, 16 Oct 2015 12:02:57 -0500 Subject: [PATCH 6/8] Forgot font changes. --- qutebrowser/browser/downloadview.py | 2 +- qutebrowser/completion/completionwidget.py | 2 +- qutebrowser/mainwindow/statusbar/bar.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/qutebrowser/browser/downloadview.py b/qutebrowser/browser/downloadview.py index b03c893f0..a701a5dc2 100644 --- a/qutebrowser/browser/downloadview.py +++ b/qutebrowser/browser/downloadview.py @@ -65,7 +65,7 @@ class DownloadView(QListView): STYLESHEET = """ QListView { background-color: {{ color['downloads.bg.bar'] }}; - {{ font['downloads'] }} + font: {{ font['downloads'] }}; } QListView::item { diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py index 888cea4c6..6701413ef 100644 --- a/qutebrowser/completion/completionwidget.py +++ b/qutebrowser/completion/completionwidget.py @@ -55,7 +55,7 @@ class CompletionView(QTreeView): # don't define that in this stylesheet. STYLESHEET = """ QTreeView { - {{ font['completion'] }} + font: {{ font['completion'] }}; background-color: {{ color['completion.bg'] }}; alternate-background-color: {{ color['completion.alternate-bg'] }}; outline: 0; diff --git a/qutebrowser/mainwindow/statusbar/bar.py b/qutebrowser/mainwindow/statusbar/bar.py index 2fc42881a..900871c97 100644 --- a/qutebrowser/mainwindow/statusbar/bar.py +++ b/qutebrowser/mainwindow/statusbar/bar.py @@ -110,7 +110,7 @@ class StatusBar(QWidget): QWidget#StatusBar, QWidget#StatusBar QLabel, QWidget#StatusBar QLineEdit { - {{ font['statusbar'] }} + font: {{ font['statusbar'] }}; background-color: {{ color['statusbar.bg'] }}; color: {{ color['statusbar.fg'] }}; } From f1b9a3408f6b93daaa9629a0cc81b76e518616b2 Mon Sep 17 00:00:00 2001 From: Nathan Isom Date: Sat, 17 Oct 2015 19:23:48 -0500 Subject: [PATCH 7/8] Remove fontdict test, edit register stylesheet test to match new font result. --- tests/unit/config/test_style.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/tests/unit/config/test_style.py b/tests/unit/config/test_style.py index 673bc0134..88385145c 100644 --- a/tests/unit/config/test_style.py +++ b/tests/unit/config/test_style.py @@ -35,7 +35,7 @@ def test_get_stylesheet(config_stub): } template = "{{ color['completion.bg'] }}\n{{ font['completion'] }}" rendered = style.get_stylesheet(template) - assert rendered == 'black\nfont: foo;' + assert rendered == 'black\nfoo' class Obj(QObject): @@ -59,9 +59,9 @@ def test_set_register_stylesheet(delete, qtbot, config_stub, caplog): records = caplog.records() assert len(records) == 1 - assert records[0].message == 'stylesheet for Obj: font: bar;' + assert records[0].message == 'stylesheet for Obj: bar' - assert obj.rendered_stylesheet == 'font: bar;' + assert obj.rendered_stylesheet == 'bar' if delete: with qtbot.waitSignal(obj.destroyed): @@ -72,9 +72,9 @@ def test_set_register_stylesheet(delete, qtbot, config_stub, caplog): config_stub.changed.emit('fonts', 'foo') if delete: - expected = 'font: bar;' + expected = 'bar' else: - expected = 'font: baz;' + expected = 'baz' assert obj.rendered_stylesheet == expected @@ -103,11 +103,3 @@ class TestColorDict: d['foo'] # pylint: disable=pointless-statement -@pytest.mark.parametrize('key, expected', [ - ('foo', 'font: one;'), - ('bar', ''), -]) -def test_font_dict(key, expected): - d = style.FontDict() - d['foo'] = 'one' - assert d[key] == expected From e92a7495c42529690e51143320721ce2191a508c Mon Sep 17 00:00:00 2001 From: Nathan Isom Date: Sun, 18 Oct 2015 10:41:15 -0500 Subject: [PATCH 8/8] keep bg/fg test. --- tests/unit/config/test_style.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/config/test_style.py b/tests/unit/config/test_style.py index 88385145c..c113a7716 100644 --- a/tests/unit/config/test_style.py +++ b/tests/unit/config/test_style.py @@ -82,10 +82,14 @@ class TestColorDict: @pytest.mark.parametrize('key, expected', [ ('foo', 'one'), + ('foo.fg', 'two'), + ('foo.bg', 'three'), ]) def test_values(self, key, expected): d = style.ColorDict() d['foo'] = 'one' + d['foo.fg'] = 'two' + d['foo.bg'] = 'three' assert d[key] == expected def test_key_error(self, caplog):