Skip to content

Commit

Permalink
gui/experiments: fix custom color application to preserve default Qt …
Browse files Browse the repository at this point in the history
…styling
  • Loading branch information
fsagbuya committed Feb 3, 2025
1 parent ff494c5 commit 1953295
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions artiq/dashboard/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,12 @@ async def _recompute_argument(self, name):
argument["desc"] = procdesc
argument["state"] = state
self.update_argument(name, argument)
self.dock.apply_colors()
self.dock.apply_window_color()

def apply_color(self, palette, color):
self.setPalette(palette)
for child in self.findChildren(QtWidgets.QWidget):
child.setPalette(palette)
child.setAutoFillBackground(True)
items = self.findItems("*",
QtCore.Qt.MatchFlag.MatchWildcard | QtCore.Qt.MatchFlag.MatchRecursive)
for item in items:
for column in range(item.columnCount()):
item.setBackground(column, QtGui.QColor(color))
def apply_color(self, color):
self.set_background_color(color)
self.set_gradient_color(color)
self.set_group_color(color)

# Hooks that allow user-supplied argument editors to react to imminent user
# actions. Here, we always keep the manager-stored submission arguments
Expand Down Expand Up @@ -329,7 +323,7 @@ async def _recompute_arguments_task(self, overrides=dict()):
self.argeditor = editor_class(self.manager, self, self.expurl)
self.layout.addWidget(self.argeditor, 0, 0, 1, 5)
self.argeditor.restore_state(argeditor_state)
self.apply_colors()
self.apply_window_color()

def contextMenuEvent(self, event):
menu = QtWidgets.QMenu(self)
Expand All @@ -353,22 +347,26 @@ def select_color(self, key):
title=f"Select {key.replace('_', ' ').title()} color")
if color.isValid():
self.manager.set_color(self.expurl, key, color.name())
self.apply_colors()
# self.apply_color(key)
if key == "title_bar":
self.apply_title_bar_color()
else:
self.apply_window_color()

def apply_colors(self):
def apply_title_bar_color(self):
colors = self.manager.get_colors(self.expurl)
if not colors:
palette = QtWidgets.QApplication.palette()
colors = {
"window": palette.color(QtGui.QPalette.ColorRole.Window).name(),
"title_bar": palette.color(QtGui.QPalette.ColorRole.Highlight).name(),
}
self.manager.colors[self.expurl] = colors
return
self.setStyle(_ColoredTitleBar(colors["title_bar"]))

def apply_window_color(self):
colors = self.manager.get_colors(self.expurl)
if not colors:
return
colors["window_text"] = "#000000" if QtGui.QColor(
colors["window"]).lightness() > 128 else "#FFFFFF"
self.modify_palette(colors)
self.setStyle(_ColoredTitleBar(colors["title_bar"]))
self.argeditor.apply_color(self.palette(), (colors["window"]))
self.argeditor.apply_color(colors["window"])

def modify_palette(self, colors):
palette = self.palette()
Expand All @@ -381,8 +379,13 @@ def modify_palette(self, colors):
self.setPalette(palette)

def reset_colors(self):
colors = self.manager.get_colors(self.expurl)
if not colors:
return
self.manager.reset_colors(self.expurl)
self.apply_colors()
self.setStyle(None)
self.setPalette(QtWidgets.QApplication.palette())
self.argeditor.apply_color(None)

async def _recompute_sched_options_task(self):
try:
Expand Down Expand Up @@ -696,7 +699,12 @@ def open_experiment(self, expurl):
self.open_experiments[expurl] = dock
dock.setAttribute(QtCore.Qt.WidgetAttribute.WA_DeleteOnClose)
self.main_window.centralWidget().addSubWindow(dock)
dock.apply_colors()
colors = self.get_colors(expurl)
if colors:
if "title_bar" in colors:
dock.apply_title_bar_color()
if "window" in colors:
dock.apply_window_color()
dock.show()
dock.sigClosed.connect(partial(self.on_dock_closed, expurl))
if expurl in self.dock_states:
Expand Down

0 comments on commit 1953295

Please sign in to comment.