Skip to content

Commit

Permalink
refactor(plugin_loader, theme_file_parse, theme_model, xrdb): pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Jan 9, 2018
1 parent 4f222c0 commit 9596aba
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
6 changes: 3 additions & 3 deletions oomox_gui/plugin_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
plugin_name,
os.path.join(plugin_path, "oomox_plugin.py")
)
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
plugin_class = foo.Plugin
plugin_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(plugin_module)
plugin_class = plugin_module.Plugin
plugin = plugin_class()
if not issubclass(plugin_class, OomoxPlugin):
continue
Expand Down
30 changes: 16 additions & 14 deletions oomox_gui/theme_file_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
from .xrdb import XrdbCache


def parse_theme_color_value(result_value):
if not result_value:
return None
if result_value == 'random_color':
result_value = get_random_theme_color()
elif result_value.startswith('xrdb.'):
xrdb_color = XrdbCache.get().get(result_value.replace('xrdb.', ''))
if xrdb_color and xrdb_color.startswith('#'):
result_value = xrdb_color.replace('#', '')
return result_value


def parse_theme_value(theme_value, colorscheme):
result_value = colorscheme.get(theme_value['key'])
fallback_key = theme_value.get('fallback_key')
Expand All @@ -16,13 +28,7 @@ def parse_theme_value(theme_value, colorscheme):

value_type = theme_value['type']
if value_type == 'color':
if result_value:
if result_value == 'random_color':
result_value = get_random_theme_color()
elif result_value.startswith('xrdb.'):
xrdb_color = XrdbCache.get().get(result_value.replace('xrdb.', ''))
if xrdb_color and xrdb_color.startswith('#'):
result_value = xrdb_color.replace('#', '')
result_value = parse_theme_color_value(result_value)
if value_type == 'bool':
if isinstance(result_value, str):
result_value = str_to_bool(result_value)
Expand Down Expand Up @@ -51,13 +57,9 @@ def read_colorscheme_from_path(preset_path):
for line in file_object.readlines():
parsed_line = line.strip().split('=')
key = parsed_line[0]
try:
if not key.startswith("#"):
if key in theme_keys:
colorscheme[key] = parsed_line[1]
# ignore unparseable lines:
except IndexError:
pass
if not key.startswith("#"):
if key in theme_keys and len(parsed_line) > 1:
colorscheme[key] = parsed_line[1]

for theme_model_item in theme_model:
key = theme_model_item.get('key')
Expand Down
3 changes: 2 additions & 1 deletion oomox_gui/theme_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def merge_theme_model_with_base(whole_theme_model, base_theme_model, plugin_mode
]
merge_theme_model_with_base(theme_model, BASE_THEME_MODEL_OPTIONS, 'options')

theme_model += [
BASE_ICON_THEME_MODEL = [
{
'type': 'separator',
'display_name': _('Iconset')
Expand All @@ -208,6 +208,7 @@ def merge_theme_model_with_base(whole_theme_model, base_theme_model, plugin_mode
'display_name': _('Icons style')
},
]
theme_model += BASE_ICON_THEME_MODEL
merge_model_with_base(
whole_theme_model=theme_model,
plugin_model_name='icons',
Expand Down
3 changes: 2 additions & 1 deletion oomox_gui/xrdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get(cls):
)
for line in iter(proc.stdout.readline, b''):
line = line.decode("utf-8")
key, value, *rest = line.split(':')
key, value, *_rest = line.split(':')
key = key.lstrip('*').lstrip('.')
value = value.strip()
result[key] = value
Expand All @@ -30,6 +30,7 @@ def get(cls):
cls._cache = result
return result
print('xrdb not found')
return None

@classmethod
def clear(cls):
Expand Down

0 comments on commit 9596aba

Please sign in to comment.