-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpidgin_smiley.py
84 lines (70 loc) · 2.47 KB
/
pidgin_smiley.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
__kupfer_name__ = _("Smiley")
__kupfer_sources__ = ("SmileySource",)
__kupfer_actions__ = ()
__description__ = _("""List and copy char of pidgin smiley theme""")
__version__ = "0.2.4"
__author__ = "Hugo Sena Ribeiro <hugosenari gmail com>"
from os import path
from kupfer import pretty, icons
from kupfer.plugin_support import PluginSettings
from kupfer.objects import Source, TextLeaf
__kupfer_settings__ = PluginSettings(
{
"key" : "smiley_source_path",
"label": _("Path of smiley theme"),
"type": str,
"value": "/usr/share/pixmaps/pidgin/emotes/default/",
},
)
#the sources
class SmileySource (Source):
def __init__(self):
Source.__init__(self, _("Smiley"))
def get_items(self):
cfg = __kupfer_settings__["smiley_source_path"]
theme_dir = path.expanduser(cfg)
theme_path = path.join(theme_dir, 'theme')
self._theme_exists(theme_path)
with open(theme_path, 'r') as theme_file:
for line in theme_file:
smiley = self._smile(line, theme_dir)
if smiley:
yield smiley
def _theme_exists(self, theme_path):
if not path.exists(theme_path):
pretty.print_debug(__name__, "StopIteration not found " + theme_path)
raise StopIteration()
def _smile(self, line, theme_dir):
values = self._values(line)
if values:
img = path.join(theme_dir, values[0])
key = values[-1]
names = values[0:]
if path.exists(img):
return SmileyLeaf(img, key, values)
def _values(self, line):
if line\
and u'.png' in line\
and not line.startswith(u'#')\
and not line.startswith(u'[')\
and not line.startswith(u'Icon=')\
and not line.startswith(u'Icon ='):
values = line.lstrip(u'!').split()
if len(values) > 1:
return values
return None
def get_icon_name(self):
return "face-smile"
#the 'objects'
class SmileyLeaf (TextLeaf):
""" Leaf represent shortcut"""
def __init__(self, img, key, names):
TextLeaf.__init__(self,
key,
u' '.join(names)
)
self._img = img
def get_thumbnail(self, width, height):
return icons.get_pixbuf_from_file(self._img, width, height)
def get_text_representation(self):
return str(self.name)