Fix minor issue in _ColorHandler

This commit is contained in:
alessandro90
2019-05-28 19:40:53 +02:00
parent 7b12d5c0c6
commit c35cfa7e9b

View File

@@ -54,10 +54,10 @@ class _ColorsHandler:
All relevant features are defined: All relevant features are defined:
- if the format is valid; - if the format is valid;
- if 'line' represent a single color or a list of colors. - if 'line' represent a single color or a list of colors.
- the quality of the color.""" - the 'quality' of the color."""
quality, color_str = line.split(ThemeConstants.COLOR_SEPARATOR) quality, color_str = line.split(ThemeConstants.COLOR_SEPARATOR)
color_str = color_str.rstrip() color_str = color_str.strip()
self.quality = quality.lower() self.quality = quality.lower().strip()
self.color_str = '' self.color_str = ''
self.color_list = [] self.color_list = []
if ',' in color_str: if ',' in color_str:
@@ -71,9 +71,9 @@ class _ColorsHandler:
def __color_is_valid(self): def __color_is_valid(self):
"""Return if the color (or the list of colors) has a valid html format.""" """Return if the color (or the list of colors) has a valid html format."""
pattern = "#([a-zA-Z0-9]){6}" pattern = "#([a-zA-Z0-9]){6}"
match_ok = lambda col: bool(re.match(pattern, col)) match_ok = lambda col: bool(re.match(pattern, col)) and len(col) == 7
if not self.is_simple_string: if not self.is_simple_string:
if self.elements == self.MAX_COLORS: if len(self.color_list) <= self.MAX_COLORS:
return all(match_ok(c) for c in self.color_list) return all(match_ok(c) for c in self.color_list)
else: else:
return False return False
@@ -101,7 +101,7 @@ class _ColorsHandler:
simple_color_list.append(color) simple_color_list.append(color)
else: else:
double_color_list.append(color) double_color_list.append(color)
if simple_color_list and double_color_list: if simple_color_list or double_color_list:
return cls(simple_color_list, double_color_list) return cls(simple_color_list, double_color_list)
@@ -344,14 +344,14 @@ class ThemeManager:
if os.path.exists(ThemeConstants.CURRENT_THEME_FILE): if os.path.exists(ThemeConstants.CURRENT_THEME_FILE):
with open(ThemeConstants.CURRENT_THEME_FILE, "r") as current_theme_path: with open(ThemeConstants.CURRENT_THEME_FILE, "r") as current_theme_path:
theme_path = current_theme_path.read() theme_path = current_theme_path.read()
theme_name = self.__pretty_name(os.path.basename(theme_path)) theme_name = self.__pretty_name(os.path.basename(theme_path))
try: try:
self.__theme_names[theme_name].setChecked(True) self.__theme_names[theme_name].setChecked(True)
except Exception: except Exception:
pop_up(self.__parent, title=ThemeConstants.THEME_NOT_FOUND, pop_up(self.__parent, title=ThemeConstants.THEME_NOT_FOUND,
text=ThemeConstants.MISSING_THEME).show() text=ThemeConstants.MISSING_THEME).show()
else: else:
self.__apply(theme_path) self.__apply(theme_path)
else: else:
try: try:
self.__theme_names[ self.__theme_names[