示例#1
0
def write_file(s,
               fname=Interact(prompt="Write file",
                              default=os.getcwd(),
                              converter=str,
                              completer=make_completer(lambda x:glob.glob(x+"*")))):
    log.debug("write_file path=%s", fname)

    doc=s.textedit.document()
    (head, tail) = os.path.split(fname)
    f = open(fname, "w")
    f.write(doc.toPlainText())
    f.close()

    if (head, tail) != doc.get_file():
        log.debug("write_file name changed %s => %s", (head,tail), doc.get_file())
        # clone the doc
        newdoc = TextDocument()
        newdoc.setPlainText(doc.toPlainText())
        newdoc.set_file(head, tail)
        s.textedit.set_document(tail, newdoc)
        QtCore.QObject.connect(s.textedit, QtCore.SIGNAL("cursorPositionChanged()"), s.dockwidget.slot_curpos_changed)

        buffers[tail] = newdoc
示例#2
0
def create_file_buffer(name):
    thename = name
    index = 2
    while thename in buffers:
        thename = name + ("<%d>" % index)
        index += 1

    doc = TextDocument()
    log.debug("create_buffer: %s", doc)
    doc.setPlainText("This is %s" % thename)
    font = QtGui.QFont()
    font.setFamily("Courier New")
    doc.setDefaultFont(font)
    doc.set_file(None, thename)
    buffers[thename] = doc
    return (doc, thename)