[kupfer] dictionary: Add support for Purple dictionary



commit 378d30761780e72fe821197df89c2d54feaf3474
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Wed Mar 23 00:45:23 2011 +0100

    dictionary: Add support for Purple dictionary
    
    Idea and first patch by Timo Kluck
    
    Launchpad-bug: https://bugs.launchpad.net/kupfer/+bug/707437

 kupfer/plugin/dictionary.py |   30 ++++++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/kupfer/plugin/dictionary.py b/kupfer/plugin/dictionary.py
index 7805bff..23b5d57 100644
--- a/kupfer/plugin/dictionary.py
+++ b/kupfer/plugin/dictionary.py
@@ -2,19 +2,41 @@ __kupfer_name__ = _("Dictionary")
 __kupfer_actions__ = ("LookUp", )
 __description__ = _("Look up word in dictionary")
 __version__ = ""
-__author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
+__author__ = "Ulrik"
 
-from kupfer.objects import Source, Action, TextLeaf
+from kupfer.objects import Source, Action, TextLeaf, OperationError
 from kupfer import utils
+from kupfer import plugin_support
+from kupfer import kupferstring
 
+dictionaries = {
+	'gnome-dictionary': ['gnome-dictionary', '--look-up='],
+	'purple': ['purple', '--define=']
+}
+
+__kupfer_settings__ = plugin_support.PluginSettings(
+	{
+		"key" : "dictionary",
+		"label": _("Dictionary"),
+		"type": str,
+		"alternatives": dictionaries.keys(),
+		"value": 'gnome-dictionary',
+	}
+)
 
 class LookUp (Action):
 	def __init__(self):
 		Action.__init__(self, _("Look Up"))
 	def activate(self, leaf):
 		text = leaf.object
-		utils.spawn_async_notify_as("gnome-dictionary.desktop",
-		                           ["gnome-dictionary", "--look-up=%s" % text])
+		dict_id = __kupfer_settings__["dictionary"]
+		dict_argv = list(dictionaries[dict_id])
+		dict_argv[-1] = dict_argv[-1] + kupferstring.tolocale(text)
+		try:
+			utils.spawn_async_notify_as(dict_id + ".desktop", dict_argv)
+		except utils.SpawnError as exc:
+			raise OperationError(exc)
+
 	def item_types(self):
 		yield TextLeaf
 	def valid_for_item(self, leaf):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]