File:  [LON-CAPA] / doc / help / latexSplitter.py
Revision 1.3: download - view: text, annotated - select for diffs
Tue Jun 10 19:45:26 2003 UTC (18 years, 11 months ago) by bowersj2
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_X, version_2_8_99_1, version_2_8_99_0, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_X, version_2_7_99_1, version_2_7_99_0, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_X, version_2_3_99_0, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_X, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_X, version_1_2_99_1, version_1_2_99_0, version_1_2_1, version_1_2_0, version_1_1_X, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, version_1_1_99_0, version_1_1_3, version_1_1_2, version_1_1_1, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, version_1_0_3, version_1_0_2, version_1_0_1, version_1_0_0, version_0_99_5, version_0_99_4, version_0_99_3, version_0_99_2, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, HEAD, GCI_3, GCI_2, GCI_1, BZ4492-merge, BZ4492-feature_horizontal_radioresponse, BZ4492-feature_Support_horizontal_radioresponse, BZ4492-Support_horizontal_radioresponse
Botched previous commit; needed to be a bit higher.

"""Latex Splitter quickee python app.

This application assists in spliting large Latex files into lots of
smaller ones.

To use this application, paste a latex file into the window. Highlight
the section you wish to save as an independent fragment. Then hit the
button, give the fragment a file name and a topic, and save
it. Continue until you've retreived everything out of the file you
want.

Starting it with a command-line parameter will try to load that file
into the text box.

This program may require Python as high as 2.2, though 2.1 should
do."""

from Tkinter import *
from ScrolledText import *
import anydbm
import sys
import string

dirprefix = "/home/jerf/loncapa/loncom/html/adm/help/tex/"

class LatexSplitter:
    def __init__(self, master):
        self.frame = Frame(master)
        self.frame.pack()

        self.label = Label(self.frame, text = "For documentation on" 
                           "this program, consult the source code.")
        self.label.pack()

        self.text = ScrolledText(self.frame, width=120, height = 40);
        self.text.pack(fill = BOTH, expand = 1)

        self.l2 = Label(self.frame, text = "File Root Name (no .tex):")
        self.l2.pack()
        self.topic = Text(self.frame, width=60, height = 1)
        self.topic.pack()

        self.button = Button(self.frame, text = "Split & Save", \
                             command = self.splitAndSave)
        self.button.pack()

        if len(sys.argv) > 1:
            f = file(sys.argv[1])
            self.text.insert("1.0", f.read())
            f.close()

    def splitAndSave(self):
        selection = self.text.get("sel.first", "sel.last")
        topic = string.strip(self.topic.get("1.0", "end"))
	labelname = string.replace(topic, " ", "_")
        filename = dirprefix + labelname + ".tex"

        try:
            f = file(filename, 'w')
        except:
            return
	f.write("\\label{%s}\n\n" % labelname)
        f.write(selection)
        f.close()

        self.topic.delete("1.0", END)
        self.text.delete("sel.first", "sel.last")

        f = file("latexSplitterTempResults", 'w')
	f.write(self.text.get("1.0", END))
        f.close()

root = Tk()
app = LatexSplitter(root)
root.mainloop()


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