Difference between revisions of "Drawing Lines and Python "For loops""

From Scribus Wiki
Jump to: navigation, search
 
m (Geishied up)
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
{{Scripting Index}}
 +
 
Here is another border, pretty useless but at least I am learnt a bit about Python - the 'for' loops need their following lines to be indented.  
 
Here is another border, pretty useless but at least I am learnt a bit about Python - the 'for' loops need their following lines to be indented.  
 
Also helps to understand the x and y co-ordinates of Scribus
 
Also helps to understand the x and y co-ordinates of Scribus
Line 4: Line 6:
 
Introduces: CreateLine SetLineWidth SetLineColor and Python for loops.
 
Introduces: CreateLine SetLineWidth SetLineColor and Python for loops.
  
from scribus import *
+
<syntaxhighlight lang="python">
Margins = (10, 10, 10, 10)
+
#!/usr/bin/env python
if NewDoc(Paper_A4, Margins, Portrait, 1, Points, NoFacingPages, FirstPageRight):
+
 
 +
from scribus import *
 +
 
 +
'''
 +
An exercise with loops and tested against 1.4.3 Uses
 +
 
 +
newDocument
 +
createLine
 +
setLineWidth
 +
setLineColor
 +
setFillShade
 +
createRect
 +
saveDocAs
 +
'''
 +
 
 +
Margins = (10, 10, 10, 10)
 +
if newDocument(PAPER_A4, Margins, PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT, 1):
 +
 
 +
  #some constants
 +
  a = 5      #line width
 +
  b="Blue"
 +
  m=33      #Fill shade, integer 0-100
 +
  g60="Grey60"
 +
  spx=30      #Start X
 +
  spy=30      #Start Y
 +
  a4w=595            #Width A4 getPageSize ?
 +
  a4d=842            #depth A4 getPageSize ?
  
#some constants
+
  #Draw the lines
a = 5 #line width
+
  d = createLine(spx-a/2,spy,a4w-30+a/2,spy) #Top
b="Blue"
+
  setLineColor(g60, d)
  m=33 #Fill shade, integer 0-100
+
  setLineWidth(a, d)
g60="Grey60"
+
  e = createLine(spx,spy,spx,a4d-27) #LH vertical
spx=30 #Start X
+
  setLineWidth(a, e)
spy=30 #Start Y
+
  setLineColor(g60, e)
a4w=595         #Width A4 getPageSize ?
+
  f = createLine(a4w-30,spy,a4w-30,a4d-27) #RH vertical
a4d=842         #depth A4 getPageSize ?
+
  setLineWidth(a, f)
 +
  setLineColor(g60, f)
 +
  g = createLine(spx-a/2,a4d-27,a4w-30+a/2,a4d-27)#Bottom
 +
  setLineWidth(a, g)
 +
  setLineColor(g60, g)
  
#Draw the lines
+
  #Draw the "holes"
d = CreateLine(spx-a/2,spy,a4w-30+a/2,spy) #Top
+
  for i in range(0,int(770/10)):
setLineColor(g60, d)
+
      l = createRect(spx+5,spy+10+10*i,10,5)
setLineWidth(a, d)
+
      setFillShade(m,l)
e = CreateLine(spx,spy,spx,a4d-27) #LH vertical
+
      setLineColor(g60,l)
setLineWidth(a, e)
+
  for i in range(0,int(770/10)):
setLineColor(g60, e)
+
      k = createRect(a4w-45,spy+10+10*i,10,5)
f = CreateLine(a4w-30,spy,a4w-30,a4d-27) #RH vertical
+
      setFillShade(m,k)
setLineWidth(a, f)
+
      setLineColor(g60,k)
setLineColor(g60, f)
 
g = CreateLine(spx-a/2,a4d-27,a4w-30+a/2,a4d-27)#Bottom
 
setLineWidth(a, g)
 
setLineColor(g60, g)
 
  
#Draw the "holes"
+
  saveDocAs("Fancy_border.sla") #Make sure this is writable
for i in range(0,int(770/10)):
 
  l = CreateRect(spx+5,spy+10+10*i,10,5)
 
  setFillShade(m,l)
 
  setLineColor(g60,l)
 
for i in range(0,int(770/10)):
 
  k = CreateRect(a4w-45,spy+10+10*i,10,5)
 
  setFillShade(m,k)
 
  setLineColor(g60,k)
 
  
SaveDocAs("Fancy_border.sla") #Make sure this is writable
+
</syntaxhighlight>

Latest revision as of 14:20, 11 November 2013

This article is part of the Scripts series.

Here is another border, pretty useless but at least I am learnt a bit about Python - the 'for' loops need their following lines to be indented. Also helps to understand the x and y co-ordinates of Scribus

Introduces: CreateLine SetLineWidth SetLineColor and Python for loops.

#!/usr/bin/env python

from scribus import *

'''
An exercise with loops and tested against 1.4.3 Uses

newDocument
createLine
setLineWidth
setLineColor
setFillShade
createRect
saveDocAs
'''

Margins = (10, 10, 10, 10)
if newDocument(PAPER_A4, Margins, PORTRAIT, 1,  UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT, 1):

   #some constants
   a = 5      #line width
   b="Blue"
   m=33      #Fill shade, integer 0-100
   g60="Grey60"
   spx=30      #Start X
   spy=30      #Start Y
   a4w=595             #Width A4 getPageSize ?
   a4d=842             #depth A4 getPageSize ?

   #Draw the lines
   d = createLine(spx-a/2,spy,a4w-30+a/2,spy) #Top
   setLineColor(g60, d)
   setLineWidth(a, d)
   e = createLine(spx,spy,spx,a4d-27)  #LH vertical
   setLineWidth(a, e)
   setLineColor(g60, e)
   f = createLine(a4w-30,spy,a4w-30,a4d-27)	#RH vertical
   setLineWidth(a, f)
   setLineColor(g60, f)
   g = createLine(spx-a/2,a4d-27,a4w-30+a/2,a4d-27)#Bottom
   setLineWidth(a, g)
   setLineColor(g60, g)

   #Draw the "holes"
   for i in range(0,int(770/10)):
       l = createRect(spx+5,spy+10+10*i,10,5)
       setFillShade(m,l)
       setLineColor(g60,l)		
   for i in range(0,int(770/10)):
       k = createRect(a4w-45,spy+10+10*i,10,5)
       setFillShade(m,k)		
       setLineColor(g60,k)

   saveDocAs("Fancy_border.sla") #Make sure this is writable