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)
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)
def clone_horizontal(): image_id = image_list_view.get_selected_image() img = model.get_image(image_id) if img is not None: img = img.transpose(Image.FLIP_LEFT_RIGHT) file = 'image_{}_flipped_h.png'.format(image_id) new_id = model.add_image(img, file) image_list_view.add_image(new_id, img) actions_controller.add_image_action(new_id)
def clone_vertical(): image_id = image_list_view.get_selected_image() img = model.get_image(image_id) if img is not None: img = img.transpose(Image.FLIP_TOP_BOTTOM) file = 'image_{}_flipped_v.png'.format(image_id) new_id = model.add_image(img, file) image_list_view.add_image(new_id, img) actions_controller.add_image_action(new_id)
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()
def _load(file): with open(file, 'r') as ifs: data = json.load(ifs) actions_model.restore_from_loaded_json(data['actions']) frames_model.restore_from_loaded_json(data['frames']) pieces_model.restore_from_loaded_json(data['pieces']) images_model.restore_from_loaded_json(data['images']) folder = _images_folder_name(file) for k, img in images_model.image_list.items(): img['img'] = Image.open(os.path.join(folder, img['file'])).convert(mode='RGBA') for k, pl in pieces_model.pieces.items(): for piece in pl: piece['img'] = images_model.get_image(piece['image_id']) frames_controller.update_view() pieces_controller.update_view() images_controller.update_view() actions_controller.update_view()