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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
import gi
from gi.repository import Gtk
import glob
from gettext import gettext as _
import toolkit.chooser as chooser
from toolkit import pixbuf
import theme
def load():
from document import Document
custom = THEMES[-1]
for i, f in enumerate(
[i for i in set(Document.tape) if not i.empty() and i.custom()]):
custom.frames[i] = f
class Frame():
def __init__(self, id):
self.id = id
self.name = ''
self._thumb = None
self._orig = None
def serialize(self):
if self._orig:
return pixbuf.to_str(self._orig)
else:
return ''
def empty(self):
return False
def custom(self):
return True
def thumb(self):
if self._thumb == None:
self._thumb = theme.scale(self.orig())
return self._thumb
def orig(self):
return self._orig
def select(self):
return True
class PreinstalledFrame(Frame):
def __init__(self, filename):
Frame.__init__(self, filename)
self._filename = filename
def custom(self):
return False
def orig(self):
if self._orig == None:
self._orig = theme.pixbuf(self._filename)
return self._orig
class EmptyFrame(Frame):
def __init__(self):
Frame.__init__(self, None)
self._thumb = theme.EMPTY_THUMB
self._orig = theme.EMPTY_ORIG
def custom(self):
return False
def empty(self):
return True;
class RestoredFrame(Frame):
def __init__(self, id, data):
Frame.__init__(self, id)
self._orig = pixbuf.from_str(data)
class CustomFrame(Frame):
def __init__(self):
Frame.__init__(self, None)
self._thumb = theme.CUSTOM_FRAME_THUMB
def orig(self):
if self._orig == None:
return theme.EMPTY_ORIG
return self._orig
def select(self):
if self._orig:
return True
self.name, self.id, self._orig = chooser.pick(
lambda jobject: (jobject.metadata['title'], jobject.object_id,
theme.pixbuf(jobject.file_path)),
(None, None, None), what=chooser.IMAGE)
if self.name:
self._thumb = theme.scale(self._orig)
return True
else:
return False
class Char():
def __init__(self, name, thumbfile, dir):
self.name = name
self.frames = []
if dir:
for i in sorted(glob.glob(theme.path(dir, '*'))):
self.frames.append(PreinstalledFrame(
os.path.join(dir, os.path.basename(i))))
self._thumb = theme.pixbuf(thumbfile, theme.THUMB_SIZE)
self._custom = False
else:
for i in range(0, theme.FRAME_ROWS * theme.FRAME_COLS):
self.frames.append(CustomFrame())
self._thumb = theme.CUSTOM_FRAME_THUMB
self._custom = True
def custom(self):
return self._custom
def thumb(self):
return self._thumb
def clean(self, index):
if self.frames[index].custom():
self.frames[index] = CustomFrame()
THEMES = (
Char(_('Elephant'), 'images/pics/Elephant/bigelephant0.gif',
'images/pics/Elephant'),
Char(_('Space Blob'), 'images/pics/SpaceBlob/bigblob8.gif',
'images/pics/SpaceBlob'),
Char(_('Turkey'), 'images/pics/Turkey/bigturkey1.gif',
'images/pics/Turkey'),
None,
Char(_('Custom'), None, None))
|