def right_click_handler(self, event): """ Select existing annotations, offer to edit or delete """ self.selected_annotation = None try: for annotation in WorldState.Instance().session_dict['annotations']: dist = 1 if annotation.type == WorldState.Instance()._TEXT_ARROW or annotation.type == WorldState.Instance()._ARROW: dist = point_to_line_distance((annotation.x1/float(WorldState.Instance().session_dict['max_time']), annotation.y1/float(WorldState.Instance().session_dict['max_height'])), (annotation.x2/float(WorldState.Instance().session_dict['max_time']), annotation.y2/float(WorldState.Instance().session_dict['max_height'])), (event.xdata/float(WorldState.Instance().session_dict['max_time']), event.ydata/float(WorldState.Instance().session_dict['max_height']))) else: dist = euclid_distance((annotation.x1/float(WorldState.Instance().session_dict['max_time']), annotation.y1/float(WorldState.Instance().session_dict['max_height'])), (event.xdata/float(WorldState.Instance().session_dict['max_time']), event.ydata/float(WorldState.Instance().session_dict['max_height']))) if dist < 0.025: if self.selected_annotation is None: self.selected_annotation = annotation break if self.selected_annotation is not None: self.selected_annotation.colour = 'red' refresh_plot() self.annotation_menu() refresh_plot() self.selected_annotation = None else: print "Missed annotation" except: print "Clicked outside of graph"
def toggle_param(self, param): WorldState.Instance().session_dict[param] = not WorldState.Instance().session_dict[param] WorldState.Instance().lamport_clock += 1 WorldState.Instance().push_state() WorldState.Instance().reorder(WorldState.Instance().lamport_clock) WorldState.Instance().client.toggle_param(param, WorldState.Instance().session_dict[param]) refresh_plot()
def toggle_param(self, param): WorldState.Instance( ).session_dict[param] = not WorldState.Instance().session_dict[param] WorldState.Instance().lamport_clock += 1 WorldState.Instance().push_state() WorldState.Instance().reorder(WorldState.Instance().lamport_clock) WorldState.Instance().client.toggle_param( param, WorldState.Instance().session_dict[param]) refresh_plot()
def show_hide_click(self, event): """ Updates the line to say don't or do draw """ cb_show_hide = event.GetEventObject() file_key = cb_show_hide.GetParent().GetParent().GetLabel() species_key = self.get_species(cb_show_hide) WorldState.Instance().session_dict['lines'][file_key][species_key].plot_line = cb_show_hide.GetValue() WorldState.Instance().lamport_clock += 1 WorldState.Instance().push_state() WorldState.Instance().reorder(WorldState.Instance().lamport_clock) refresh_plot()
def intensity_click(self, event): """ Event for toggling between colour intensity plot and normal plot """ cb_intense = event.GetEventObject() file_key = cb_intense.GetParent().GetParent().GetLabel() species_key = self.get_species(cb_intense) WorldState.Instance().session_dict['lines'][file_key][species_key].intense_plot = cb_intense.GetValue() WorldState.Instance().lamport_clock += 1 WorldState.Instance().push_state() WorldState.Instance().reorder(WorldState.Instance().lamport_clock) refresh_plot()
def intensity_click(self, event): """ Event for toggling between colour intensity plot and normal plot """ cb_intense = event.GetEventObject() file_key = cb_intense.GetParent().GetParent().GetLabel() species_key = self.get_species(cb_intense) WorldState.Instance().session_dict['lines'][file_key][ species_key].intense_plot = cb_intense.GetValue() WorldState.Instance().lamport_clock += 1 WorldState.Instance().push_state() WorldState.Instance().reorder(WorldState.Instance().lamport_clock) refresh_plot()
def show_hide_click(self, event): """ Updates the line to say don't or do draw """ cb_show_hide = event.GetEventObject() file_key = cb_show_hide.GetParent().GetParent().GetLabel() species_key = self.get_species(cb_show_hide) WorldState.Instance().session_dict['lines'][file_key][ species_key].plot_line = cb_show_hide.GetValue() WorldState.Instance().lamport_clock += 1 WorldState.Instance().push_state() WorldState.Instance().reorder(WorldState.Instance().lamport_clock) refresh_plot()
def right_click_handler(self, event): """ Select existing annotations, offer to edit or delete """ self.selected_annotation = None try: for annotation in WorldState.Instance( ).session_dict['annotations']: dist = 1 if annotation.type == WorldState.Instance( )._TEXT_ARROW or annotation.type == WorldState.Instance( )._ARROW: dist = point_to_line_distance(( annotation.x1 / float(WorldState.Instance().session_dict['max_time']), annotation.y1 / float(WorldState.Instance().session_dict['max_height']) ), ( annotation.x2 / float(WorldState.Instance().session_dict['max_time']), annotation.y2 / float(WorldState.Instance().session_dict['max_height']) ), (event.xdata / float(WorldState.Instance().session_dict['max_time']), event.ydata / float( WorldState.Instance().session_dict['max_height']))) else: dist = euclid_distance(( annotation.x1 / float(WorldState.Instance().session_dict['max_time']), annotation.y1 / float(WorldState.Instance().session_dict['max_height']) ), (event.xdata / float(WorldState.Instance().session_dict['max_time']), event.ydata / float( WorldState.Instance().session_dict['max_height']))) if dist < 0.025: if self.selected_annotation is None: self.selected_annotation = annotation break if self.selected_annotation is not None: self.selected_annotation.colour = 'red' refresh_plot() self.annotation_menu() refresh_plot() self.selected_annotation = None else: print "Missed annotation" except: print "Clicked outside of graph"
def toggle_param(self, clock, param, value): old_clock = clock if WorldState.Instance().lamport_clock == clock: if self.port == 8000: WorldState.Instance().lamport_clock += 1 else: clock += 1 WorldState.Instance().push_state() WorldState.Instance().lamport_clock = max(WorldState.Instance().lamport_clock, clock) + 1 WorldState.Instance().session_dict[param] = value WorldState.Instance().reorder(clock) refresh_plot() if old_clock != clock: return clock else: None
def toggle_param(self, clock, param, value): old_clock = clock if WorldState.Instance().lamport_clock == clock: if self.port == 8000: WorldState.Instance().lamport_clock += 1 else: clock += 1 WorldState.Instance().push_state() WorldState.Instance().lamport_clock = max( WorldState.Instance().lamport_clock, clock) + 1 WorldState.Instance().session_dict[param] = value WorldState.Instance().reorder(clock) refresh_plot() if old_clock != clock: return clock else: None
def update(self, csv, file_key, species_key): """ Updates the legend to reflect any new changes - colour, show/hide, intense/normal """ update = False for child in csv.GetChildren(): if (child.GetName() == "staticText"): update = True if (child.GetLabel() == species_key) else False if child.GetLabel() == "" and update: child.SetBackgroundColour(WorldState.Instance().session_dict['lines'][file_key][species_key].flat_colour) elif child.GetName() == "check" and update: if child.GetLabel() == "Show": child.SetValue(WorldState.Instance().session_dict['lines'][file_key][species_key].plot_line) elif child.GetLabel() == "Ints" and update: child.SetValue(WorldState.Instance().session_dict['lines'][file_key][species_key].intense_plot) self.legend_panel.Refresh() refresh_plot()
def add_annotation(self, clock, annotation): """ Works """ old_clock = clock if WorldState.Instance().lamport_clock == clock: if self.port == 8000: WorldState.Instance().lamport_clock += 1 else: clock += 1 WorldState.Instance().push_state() WorldState.Instance().lamport_clock = max(WorldState.Instance().lamport_clock, clock) + 1 WorldState.Instance().session_dict['annotations'].append(pickle.loads(annotation)) WorldState.Instance().reorder(clock) refresh_plot() if old_clock != clock: return clock else: None
def on_save_plot(self, event): """ Save the graph """ file_choices = "PNG (*.png)|*.png" dlg = wx.FileDialog(self, message="Export plot as...", defaultDir=os.getcwd(), defaultFile="plot.png", wildcard=file_choices, style=wx.SAVE) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() WorldState.Instance().draw_plot.mpl_legend = True refresh_plot() self.graph_canvas.print_figure(path, dpi=_DPI) WorldState.Instance().draw_plot.mpl_legend = False refresh_plot()
def on_save_plot(self, event): """ Save the graph """ file_choices = "PNG (*.png)|*.png" dlg = wx.FileDialog( self, message="Export plot as...", defaultDir=os.getcwd(), defaultFile="plot.png", wildcard=file_choices, style=wx.SAVE) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() WorldState.Instance().draw_plot.mpl_legend = True refresh_plot() self.graph_canvas.print_figure(path, dpi=_DPI) WorldState.Instance().draw_plot.mpl_legend = False refresh_plot()
def add_annotation(self, clock, annotation): """ Works """ old_clock = clock if WorldState.Instance().lamport_clock == clock: if self.port == 8000: WorldState.Instance().lamport_clock += 1 else: clock += 1 WorldState.Instance().push_state() WorldState.Instance().lamport_clock = max( WorldState.Instance().lamport_clock, clock) + 1 WorldState.Instance().session_dict['annotations'].append( pickle.loads(annotation)) WorldState.Instance().reorder(clock) refresh_plot() if old_clock != clock: return clock else: None
def update(self, csv, file_key, species_key): """ Updates the legend to reflect any new changes - colour, show/hide, intense/normal """ update = False for child in csv.GetChildren(): if (child.GetName() == "staticText"): update = True if (child.GetLabel() == species_key) else False if child.GetLabel() == "" and update: child.SetBackgroundColour( WorldState.Instance().session_dict['lines'][file_key] [species_key].flat_colour) elif child.GetName() == "check" and update: if child.GetLabel() == "Show": child.SetValue(WorldState.Instance().session_dict['lines'] [file_key][species_key].plot_line) elif child.GetLabel() == "Ints" and update: child.SetValue(WorldState.Instance().session_dict['lines'] [file_key][species_key].intense_plot) self.legend_panel.Refresh() refresh_plot()