guides_creator.py revision 9fa06a672fcfff82e415e4cbbcbc9b3702b9dcf9
'''
Guides Creator v2.0 (25/11/2008)
Copyright (C) 2008 Jonas Termeau - jonas.termeau **AT** gmail.com
Thanks to Bernard Gray - bernard.gray **AT** gmail.com
## This basic extension allows you to automatically draw guides in inkscape.
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
'''
# inspired by hello_world turorial by Blackhex and Rubikcube
# Making an .INX file : http://wiki.inkscape.org/wiki/index.php/MakingAnINX
# see also http://codespeak.net/lxml/dev/tutorial.html#namespaces for XML namespaces manipulation
# # # # # # # #
#
# # # # # # # #
# # # extension's begining # # #
# These two lines are only needed if you don't put the script directly into
# the installation directory
import sys
# We will use the inkex module with the predefined Effect base class.
import inkex
from simplestyle import *
# for golden number formulae
# for printing debugging output
import gettext
def printDebug(string):
if (division > 0):
if (edges):
var = 1
else:
var = 0
# setting up the guide's attributes (id is generated automatically)
if (division > 0):
if (edges):
var = 1
else:
var = 0
# setting up the guide's attributes (id is generated automatically)
# Create a sodipodi:guide node
# (look into inkex's namespaces to find 'sodipodi' value in order to make a "sodipodi:guide" tag)
# see NSS array in file inkex.py for the other namespaces
inkex.etree.SubElement(parent,'{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}guide',{'position':position,'orientation':orientation})
# take a "string1;string2" preset
# and return "string1"
return result
# take a "string1;string2" preset
# and return "string2"
return result
"""
Constructor.
Defines options of the script.
"""
# Call the base class constructor.
# Define string option "--preset" with default value 'custom'.
help = 'Preset')
# Define string option "--vertical_guides" with default value '0'.
help = 'Vertical guides each:')
# Define string option "--horizontal_guides" with default value '0'.
help = 'Horizontal guides each:')
# Define string option "--start_from_edges" with default value False.
help = 'Start from edges')
# Define string option "--delete_existing_guides" with default value False.
help = 'Delete existing guides')
# Get script's options value.
# Get access to main SVG document element and get its dimensions.
# getting the width and height attributes of the canvas
# getting the parent tag of the guide
if (delete_existing):
# getting all the guides
# removing each guides
if (preset == 'custom'):
# creating vertical guides
# creating horizontal guides
elif (preset == 'golden'):
# horizontal golden guides
# vertical golden guides
if (from_edges):
# horizontal borders
# horizontal borders
else:
# Create effect instance and apply it.
effect = Guides_Creator()
## end of file guide_creator.py ##