21.12.2022 Views

python_para_desenvolvedores_2ed

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

308 Inkscape

"""

def __init__(self):

# Evoca a inicialização da superclasse

inkex.Effect.__init__(self)

# Adiciona um parâmetro para ser recebido do Inkscape

self.OptionParser.add_option('-t', '--texto',

action = 'store', type = 'string',

dest = 'texto', default = 'Python',

help = 'Texto para ser randomizado')

self.OptionParser.add_option('-q', '--quantidade',

action='store', type='int',

dest='quantidade', default=20,

help='Quantidade de vezes que o texto irá aparecer')

self.OptionParser.add_option('-l', '--largura',

action='store', type='int',

dest='largura', default=1000,

help='Largura da área')

self.OptionParser.add_option('-c', '--altura',

action='store', type='int',

dest='altura', default=1000,

help='Altura da área')

def effect(self):

# Pega as variáveis que foram passadas como

# opções de linha de comando pelo Inkscape

texto = self.options.texto

quantidade = self.options.quantidade

largura = self.options.largura

altura = self.options.altura

# Raiz do SVG

svg = self.document.getroot()

# Altura e largura do documento

doc_largura = inkex.unittouu(svg.attrib['width'])

doc_altura = inkex.unittouu(svg.attrib['height'])

# Cria uma camada no documento

camada = inkex.etree.SubElement(svg, 'g')

camada.set(inkex.addNS('label', 'inkscape'), 'randomtext')

camada.set(inkex.addNS('groupmode', 'inkscape'), 'camada')

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!