HEX
Server: Apache
System: Linux opal14.opalstack.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User: curbgloabal_opal (1234)
PHP: 8.1.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/share/inkscape/extensions/guillotine.pyo
�
��Yc@s�dZddlZddlZddlZy ddlmZmZeZWn
e	ZnXddl
Z
ddlZejej
d�d�Zde
jfd��YZedkr�e�Zej�ndS(	sp
guillotine.py

Copyright (C) 2010 Craig Marshall, craig9 [at] gmail.com

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

-----------------------

This script slices an inkscape drawing along the guides, similarly to
the GIMP plugin called "guillotine". It can optionally export to the
same directory as the SVG file with the same name, but with a number
suffix. e.g.

/home/foo/drawing.svg

will export to:

/home/foo/drawing0.png
/home/foo/drawing1.png
/home/foo/drawing2.png
/home/foo/drawing3.png

etc.

i����N(tPopentPIPEtcCstt|�t|��S(s�
    This is used to sort the horizontal and vertical guide positions,
    which are floating point numbers, but which are held as text.
    (tcmptfloat(tatb((s,/usr/share/inkscape/extensions/guillotine.pyt
float_sort7st
GuillotinecBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�ZRS(s Exports slices made using guidescCs�tjj|�|jjdddddddddd	d
�|jjdddddddddd	d
�|jjd
ddddddddd	d
�dS(Ns--directorytactiontstorettypetstringtdestt	directorytdefaultthelpRs--imagetimages--ignoretinkbooltignore(tinkextEffectt__init__tOptionParsert
add_optiontNone(tself((s,/usr/share/inkscape/extensions/guillotine.pyR@s

cCs�|jj�}g}|jjddtj�}x�|D]�}i}|jdjd�\}}|jdd dkr�d|d<||d<|j|�q7|jdd	d
kr7d|d<||d<|j|�q7q7W|S(sF
        Returns all guide elements as an iterable collection
        s//sodipodi:guidet
namespacestpositiont,torientationis0,t
horizontali����s,0tvertical(tdocumenttgetroottxpathRtNSStattribtsplittappend(RtroottguidesR#tgtguidetxty((s,/usr/share/inkscape/extensions/guillotine.pyt
get_guidesNs 




cCsEg}x8|j�D]*}|ddkr|j|d�qqW|S(s�
        Returns all horizontal guides as a list of floats stored as
        strings. Each value is the position from 0 in pixels.
        RRR(R.R'(RR)R*((s,/usr/share/inkscape/extensions/guillotine.pytget_all_horizontal_guidescs
cCsEg}x8|j�D]*}|ddkr|j|d�qqW|S(s�
        Returns all vertical guides as a list of floats stored as
        strings. Each value is the position from 0 in pixels.
        RR R(R.R'(RR)R*((s,/usr/share/inkscape/extensions/guillotine.pytget_all_vertical_guidesns
cCs�|jj�}dg}|j|jd�}xH|j�D]:}|dkr;t|�t|�kr;|j|�q;q;W|j|�|jdt�|S(s�
        Make a sorted list of all horizontal guide positions,
        including 0 and the document height, but not including
        those outside of the canvas
        t0theightiR(	R!R"tunittouuR%R/RR'tsortR(RR(thorizontalsR2th((s,/usr/share/inkscape/extensions/guillotine.pytget_horizontal_slice_positionsys	$
cCs�|jj�}dg}|j|jd�}xH|j�D]:}|dkr;t|�t|�kr;|j|�q;q;W|j|�|jdt�|S(s�
        Make a sorted list of all vertical guide positions,
        including 0 and the document width, but not including
        those outside of the canvas.
        R1twidthiR(	R!R"R3R%R0RR'R4R(RR(t	verticalsR8tv((s,/usr/share/inkscape/extensions/guillotine.pytget_vertical_slice_positions�s	$
c	Cs�|j�}|j�}g}xptt|�d�D]X}xOtt|�d�D]7}|j||||||d||dg�qRWq5W|S(s�
        Returns a list of all "slices" as denoted by the guides
        on the page. Each slice is really just a 4 element list of
        floats (stored as strings), consisting of the X and Y start
        position and the X and Y end position.
        i(R7R;trangetlenR'(Rthstvstslicestitj((s,/usr/share/inkscape/extensions/guillotine.pyt
get_slices�s9cCs|jjtkri|jjdks6|jjdkrStjd�tjd�n|jj	|jjfS|j
j�}d}y|j|}Wn3t
k
r�tjddd�tjd�nXtjj|�\}}|jd	d
�d}||fSdS(s�
        Attempts to get directory and image as passed in by the inkscape
        dialog. If the boolean ignore flag is set, then it will ignore
        these settings and try to use the settings from the export
        filename.
        RsPlease enter an image nameis<{http://www.inkscape.org/namespaces/inkscape}export-filenames$To use the export hints option, you s/need to have previously exported the document. s Otherwise no export hints exist!i����t.iN(toptionsRtFalseRRRterrormsgtsystexitRR!R"R%tKeyErrortostpathR&trsplit(Rtsvgtatttexport_filetdirnametfilename((s,/usr/share/inkscape/extensions/guillotine.pytget_filename_parts�s"$
	
cCs&tjj|�s"tj|�ndS(N(RKRLtisdirtmakedirs(Rtdir((s,/usr/share/inkscape/extensions/guillotine.pytcheck_dir_exists�scCstjdt|�d�S(Ns%.fi(tlocaletformatR(Rtstr((s,/usr/share/inkscape/extensions/guillotine.pytget_localised_string�sc
Cs�|jd}d|j|d�|j|d�|j|d�|j|d�||f}tr�t|dtdtd	t�}|j�}|j}|j}nt	j
|�\}	}}|j�d
S(s�
        Runs inkscape's command line interface and exports the image
        slice from the 4 coordinates in s, and saves as the filename
        given.
        i����s%inkscape -a %s:%s:%s:%s -e "%s" "%s" iiiitshelltstdouttstderrN(targsR[tbsubprocessRtTrueRtwaitR]R^RKtopen3tclose(
RtsRRtsvg_filetcommandtptreturn_codetfterrt_((s,/usr/share/inkscape/extensions/guillotine.pytexport_slice�s
P	cCs&|j�\}}t�}|dks3|d
kr<d}ntjj|�}tjj|�}tjj|�}|dtjjkr�|tjj7}n|j	|�d}xM|D]E}||t
|�d}|j|�|j||�|d7}q�Wt
jtd�dd	j|��d
S(s{
        Takes the slices list and passes each one with a calculated
        filename/directory into export_slice.
        Rs./i����is.pngis&The sliced bitmaps have been saved as:s

s
N(RStlistRRKRLt
expandusert
expandvarstabspathtsepRWRZR'RmRRGRltjoin(RR@RQRRtoutput_filesRAReRj((s,/usr/share/inkscape/extensions/guillotine.pyt
export_slices�s"		


cCs|j�}|j|�dS(N(RCRu(RR@((s,/usr/share/inkscape/extensions/guillotine.pyteffect�s(t__name__t
__module__t__doc__RR.R/R0R7R;RCRSRWR[RmRuRv(((s,/usr/share/inkscape/extensions/guillotine.pyR>s								"				t__main__(RyRXRKRHt
subprocessRRRaR`RFRtsimplestylet	setlocaletLC_ALLRRRRwtetaffect(((s,/usr/share/inkscape/extensions/guillotine.pyt<module>'s 

	�