From bc657f55fec48be38bd8ac2d2c5ab7db7ef9d6f6 Mon Sep 17 00:00:00 2001 From: inb Date: Tue, 25 Apr 2017 08:41:02 +0100 Subject: [PATCH] Add a tab to the Settings dialog. Users can directly open the plugins folder. Can also disable plugins by adding ".disabled" to the end of their folder name. --- plug.py | 13 +++++++++++-- prefs.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/plug.py b/plug.py index efdb30a2..7384c14c 100644 --- a/plug.py +++ b/plug.py @@ -19,12 +19,17 @@ def find_plugins(): :return: """ found = dict() + disabled = list() plug_folders = os.listdir(config.plugin_dir) for name in plug_folders: + if name.endswith(".disabled"): + name, discard = name.rsplit(".", 1) + disabled.append(name) + continue loadfile = os.path.join(config.plugin_dir, name, "load.py") if os.path.isfile(loadfile): found[name] = loadfile - return found + return found, disabled def load_plugins(): @@ -32,10 +37,14 @@ def load_plugins(): Load all found plugins :return: """ - found = find_plugins() + found, disabled = find_plugins() imp.acquire_lock() + for plugname in disabled: + sys.stdout.write("plugin {} disabled\n".format(plugname)) + for plugname in found: try: + sys.stdout.write("loading plugin {}\n".format(plugname)) with open(found[plugname], "rb") as plugfile: plugmod = imp.load_module(plugname, plugfile, found[plugname], (".py", "r", imp.PY_SOURCE)) diff --git a/prefs.py b/prefs.py index 9101cbfa..84ff9560 100644 --- a/prefs.py +++ b/prefs.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- - +import os from os.path import dirname, expanduser, expandvars, exists, isdir, join, normpath from sys import platform @@ -306,6 +306,36 @@ class PreferencesDialog(tk.Toplevel): notebook.add(themeframe, text=_('Appearance')) # Tab heading in settings + # Plugin settings and info + plugsframe = nb.Frame(notebook) + plugsframe.columnconfigure(1, weight=1) + plugdir = config.plugin_dir + + plugnames, disabled_plugins = plug.find_plugins() + + nb.Label(plugsframe, text=_('Plugins Folder:')).grid(padx=PADX, sticky=tk.W) + nb.Label(plugsframe, text=plugdir).grid(padx=PADX, sticky=tk.W) + if platform == "win32": + nb.Button(plugsframe, text="Open", + command=lambda: os.startfile(plugdir)).grid(padx=PADX, sticky=tk.W) + + nb.Label(plugsframe, text=_("Tip: You can disable a plugin by\nadding '.disabled' to it's folder name")).grid( + padx=PADX, pady=10, sticky=tk.NSEW) + + if len(plugnames): + ttk.Separator(plugsframe, orient=tk.HORIZONTAL).grid(columnspan=3, padx=PADX, pady=PADY * 8, sticky=tk.EW) + nb.Label(plugsframe, text=_('Enabled Plugins:')).grid(padx=PADX, sticky=tk.W) + for plugname in plugnames: + nb.Label(plugsframe, text=plugname).grid(padx=PADX + 5, sticky=tk.W) + if len(disabled_plugins): + ttk.Separator(plugsframe, orient=tk.HORIZONTAL).grid(columnspan=3, padx=PADX, pady=PADY * 8, sticky=tk.EW) + nb.Label(plugsframe, text=_('Disabled Plugins:')).grid(padx=PADX, sticky=tk.W) + for plugname in disabled_plugins: + nb.Label(plugsframe, text=plugname).grid(padx=PADX + 5, sticky=tk.W) + + notebook.add(plugsframe, text=_('Plugins')) + + if platform=='darwin': self.protocol("WM_DELETE_WINDOW", self.apply) # close button applies changes else: