From 34f1e67d493ae2f433c6273a84bf0d9ee9613c98 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 7 Sep 2017 21:37:48 +1200 Subject: [PATCH] make it possible for subiquity and console_conf to use different colours --- console_conf/core.py | 2 ++ subiquity/core.py | 2 ++ subiquitycore/core.py | 5 ++-- subiquitycore/palette.py | 60 --------------------------------------- subiquitycore/ui/utils.py | 34 ++++++++++++++++------ 5 files changed, 31 insertions(+), 72 deletions(-) delete mode 100644 subiquitycore/palette.py diff --git a/console_conf/core.py b/console_conf/core.py index fc476fd5..d77d1722 100644 --- a/console_conf/core.py +++ b/console_conf/core.py @@ -22,6 +22,8 @@ log = logging.getLogger('console_conf.core') class ConsoleConf(Application): + from console_conf.palette import STYLES, STYLES_MONO + project = "console_conf" controllers = [ "Welcome", diff --git a/subiquity/core.py b/subiquity/core.py index 1c55af4c..2320f908 100644 --- a/subiquity/core.py +++ b/subiquity/core.py @@ -22,6 +22,8 @@ log = logging.getLogger('console_conf.core') class Subiquity(Application): + from subiquity.palette import STYLES, STYLES_MONO + project = "subiquity" controllers = [ "Welcome", diff --git a/subiquitycore/core.py b/subiquitycore/core.py index 24d39051..819e59a3 100644 --- a/subiquitycore/core.py +++ b/subiquitycore/core.py @@ -19,7 +19,6 @@ import logging import urwid from subiquitycore.signals import Signal -from subiquitycore.palette import STYLES, STYLES_MONO from subiquitycore.prober import Prober, ProberException log = logging.getLogger('subiquitycore.core') @@ -122,7 +121,7 @@ class Application: def run(self): if not hasattr(self, 'loop'): - palette = STYLES + palette = self.STYLES additional_opts = { 'screen': urwid.raw_display.Screen(), 'unhandled_input': self.header_hotkeys, @@ -130,7 +129,7 @@ class Application: 'pop_ups': True, } if self.common['opts'].run_on_serial: - palette = STYLES_MONO + palette = self.STYLES_MONO else: additional_opts['screen'].set_terminal_properties(colors=256) additional_opts['screen'].reset_default_terminal_palette() diff --git a/subiquitycore/palette.py b/subiquitycore/palette.py deleted file mode 100644 index 207d0960..00000000 --- a/subiquitycore/palette.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2015 Canonical, Ltd. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -""" Palette definitions """ - -dark_magenta = 'dark magenta' -light_magenta = 'light magenta' -light_green = 'light green' -dark_green = 'dark green' -white = 'white' -black = 'black' -light_gray = 'light gray' -dark_gray = 'dark gray' -dark_red = 'dark red' -light_red = 'light red' - -STYLES = [ - ('frame_header', '', '', '', white, ''), - ('frame_footer', '', '', '', white, ''), - ('body', '', '', '', white, ''), - ('menu_button', '', '', '', white, ''), - ('menu_button focus', '', '', '', black, light_gray), - ('button', '', '', '', white, ''), - ('button focus', '', '', '', black, dark_green), - ('info_primary', '', '', '', white, ''), - ('info_major', '', '', '', light_gray, ''), - ('info_minor', '', '', '', dark_gray, ''), - ('info_error', '', '', '', dark_red, ''), - ('string_input', '', '', '', black, light_gray), - ('string_input focus', '', '', '', white, dark_gray), - ('progress_incomplete', '', '', '', white, dark_magenta), - ('progress_complete', '', '', '', white, light_magenta) -] - -STYLES_MONO = [ - ('frame_header', white, black, '', '', ''), - ('frame_footer', white, black, '', '', ''), - ('body', white, black, '', '', ''), - ('info_minor', white, black, '', '', ''), - ('menu_button', '', '', '', white, ''), - ('menu_button focus', '', '', '', white, ''), - ('button', white, black, '', '', ''), - ('button focus', white, black, '', '', ''), - ('string_input', '', '', '', white, ''), - ('string_input focus', '', '', '', white, ''), - ('progress_incomplete', '', '', '', '', black), - ('progress_complete', '', '', '', '', white), -] diff --git a/subiquitycore/ui/utils.py b/subiquitycore/ui/utils.py index 54c86247..18ad6062 100644 --- a/subiquitycore/ui/utils.py +++ b/subiquitycore/ui/utils.py @@ -18,7 +18,6 @@ from urwid import Padding as _Padding from urwid import AttrMap, Text from functools import partialmethod -from subiquitycore.palette import STYLES def apply_padders(cls): @@ -124,6 +123,26 @@ class Padding: """ line_break = partialmethod(Text) +# This makes assumptions about the style names defined by both +# subiquity and console_conf. The fix is to stop using the Color class +# below, I think. +STYLE_NAMES = set([ + 'frame_header', + 'frame_footer', + 'body', + 'menu_button', + 'menu_button focus', + 'button', + 'button focus', + 'info_primary', + 'info_major', + 'info_minor', + 'info_error', + 'string_input', + 'string_input focus', + 'progress_incomplete', + 'progress_complete', +]) def apply_style_map(cls): """ Applies AttrMap attributes to Color class @@ -133,15 +152,12 @@ def apply_style_map(cls): Color.frame_header(Text("I'm text in the Orange frame header")) Color.body(Text("Im text in wrapped with the body color")) """ - style_names = set() - for k in STYLES: - style_names.add(k[0]) - for k in STYLES: - kf = k[0] + ' focus' - if k[0] + ' focus' in style_names: - setattr(cls, k[0], partialmethod(AttrMap, attr_map=k[0], focus_map=kf)) + for k in STYLE_NAMES: + kf = k + ' focus' + if kf in STYLE_NAMES: + setattr(cls, k, partialmethod(AttrMap, attr_map=k[0], focus_map=kf)) else: - setattr(cls, k[0], partialmethod(AttrMap, attr_map=k[0])) + setattr(cls, k, partialmethod(AttrMap, attr_map=k[0])) return cls