diff --git a/src/audian/databrowser.py b/src/audian/databrowser.py index cb4c117..c5f16e3 100644 --- a/src/audian/databrowser.py +++ b/src/audian/databrowser.py @@ -9,7 +9,7 @@ except ImportError: from PyQt5.QtCore import pyqtSignal as Signal from PyQt5.QtCore import Qt, QTimer -from PyQt5.QtGui import QCursor, QKeySequence +from PyQt5.QtGui import QCursor, QKeySequence, QPalette from PyQt5.QtWidgets import QWidget, QVBoxLayout, QScrollArea from PyQt5.QtWidgets import QAction, QMenu, QToolBar, QComboBox, QCheckBox from PyQt5.QtWidgets import QLabel, QSizePolicy, QTableView @@ -165,6 +165,7 @@ def __init__(self, file_path, load_kwargs, plugins, channels, # plots: self.color_map = 0 # index into color_maps self.figs = [] # all GraphicsLayoutWidgets - one for each channel + self.border_height = 1 self.borders = [] self.sig_proxies = [] # nested lists (channel, panel): @@ -177,6 +178,10 @@ def __init__(self, file_path, load_kwargs, plugins, channels, self.spec_region_labels = [] # regions with labels on spectrograms # full traces: self.datafig = None + # default colors: + text_color = self.palette().color(QPalette.WindowText) + pg.setConfigOption('background', 'black') + pg.setConfigOption('foreground', text_color) def __del__(self): @@ -323,6 +328,7 @@ def open(self, gui, unwrap, unwrap_clip, highpass_cutoff, lowpass_cutoff): # font size: xwidth = self.fontMetrics().averageCharWidth() xwidth2 = xwidth/2 + self.border_height = 0.5*xwidth for c in range(self.data.channels): self.axs.append([]) self.axgs.append([]) @@ -332,7 +338,7 @@ def open(self, gui, unwrap, unwrap_clip, highpass_cutoff, lowpass_cutoff): fig = pg.GraphicsLayoutWidget() fig.setBackground(None) fig.ci.layout.setContentsMargins(xwidth2, xwidth2, xwidth2, xwidth2) - fig.ci.layout.setVerticalSpacing(0) + fig.ci.layout.setVerticalSpacing(-1) fig.ci.layout.setHorizontalSpacing(xwidth2) fig.ci.layout.setHorizontalSpacing(0) fig.setVisible(c in self.show_channels) @@ -343,7 +349,7 @@ def open(self, gui, unwrap, unwrap_clip, highpass_cutoff, lowpass_cutoff): # border: border = QGraphicsRectItem() border.setZValue(-1000) - border.setPen(pg.mkPen('#aaaaaa', width=xwidth+1)) + border.setPen(pg.mkPen('#aaaaaa', width=self.border_height)) fig.scene().addItem(border) fig.sigDeviceRangeChanged.connect(self.update_borders) self.borders.append(border) @@ -361,6 +367,7 @@ def open(self, gui, unwrap, unwrap_clip, highpass_cutoff, lowpass_cutoff): elif panel.is_trace(): ylabel = panel.name if panel.name != 'trace' else '' axt = TimePlot(panel.ax_spec, c, self, xwidth, ylabel) + axt.polish() self.audio_markers[-1].append(axt.vmarker) fig.addItem(axt, row=row, col=0) self.axgs[-1].append(axt) @@ -384,6 +391,7 @@ def open(self, gui, unwrap, unwrap_clip, highpass_cutoff, lowpass_cutoff): axs = SpectrogramPlot(panel.ax_spec, c, self, xwidth, self.color_maps[self.color_map], self.show_cbars, self.show_powers) + axs.polish() self.audio_markers[-1].append(axs.vmarker) panel.add_ax(row, axs, axs.cbar) panel.add_traces(c, self.data) @@ -577,6 +585,7 @@ def open(self, gui, unwrap, unwrap_clip, highpass_cutoff, lowpass_cutoff): # full data: self.datafig = FullTracePlot(self.data.data, self.panels['trace'].axs) + self.datafig.polish() self.vbox.addWidget(self.datafig) self.setEnabled(True) @@ -999,7 +1008,7 @@ def adjust_layout(self, width, height): ntraces += 1 nrows = len(self.show_channels) # subtract border height: - border_height = 1.5*xwidth + border_height = self.border_height height -= nrows*border_height # subtract spacer height: spacer_height = 0*xheight diff --git a/src/audian/fulltraceplot.py b/src/audian/fulltraceplot.py index 40be726..4788e10 100644 --- a/src/audian/fulltraceplot.py +++ b/src/audian/fulltraceplot.py @@ -10,6 +10,7 @@ import numpy as np from PyQt5.QtCore import Qt, QTimer from PyQt5.QtWidgets import QGraphicsSimpleTextItem, QApplication +from PyQt5.QtGui import QPalette import pyqtgraph as pg from .traceitem import down_sample_peak @@ -130,6 +131,12 @@ def __init__(self, data, axtraces, *args, **kwargs): QTimer.singleShot(10, self.load_data) + + def polish(self): + text_color = self.palette().color(QPalette.WindowText) + for label in self.labels: + label.setBrush(text_color) + def load_data(self): i = 2*self.index//self.step diff --git a/src/audian/spectrogramplot.py b/src/audian/spectrogramplot.py index f5e1d50..7f0a090 100644 --- a/src/audian/spectrogramplot.py +++ b/src/audian/spectrogramplot.py @@ -6,6 +6,7 @@ from PyQt5.QtCore import Signal except ImportError: from PyQt5.QtCore import pyqtSignal as Signal +from PyQt5.QtGui import QPalette import pyqtgraph as pg from thunderlab.powerspectrum import decibel from .panels import Panel @@ -70,14 +71,14 @@ def __init__(self, aspec, channel, browser, xwidth, color_map, show_cbars, # axis: self.getAxis('bottom').showLabel(False) self.getAxis('bottom').setStyle(showValues=False) - self.getAxis('left').setLabel('Frequency', 'Hz', color='black') + self.getAxis('left').setLabel('Frequency', 'Hz') + self.getAxis('left').enableAutoSIPrefix() # color bar: self.cbar = pg.ColorBarItem(colorMap=color_map, interactive=True, rounding=1, limits=(-200, 20)) self.cbar.setLabel('right', 'Power (dB)') - self.cbar.getAxis('right').setTextPen('black') self.cbar.getAxis('right').setWidth(6*xwidth) self.cbar.setVisible(show_cbars) @@ -111,6 +112,12 @@ def __init__(self, aspec, channel, browser, xwidth, color_map, show_cbars, self.sigUpdateFilter.connect(browser.update_filter) + def polish(self): + TimePlot.polish(self) + text_color = self.palette().color(QPalette.WindowText) + self.cbar.getAxis('right').setTextPen(text_color) + + def add_item(self, item, is_data=False): super().add_item(item, is_data) if is_data and isinstance(item, SpecItem): diff --git a/src/audian/timeplot.py b/src/audian/timeplot.py index cc600cf..906a900 100644 --- a/src/audian/timeplot.py +++ b/src/audian/timeplot.py @@ -6,6 +6,8 @@ from PyQt5.QtCore import Signal except ImportError: from PyQt5.QtCore import pyqtSignal as Signal +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QPalette, QColor import pyqtgraph as pg from .rangeplot import RangePlot from .timeaxisitem import TimeAxisItem @@ -15,31 +17,21 @@ class TimePlot(RangePlot): def __init__(self, aspec, channel, browser, xwidth, ylabel=''): - - # text color: - #text_color = self.palette().color( QPalette.WindowText ) - # TODO: palette() can not be called within constructor. - # We need some late initialization of the colors. - # axis: bottom_axis = TimeAxisItem(orientation='bottom', showValues=True) - bottom_axis.setLabel('Time', 's', color='black') - bottom_axis.setPen('white') - bottom_axis.setTextPen('black') + bottom_axis.setLabel('Time', 's') bottom_axis.set_start_time(browser.data.start_time) top_axis = TimeAxisItem(orientation='top', showValues=False) top_axis.set_start_time(browser.data.start_time) left_axis = YAxisItem(orientation='left', showValues=True) - left_axis.setPen('white') - left_axis.setTextPen('black') left_axis.setWidth(8*xwidth) if ylabel: - left_axis.setLabel(ylabel, color='black') + left_axis.setLabel(ylabel) else: if browser.data.channels > 4: - left_axis.setLabel(f'C{channel}', color='black') + left_axis.setLabel(f'C{channel}') else: - left_axis.setLabel(f'channel {channel}', color='black') + left_axis.setLabel(f'channel {channel}') right_axis = YAxisItem(orientation='right', showValues=False) # plot: @@ -60,6 +52,20 @@ def __init__(self, aspec, channel, browser, xwidth, ylabel=''): self.addItem(self.vmarker, ignoreBounds=True) + def polish(self): + text_color = self.palette().color(QPalette.Text) + for axis in ['left', 'right', 'top', 'bottom']: + self.getAxis(axis).setPen(style=Qt.NoPen) + self.getAxis(axis).setTickPen(style=Qt.SolidLine) + self.getAxis(axis).setTextPen(text_color) + self.getAxis('left').setLabel(self.getAxis('left').labelText, + self.getAxis('left').labelUnits, + color=text_color) + self.getAxis('bottom').setLabel(self.getAxis('bottom').labelText, + self.getAxis('bottom').labelUnits, + color=text_color) + + def range(self, axspec): if axspec == self.x(): if len(self.data_items) > 0: