File:  [LON-CAPA] / doc / help / latexSplitter.py
Revision 1.2: download - view: text, annotated - select for diffs
Tue Jun 10 18:57:30 2003 UTC (20 years, 11 months ago) by bowersj2
Branches: MAIN
CVS tags: HEAD
Help file style: latexSplitter should store the label we look for on
each help file it generates.

    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: 
   24: dirprefix = "/home/httpd/html/adm/help/"
   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"))
   55:         filename = dirprefix + string.replace(topic, " ", "_") + ".tex"
   56: 
   57:         try:
   58:             f = file(filename, 'w')
   59:         except:
   60:             return
   61:         f.write(selection)
   62:         f.close()
   63: 
   64:         self.topic.delete("1.0", END)
   65:         self.text.delete("sel.first", "sel.last")
   66: 
   67:         f = file("latexSplitterTempResults", 'w')
   68: 	f.write("\\label{%s}\n\n" % filename)
   69:         f.write(self.text.get("1.0", END))
   70:         f.close()
   71: 
   72: root = Tk()
   73: app = LatexSplitter(root)
   74: root.mainloop()
   75: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>