예제 #1
0
def load_buffer(filename, buff=None):
    """
    Creates a CulebraBuffer from a filename
    """
    new_entry = True
    if buff is None:
        buff = CulebraBuffer(filename=filename)
    # We only update the contents of a new buffer
    fd = open(filename)
    try:
        buff.begin_not_undoable_action()
        buff.set_text("")
        data = fd.read()
        enc_data = None
        for enc in (sys.getdefaultencoding(), "utf-8", "iso8859", "ascii"):
            try:
                enc_data = unicode(data, enc)
                buff.encoding = enc
                break
            except UnicodeDecodeError:
                pass
        assert enc_data is not None, "There was a problem detecting the encoding"

        buff.set_text(enc_data)
        buff.set_modified(False)
        buff.place_cursor(buff.get_start_iter())
        buff.end_not_undoable_action()

    finally:
        fd.close()

    return buff
예제 #2
0
def create_editor(filename, action_group):
    view = CulebraView(action_group)
    # XXX: there's no way to select an encoding
    buff = CulebraBuffer(filename)
    buff.load_from_file()
    view.set_buffer(buff)

    return view