3
Copyright (C) 2010 Aurelio A. Heckert, aurium (a) gmail dot com
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
from webslicer_effect import *
26
class WebSlicer_CreateRect(WebSlicer_Effect):
29
WebSlicer_Effect.__init__(self)
30
self.OptionParser.add_option("--name",
31
action="store", type="string",
34
self.OptionParser.add_option("--format",
35
action="store", type="string",
38
self.OptionParser.add_option("--dpi",
39
action="store", type="int",
42
self.OptionParser.add_option("--dimension",
43
action="store", type="string",
46
self.OptionParser.add_option("--bg-color",
47
action="store", type="string",
50
self.OptionParser.add_option("--quality",
51
action="store", type="int",
54
self.OptionParser.add_option("--gif-type",
55
action="store", type="string",
58
self.OptionParser.add_option("--palette-size",
59
action="store", type="int",
62
self.OptionParser.add_option("--html-id",
63
action="store", type="string",
66
self.OptionParser.add_option("--html-class",
67
action="store", type="string",
70
self.OptionParser.add_option("--layout-disposition",
71
action="store", type="string",
72
dest="layout_disposition",
74
self.OptionParser.add_option("--layout-position-anchor",
75
action="store", type="string",
76
dest="layout_position_anchor",
78
# inkscape param workarround
79
self.OptionParser.add_option("--tab")
82
def unique_slice_name(self):
83
name = self.options.name
84
el = self.document.xpath( '//*[@id="'+name+'"]', namespaces=inkex.NSS )
86
if name[-3:] == '-00': name = name[:-3]
92
if len(num_s)==1 : num_s = '0'+num_s
93
el = self.document.xpath( '//*[@id="'+name+'-'+num_s+'"]',
94
namespaces=inkex.NSS )
95
self.options.name = name+'-'+num_s
98
def validate_options(self):
99
self.options.format = self.options.ensure_value('format', 'png').lower()
100
if not is_empty( self.options.dimension ):
101
self.options.dimension
104
self.validate_options()
105
layer = self.get_slicer_layer(True)
106
#TODO: get selected elements to define location and size
107
rect = inkex.etree.SubElement(layer, 'rect')
108
if is_empty(self.options.name):
109
self.options.name = 'slice-00'
110
self.unique_slice_name()
111
rect.set('id', self.options.name)
112
rect.set('fill', 'red')
113
rect.set('opacity', '0.5')
114
rect.set('x', '-100')
115
rect.set('y', '-100')
116
rect.set('width', '200')
117
rect.set('height', '200')
118
desc = inkex.etree.SubElement(rect, 'desc')
119
conf_txt = "format:"+ self.options.format +"\n"
120
if not is_empty(self.options.dpi):
121
conf_txt += "dpi:" + str(self.options.dpi) +"\n"
122
if not is_empty(self.options.html_id):
123
conf_txt += "html-id:" + self.options.html_id
124
desc.text = self.get_conf_text_from_list( self.get_conf_list() )
127
def get_conf_list(self):
128
conf_list = [ 'format' ]
129
if self.options.format == 'gif':
130
conf_list.extend( [ 'gif_type', 'palette_size' ] )
131
if self.options.format == 'jpg':
132
conf_list.extend( [ 'quality' ] )
135
'bg_color', 'html_id', 'html_class',
136
'layout_disposition', 'layout_position_anchor'
142
if __name__ == '__main__':
143
e = WebSlicer_CreateRect()