Skip to content

Commit 21390d3

Browse files
setting highlights and fix discontinue
1 parent 750f8b6 commit 21390d3

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

ephys/GUI/gui_app.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
QApplication,
1515
)
1616

17-
# from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
18-
# from matplotlib.backends.backend_qtagg import NavigationToolbar2QT as NavigationToolbar
19-
17+
import pyqtgraph as pg
2018

2119
from .styles import apply_style
2220
from ephys.classes.experiment_objects import ExpData
2321
from ephys.GUI.mainwindow import MainWindow
2422

25-
# filepath: /home/daniel/Work/RETAIN/Code/MossyFibre/ephys/GUI/gui_app.py
23+
pg.setConfigOptions(antialias=True)
2624

2725

2826
class DataLoader(QRunnable):

ephys/GUI/mainwindow.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
QCheckBox,
1010
)
1111

12-
from ephys.classes.experiment_objects import ExpData
12+
from ephys.classes.experiment_objects import ExpData, MetaData
1313
from ephys.GUI.sessioninfo import SessionInfo
1414
from ephys.GUI.sidemenu import SideMenu, SideMenuContainer
1515
from ephys.GUI.sidebar_right import SideBarRight
@@ -26,7 +26,6 @@ def __init__(self):
2626
self.session_info = SessionInfo()
2727

2828
self.threadpool = QThreadPool()
29-
self.highlight = False
3029
thread_count = self.threadpool.maxThreadCount()
3130
print(f"Multithreading enabled with {thread_count} threads.")
3231

@@ -56,7 +55,7 @@ def __init__(self):
5655
self.sweep_selector.setSingleStep(1)
5756

5857
self.highlight_switch = QCheckBox("Highlight")
59-
self.highlight_switch.setChecked(self.highlight)
58+
self.highlight_switch.setChecked(False)
6059
self.highlight_switch.stateChanged.connect(self.change_highlight)
6160
self.status_bar.addPermanentWidget(self.highlight_switch)
6261

@@ -83,9 +82,12 @@ def __init__(self):
8382
)
8483
# splitter.addWidget(sidebar_frame)
8584
# Create a layout for the frame
86-
menu_layout_left = SideMenu(self)
85+
self.menu_layout_left = SideMenu(self)
86+
self.menu_layout_left.combobox.currentTextChanged.connect(
87+
self.select_file_from_list
88+
)
8789

88-
sidebar_frame.setLayout(menu_layout_left)
90+
sidebar_frame.setLayout(self.menu_layout_left)
8991

9092
splitter.addWidget(sidebar_frame)
9193
# splitter.addWidget(menu_layout_left)
@@ -105,7 +107,7 @@ def __init__(self):
105107
sidebar_right.setMaximumSize(QSize(300, 1200))
106108
splitter.addWidget(sidebar_right)
107109

108-
menu_layout_left.addWidget(self.side_menu_container)
110+
self.menu_layout_left.addWidget(self.side_menu_container)
109111
# Add the session info widget
110112

111113
# decouple tab_widget from the splitter
@@ -114,6 +116,9 @@ def __init__(self):
114116

115117
def closeEvent(self, event) -> None:
116118
print("Window closed")
119+
# Perform any necessary cleanup here
120+
if isinstance(self.data, ExpData):
121+
self.data = None
117122
event.accept()
118123

119124
def close_tab(self, index: int) -> None:
@@ -124,14 +129,17 @@ def close_tab(self, index: int) -> None:
124129

125130
# Disconnect the tabCloseRequested signal temporarily to prevent cascading closes
126131
old_signal = self.trace_plot.tabCloseRequested.disconnect()
127-
132+
if isinstance(self.data, ExpData):
133+
self.data.remove_file(index=index)
134+
self.session_info.set_file_path(self.data.meta_data.get_file_path())
135+
self.session_info.set_file_list(self.data.meta_data.get_file_name())
128136
# Remove just this one tab
129137
self.trace_plot.removeTab(index)
130138
print(f"Closed tab '{tab_title}' at index {index}")
131139

132140
# Reconnect the signal
133141
self.trace_plot.tabCloseRequested.connect(self.close_tab)
134-
142+
self.menu_layout_left.refresh_file_list()
135143
# Clean up the tab's resources safely
136144
if isinstance(tab_selected, TracePlotWindow):
137145
try:
@@ -149,12 +157,9 @@ def on_color_selected(self, color) -> None:
149157
def _sweep_highlight(self, sweep_number: int | None) -> None:
150158
"""Highlight a specific sweep in the plot."""
151159
current_tab_index = self.trace_plot.currentIndex()
152-
print(current_tab_index)
153160
current_trace_tab = self.trace_plot.widget(0)
154161
sweep_index = None
155162
if isinstance(current_trace_tab, TracePlotWindow):
156-
print(current_trace_tab.trace_list)
157-
print(len(current_trace_tab.trace_list))
158163
current_plot = current_trace_tab.trace_list[current_tab_index]
159164
if sweep_number is None:
160165
sweep_index = None
@@ -170,21 +175,30 @@ def sweep_highlight(self, sweep_number: int | None = None) -> None:
170175

171176
def connect_sweep_selector(self) -> None:
172177
current_tab_index: int = self.trace_plot.currentIndex()
173-
print(current_tab_index)
174-
self.sweep_selector.setRange(
175-
1, self.trace_list[current_tab_index].trace.sweep_count
176-
)
177-
print(self.trace_list[current_tab_index].trace.sweep_count)
178-
self.sweep_selector.setValue(
179-
self.trace_list[current_tab_index].highlight["sweep_index"]
180-
)
178+
if current_tab_index >= 0 and len(self.trace_list) > 0:
179+
if self.trace_list[current_tab_index].trace.sweep_count == 1:
180+
self.sweep_selector.setEnabled(False)
181+
else:
182+
self.sweep_selector.setEnabled(True)
183+
self.sweep_selector.setRange(
184+
1, self.trace_list[current_tab_index].trace.sweep_count
185+
)
186+
if self.trace_list[current_tab_index].highlight["sweep_index"] is None:
187+
self.sweep_selector.setValue(1)
188+
else:
189+
self.sweep_selector.setValue(
190+
self.trace_list[current_tab_index].highlight["sweep_index"]
191+
)
181192

182193
def change_highlight(self) -> None:
183194
if not self.highlight_switch.isChecked():
184195
self.sweep_highlight(sweep_number=None)
185196
else:
186197
self.sweep_highlight(sweep_number=self.sweep_selector.value())
187198

199+
def select_file_from_list(self, s):
200+
print("text change: ", s)
201+
188202
# def close_tab(self, index: int) -> None:
189203
# """Close the tab at the given index."""
190204
# tab_selected: TracePlotWindow = cast(
@@ -219,4 +233,4 @@ def change_highlight(self) -> None:
219233
# self.the_button_was_clicked(file_path)
220234
# if isinstance(file_path, str):
221235
# file_path = [file_path]
222-
# self.file_list = file_path
236+
# self.file_list = file_pathlen(self.trace_list)

ephys/GUI/trace_view.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def __init__(self, main_window: MainWindow, file_name: str) -> None:
5656
)
5757

5858
# Trace List
59-
# TODO: manage handling of list - removing items etc.
6059
if isinstance(self.main_window.trace_list, list):
6160
self.trace_list = self.main_window.trace_list
6261

ephys/classes/plot/plot_trace.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def sweep_highlight(
557557
highlight_exists = False
558558
if self.params.alpha != 0.1:
559559
for plot_item in plot_items:
560-
self._set_curve_pen(plot_item.listDataItems(), alpha=0.1)
560+
self._set_curve_alpha(plot_item.listDataItems(), alpha=0.1)
561561

562562
for plot_item in plot_items:
563563
for sweep in plot_item.listDataItems():
@@ -587,7 +587,7 @@ def sweep_highlight(
587587
if not highlight_exists:
588588
for plot_item in plot_items:
589589
item_list = plot_item.listDataItems()
590-
self._set_curve_pen(item_list, alpha=self.params.alpha)
590+
self._set_curve_alpha(item_list, alpha=self.params.alpha)
591591
for sweep in item_list:
592592
if isinstance(sweep, HighlightCurve):
593593
plot_item.removeItem(sweep)
@@ -613,3 +613,12 @@ def _set_curve_pen(self, curves, alpha=None) -> None:
613613
color=self.params.color,
614614
)
615615
)
616+
617+
def _set_curve_alpha(self, curves, alpha=None) -> None:
618+
if alpha is None:
619+
alpha = self.params.alpha
620+
for i, curve in enumerate(curves):
621+
if curve.opts["pen"].color().alphaF() != alpha:
622+
col = curve.opts["pen"].color()
623+
col.setAlphaF(alpha)
624+
curve.setPen(color=col)

0 commit comments

Comments
 (0)