def on_mouse_release(self, event): if self.selected_boundary == self.osc_boundary_start: self.opstack.push(Update(self.i, 'start', float(event.xdata))) elif self.selected_boundary == self.osc_boundary_stop: self.opstack.push(Update(self.i, 'stop', float(event.xdata))) if self.selected_boundary: self.selected_boundary.set_color('r') self.update_syl_boundaries() self.selected_boundary = None self.canvas.draw()
def test_read_write2(tempfile, opstack): opstack.push(Update(0, 'name', 'z')) write_stack(tempfile, opstack) new_opstack = read_stack(tempfile) assert new_opstack.original_events == opstack.original_events assert new_opstack.events == opstack.events assert new_opstack.events != new_opstack.original_events
def on_key_press(self, event): if event.key() == Qt.Key_Right: self.inc_i() elif event.key() == Qt.Key_Left: self.dec_i() if event.key() == Qt.Key_Down: self.zoom_in_x() elif event.key() == Qt.Key_Up: self.zoom_out_x() elif event.key() <= Qt.Key_Z and event.key() >= Qt.Key_A: if self.N_points > int(round(self.sr * self.gap * self.maxpoint)): return newlabel = chr(event.key()) self.opstack.push(Update(self.label_index, 'name', newlabel)) self.inc_i() elif event.key() <= Qt.Key_9 and event.key() >= Qt.Key_0: if self.N_points > int(round(self.sr * self.gap * self.maxpoint)): return newlabel = number_shortcut[chr(event.key())] self.opstack.push(Update(self.label_index, 'name', newlabel)) self.inc_i()
def on_key_press(self, event): #print('you pressed ', event.key) if event.key in ('pagedown', ' ', 'right'): self.inc_i() elif event.key in ('pageup', 'backspace', 'left'): self.dec_i() elif event.key in self.keymap: newlabel = self.keymap[event.key] self.opstack.push(Update(self.i, 'name', newlabel)) self.inc_i() elif event.key in ('ctrl+i', 'down'): if self.N_points > 5000: self.N_points -= 5000 self.update_plot_data() elif event.key in ('ctrl+o', 'up'): self.N_points += 5000 self.update_plot_data() elif event.key == 'ctrl+s': self.save() elif event.key == 'ctrl+h': print(help_string) elif event.key in ('ctrl+m', 'ctrl+backspace') and self.i > 0: self.i -= 1 self.opstack.push(Merge(self.i)) self.inc_i() elif event.key in ('ctrl+x', 'tab'): self.opstack.push(Delete(self.i)) if self.i >= len(self.opstack.events): self.i = len(self.opstack.events) - 1 self.update_plot_data() elif event.key == 'ctrl+z' and self.opstack.ops: self.opstack.undo() self.i = self.opstack.undo_ops[-1].index self.update_plot_data() elif event.key == 'ctrl+y' and self.opstack.undo_ops: self.opstack.redo() self.i = self.opstack.ops[-1].index self.update_plot_data()
def deletelabel(self): if self.N_points > int(round(self.sr * self.gap * self.maxpoint)): return self.opstack.push(Update(self.label_index, 'name', "")) self.dec_i()
def addlabel(self, str): if self.N_points > int(round(self.sr * self.gap * self.maxpoint)): return self.opstack.push(Update(self.label_index, 'name', str)) self.inc_i()
def test_stack_undo(opstack): opstack.push(Update(0, 'name', 'z')) opstack.undo() assert len(opstack.ops) == 0 assert len(opstack.undo_ops) == 1 assert opstack.events == opstack.original_events
def test_stack_push(opstack): opstack.push(Update(0, 'name', 'z')) assert len(opstack.ops) == 1 assert opstack.events != opstack.original_events
def test_chain(labels): Update(2, 'stop', 100).on(labels) Update(1, 'start', 100).on(labels) assert labels[2]['stop'] == 100 assert labels[1]['start'] == 100
def test_stop(labels): Update(2, 'stop', 100).on(labels) assert labels[2]['stop'] == 100
def test_start(labels): Update(1, 'start', 100).on(labels) assert labels[1]['start'] == 100
def test_name(labels): Update(0, 'name', 'a2').on(labels) assert labels[0]['name'] == 'a2'