def apply(frame, total_time, frame_len): if frame not in range(0, len(frames_model.frames) - 1): view_util.error('Invalid frame') return start_fid = frames_model.get_frame_from_pos(frame)['id'] end_fid = frames_model.get_frame_from_pos(frame + 1)['id'] start_pieces = pieces_model.pieces[start_fid] end_pieces = pieces_model.pieces[end_fid] sid_list = [p['id'] for p in start_pieces] eid_list = [p['id'] for p in end_pieces] if sid_list != eid_list: view_util.error( 'Interpolating between frames requires that they are clones of one another\n' 'Images can not be added or removed, only modified\n' 'Image order must be the same (no moving up or down)') return fc = int(total_time / frame_len + 0.999) - 1 res = view_util.yesnobox( 'This will create {} frames. Continue?'.format(fc)) if res == tk.YES: actions_controller.interpolate_action(start_fid, end_fid, total_time, frame_len) interpolate(frame, total_time, frame_len)
def open_towns(): try: controller.reset() model.town_list = file_util.load_towns('map.db') controller.update_view() except: view_util.error('Error loading map.db. Making new one')
def _apply(self): start_frame = self.fframe.get() if self.fframe.get() else 0 end_frame = self.lframe.get() if self.lframe.get() else 0 frame_len = self.frame_len.get() if self.frame_len.get() else 0 xpos = self.xpos.get() if self.xpos.get() else 0 ypos = self.ypos.get() if self.ypos.get() else 0 xscale = self.xscale.get() if self.xscale.get() else 0 yscale = self.yscale.get() if self.yscale.get() else 0 alpha = self.trans_scale.get() rot = self.rotation_scale.get() try: start_frame = int(start_frame) end_frame = int(end_frame) frame_len = int(frame_len) xpos = float(xpos) ypos = float(ypos) xscale = float(xscale) yscale = float(yscale) except: util.error('Input needs to be blank or numerical') return start_frame = start_frame - 1 if start_frame != 0 else start_frame end_frame = end_frame - 1 controller.batch_edit(self.frame_sel.get(), start_frame, end_frame, self.change_type.get(), frame_len, xpos, ypos, xscale, yscale, alpha, rot)
def _chg_img(self): x = self.xpos_entry.get() y = self.ypos_entry.get() xs = self.xscale_entry.get() ys = self.yscale_entry.get() r = self.rotation_scale.get() xc = self.xcrop_entry.get() yc = self.ycrop_entry.get() wc = self.wcrop_entry.get() hc = self.hcrop_entry.get() t = self.trans_scale.get() try: x = float(x) y = float(y) xs = float(xs) / 100 ys = float(ys) / 100 xc = float(xc) / 100 yc = float(yc) / 100 wc = float(wc) / 100 hc = float(hc) / 100 except: util.error('Must have a piece selected') return self.update_piece(self.piece) controller.change_image(self.piece)
def _apply(self): try: total_time = int(self.time.get()) frame_len = int(self.frame_len.get()) frame = int(self.frame.get()) - 1 except: util.error('Input must be integers') return if total_time <= 0 or frame_len <= 0: util.error('Times must be greater than 0') controller.apply(frame, total_time, frame_len)
def import_spritesheet_open(): global main_view global image_list_view filename = util.get_image_file() if filename: try: img = Image.open(filename).convert(mode='RGBA') except: util.error('Failed to open image: ' + filename) return SpritesheetImporter(main_view.TK_ROOT, filename, img)
def import_image(): global main_view global image_list_view filename = util.get_image_file() if filename: try: img = Image.open(filename).convert(mode='RGBA') except: util.error('Failed to open image: ' + filename) return image_id = model.add_image(img, filename) image_list_view.add_image(image_id, img) actions_controller.add_image_action(image_id)
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
def _apply(self): x = self.xpos_entry.get() y = self.ypos_entry.get() xs = self.xscale_entry.get() ys = self.yscale_entry.get() r = self.rotation_scale.get() xc = self.xcrop_entry.get() yc = self.ycrop_entry.get() wc = self.wcrop_entry.get() hc = self.hcrop_entry.get() t = self.trans_scale.get() try: x = float(x) y = float(y) xs = float(xs) / 100 ys = float(ys) / 100 xc = float(xc) / 100 yc = float(yc) / 100 wc = float(wc) / 100 hc = float(hc) / 100 except: util.error('Input must be numerical') return if xs <= 0 or ys <= 0 or xc < 0 or yc < 0 or wc < 0 or hc < 0: util.error('Input must be positive') return old = dict(self.piece) self.piece['x'] = x self.piece['y'] = y self.piece['x_scale'] = xs self.piece['y_scale'] = ys self.piece['rotation'] = r self.piece['alpha'] = t self.piece['top_crop'] = yc self.piece['right_crop'] = wc self.piece['bottom_crop'] = hc self.piece['left_crop'] = xc controller.update_piece(old, self.piece)
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')
def _validate_input(self): x = self.x_entry.get() y = self.y_entry.get() w = self.w_entry.get() h = self.h_entry.get() rows = self.row_entry.get() cols = self.col_entry.get() try: x = int(x) y = int(y) w = int(w) h = int(h) rows = int(rows) cols = int(cols) except: util.error('Input must be integers') return None if x < 0 or y < 0 or w <= 0 or h <= 0 or rows <= 0 or cols <= 0: util.error('Input must be positive') return None return x, y, w, h, rows, cols
def batch_edit(one_piece, start_frame, end_frame, percent, frame_len, xpos, ypos, xscale, yscale, alpha, rot): if one_piece == 1 and not main_view.get_main_canvas().active_piece(): view_util.error('A piece must be selected') return elif one_piece == 1: piece_id = main_view.get_main_canvas().active_piece() else: piece_id = None if start_frame not in range(0, len( frames_model.frames)) or end_frame not in range( -1, len(frames_model.frames)): view_util.error('Invalid frame range') return if end_frame == -1: end_frame = len(frames_model.frames) - 1 elif end_frame < start_frame: temp = end_frame end_frame = start_frame start_frame = temp if percent == 0: if frame_len < 0: view_util.error( 'All frames have their length set to the input length\n' 'This is not a shift, so it must be greater than 0') return if frame_len > 0: res = view_util.yesnobox( 'WARNING: Setting all frame lengths via batch edit cannot be undo\n' 'Do it anyways?') if res == tk.NO: return batch_shift(piece_id, start_frame, end_frame, frame_len, xpos, ypos, xscale, yscale, alpha, rot) else: percent_shift(piece_id, start_frame, end_frame, frame_len, xscale, yscale, alpha, rot) actions_controller.batch_action(piece_id, start_frame, end_frame, percent, frame_len, xpos, ypos, xscale, yscale, alpha, rot)
def undo(): if model.current_action is not None and model.current_action in range( 1, len(model.actions)): action = model.actions[model.current_action] data = action['data'] if action['type'] == 'add_piece': pieces_model.remove_piece(data['frame_id'], data['piece']['id']) pieces_controller.update_view() elif action['type'] == 'update_piece': pieces_model.update_piece(data['frame_id'], data['old']) pieces_controller.update_view() elif action['type'] == 'delete_piece': pieces_model.pieces[data['frame_id']].append(data['piece']) pieces_controller.update_view() elif action['type'] == 'move_piece': i = 0 for p in pieces_model.pieces[data['frame_id']]: if p['id'] == data['piece_id']: break i += 1 ni = i - data['index_change'] temp = pieces_model.pieces[data['frame_id']][i] pieces_model.pieces[data['frame_id']][i] = pieces_model.pieces[ data['frame_id']][ni] pieces_model.pieces[data['frame_id']][ni] = temp pieces_controller.update_view() elif action['type'] == 'add_image': images_model.remove_image(data['id']) images_controller.update_view() elif action['type'] == 'delete_image': view_util.error('This cannot be undone') elif action['type'] == 'add_frame': if data['frame']['id'] in pieces_model.pieces.keys(): del pieces_model.pieces[data['frame']['id']] del frames_model.frames[data['index']] frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'update_frame': i = frames_model.get_frame_position(data['frame_id']) frames_model.frames[i]['length'] = data['old_len'] frames_controller.update_view() elif action['type'] == 'move_frame': i = frames_model.get_frame_position(data['frame_id']) ni = i - data['index_change'] temp = frames_model.frames[i] frames_model.frames[i] = frames_model.frames[ni] frames_model.frames[ni] = temp frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'delete_frame': frames_model.frames.insert(data['index'], data['frame']) pieces_model.pieces[data['frame']['id']] = data['pieces'] frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'save': view_util.popup('Oh F**k', 'Your Peoplemon game save has been deleted') elif action['type'] == 'batch': if data['percent'] == 0: batch_controller.batch_shift(data['piece_id'], data['start_frame'], data['end_frame'], 0, -data['xpos'], -data['ypos'], -data['xscale'], -data['yscale'], -data['alpha'], -data['rot']) else: xs = (-data['xscale']) / (100 + data['xscale']) * 100 ys = (-data['yscale']) / (100 + data['yscale']) * 100 a = (-data['alpha']) / (100 + data['alpha']) * 100 r = (-data['rot']) / (100 + data['rot']) * 100 fl = (-data['frame_len']) / (100 + data['frame_len']) * 100 batch_controller.percent_shift(data['piece_id'], data['start_frame'], data['end_frame'], fl, xs, ys, a, r) elif action['type'] == 'interpolate': s = frames_model.get_frame_position(data['start_frame']) + 1 e = frames_model.get_frame_position(data['end_frame']) fids = [ frames_model.get_frame_from_pos(i)['id'] for i in range(s, e) ] for fid in fids: i = frames_model.get_frame_position(fid) if fid in pieces_model.pieces.keys(): del pieces_model.pieces[fid] del frames_model.frames[i] frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'toggle_loop': frames_model.is_loop = not frames_model.is_loop frames_controller.update_view() model.current_action -= 1 controller.update_view()
def redo(): if model.current_action is not None and model.current_action in range( 0, len(model.actions) - 1): action = model.actions[model.current_action + 1] data = action['data'] if action['type'] == 'add_piece': pieces_model.pieces[data['frame_id']].append(data['piece']) pieces_controller.update_view() elif action['type'] == 'update_piece': pieces_model.update_piece(data['frame_id'], data['new']) pieces_controller.update_view() elif action['type'] == 'delete_piece': pieces_model.remove_piece(data['frame_id'], data['piece']['id']) pieces_controller.update_view() elif action['type'] == 'move_piece': i = 0 for p in pieces_model.pieces[data['frame_id']]: if p['id'] == data['piece_id']: break i += 1 ni = i + data['index_change'] temp = pieces_model.pieces[data['frame_id']][i] pieces_model.pieces[data['frame_id']][i] = pieces_model.pieces[ data['frame_id']][ni] pieces_model.pieces[data['frame_id']][ni] = temp pieces_controller.update_view() elif action['type'] == 'add_image': view_util.error('This cannot be redone') elif action['type'] == 'delete_image': view_util.popup('This cannot be redone') elif action['type'] == 'add_frame': frames_model.frames.insert(data['index'], data['frame']) pieces_model.pieces[data['frame']['id']] = data['pieces'] frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'update_frame': i = frames_model.get_frame_position(data['frame_id']) frames_model.frames[i]['length'] = data['new_len'] frames_controller.update_view() elif action['type'] == 'move_frame': i = frames_model.get_frame_position(data['frame_id']) ni = i + data['index_change'] temp = frames_model.frames[i] frames_model.frames[i] = frames_model.frames[ni] frames_model.frames[ni] = temp frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'delete_frame': if data['frame']['id'] in pieces_model.pieces.keys(): del pieces_model.pieces[data['frame']['id']] del frames_model.frames[data['index']] frames_controller.update_view() pieces_controller.update_view() elif action['type'] == 'save': view_util.popup('Awesome', 'Your Peoplemon game save has been restored') elif action['type'] == 'batch': if data['percent'] == 0: batch_controller.batch_shift( data['piece_id'], data['start_frame'], data['end_frame'], data['frame_len'], data['xpos'], data['ypos'], data['xscale'], data['yscale'], data['alpha'], data['rot']) else: batch_controller.percent_shift(data['piece_id'], data['start_frame'], data['end_frame'], data['frame_len'], data['xscale'], data['yscale'], data['alpha'], data['rot']) elif action['type'] == 'interpolate': i = frames_model.get_frame_position(data['start_frame']) interpolate_controller.interpolate(i, data['total_time'], data['frame_len']) pieces_controller.update_view() frames_controller.update_view() elif action['type'] == 'toggle_loop': frames_model.is_loop = not frames_model.is_loop frames_controller.update_view() model.current_action += 1 controller.update_view()