Skip to content

Commit

Permalink
[databrowser] improved dark mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
janscience committed Sep 12, 2024
1 parent 72863f8 commit 39606e6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
17 changes: 13 additions & 4 deletions src/audian/databrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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([])
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/audian/fulltraceplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/audian/spectrogramplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
34 changes: 20 additions & 14 deletions src/audian/timeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 39606e6

Please sign in to comment.