guides_creator.py revision 8b2ab03b3ec17532a2ee46dd8716d9d8bef380f7
'''
Guides Creator v2.31 (05/07/2009)
Copyright (C) 2008 Jonas Termeau - jonas.termeau **AT** gmail.com
Thanks to:
Bernard Gray - bernard.gray **AT** gmail.com (python helping)
Jamie Heames (english translation issues)
~suv (bug report in v2.3)
http://www.gutenberg.eu.org/publications/ (9x9 margins settings)
## 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; version 2 of the License.
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
# for golden number formulae
# We will use the inkex module with the predefined Effect base class.
import inkex
from simplestyle import *
# for localized debugging output
# for golden number formula and diagonal guides
# 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
def deleteAllGuides(document):
# getting the parent's tag of the guides
# getting all the guides
# removing each guides
"""
Constructor.
Defines options of the script.
"""
# Call the base class constructor.
# Define option for the tab.
help="")
# 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 boolean option "--start_from_edges" with default value False.
help = 'Start from edges')
# Define boolean option "--delete_existing_guides" with default value False.
help = 'Delete existing guides')
# Define boolean option "--upper_left_corner" with default value False.
help = 'Upper left corner')
# Define boolean option "--upper_right_corner" with default value False.
help = 'Upper right corner')
# Define boolean option "--lower_left_corner" with default value False.
help = 'Lower left corner')
# Define boolean option "--upper_left_corner" with default value False.
help = 'Lower right corner')
# Define boolean option "--delete_existing_guides2" with default value False.
help = 'Delete existing guides')
# Define string option "--margins_preset" with default value 'custom'.
help = 'Margins preset')
# Define boolean option "--delete_existing_guides3" with default value False.
help = 'Delete existing guides')
# Define string option "--vertical_subdivisions" with default value '0'.
help = 'Vertical subdivisions')
# Define string option "--horizontal_subdivisions" with default value '0'.
help = 'Horizontal subdivisions')
# Define string option "--header_margin" with default value '6'.
help = 'Header margin')
# Define string option "--footer_margin" with default value '6'.
help = 'Footer margin')
# Define string option "--left_margin" with default value '6'.
help = 'Left margin')
# Define string option "--right_margin" with default value '6'.
help = 'Right margin')
# Define boolean option "--start_from_edges2" with default value False.
help = 'Start from edges')
# Get script's options value.
# first tab
# second tab
# third tab
# getting the main SVG document element (canvas)
# getting the width and height attributes of the canvas
# getting edges coordinates
# getting parent tag of the guides
if (tab == "\"regular_guides\""):
if (delete_existing):
if (guides_preset == 'custom'):
v_division = 1
h_division = 1
# creating vertical guides
# creating horizontal guides
elif (guides_preset == 'golden'):
# horizontal golden guides
# vertical golden guides
if (from_edges):
# horizontal borders
# vertical borders
else:
elif (tab == "\"diagonal_guides\""):
if (delete_existing2):
# diagonal
angle = 45
# X axe
left = 0
# Y axe
down = 0
if (upper_left):
if (upper_right):
if (lower_left):
if (lower_right):
elif (tab == "\"margins\""):
if (delete_existing3):
if (from_edges2):
# horizontal borders
# vertical borders
if (margins_preset == 'custom'):
y_footer = 0
x_left = 0
if (header_margin != 0):
if (footer_margin != 0):
if (left_margin != 0):
if (right_margin != 0):
elif (margins_preset == 'book_left'):
# 1/9th header
# 2/9th footer
# 2/9th left margin
# 1/9th right margin
elif (margins_preset == 'book_right'):
# 1/9th header
# 2/9th footer
# 2/9th left margin
# 1/9th right margin
# setting up properties of the rectangle created between guides
if (h_subdiv != 0):
# creating horizontal guides
if (v_subdiv != 0):
# creating vertical guides
if __name__ == '__main__':
# Create effect instance and apply it.
effect = Guides_Creator()
## end of file guide_creator.py ##