def select(self, ti): "select the frame at ti(th) place." self.selected = ti x = int(self.FRAME_WIDTH * (self.selected - self.viewpos - 0.5)) self.selectHinter.pos = (x, 0) a = self.get_a_at(ti) hint('frame %d(a=%d, adv=%d, t=%.3fs)' %( ti, a, self.angle2ad(a), ti * self.parent.timeStep))
def remove_frame(self, ti): i, dti = self.find_ti_pos(ti) if i < len(self.keyFrames): if dti > 0: self.keyFrames[i].dti -= 1 elif i > 0: self.keyFrames[i-1].dti += self.keyFrames[i].dti del self.keyFrames[i] self.mark_redraw() hint('removed frame at %d' % ti)
def cb_toggle(self, *args): if self.btn_pause.is_visible(): hint("paused") self.servoc.pause() self.btn_play.show() self.btn_pause.hide() else: hint("start playing") self.servoc.play() self.btn_play.hide() self.btn_pause.show()
def backup_file(self, filename): MaxBackupNum = 5 files = [] for i in xrange(MaxBackupNum): backupName = '.%s.~%d~' % (filename, i+1) if not os.path.exists(backupName): break files.append((os.stat(backupName).st_ctime, backupName)) else: files.sort() backupName = files[0][1] shutil.copyfile(filename, backupName) hint('backup "%s" as "%s"' % (filename, backupName))
def insert_key_frame(self, ti, a=None): """ insert key frame at time ti, with value a """ i, dti = self.find_ti_pos(ti) if a is None: a = self.get_a_at(ti) keyFrames = self.keyFrames if i < len(keyFrames): newFrame = KeyFrame(keyFrames[i].dti - dti, a) keyFrames[i].dti = max(1, dti) else: newFrame = KeyFrame(1, a) keyFrames[-1].dti += dti keyFrames.insert(i + 1, newFrame) hint('insert %s' % newFrame) self.mark_redraw()
def save(self, filename, remember=True): servoc = self.servoc try: if os.path.exists(filename): # file exist, backup self.backup_file(filename) except IOError as e: warn('%r' % e) try: data = self.gen_save_data() with open(filename, 'wb') as f: cPickle.dump(data, f, -1) if remember: self.lastSave = filename self.lastSaveData = data self.write_session() except Exception as ex: raise SaveLoadError(ex) hint('save data to file "%s"' % filename)
def load(self, filename): servoc = self.servoc # try: with open(filename, 'rb') as f: data = cPickle.load(f) servosData = data['servos'] servoc.remove_servo() for adata in servosData: keyFrames = adata['keyFrames'] del adata['keyFrames'] servo = ServoBoard(servoc, **adata) del servo.keyFrames[:] for a, dti in keyFrames: servo.keyFrames.append(KeyFrame(dti, a)) servoc.add_servo(servo) servoc.reset() servoc.mark_redraw() hint('load data from file "%s"' % filename) self.lastSave = filename
def cb_pause(self, *args): if self.btn_pause.is_visible(): hint("paused") self.servoc.pause() self.btn_play.show() self.btn_pause.hide()
def cb_play(self, *args): if self.btn_play.is_visible(): hint("start playing") self.servoc.play() self.btn_play.hide() self.btn_pause.show()