forked from rradczewski/swk_nametags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_name_tags.py
135 lines (108 loc) · 4.51 KB
/
generate_name_tags.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import math
import json
from pprint import pprint
try:
# Please do not use 'from scribus import *' . If you must use a 'from import',
# Do so _after_ the 'import scribus' and only import the names you need, such
# as commonly used constants.
import scribus
except ImportError,err:
print "This Python script is written for the Scribus scripting interface."
print "It can only be run from within Scribus."
sys.exit(1)
#########################
# YOUR IMPORTS GO HERE #
#########################
EVENT_NAME = "SoCraMOB OpenSpace 2015.1"
EVENT_LOCATION = "Münster, 21.03.2015"
STYLE_FIRST_NAME = "FirstName"
STYLE_LAST_NAME = "LastName"
STYLE_META = "Meta"
LOGO_WIDTH = 17.0
LOGO_HEIGHT = 17.0
OFFSETS = [
{"x": 17.5, "y": 13.5},
{"x": 112.500, "y": 13.5},
{"x": 17.5, "y": 68.5},
{"x": 112.500, "y": 68.5},
{"x": 17.5, "y": 123.5},
{"x": 112.500, "y": 123.5},
{"x": 17.5, "y": 178.5},
{"x": 112.500, "y": 178.5},
{"x": 17.5, "y": 233.5},
{"x": 112.500, "y": 233.5}
]
def drawNameTag(xOff, yOff, participant):
firstNamePos = {"x": xOff+5.0, "y": yOff+12.5}
lastNamePos = {"x": xOff+5.0, "y": yOff+20.5}
drawNameTagBox(xOff, yOff)
firstName = scribus.createText(firstNamePos["x"], firstNamePos["y"], 70, 9)
scribus.setText(participant["Vorname"], firstName)
scribus.setStyle(STYLE_FIRST_NAME, firstName)
lastName = scribus.createText(lastNamePos["x"], lastNamePos["y"], 70, 9)
scribus.setText(participant["Nachname"], lastName)
scribus.setStyle(STYLE_LAST_NAME, lastName)
def drawNameTagBox(xOff, yOff):
logoPos = {"x": xOff+75.0-LOGO_WIDTH, "y": yOff+10.5}
metaEventPos = {"x": xOff+5.0, "y": yOff+39.795}
metaLocationPos = {"x": xOff+5.0, "y": yOff+43.6}
#swkLogo = scribus.createImage(xOff+5.0, yOff+5.0, 70, 40)
#scribus.loadImage("softwerkskammer.png", swkLogo)
#scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=swkLogo)
#scribus.setProperty(swkLogo, "fillTransparency", 0.9)
metaEvent = scribus.createText(metaEventPos["x"], metaEventPos["y"], 70, 9)
scribus.setText(EVENT_NAME, metaEvent)
scribus.setStyle(STYLE_META, metaEvent)
metaLocation = scribus.createText(metaLocationPos["x"], metaLocationPos["y"], 70, 9)
scribus.setText(EVENT_LOCATION, metaLocation)
scribus.setStyle(STYLE_META, metaLocation)
metaLogo = scribus.createImage(logoPos["x"], logoPos["y"], LOGO_WIDTH, LOGO_HEIGHT)
scribus.loadImage("logo.png", metaLogo)
scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=metaLogo)
def drawLines():
scribus.createLine(0, 49.767, 210.0, 49.767)
scribus.createLine(0, 104.678, 210.0, 104.678)
scribus.createLine(0, 159.678, 210.0, 159.678)
scribus.createLine(0, 214.678, 210.0, 214.678)
scribus.createLine(0, 269.678, 210.0, 269.678)
def main(argv):
with open('participants.json') as data_file:
participants = json.load(data_file)
numOfParticipant = 0
drawLines()
for participant in participants:
relOffset = OFFSETS[numOfParticipant % 10]
drawNameTag(relOffset["x"], relOffset["y"], participant)
numOfParticipant = numOfParticipant+1
if numOfParticipant % 10 == 0:
scribus.newPage(-1)
drawLines()
while numOfParticipant % 10 != 0:
relOffset = OFFSETS[numOfParticipant % 10]
drawNameTagBox(relOffset["x"], relOffset["y"])
numOfParticipant = numOfParticipant + 1
def main_wrapper(argv):
"""The main_wrapper() function disables redrawing, sets a sensible generic
status bar message, and optionally sets up the progress bar. It then runs
the main() function. Once everything finishes it cleans up after the main()
function, making sure everything is sane before the script terminates."""
try:
scribus.statusMessage("Running script...")
scribus.progressReset()
main(argv)
finally:
# Exit neatly even if the script terminated with an exception,
# so we leave the progress bar and status bar blank and make sure
# drawing is enabled.
if scribus.haveDoc():
scribus.setRedraw(True)
scribus.statusMessage("")
scribus.progressReset()
# This code detects if the script is being run as a script, or imported as a module.
# It only runs main() if being run as a script. This permits you to import your script
# and control it manually for debugging.
if __name__ == '__main__':
main_wrapper(sys.argv)