mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
add options to delete and edit addons
This commit is contained in:
parent
69355be953
commit
3abd433337
3 changed files with 113 additions and 1 deletions
|
@ -5,7 +5,8 @@
|
||||||
import sys, os, re, traceback, time
|
import sys, os, re, traceback, time
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.utils import showInfo, showWarning, openFolder, isWin, openLink
|
from aqt.utils import showInfo, showWarning, openFolder, isWin, openLink, \
|
||||||
|
askUser
|
||||||
from anki.hooks import runHook, addHook, remHook
|
from anki.hooks import runHook, addHook, remHook
|
||||||
from aqt.webview import AnkiWebView
|
from aqt.webview import AnkiWebView
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
@ -14,6 +15,9 @@ import aqt
|
||||||
from anki.sync import httpCon
|
from anki.sync import httpCon
|
||||||
import aqt.sync # monkey-patches httplib2
|
import aqt.sync # monkey-patches httplib2
|
||||||
|
|
||||||
|
# in the future, it would be nice to save the addon id and unzippped file list
|
||||||
|
# to the config so that we can clear up all files and check for updates
|
||||||
|
|
||||||
class AddonManager(object):
|
class AddonManager(object):
|
||||||
|
|
||||||
def __init__(self, mw):
|
def __init__(self, mw):
|
||||||
|
@ -21,6 +25,7 @@ class AddonManager(object):
|
||||||
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.actionDownloadSharedPlugin, s, self.onGetAddons)
|
self.mw.connect(f.actionDownloadSharedPlugin, s, self.onGetAddons)
|
||||||
|
self._menus = []
|
||||||
if isWin:
|
if isWin:
|
||||||
self.clearAddonCache()
|
self.clearAddonCache()
|
||||||
sys.path.insert(0, self.addonsFolder())
|
sys.path.insert(0, self.addonsFolder())
|
||||||
|
@ -36,6 +41,7 @@ class AddonManager(object):
|
||||||
__import__(file.replace(".py", ""))
|
__import__(file.replace(".py", ""))
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
self.rebuildAddonsMenu()
|
||||||
|
|
||||||
# Menus
|
# Menus
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@ -45,6 +51,44 @@ class AddonManager(object):
|
||||||
path = self.addonsFolder()
|
path = self.addonsFolder()
|
||||||
openFolder(path)
|
openFolder(path)
|
||||||
|
|
||||||
|
def rebuildAddonsMenu(self):
|
||||||
|
for m in self._menus:
|
||||||
|
self.mw.form.menuPlugins.removeAction(m.menuAction())
|
||||||
|
for file in self.files():
|
||||||
|
m = self.mw.form.menuPlugins.addMenu(
|
||||||
|
os.path.splitext(file)[0])
|
||||||
|
self._menus.append(m)
|
||||||
|
a = QAction(_("Edit..."), self.mw)
|
||||||
|
p = os.path.join(self.addonsFolder(), file)
|
||||||
|
self.mw.connect(a, SIGNAL("triggered()"),
|
||||||
|
lambda p=p: self.onEdit(p))
|
||||||
|
m.addAction(a)
|
||||||
|
a = QAction(_("Delete..."), self.mw)
|
||||||
|
self.mw.connect(a, SIGNAL("triggered()"),
|
||||||
|
lambda p=p: self.onRem(p))
|
||||||
|
m.addAction(a)
|
||||||
|
|
||||||
|
def onEdit(self, path):
|
||||||
|
d = QDialog(self.mw)
|
||||||
|
frm = aqt.forms.editaddon.Ui_Dialog()
|
||||||
|
frm.setupUi(d)
|
||||||
|
d.setWindowTitle(os.path.basename(path))
|
||||||
|
frm.text.setPlainText(open(path).read())
|
||||||
|
d.connect(frm.buttonBox, SIGNAL("accepted()"),
|
||||||
|
lambda: self.onAcceptEdit(path, frm))
|
||||||
|
d.exec_()
|
||||||
|
|
||||||
|
def onAcceptEdit(self, path, frm):
|
||||||
|
open(path, "w").write(frm.text.toPlainText())
|
||||||
|
showInfo(_("Edits saved. Please restart Anki."))
|
||||||
|
|
||||||
|
def onRem(self, path):
|
||||||
|
if not askUser(_("Delete %s?") % os.path.basename(path)):
|
||||||
|
return
|
||||||
|
os.unlink(path)
|
||||||
|
self.rebuildAddonsMenu()
|
||||||
|
showInfo(_("Deleted. Please restart Anki."))
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
67
designer/editaddon.ui
Normal file
67
designer/editaddon.ui
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>606</width>
|
||||||
|
<height>473</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPlainTextEdit" name="text"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
|
@ -89,6 +89,7 @@
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionDownloadSharedPlugin"/>
|
<addaction name="actionDownloadSharedPlugin"/>
|
||||||
<addaction name="actionOpenPluginFolder"/>
|
<addaction name="actionOpenPluginFolder"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuMaintenance">
|
<widget class="QMenu" name="menuMaintenance">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
|
Loading…
Reference in a new issue