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
|
#!/usr/bin/python
#coding: utf-8
#
# @version: 0.1
# @date: 19.04.2011
#
# @description: A quick script to output a html page that prints
# switch labels in the format: <row>-<switch>
# i.e: 71-4. One label per page.
#
# NB! only makes odd number labels.
#
# @author: technocake
# Found at: blog.technocake.net
#--------------------------------------------
import sys
######################################
# Configuration
######################################
rows = 84 #rows
switches = 4 #switches per row
outFile = "tg-switch-labels-print-me.html"
#### CREATIVIA ####
creative_rows = 12
creative_prepend = "C"
output = ""
# the top of the html page
def head():
return """<!Doctype html>
<html> <head>
<style>
div.a4 {
font-size: 24em;
text-align: center;
@page size: A4 landscape;
/* this is the part that makes each div print per page. */
page-break-after: always;
}
</style>
</head>
<body>
"""
#the bottom of the html page
def tail():
return "</body></html>"
#ONE switch label
def a4(s ):
return "<div class='a4'> %s </div>" % (s, )
def saveToFile(data, fileName):
f = open(fileName, 'w+')
f.write( data )
f.close()
# In python 3, raw_input is renamed to input. In python v <3. input does something else.
# this function fixes that
def prompt(text):
try:
return raw_input(text)
except:
try:
return input(text)
except:
exit()
###################################################
# This is where the actual generating takes place
###################################################
if __name__ == "__main__":
output += head()
#Generating all the labels for the switches
for row in range(1, rows+1, 2):
for SWITCH in range(1, switches+1):
output += a4("%s-%s\n" % (row, SWITCH) )
# Generating all the labels for the CREATIVE area
for row in range(1, creative_rows+1):
output += a4("%s-%s\n" % (creative_prepend, row))
output += tail()
# Taking it out to the big tg-world
if len(sys.argv) > 1:
#Printing to stdout if second argument is passed to the script
print ( output )
else:
saveToFile(output, outFile)
#normally, this is what happens. Saving it to a new html file
print ( """
Generated labels for %d switches per row and %d rows. \n
The html file is in this folder, and is named %s \n
Pages to print: %d \n\n
"""
% (switches, rows, outFile, (switches*rows)/2 + creative_rows)
)
prompt( "Press any key to exit...")
|