mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
remove plugin enabling/disabling
This commit is contained in:
parent
e13a9bd21a
commit
69355be953
2 changed files with 5 additions and 69 deletions
|
@ -20,85 +20,31 @@ class AddonManager(object):
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
f = self.mw.form; s = SIGNAL("triggered()")
|
f = self.mw.form; s = SIGNAL("triggered()")
|
||||||
self.mw.connect(f.actionOpenPluginFolder, s, self.onOpenAddonFolder)
|
self.mw.connect(f.actionOpenPluginFolder, s, self.onOpenAddonFolder)
|
||||||
self.mw.connect(f.actionEnableAllPlugins, s, self.onEnableAllAddons)
|
|
||||||
self.mw.connect(f.actionDisableAllPlugins, s, self.onDisableAllAddons)
|
|
||||||
self.mw.connect(f.actionDownloadSharedPlugin, s, self.onGetAddons)
|
self.mw.connect(f.actionDownloadSharedPlugin, s, self.onGetAddons)
|
||||||
if isWin:
|
if isWin:
|
||||||
self.clearAddonCache()
|
self.clearAddonCache()
|
||||||
sys.path.insert(0, self.addonsFolder())
|
sys.path.insert(0, self.addonsFolder())
|
||||||
self.loadAddons()
|
self.loadAddons()
|
||||||
|
|
||||||
|
def files(self):
|
||||||
|
return [f for f in os.listdir(self.addonsFolder())
|
||||||
|
if f.endswith(".py")]
|
||||||
|
|
||||||
def loadAddons(self):
|
def loadAddons(self):
|
||||||
on, off = self.files()
|
for file in self.files():
|
||||||
for file in on:
|
|
||||||
try:
|
try:
|
||||||
__import__(file.replace(".py", ""))
|
__import__(file.replace(".py", ""))
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
self.rebuildAddonsMenu()
|
|
||||||
|
|
||||||
# Menus
|
# Menus
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def rebuildAddonsMenu(self):
|
|
||||||
if getattr(self, "addonActions", None) is None:
|
|
||||||
self.addonActions = []
|
|
||||||
for action in self.addonActions:
|
|
||||||
self.mw.form.menuStartup.removeAction(action)
|
|
||||||
self.addonActions = []
|
|
||||||
on, off = self.files()
|
|
||||||
def addObjs(l, enabled):
|
|
||||||
l.sort()
|
|
||||||
for file in l:
|
|
||||||
p = re.sub("\.py(\.off)?", "", file)
|
|
||||||
a = QAction(p, self.mw)
|
|
||||||
a.setCheckable(True)
|
|
||||||
a.setChecked(enabled)
|
|
||||||
self.mw.connect(a, SIGNAL("triggered()"),
|
|
||||||
lambda f=file: self.toggleAddon(f))
|
|
||||||
self.mw.form.menuStartup.addAction(a)
|
|
||||||
self.addonActions.append(a)
|
|
||||||
addObjs(on, True)
|
|
||||||
addObjs(off, False)
|
|
||||||
|
|
||||||
def onOpenAddonFolder(self, path=None):
|
def onOpenAddonFolder(self, path=None):
|
||||||
if path is None:
|
if path is None:
|
||||||
path = self.addonsFolder()
|
path = self.addonsFolder()
|
||||||
openFolder(path)
|
openFolder(path)
|
||||||
|
|
||||||
# Enabled/disabled list
|
|
||||||
######################################################################
|
|
||||||
|
|
||||||
def files(self):
|
|
||||||
on = []
|
|
||||||
off = []
|
|
||||||
for f in os.listdir(self.addonsFolder()):
|
|
||||||
if not f.endswith(".py"):
|
|
||||||
continue
|
|
||||||
if f in self.mw.pm.meta['disabledAddons']:
|
|
||||||
off.append(f)
|
|
||||||
else:
|
|
||||||
on.append(f)
|
|
||||||
return on, off
|
|
||||||
|
|
||||||
def onEnableAllAddons(self):
|
|
||||||
self.mw.pm.meta['disabledAddons'] = []
|
|
||||||
self.mw.pm.save()
|
|
||||||
self.rebuildAddonsMenu()
|
|
||||||
|
|
||||||
def onDisableAllAddons(self):
|
|
||||||
on, off = self.files()
|
|
||||||
self.mw.pm.meta['disabledAddons'] = on + off
|
|
||||||
self.rebuildAddonsMenu()
|
|
||||||
|
|
||||||
def toggleAddon(self, file):
|
|
||||||
if file in self.mw.pm.meta['disabledAddons']:
|
|
||||||
self.mw.pm.meta['disabledAddons'].remove(file)
|
|
||||||
else:
|
|
||||||
self.mw.pm.meta['disabledAddons'].append(file)
|
|
||||||
self.mw.pm.save()
|
|
||||||
self.rebuildAddonsMenu()
|
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
|
@ -87,18 +87,8 @@
|
||||||
<iconset resource="icons.qrc">
|
<iconset resource="icons.qrc">
|
||||||
<normaloff>:/icons/preferences-plugin.png</normaloff>:/icons/preferences-plugin.png</iconset>
|
<normaloff>:/icons/preferences-plugin.png</normaloff>:/icons/preferences-plugin.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuStartup">
|
|
||||||
<property name="title">
|
|
||||||
<string>Startup</string>
|
|
||||||
</property>
|
|
||||||
<addaction name="actionEnableAllPlugins"/>
|
|
||||||
<addaction name="actionDisableAllPlugins"/>
|
|
||||||
<addaction name="separator"/>
|
|
||||||
</widget>
|
|
||||||
<addaction name="actionDownloadSharedPlugin"/>
|
<addaction name="actionDownloadSharedPlugin"/>
|
||||||
<addaction name="actionOpenPluginFolder"/>
|
<addaction name="actionOpenPluginFolder"/>
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="menuStartup"/>
|
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuMaintenance">
|
<widget class="QMenu" name="menuMaintenance">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
|
Loading…
Reference in a new issue