-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract xresources-related functionality to a separate plugin
- Loading branch information
1 parent
29c3891
commit e1fa979
Showing
14 changed files
with
101 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import os | ||
import subprocess | ||
|
||
from oomox_gui.plugin_api import OomoxImportPlugin | ||
from oomox_gui.color import convert_gdk_to_theme_color | ||
|
||
|
||
PLUGIN_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
class XrdbCache(): | ||
|
||
_cache = None | ||
|
||
@classmethod | ||
def get(cls): | ||
if cls._cache: | ||
return cls._cache | ||
|
||
timeout = 10 | ||
command = ['xrdb', '-query'] | ||
|
||
result = {} | ||
proc = subprocess.Popen( | ||
command, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT | ||
) | ||
for line in iter(proc.stdout.readline, b''): | ||
line = line.decode("utf-8") | ||
key, value, *_rest = line.split(':') | ||
key = key.lstrip('*').lstrip('.') | ||
value = value.strip() | ||
result[key] = value | ||
proc.communicate(timeout=timeout) | ||
if proc.returncode == 0: | ||
cls._cache = result | ||
return result | ||
print('xrdb not found') | ||
return None | ||
|
||
@classmethod | ||
def clear(cls): | ||
cls._cache = None | ||
|
||
|
||
class Plugin(OomoxImportPlugin): | ||
|
||
name = 'import_xresources' | ||
display_name = 'Xresources' | ||
plugin_theme_dir = os.path.abspath( | ||
os.path.join(PLUGIN_DIR, 'colors') | ||
) | ||
|
||
# theme_model_import = [] | ||
|
||
def read_colorscheme_from_path(self, preset_path): | ||
# pylint:disable=bad-option-value,import-outside-toplevel | ||
from oomox_gui.theme_model import THEME_MODEL | ||
|
||
theme_keys = [item['key'] for item in THEME_MODEL if 'key' in item] | ||
|
||
colorscheme = {} | ||
|
||
with open(preset_path) as file_object: | ||
for line in file_object.readlines(): | ||
key, _sep, value = line.strip().partition('=') | ||
if key.startswith("#") or key not in theme_keys: | ||
continue | ||
if value.startswith('xrdb.'): | ||
xrdb_color = XrdbCache.get().get(value.replace('xrdb.', '')) | ||
if xrdb_color and xrdb_color.startswith('#'): | ||
value = xrdb_color.replace('#', '') | ||
colorscheme[key] = value | ||
|
||
XrdbCache.clear() | ||
return colorscheme |