1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 08:17:13 +03:00

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.

This commit is contained in:
inb 2017-04-25 08:41:02 +01:00
parent 2810b61bda
commit bc657f55fe
2 changed files with 42 additions and 3 deletions

13
plug.py
View File

@ -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))

View File

@ -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: