summaryrefslogtreecommitdiff
path: root/support/textoolspro/boxerer.py
blob: 7be1a151b20b3314f1d1d9b56f7df124d9a3d3bb (plain)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"""
Manuel Gutierrez Algaba 1999

You are free to use , modify, distribute and copy this piece of
python code, if you keep this free copyright notice in it.

boxerer Version 1.1

Constructor of boxes:

This code does a series of boxes, one inside another ,
so that the structure of a specific thing is clearly shown.

"""
import string

class included:
    def __init__(self, title_of_the_thing,  width = 350, decrement = 20, spaced = 'on' ):
	self.limit_of_generation=10000
	self.spaced= spaced
	self.title = title_of_the_thing[0]
	self.set_of_articles = []
	self.width = width
	self.decrement = decrement
	print title_of_the_thing
	if not title_of_the_thing[1] is None:
	    for i in title_of_the_thing[1]:
		#print "line 18",i
		self.add(included(i,width - decrement, decrement))
	try:
	    self.coment = title_of_the_thing[2]
	except:
	    self.coment = ""

    def do_limit_of_generation(self,y):
	self.limit_of_generation= y

    def add(self,i):
	self.set_of_articles.append(i)

    def genera(self, f, level = 0):
	if level==self.limit_of_generation:
	    return -1
	f.write("\\framebox{\\parbox{"+str(self.width)+" pt }{\\textit{ "+ self.title+"}")
	print self.coment
	if self.coment!="":
	    f.write("\\newline "+self.coment)
	if self.set_of_articles !=[]:
	    f.write(" \\newline")
	    if self.spaced=='on':
		f.write("\\vspace*{3 pt} \n")
 	for i in self.set_of_articles[:-1]:
	    if i.genera(f,level + 1)==1:
		f.write(" \\newline")
		if self.spaced=='on':
		    f.write("\\vspace*{3 pt} \n")

	if self.set_of_articles !=[]:
	    self.set_of_articles[len(self.set_of_articles)-1].genera(f)
	f.write("}}")
	return 1

"""
inputoutputfunction

This class creates a box, where it's detailed what is that 
module of function for, what are its inputs,outputs and what internal
functions does it call.
"""

class inputoutputfunction:
    def __init__(self, name, description, lang='en'):
	self.name = name
	self.description = description
	self.lang = lang
	self.inputnamelang={'en':'Inputs','es':'Entradas'}
	self.outputnamelang={'en':'Outputs','es':'Salidas'}
	self.functionnamelang={'en':'Functions','es':'Funciones'}
	if lang=='en':
	    self.inputs=("None",0)
	    self.outputs=("None",0)
	    self.functions=("None",0)
	elif lang=='es':
	    self.inputs=("No hay",0)
	    self.outputs=("No hay",0)
	    self.functions=("No hay",0)

    def do_inputs(self, inputs):
	self.inputs=[]
	for i in inputs:
	    self.inputs.append(string.replace(i,"_","\_"))

    def do_outputs(self, outputs):
	self.outputs=[]
	for i in outputs:
	    self.outputs.append(string.replace(i,"_","\_"))

    def do_functions(self, functions):
	self.functions=[]
	for i in functions:
	    self.functions.append(string.replace(i,"_","\_"))

    def generate_latex_code(self,file,width):
	f = open(file,"w")
	inputs = self.generate_inputs()
	outputs = self.generate_outputs()
	functions = self.generate_functions()
	#print (self.name, [inputs,functions,outputs], self.description)
	i = included((self.name, [inputs,functions,outputs],
		      self.description), width)
	f = open(file,"w")
	i.genera(f)
	f.close()

    def generate_inputs(self):
	return self.generate_thing(self.inputs, self.inputnamelang)

    def generate_outputs(self):
	return self.generate_thing(self.outputs, self.outputnamelang)

    def generate_functions(self):
	return self.generate_thing(self.functions, self.functionnamelang)

    def generate_thing(self,thing,dic):
	if type(thing)==type((0,0)):
	    return (dic[self.lang],None,thing[0])
	else:
	    t = ""
	    for i in thing:
		t=t+"\\item{"+i+"}"+"\n"
	    head = "\\begin{list}{*}{\\baselineskip 2pt}\n"
	    foot = "\\end{list}\n"
	    all= head+t+foot
	    return (dic[self.lang],None,all)
	

def test():
    r0 = ("men\\_prin.py",None,"Here it's the main menu is defined")
    r1 = ("Graphic representation", [("tkinter.py",None,"Main calling module"),r0], "Graphic interfases with the user, mainly")
    r2 = ("Structures of the languages(grammar)", None)
    r3 = ("Configuration", [("Database of words",None),
			     ("Labels",None)])
    i = included(("Lritaunas Peki",[r1,r2,r3]," This programm aims to teach vocabulary and grammar of different languages."))
    f = open("result.tex","w")
    i.genera(f)
    f.close()
    
    example2=inputoutputfunction('taxman',"This is your best friend, who helps you when you earn too much")
    example2.do_inputs(["Your income","Your properties","The Law"])
    example2.do_outputs(["Your taxes","Your fines","Historical information"])
    example2.do_functions(["Compute your taxes","Check your lies",
			  "Send you to prison","Bribery"])
    example2.generate_latex_code("result2.tex",200)

    example3=inputoutputfunction('doctor',"This is your best friend, who helps you when you are tired of life")
    example3.do_inputs(["Your income","Your properties","Your confidence"])
    example3.do_functions(["Kill you","Heal you"])
    example3.generate_latex_code("result3.tex",200)
    
if __name__=='__main__':
    test()