From 303818077672c96684d56a24381f7fbed4c6c2ff Mon Sep 17 00:00:00 2001 From: Jeffrey Gill Date: Sat, 29 Feb 2020 17:08:31 -0500 Subject: [PATCH] Add label_size parameter to viewers for resizing channel labels --- ephyviewer/epochencoder.py | 8 ++++++++ ephyviewer/epochviewer.py | 4 ++++ ephyviewer/spiketrainviewer.py | 9 +++++++++ ephyviewer/traceviewer.py | 9 +++++++++ 4 files changed, 30 insertions(+) diff --git a/ephyviewer/epochencoder.py b/ephyviewer/epochencoder.py index e00740d..6e744ab 100644 --- a/ephyviewer/epochencoder.py +++ b/ephyviewer/epochencoder.py @@ -23,6 +23,7 @@ {'name': 'background_color', 'type': 'color', 'value': 'k'}, {'name': 'vline_color', 'type': 'color', 'value': '#FFFFFFAA'}, {'name': 'label_fill_color', 'type': 'color', 'value': '#222222DD'}, + {'name': 'label_size', 'type': 'int', 'value': 8, 'limits': (1,np.inf)}, {'name': 'new_epoch_step', 'type': 'float', 'value': .1, 'step': 0.1, 'limits':(0,np.inf)}, {'name': 'exclusive_mode', 'type': 'bool', 'value': True}, {'name': 'view_mode', 'type': 'list', 'value':'stacked', 'values' : ['stacked', 'flat']}, @@ -332,6 +333,9 @@ def initialize_plot(self): color = self.by_label_params['label'+str(i), 'color'] label_item = pg.TextItem(label, color=color, anchor=(0, 0.5), border=None, fill=self.params['label_fill_color']) label_item.setZValue(11) + font = label_item.textItem.font() + font.setPointSize(self.params['label_size']) + label_item.setFont(font) self.plot.addItem(label_item) self.label_items.append(label_item) @@ -357,6 +361,10 @@ def on_param_change(self): else: self.btn_insertion_mode_overlapping.setChecked(True) self.vline.setPen(color=self.params['vline_color']) + for label_item in self.label_items: + font = label_item.textItem.font() + font.setPointSize(self.params['label_size']) + label_item.setFont(font) self.refresh() def on_change_keys(self, refresh=True): diff --git a/ephyviewer/epochviewer.py b/ephyviewer/epochviewer.py index 6770b01..2ae7155 100644 --- a/ephyviewer/epochviewer.py +++ b/ephyviewer/epochviewer.py @@ -20,6 +20,7 @@ {'name': 'background_color', 'type': 'color', 'value': 'k'}, {'name': 'vline_color', 'type': 'color', 'value': '#FFFFFFAA'}, {'name': 'label_fill_color', 'type': 'color', 'value': '#222222DD'}, + {'name': 'label_size', 'type': 'int', 'value': 8, 'limits': (1,np.inf)}, {'name': 'display_labels', 'type': 'bool', 'value': True}, ] @@ -165,6 +166,9 @@ def on_data_ready(self, t_start, t_stop, visibles, data): if self.params['display_labels']: label_name = '{}: {}'.format(chan, self.source.get_channel_name(chan=chan)) label = pg.TextItem(label_name, color=color, anchor=(0, 0.5), border=None, fill=self.params['label_fill_color']) + font = label.textItem.font() + font.setPointSize(self.params['label_size']) + label.setFont(font) self.plot.addItem(label) label.setPos(t_start, ypos+0.45) diff --git a/ephyviewer/spiketrainviewer.py b/ephyviewer/spiketrainviewer.py index 0380e0a..73248aa 100644 --- a/ephyviewer/spiketrainviewer.py +++ b/ephyviewer/spiketrainviewer.py @@ -32,6 +32,7 @@ {'name': 'background_color', 'type': 'color', 'value': 'k'}, {'name': 'vline_color', 'type': 'color', 'value': '#FFFFFFAA'}, {'name': 'label_fill_color', 'type': 'color', 'value': '#222222DD'}, + {'name': 'label_size', 'type': 'int', 'value': 8, 'limits': (1,np.inf)}, {'name': 'display_labels', 'type': 'bool', 'value': True}, ] @@ -127,6 +128,9 @@ def initialize_plot(self): label_name = '{}: {}'.format(c, self.source.get_channel_name(chan=c)) color = self.by_channel_params.children()[c].param('color').value() label = pg.TextItem(label_name, color=color, anchor=(0, 0.5), border=None, fill=self.params['label_fill_color']) + font = label.textItem.font() + font.setPointSize(self.params['label_size']) + label.setFont(font) self.plot.addItem(label) self.labels.append(label) @@ -188,5 +192,10 @@ def on_param_change(self, params=None, changes=None): if change != 'value': continue if param.name()=='scatter_size': self.scatter.setSize(self.params['scatter_size']) + if param.name()=='label_size': + for label in self.labels: + font = label.textItem.font() + font.setPointSize(self.params['label_size']) + label.setFont(font) self.refresh() diff --git a/ephyviewer/traceviewer.py b/ephyviewer/traceviewer.py index 6898958..dfb06e3 100644 --- a/ephyviewer/traceviewer.py +++ b/ephyviewer/traceviewer.py @@ -35,6 +35,7 @@ {'name': 'background_color', 'type': 'color', 'value': 'k'}, {'name': 'vline_color', 'type': 'color', 'value': '#FFFFFFAA'}, {'name': 'label_fill_color', 'type': 'color', 'value': '#222222DD'}, + {'name': 'label_size', 'type': 'int', 'value': 8, 'limits': (1,np.inf)}, {'name': 'display_labels', 'type': 'bool', 'value': False}, {'name': 'display_offset', 'type': 'bool', 'value': False}, {'name': 'antialias', 'type': 'bool', 'value': False}, @@ -488,6 +489,9 @@ def initialize_plot(self): ch_name = '{}: {}'.format(c, self.source.get_channel_name(chan=c)) label = TraceLabelItem(text=ch_name, color=color, anchor=(0, 0.5), border=None, fill=self.params['label_fill_color']) label.setZValue(2) # ensure labels are drawn above scatter + font = label.textItem.font() + font.setPointSize(self.params['label_size']) + label.setFont(font) label.label_dragged.connect(lambda label_y, chan_index=c: self.params_controller.apply_label_drag(label_y, chan_index)) label.label_ygain_zoom.connect(lambda factor_ratio, chan_index=c: self.params_controller.apply_ygain_zoom(factor_ratio, chan_index)) @@ -525,6 +529,11 @@ def on_param_change(self, params=None, changes=None): if param.name()=='label_fill_color': for label in self.channel_labels: label.fill = pg.mkBrush(self.params['label_fill_color']) + if param.name()=='label_size': + for label in self.channel_labels: + font = label.textItem.font() + font.setPointSize(self.params['label_size']) + label.setFont(font) self.refresh()