Skip to content

Commit

Permalink
feat(plugins: export: xresources): add support for multi-export
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Jun 16, 2024
1 parent b3acdd9 commit 3da894c
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions plugins/export_xresources/oomox_plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import re
from typing import TYPE_CHECKING

from oomox_gui.export_common import ExportDialog
from oomox_gui.config import DEFAULT_ENCODING
from oomox_gui.export_common import DialogWithExportPath
from oomox_gui.helpers import natural_sort
from oomox_gui.i18n import translate
from oomox_gui.plugin_api import OomoxExportPlugin
Expand Down Expand Up @@ -31,7 +33,10 @@ def generate_xresources(terminal_colorscheme: "dict[str, HexColor]") -> str:
])


class XresourcesExportDialog(ExportDialog):
class XresourcesExportDialog(DialogWithExportPath):

config_name = "xresources"
default_export_dir = f"{os.environ['HOME']}/.Xresources_themes"

def __init__(self, *args: "Any", **kwargs: "Any") -> None:
super().__init__(
Expand All @@ -45,12 +50,25 @@ def __init__(self, *args: "Any", **kwargs: "Any") -> None:
self.scrolled_window.show_all()
try:
term_colorscheme = generate_xrdb_theme_from_oomox(self.colorscheme)
xresources_theme = generate_xresources(term_colorscheme)
self.xresources_theme = generate_xresources(term_colorscheme)
except Exception as exc:
self.set_text(exc)
self.show_error()
else:
self.set_text(xresources_theme)
self.set_text(self.xresources_theme)

def do_export(self) -> None:
export_path = os.path.expanduser(
self.option_widgets[self.OPTIONS.DEFAULT_PATH].get_text(), # type: ignore[attr-defined]
)
parent_dir = os.path.dirname(export_path)
if not os.path.exists(parent_dir):
os.makedirs(parent_dir)
with open(export_path, "w", encoding=DEFAULT_ENCODING) as fobj:
fobj.write(self.xresources_theme)
self.remove_preset_name_from_path_config()
self.export_config.save()
self.dialog_done()


class Plugin(OomoxExportPlugin):
Expand All @@ -59,4 +77,3 @@ class Plugin(OomoxExportPlugin):
export_text = translate("Export _Xresources theme…")
shortcut = "<Primary>X"
export_dialog = XresourcesExportDialog
multi_export_supported: bool = False

0 comments on commit 3da894c

Please sign in to comment.