Annotation of doc/help/simpleEdit.py, revision 1.1

1.1     ! bowersj2    1: """simpleEdit can be used to edit the tex fragments in context
        !             2: determined by a texxml file.
        !             3: 
        !             4: Use:
        !             5: 
        !             6: python simpleEdit.py [name of texxml file]
        !             7: 
        !             8: simpleEdit will read the texxml file, and present the referenced tex
        !             9: fragments in order determined by the file. When you save (CTRL-S),
        !            10: simpleEdit will save all the tex fragments back to their little
        !            11: files.
        !            12: 
        !            13: Very, very simple.
        !            14: """
        !            15: 
        !            16: import sys
        !            17: if len(sys.argv) < 2:
        !            18:     print "Usage: python simpleEdit.py [name of texxml file]"
        !            19:     print "See top of source code for usage."
        !            20:     print "To save files, press CTRL-s in the editor."
        !            21:     sys.exit()
        !            22: 
        !            23: import xml.parsers.expat
        !            24: 
        !            25: dirprefix = "/home/httpd/html/adm/help/tex/"
        !            26: 
        !            27: fileList = []
        !            28: 
        !            29: def startElement(name, attrs):
        !            30:     if name == "file":
        !            31:         fileList.append(str(attrs["name"]))
        !            32: 
        !            33: p = xml.parsers.expat.ParserCreate()
        !            34: p.StartElementHandler = startElement
        !            35: f = file(sys.argv[1], 'r')
        !            36: p.Parse(f.read())
        !            37: 
        !            38: 
        !            39: from Tkinter import *
        !            40: from ScrolledText import *
        !            41: import string
        !            42: import os
        !            43: 
        !            44: class simpleEditor:
        !            45:     def __init__(self, master):
        !            46:         self.frame = Frame(master)
        !            47:         self.frame.pack()
        !            48: 
        !            49:         self.label = Label(self.frame, text = "For documentation on" 
        !            50:                            "this program, consult the source code.")
        !            51:         self.label.pack()
        !            52: 
        !            53:         self.text = ScrolledText(self.frame, width=120, height = 40);
        !            54:         self.text.pack(fill = BOTH, expand = 1)
        !            55: 
        !            56:         self.searchText = Text(self.frame, width = 40, height = 1);
        !            57:         self.searchText.pack()
        !            58:         self.searchButton = Button(self.frame, text = "Search",
        !            59:                                    command = self.search)
        !            60:         self.searchButton.pack()
        !            61: 
        !            62:         self.button = Button(self.frame, text = "Save", \
        !            63:                              command = self.save)
        !            64:         self.button.pack()
        !            65: 
        !            66:     def search(self):
        !            67:         searchText = self.searchText.get("1.0", END)
        !            68:         searchText = searchText.strip()
        !            69:         print self.text.index(INSERT + "+%ic" % len(searchText))
        !            70:         pos = self.text.search(searchText,
        !            71:                                self.searchText.index(INSERT) +
        !            72:                                "+%ic" % (len(searchText) + 1))
        !            73:         self.text.see(pos)
        !            74:         self.text.tag_add(SEL, pos, pos + "+%ic" % len(searchText))
        !            75:         self.text.mark_set(INSERT, pos)
        !            76: 
        !            77:     def load(self):
        !            78:         """Loads in all the tex files."""
        !            79: 
        !            80:         colors = ["#FFFFFF", "#CCCCCC"]
        !            81: 
        !            82:         c = 0
        !            83: 
        !            84:         for f in fileList:
        !            85:             f = file(dirprefix + f, 'r')
        !            86:             tex = f.read()
        !            87:             f.close()
        !            88:             self.text.tag_config("texfile%i" % c,
        !            89:                                  background = colors[c%len(colors)])
        !            90:             self.text.insert(END, tex, "texfile%i" % c)
        !            91:             self.text.insert(END, "\n\n") # prettier
        !            92:             c += 1
        !            93: 
        !            94:     def save(self):
        !            95:         c = 0
        !            96:         
        !            97:         for f in fileList:
        !            98:             tex = self.text.get("texfile%i.first" % c,
        !            99:                                 "texfile%i.last" % c)
        !           100:             os.rename ( dirprefix + f, dirprefix + f + "~" )
        !           101:             f = file(dirprefix + f, 'w')
        !           102:             f.write(tex)
        !           103:             f.close()
        !           104:             c += 1
        !           105: 
        !           106:             
        !           107: 
        !           108: 
        !           109: root = Tk()
        !           110: app = simpleEditor(root)
        !           111: app.load()
        !           112: root.mainloop()
        !           113: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.