Skip to content

Commit

Permalink
chore: extract xresources-related functionality to a separate plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed May 29, 2020
1 parent 29c3891 commit e1fa979
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 60 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ install_import_random:
$(DEST_PLUGIN_DIR)/


install_import_xresources:
$(eval PLUGIN_NAME := "import_xresources")

mkdir -p $(DEST_PLUGIN_DIR)
cp -prf \
plugins/$(PLUGIN_NAME) \
$(DEST_PLUGIN_DIR)/


install_import_images:
$(eval PLUGIN_NAME := "import_pil")

Expand Down Expand Up @@ -197,8 +206,8 @@ install_icons_suruplus_aspromauros:


.PHONY: install
.PHONY: install_gui install_import_random install_theme_arc install_theme_oomox install_theme_materia install_export_oomoxify install_import_images install_plugin_base16 install_icons_archdroid install_icons_gnomecolors install_icons_numix install_icons_papirus install_icons_suruplus install_icons_suruplus_aspromauros
install: install_gui install_theme_arc install_theme_oomox install_theme_materia install_export_oomoxify install_import_images install_plugin_base16 install_icons_archdroid install_icons_gnomecolors install_icons_numix install_icons_papirus install_icons_suruplus install_icons_suruplus_aspromauros
.PHONY: install_gui install_import_random install_theme_arc install_theme_oomox install_theme_materia install_export_oomoxify install_import_images install_plugin_base16 install_icons_archdroid install_icons_gnomecolors install_icons_numix install_icons_papirus install_icons_suruplus install_icons_suruplus_aspromauros install_import_xresources
install: install_gui install_theme_arc install_theme_oomox install_theme_materia install_export_oomoxify install_import_images install_plugin_base16 install_icons_archdroid install_icons_gnomecolors install_icons_numix install_icons_papirus install_icons_suruplus install_icons_suruplus_aspromauros install_import_xresources

.PHONY: all
all: install
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ For GUI app itself:
- `python3-gobject`
- `gtk3>=3.18`
- `gdk-pixbuf2`
- `xorg-xrdb` - optional, for xresources themes

##### For plugins:

Expand Down Expand Up @@ -154,6 +153,9 @@ Base16 format support:
- `python3 pystache`
- `python3 yaml`

Xresources import:
- `xorg-xrdb` - optional, for xresources themes


#### Installation

Expand Down
14 changes: 0 additions & 14 deletions oomox_gui/theme_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from .i18n import _
from .theme_model import THEME_MODEL
from .xrdb import XrdbCache
from .plugin_loader import IMPORT_PLUGINS


Expand All @@ -21,16 +20,6 @@ def str_to_bool(value):
return value.lower() == 'true'


def parse_theme_color_value(result_value):
if not result_value:
return None
if 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): # pylint: disable=too-many-branches
result_value = colorscheme.get(theme_value['key'])
fallback_key = theme_value.get('fallback_key')
Expand All @@ -46,8 +35,6 @@ def parse_theme_value(theme_value, colorscheme): # pylint: disable=too-many-bra
result_value = fallback_function(colorscheme)

value_type = theme_value['type']
if value_type == 'color':
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 @@ -106,5 +93,4 @@ def read_colorscheme_from_path(preset_path):
if from_plugin:
colorscheme['FROM_PLUGIN'] = from_plugin

XrdbCache.clear()
return colorscheme
37 changes: 0 additions & 37 deletions oomox_gui/xrdb.py

This file was deleted.

2 changes: 1 addition & 1 deletion packaging/arch/PKGBUILD_full
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ depends=(

'themix-plugin-base16'

'themix-theme-arc'
#'themix-theme-arc'
'themix-theme-materia'
'themix-theme-oomox'

Expand Down
2 changes: 1 addition & 1 deletion packaging/arch/PKGBUILD_full_git
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ depends=(

'themix-plugin-base16-git'

'themix-theme-arc-git'
#'themix-theme-arc-git'
'themix-theme-materia-git'
'themix-theme-oomox-git'

Expand Down
4 changes: 2 additions & 2 deletions packaging/arch/PKGBUILD_gui
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ optdepends=(

'themix-plugin-base16: Import and export from Base16 project format'

'themix-theme-arc: Theme Style plugin'
#'themix-theme-arc: Theme Style plugin'
'themix-theme-materia: Theme Style plugin'
'themix-theme-oomox: Theme Style plugin'

Expand Down Expand Up @@ -58,7 +58,7 @@ package() {
_oomox_gui_dir=${_oomox_dir}/oomox_gui

cd "${srcdir}/oomox"
make DESTDIR="${pkgdir}" APPDIR="${_oomox_dir}" PREFIX="/usr" install_gui
make DESTDIR="${pkgdir}" APPDIR="${_oomox_dir}" PREFIX="/usr" install_gui install_import_xresources
python -O -m compileall ${pkgdir}${_oomox_gui_dir} -d ${_oomox_gui_dir}
}

Expand Down
4 changes: 3 additions & 1 deletion packaging/ubuntu/Dockerfile_cosmic
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ RUN sed -i -re 's/([a-z]{2}\.)?archive.ubuntu.com|security.ubuntu.com/old-releas
CMD ["/bin/bash", "./packaging/ubuntu/create_ubuntu_package.sh", "control_1810", "--install"]
RUN apt update --allow-unauthenticated && \
apt install -y make gettext fakeroot
COPY . /opt/oomox/
#COPY . /opt/oomox/

# vim: set ft=dockerfile :
4 changes: 3 additions & 1 deletion packaging/ubuntu/Dockerfile_zesty
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ RUN sed -i -re 's/([a-z]{2}\.)?archive.ubuntu.com|security.ubuntu.com/old-releas
CMD ["/bin/bash", "./packaging/ubuntu/create_ubuntu_package.sh", "control", "--install"]
RUN apt-get update && \
apt-get install -y make gettext fakeroot
COPY . /opt/oomox/
#COPY . /opt/oomox/

# vim: set ft=dockerfile :
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
77 changes: 77 additions & 0 deletions plugins/import_xresources/oomox_plugin.py
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

0 comments on commit e1fa979

Please sign in to comment.