diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/textoolspro/boxerer.py |
Initial commit
Diffstat (limited to 'support/textoolspro/boxerer.py')
-rw-r--r-- | support/textoolspro/boxerer.py | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/support/textoolspro/boxerer.py b/support/textoolspro/boxerer.py new file mode 100644 index 0000000000..7be1a151b2 --- /dev/null +++ b/support/textoolspro/boxerer.py @@ -0,0 +1,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() |