From de8eb903ade499880209bbdacb6f775f79d1354c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Ho=CC=88ner?= Date: Fri, 22 Jun 2018 06:48:21 +0200 Subject: [PATCH] Revert to using relative theme pathes in settings Also, added code that auto-fixes absolute pathes saved by v2.0.0 Resolves #37 --- plugins/idaskins/plugin.py | 24 ++++++++++++++++-------- plugins/idaskins/themeselector.py | 7 ++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/plugins/idaskins/plugin.py b/plugins/idaskins/plugin.py index f281672..a908d49 100644 --- a/plugins/idaskins/plugin.py +++ b/plugins/idaskins/plugin.py @@ -3,7 +3,7 @@ import os import idaapi -from idaskins import IDA_DIR +from idaskins import IDA_DIR, THEMES_DIR from idaskins.idafontconfig import IdaFontConfig from idaskins.objectinspector import ObjectInspector from idaskins.settings import Settings @@ -71,6 +71,13 @@ def __init__(self, *args, **kwargs): self.open_theme_selector() self._settings.first_start = False + else: + # v2.0.0 used absolute pathes due to a bug. + # Fix settings from this particular version here. + theme_dir = self._settings.selected_theme_dir + if theme_dir and os.path.isabs(theme_dir): + print('[IDASkins] Updating buggy v2.0.0 theme path') + self._settings.selected_theme_dir = os.path.split(theme_dir)[-1] self._theme_selector = None self.apply_stylesheet_from_settings() @@ -79,9 +86,9 @@ def __init__(self, *args, **kwargs): self._ui_hooks = UiHooks() self._ui_hooks.hook() - def preprocess_stylesheet(self, qss, theme_dir): + def preprocess_stylesheet(self, qss, abs_theme_dir): qss = qss.replace('', QDir.fromNativeSeparators(IDA_DIR)) - qss = qss.replace('', QDir.fromNativeSeparators(theme_dir)) + qss = qss.replace('', QDir.fromNativeSeparators(abs_theme_dir)) def replace_keyword(x, keyword, kind): cfg = IdaFontConfig(kind) @@ -102,31 +109,32 @@ def replace_keyword(x, keyword, kind): return qss - def apply_stylesheet(self, theme_dir, manifest): + def apply_stylesheet(self, abs_theme_dir, manifest): try: - with open(os.path.join(theme_dir, manifest.qss_file)) as f: + with open(os.path.join(abs_theme_dir, manifest.qss_file)) as f: qss = f.read() except IOError as exc: print('[IDASkins] Unable to load stylesheet.') return - qss = self.preprocess_stylesheet(qss, theme_dir) + qss = self.preprocess_stylesheet(qss, abs_theme_dir) qApp.setStyleSheet(qss) #idaapi.request_refresh(idaapi.IWID_ALL) print('[IDASkins] Skin file successfully applied!') def apply_stylesheet_from_settings(self): theme_dir = self._settings.selected_theme_dir + abs_theme_dir = os.path.join(THEMES_DIR, theme_dir) if theme_dir: try: manifest = ThemeManifest(open(os.path.join( - theme_dir, 'manifest.json' + abs_theme_dir, 'manifest.json' ))) except ManifestError as exc: print('[IDASkins]', str(exc)) return - self.apply_stylesheet(theme_dir, manifest) + self.apply_stylesheet(abs_theme_dir, manifest) def open_theme_selector(self): self._theme_selector = ThemeSelector(qApp.activeWindow()) diff --git a/plugins/idaskins/themeselector.py b/plugins/idaskins/themeselector.py index 5ba78cd..9b364a4 100644 --- a/plugins/idaskins/themeselector.py +++ b/plugins/idaskins/themeselector.py @@ -47,7 +47,7 @@ def refresh(self): try: self._theme_list = [ ( - os.path.join(THEMES_DIR, x), + x, ThemeManifest(open( os.path.join(THEMES_DIR, x, 'manifest.json') ), @@ -69,18 +69,19 @@ def refresh(self): def theme_selected(self): theme_dir, manifest = self._get_selected() + abs_theme_dir = os.path.join(THEMES_DIR, theme_dir) self._ui.lblAuthorVal.setText(manifest.author) self._ui.lblVersionVal.setText(manifest.version) self._ui.lblNotesVal.setText(manifest.notes) self._ui.leClrPathVal.setText( - os.path.join(theme_dir, manifest.clr_file) + os.path.join(abs_theme_dir, manifest.clr_file) if manifest.clr_file else None ) if manifest.preview_image: - abs_path = os.path.join(theme_dir, manifest.preview_image) + abs_path = os.path.join(abs_theme_dir, manifest.preview_image) self._preview_pixmap = QPixmap(abs_path) self.update_preview() else: