Skip to content

Commit 57275a9

Browse files
set antialiasing in config, add performance settings
1 parent 681de92 commit 57275a9

File tree

7 files changed

+120
-67
lines changed

7 files changed

+120
-67
lines changed

ephys/GUI/GUI_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
theme = "dark"
2+
CURVE_COLOR = "viridis"
3+
USE_COLOR_MODE = True
4+
USE_ANTIALIASING = True

ephys/GUI/gui_app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
from ephys.classes.experiment_objects import ExpData
2121
from ephys.GUI.mainwindow import MainWindow
2222

23-
pg.setConfigOptions(antialias=True)
24-
2523

2624
class DataLoader(QRunnable):
2725
def __init__(self, file_path, experimenter_name):

ephys/GUI/mainwindow.py

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
from ephys.GUI.sidebar_right import SideBarRight
1616
from ephys.GUI.menubar import FileMenu
1717
from ephys.GUI.trace_view import TracePlotWindow
18+
from ephys.GUI.performance_menu import PerformanceMenu
1819
from PySide6.QtWidgets import QWidget, QHBoxLayout
20+
import ephys.GUI.GUI_config as config
21+
import pyqtgraph as pg
22+
23+
pg.setConfigOptions(antialias=config.USE_ANTIALIASING)
1924

2025

2126
class MainWindow(QMainWindow):
@@ -25,9 +30,7 @@ def __init__(self):
2530
self.data: ExpData | None = None
2631
self.session_info = SessionInfo()
2732

28-
self.threadpool = QThreadPool()
29-
thread_count = self.threadpool.maxThreadCount()
30-
print(f"Multithreading enabled with {thread_count} threads.")
33+
self.set_multi_threading(thread_n=4)
3134

3235
self.setWindowTitle("EphysTools")
3336
self.setGeometry(100, 100, 1200, 800)
@@ -50,26 +53,56 @@ def __init__(self):
5053
sweep_selector_container = QWidget()
5154
sweep_selector_layout = QHBoxLayout(sweep_selector_container)
5255
sweep_selector_layout.setContentsMargins(0, 0, 0, 0)
56+
sweep_selector_layout.setAlignment(Qt.AlignmentFlag.AlignRight)
5357

5458
self.sweep_selector = QSpinBox()
5559
self.sweep_selector.setSingleStep(1)
5660

61+
# Add menue to change visual trace color and antialiasing (Fast mode)
62+
self.fast_mode_menu = PerformanceMenu(parent=self)
63+
sweep_selector_layout.addWidget(self.fast_mode_menu)
64+
# self.status_bar.addPermanentWidget(self.fast_mode_menue)
65+
5766
self.highlight_switch = QCheckBox("Highlight")
5867
self.highlight_switch.setChecked(False)
5968
self.highlight_switch.stateChanged.connect(self.change_highlight)
60-
self.status_bar.addPermanentWidget(self.highlight_switch)
69+
# self.status_bar.addPermanentWidget(self.highlight_switch)
6170

71+
sweep_selector_layout.addWidget(self.highlight_switch)
6272
sweep_selector_layout.addWidget(self.sweep_selector)
6373
self.sweep_selector.valueChanged.connect(self.sweep_highlight)
6474

6575
self.status_bar.addPermanentWidget(sweep_selector_container)
6676

6777
# Create a splitter
68-
splitter = QSplitter()
69-
splitter.setOrientation(Qt.Orientation.Horizontal)
70-
self.setCentralWidget(splitter)
71-
# Create a frame
78+
self.splitter = QSplitter()
79+
self.splitter.setOrientation(Qt.Orientation.Horizontal)
80+
self.setCentralWidget(self.splitter)
81+
82+
self._init_side_bar_left()
83+
self._init_trace_tabs()
84+
self._init_sidebar_right()
85+
86+
# Add the session info widget
87+
88+
# decouple tab_widget from the splitter
89+
90+
self.show()
91+
92+
def set_multi_threading(self, thread_n: int | None) -> None:
93+
self.threadpool = QThreadPool()
94+
if (
95+
isinstance(thread_n, int)
96+
and thread_n > 0
97+
and thread_n <= self.threadpool.maxThreadCount()
98+
):
99+
self.threadpool.setMaxThreadCount(thread_n)
100+
else:
101+
thread_n = self.threadpool.maxThreadCount()
102+
self.threadpool.setMaxThreadCount(thread_n)
103+
print(f"Multithreading enabled with {thread_n} threads.")
72104

105+
def _init_side_bar_left(self) -> None:
73106
sidebar_frame = QFrame()
74107
sidebar_frame.setFrameShape(QFrame.Shape.StyledPanel)
75108
sidebar_frame.setMinimumSize(QSize(150, 150))
@@ -80,39 +113,29 @@ def __init__(self):
80113
self.side_menu_container.set_background_svg(
81114
svg_path="logos/Ephys_letters_gray.svg"
82115
)
83-
# splitter.addWidget(sidebar_frame)
84116
# Create a layout for the frame
85117
self.menu_layout_left = SideMenu(self)
118+
self.menu_layout_left.addWidget(self.side_menu_container)
86119
self.menu_layout_left.combobox.currentTextChanged.connect(
87120
self.select_file_from_list
88121
)
89-
90122
sidebar_frame.setLayout(self.menu_layout_left)
123+
self.splitter.addWidget(sidebar_frame)
91124

92-
splitter.addWidget(sidebar_frame)
93-
# splitter.addWidget(menu_layout_left)
94-
125+
def _init_trace_tabs(self) -> None:
95126
self.trace_plot = QTabWidget()
96127
self.trace_plot.setTabsClosable(True)
97128
self.trace_plot.setMovable(True)
98129
self.trace_plot.setMinimumSize(800, 600)
99130
self.trace_plot.currentChanged.connect(self.connect_sweep_selector)
100131
self.trace_plot.tabCloseRequested.connect(self.close_tab)
132+
self.splitter.addWidget(self.trace_plot)
101133

102-
splitter.addWidget(self.trace_plot)
103-
104-
# Add a sidebar on the right side
134+
def _init_sidebar_right(self) -> None:
105135
sidebar_right = SideBarRight(self)
106136
sidebar_right.setMinimumSize(QSize(180, 150))
107137
sidebar_right.setMaximumSize(QSize(300, 1200))
108-
splitter.addWidget(sidebar_right)
109-
110-
self.menu_layout_left.addWidget(self.side_menu_container)
111-
# Add the session info widget
112-
113-
# decouple tab_widget from the splitter
114-
115-
self.show()
138+
self.splitter.addWidget(sidebar_right)
116139

117140
def closeEvent(self, event) -> None:
118141
print("Window closed")
@@ -159,7 +182,9 @@ def _sweep_highlight(self, sweep_number: int | None) -> None:
159182
current_tab_index = self.trace_plot.currentIndex()
160183
current_trace_tab = self.trace_plot.widget(0)
161184
sweep_index = None
162-
if isinstance(current_trace_tab, TracePlotWindow):
185+
if isinstance(current_trace_tab, TracePlotWindow) and isinstance(
186+
current_trace_tab.trace_list, list
187+
):
163188
current_plot = current_trace_tab.trace_list[current_tab_index]
164189
if sweep_number is None:
165190
sweep_index = None
@@ -198,39 +223,3 @@ def change_highlight(self) -> None:
198223

199224
def select_file_from_list(self, s):
200225
print("text change: ", s)
201-
202-
# def close_tab(self, index: int) -> None:
203-
# """Close the tab at the given index."""
204-
# tab_selected: TracePlotWindow = cast(
205-
# TracePlotWindow, self.trace_plot.widget(index)
206-
# )
207-
# print(index, tab_selected)
208-
# if index >= 0:
209-
# self.trace_plot.removeTab(index)
210-
# print(f"Closed tab at index {index}")
211-
# if hasattr(tab_selected, "cleanup") and callable(
212-
# getattr(tab_selected, "cleanup", None)
213-
# ):
214-
# tab_selected.cleanup()
215-
# if tab_selected is not None:
216-
# # Ensure the tab is properly deleted
217-
# if hasattr(tab_selected, "deleteLater"):
218-
# tab_selected.deleteLater()
219-
# else:
220-
# print("Tab selected does not have deleteLater method")
221-
222-
# def choose_file(self):
223-
# # Store the dialog as an instance attribute to prevent it from being deleted
224-
# self.get_file = FileSelector()
225-
# # self.get_file.exec()
226-
# file_path = self.get_file.getOpenFileNames(
227-
# self, "Select WCP files", "data/WCP/WholeCell", "WCP files (*.wcp)"
228-
# )[0]
229-
# # if not file_path:
230-
# # print("No files selected")
231-
# # return None
232-
# print(f"Selected files: {file_path}")
233-
# self.the_button_was_clicked(file_path)
234-
# if isinstance(file_path, str):
235-
# file_path = [file_path]
236-
# self.file_list = file_pathlen(self.trace_list)

ephys/GUI/performance_menu.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Add menu to change visual trace color and antialiasing (Fast mode)
2+
from __future__ import annotations
3+
from typing import TYPE_CHECKING
4+
import ephys.GUI.GUI_config as config
5+
from ephys.GUI.style_sheets.dark_theme import dark_vars
6+
from ephys.GUI.style_sheets.light_theme import light_vars
7+
from PySide6.QtWidgets import (
8+
QMenuBar,
9+
QCheckBox,
10+
QToolBar,
11+
QWidget,
12+
QHBoxLayout,
13+
)
14+
from PySide6.QtGui import QAction
15+
16+
import pyqtgraph as pg
17+
18+
if TYPE_CHECKING:
19+
from ephys.GUI.mainwindow import MainWindow
20+
from ephys.GUI.trace_view import TracePlotWindow
21+
22+
23+
class PerformanceMenu(QWidget):
24+
def __init__(self, parent: MainWindow):
25+
super().__init__(parent)
26+
layout = QHBoxLayout()
27+
layout.setContentsMargins(0, 0, 0, 0)
28+
29+
self.color_mode_action = QCheckBox("Color Mode")
30+
self.color_mode_action.setChecked(config.USE_COLOR_MODE)
31+
self.color_mode_action.toggled.connect(self.toggle_color_mode)
32+
33+
self.antialiasing_action = QCheckBox("Antialiasing")
34+
self.antialiasing_action.setChecked(config.USE_ANTIALIASING)
35+
self.antialiasing_action.toggled.connect(self.toggle_antialiasing)
36+
37+
layout.addWidget(self.color_mode_action)
38+
layout.addWidget(self.antialiasing_action)
39+
self.setLayout(layout)
40+
41+
def toggle_color_mode(self):
42+
config.USE_COLOR_MODE = not config.USE_COLOR_MODE
43+
# change color according to theme
44+
if config.USE_COLOR_MODE:
45+
config.CURVE_COLOR = "viridis"
46+
else:
47+
if config.theme == "dark":
48+
config.CURVE_COLOR = dark_vars["color"]
49+
else:
50+
config.CURVE_COLOR = light_vars["color"]
51+
52+
def toggle_antialiasing(self):
53+
config.USE_ANTIALIASING = not config.USE_ANTIALIASING
54+
print(f"Antialiasing set to {config.USE_ANTIALIASING}")
55+
pg.setConfigOptions(antialias=config.USE_ANTIALIASING)

ephys/GUI/sidemenu.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ def update_plot_tab(self) -> None:
317317
trace_plot = TracePlotWindow(
318318
main_window=self.main_window, file_name=self.file_paths[i]
319319
)
320-
trace_plot.add_trace_plot(trace=self.main_window.data.protocols[i])
320+
trace_plot.add_trace_plot(
321+
trace=self.main_window.data.protocols[i],
322+
color=config.CURVE_COLOR,
323+
antialiasing=config.USE_ANTIALIASING,
324+
)
321325
self.main_window.trace_plot.addTab(trace_plot, file_name)
322326
else:
323327
print("No data loaded yet.")

ephys/GUI/trace_view.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def __init__(self, main_window: MainWindow, file_name: str) -> None:
5858
# Trace List
5959
if isinstance(self.main_window.trace_list, list):
6060
self.trace_list = self.main_window.trace_list
61+
else:
62+
self.main_window.trace_list = []
63+
self.trace_list = []
6164

6265
# Create a frame for the plot
6366
plot_frame = QFrame()
@@ -85,14 +88,14 @@ def __init__(self, main_window: MainWindow, file_name: str) -> None:
8588
self.plot_area_layout = QVBoxLayout(plot_area)
8689
plot_area.setLayout(self.plot_area_layout)
8790

88-
def add_trace_plot(self, trace: Trace, **kwargs) -> None:
91+
def add_trace_plot(self, trace: Trace, color="viridis", **kwargs) -> None:
8992
from ephys.classes.plot.plot_trace import TracePlotPyQt
9093

9194
"""Add a trace plot widget to the plot area."""
9295
trace_plot: None | TracePlotPyQt | tuple[Figure, Axes] = trace.plot(
9396
backend="pyqt",
94-
alpha=1,
95-
color="viridis",
97+
alpha=kwargs.get("alpha", 1.0),
98+
color=color,
9699
show=False,
97100
return_fig=True,
98101
theme=self.main_window.session_info.theme,

ephys/classes/plot/plot_trace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ def make_region_callback(region_obj, channel_items, window_index=0):
468468
region.sigRegionChanged.connect(
469469
make_region_callback(region, win_item, window_index=win_index)
470470
)
471+
print("moved:", region.moving)
471472
region.setZValue(10 + win_index)
472473
for line in region.lines:
473474
line.setPen(self.params.window_color)

0 commit comments

Comments
 (0)