コード例 #1
0
def add_from_image():
    image_id = images_view.get_selected_image()
    img = images_model.get_image(image_id)
    piece_id = model.add_from_image(image_id, img, frames_model.active_frame())
    piece = model.get_piece(frames_model.active_frame(), piece_id)
    canvas_view.add_piece(piece)
    actions_controller.add_piece_action(frames_model.active_frame(), piece)
コード例 #2
0
def update_view():
    clear_active()
    canvas_view.clear()
    if frames_model.active_frame() in model.pieces.keys():
        for piece in model.pieces[frames_model.active_frame()]:
            piece['img'] = images_model.get_image(piece['image_id'])
            canvas_view.add_piece(piece)
コード例 #3
0
def update_piece(old_piece, new_piece):
    actions_controller.update_piece_action(frames_model.active_frame(), old_piece, new_piece)
    fid = frames_model.active_frame()
    model.update_piece(fid, new_piece)
    canvas_view.update_piece(new_piece)
    pieces_view.update_piece(new_piece)
    _reorder_canvas()
コード例 #4
0
def add_from_piece():
    if active_piece is not None:
        piece = model.get_piece(frames_model.active_frame(), active_piece)
        if piece is not None:
            piece = dict(piece)
            piece['x'] = 100
            piece['y'] = 100
            pid = model.add_from_piece(frames_model.active_frame(), piece)
            piece = model.get_piece(frames_model.active_frame(), pid)
            canvas_view.add_piece(piece)
            actions_controller.add_piece_action(frames_model.active_frame(), piece)
コード例 #5
0
def change_image(piece):
    old = dict(piece)
    oldimg = piece['img'].copy()
    piece['image_id'] = images_view.get_selected_image()
    piece['img'] = images_model.get_image(piece['image_id'])
    piece['x_scale'], piece['y_scale'] = _estimate_new_scale(oldimg, piece['img'], piece)

    pieces_view.update_piece(piece)
    canvas_view.update_piece(piece)
    model.update_piece(frames_model.active_frame(), piece)
    actions_controller.update_piece_action(frames_model.active_frame(), old, piece)
    _reorder_canvas()
コード例 #6
0
def clone_frame():
    i = model.get_frame_position(model.active_frame())
    frame = dict(model.get_frame(model.active_frame()))
    frame['id'] = model.next_id
    model.next_id += 1
    model.frames.insert(i + 1, frame)
    if model.active_frame() in pieces_model.pieces.keys():
        pieces_model.pieces[frame['id']] = [
            dict(p) for p in pieces_model.pieces[model.active_frame()]
        ]
    update_view()
    actions_controller.add_frame_action(frame, i + 1,
                                        pieces_model.pieces[frame['id']])
コード例 #7
0
def update_frame():
    new_len = view_options.get_length_str()
    try:
        new_len = int(new_len)
    except:
        util.error('Frame length must be an integer')
        return
    if new_len <= 0:
        util.error('Frame length <= 0 ?!')
        return
    i = model.get_frame_position(model.active_frame())
    actions_controller.update_frame_action(model.active_frame(),
                                           model.frames[i]['length'], new_len)
    model.frames[i]['length'] = new_len
コード例 #8
0
def move_piece_down():
    if active_piece is not None:
        fid = frames_model.active_frame()
        if fid in model.pieces.keys():
            index = None
            for i in range(0, len(model.pieces[fid])):
                if model.pieces[fid][i]['id'] == active_piece:
                    index = i
                    break
            if index is not None:
                ni = index - 1
                if ni >= 0:
                    temp = model.pieces[fid][index]
                    model.pieces[fid][index] = model.pieces[fid][ni]
                    model.pieces[fid][ni] = temp
                    actions_controller.move_piece_action(frames_model.active_frame(), active_piece, -1)
                    _reorder_canvas()
コード例 #9
0
def remove_piece(piece_id=None):
    if piece_id is not None:
        for fid in model.pieces.keys():
            piece = model.get_piece(fid, piece_id)
            if piece is not None:
                actions_controller.delete_piece_action(fid, piece)
            model.remove_piece(fid, piece_id)
        canvas_view.delete_piece(piece_id)
        if active_piece == piece_id:
            clear_active()

    elif active_piece is not None:
        piece = model.get_piece(frames_model.active_frame(), active_piece)
        if piece is not None:
            actions_controller.delete_piece_action(frames_model.active_frame(), piece)
        model.remove_piece(frames_model.active_frame(), active_piece)
        canvas_view.delete_piece(active_piece)
        clear_active()
コード例 #10
0
def update_view():
    i = model.get_frame_position(model.active_frame())
    if i is None:
        i = 0
        model._active_frame = model.frames[0]['id']
    length = model.get_frame_from_pos(i)['length']
    view_options.set_frame_count(len(model.frames))
    view_options.set_active(i)
    view_options.set_length(length)
    loop_view.set_is_loop(model.is_loop)
コード例 #11
0
def move_frame_up():
    i = model.get_frame_position(model.active_frame())
    ni = i - 1
    if ni >= 0:
        actions_controller.move_frame_action(
            model.get_frame_from_pos(i)['id'], -1)
        temp = model.frames[ni]
        model.frames[ni] = model.frames[i]
        model.frames[i] = temp
        update_view()
コード例 #12
0
def move_frame_down():
    i = model.get_frame_position(model.active_frame())
    ni = i + 1
    if ni < len(model.frames):
        actions_controller.move_frame_action(
            model.get_frame_from_pos(i)['id'], 1)
        temp = model.frames[ni]
        model.frames[ni] = model.frames[i]
        model.frames[i] = temp
        update_view()
コード例 #13
0
def delete_frame():
    if len(model.frames) > 1:
        i = model.get_frame_position(model.active_frame())
        frame = model.get_frame(model.active_frame())
        actions_controller.delete_frame_action(
            frame, i, pieces_model.pieces[frame['id']])

        ni = i + 1
        if ni >= len(model.frames):
            ni = len(model.frames) - 2  # Deleting last, next is second last
        model._active_frame = model.get_frame_from_pos(ni)['id']

        pieces_controller.change_active_frame(frame['id'],
                                              model.active_frame())
        model.frames.remove(frame)
        if frame['id'] in pieces_model.pieces.keys():
            del pieces_model.pieces[frame['id']]

        update_view()

    else:
        util.error('You need to have at least one frame, jackass')
コード例 #14
0
def change_active_frame():
    old = model.active_frame()
    model._active_frame = model.get_frame_from_pos(
        view_options.get_selected_index())['id']
    pieces_controller.change_active_frame(old, model.active_frame())
    update_view()
コード例 #15
0
def active_frame_index():
    return model.get_frame_position(model.active_frame())
コード例 #16
0
def new_frame_insert():
    i = model.get_frame_position(model.active_frame())
    frame = model.get_new_frame()
    model.frames.insert(i, frame)
    update_view()
    actions_controller.add_frame_action(frame, i, {})
コード例 #17
0
def _reorder_canvas():
    for p in model.pieces[frames_model.active_frame()]:
        canvas_view.update_piece(p)
コード例 #18
0
def activate_piece(piece_id):
    global active_piece

    active_piece = piece_id
    piece = model.get_piece(frames_model.active_frame(), piece_id)
    pieces_view.update_piece(piece)