Annotation of doc/help/latexSplitter.py, revision 1.3
1.1 bowersj2 1: """Latex Splitter quickee python app.
2:
3: This application assists in spliting large Latex files into lots of
4: smaller ones.
5:
6: To use this application, paste a latex file into the window. Highlight
7: the section you wish to save as an independent fragment. Then hit the
8: button, give the fragment a file name and a topic, and save
9: it. Continue until you've retreived everything out of the file you
10: want.
11:
12: Starting it with a command-line parameter will try to load that file
13: into the text box.
14:
15: This program may require Python as high as 2.2, though 2.1 should
16: do."""
17:
18: from Tkinter import *
19: from ScrolledText import *
20: import anydbm
21: import sys
22: import string
23:
1.3 ! bowersj2 24: dirprefix = "/home/jerf/loncapa/loncom/html/adm/help/tex/"
1.1 bowersj2 25:
26: class LatexSplitter:
27: def __init__(self, master):
28: self.frame = Frame(master)
29: self.frame.pack()
30:
31: self.label = Label(self.frame, text = "For documentation on"
32: "this program, consult the source code.")
33: self.label.pack()
34:
35: self.text = ScrolledText(self.frame, width=120, height = 40);
36: self.text.pack(fill = BOTH, expand = 1)
37:
38: self.l2 = Label(self.frame, text = "File Root Name (no .tex):")
39: self.l2.pack()
40: self.topic = Text(self.frame, width=60, height = 1)
41: self.topic.pack()
42:
43: self.button = Button(self.frame, text = "Split & Save", \
44: command = self.splitAndSave)
45: self.button.pack()
46:
47: if len(sys.argv) > 1:
48: f = file(sys.argv[1])
49: self.text.insert("1.0", f.read())
50: f.close()
51:
52: def splitAndSave(self):
53: selection = self.text.get("sel.first", "sel.last")
54: topic = string.strip(self.topic.get("1.0", "end"))
1.3 ! bowersj2 55: labelname = string.replace(topic, " ", "_")
! 56: filename = dirprefix + labelname + ".tex"
1.1 bowersj2 57:
58: try:
59: f = file(filename, 'w')
60: except:
61: return
1.3 ! bowersj2 62: f.write("\\label{%s}\n\n" % labelname)
1.1 bowersj2 63: f.write(selection)
64: f.close()
65:
66: self.topic.delete("1.0", END)
67: self.text.delete("sel.first", "sel.last")
68:
69: f = file("latexSplitterTempResults", 'w')
1.3 ! bowersj2 70: f.write(self.text.get("1.0", END))
1.1 bowersj2 71: f.close()
72:
73: root = Tk()
74: app = LatexSplitter(root)
75: root.mainloop()
76:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>