Skip to content

Commit 41a96b3

Browse files
committed
before merge j branch
1 parent b3420da commit 41a96b3

File tree

3 files changed

+76
-16
lines changed

3 files changed

+76
-16
lines changed

src/pymapmanager/interface/stackWidgets/channelEditor.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
import os
23
from pprint import pprint
34
from PyQt5.QtWidgets import (
45
QApplication, QWidget, QVBoxLayout, QLabel, QFrame, QHBoxLayout, QLineEdit,
@@ -7,6 +8,8 @@
78
from PyQt5.QtCore import Qt, QPoint, pyqtSignal, QMimeData
89
from PyQt5.QtGui import QPainter, QColor, QDrag, QPixmap
910

11+
from mapmanagercore.imageImporter import acceptedExtensions
12+
1013
from pymapmanager.interface import PyMapManagerApp
1114
from pymapmanager.interface.stackWidgets.stackWidget import stackWidget
1215
from pymapmanager.interface.stackWidgets.base.mmWidget2 import mmWidget2, pmmEventType
@@ -338,11 +341,18 @@ def __init__(self, stackWidget:stackWidget):
338341
# status_label.setStyleSheet("QLabel { color: #666; }")
339342
# toolbar_layout.addWidget(status_label)
340343

341-
count_label = QLabel("Channels: 0")
344+
shapeTuple = self.getStackWidget().getStack().getMetadata().shape
345+
count_label = QLabel(f"Pixels:{shapeTuple}")
342346
count_label.setObjectName("count_label")
343347
count_label.setStyleSheet("QLabel { color: #666; }")
344348
toolbar_layout.addWidget(count_label)
345349

350+
voxelTuple = self.getStackWidget().getStack().getMetadata().voxelMetadata.shape
351+
voxelLabel = QLabel(f"Voxels:{voxelTuple}")
352+
voxelLabel.setObjectName("voxelLabel")
353+
voxelLabel.setStyleSheet("QLabel { color: #666; }")
354+
toolbar_layout.addWidget(voxelLabel)
355+
346356
# Add Import File button to top toolbar
347357
self.importButton = QPushButton("Import File")
348358
self.importButton.setAcceptDrops(True)
@@ -573,19 +583,35 @@ def onImportButtonClicked(self):
573583

574584
def onImportButtonDragEnter(self, event):
575585
"""Handle drag enter event on import button."""
586+
576587
if event.mimeData().hasUrls():
577-
event.acceptProposedAction()
578-
self.importButton.setStyleSheet("""
579-
QPushButton {
580-
background-color: #2196F3;
581-
color: white;
582-
border: 2px dashed #1976D2;
583-
padding: 6px 12px;
584-
border-radius: 4px;
585-
font-weight: bold;
586-
font-size: 12px;
587-
}
588-
""")
588+
# Check if any of the dragged files have accepted extensions
589+
accepted_exts = acceptedExtensions()
590+
has_valid_file = False
591+
592+
for url in event.mimeData().urls():
593+
file_path = url.toLocalFile()
594+
if file_path:
595+
_, ext = os.path.splitext(file_path)
596+
if ext in accepted_exts:
597+
has_valid_file = True
598+
break
599+
600+
if has_valid_file:
601+
event.acceptProposedAction()
602+
self.importButton.setStyleSheet("""
603+
QPushButton {
604+
background-color: #2196F3;
605+
color: white;
606+
border: 2px dashed #1976D2;
607+
padding: 6px 12px;
608+
border-radius: 4px;
609+
font-weight: bold;
610+
font-size: 12px;
611+
}
612+
""")
613+
else:
614+
event.ignore()
589615
else:
590616
event.ignore()
591617

@@ -607,9 +633,17 @@ def onImportButtonDrop(self, event):
607633
file_paths.append(file_path)
608634

609635
if file_paths:
610-
self.filesImported.emit(file_paths)
636+
# self.filesImported.emit(file_paths)
611637
print(f"Files dropped: {file_paths}")
612638

639+
editChannelEvent = EditChannelEvent(
640+
eventType = pmmEventType.editChannel,
641+
mmWidget = self.getStackWidget(),
642+
editType = ChannelEditType.import_new_channel,
643+
importPath = file_paths[0] # just the first file
644+
)
645+
self.emitEvent(editChannelEvent)
646+
613647
# Reset button style
614648
self.importButton.setStyleSheet("""
615649
QPushButton {

src/pymapmanager/interface/stackWidgets/stackWidget.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,8 @@ def editChannelEvent(self, event : EditChannelEvent):
13681368
if _deleted is None:
13691369
return False
13701370

1371+
self._topToolbar._setStack(theStack=self._stack)
1372+
13711373
# if _topToolbar is displaying the deleted channel, need to update it
13721374
if self._topToolbar.getCurrentChannel() == event.getSrcChannelKey():
13731375
channelKeys = self.getStack().getChannelKeys()
@@ -1417,11 +1419,27 @@ def loadInNewChannel(self, path:Optional[str] = None) -> int | None:
14171419
self, path: Union[str, np.ndarray], time: int = 0, channel: int = 0):
14181420
"""
14191421
if path is None:
1420-
importPath = QtWidgets.QFileDialog.getOpenFileName(None, 'New Tif File')[0]
1422+
from mapmanagercore.imageImporter import acceptedExtensions
1423+
# importPath = QtWidgets.QFileDialog.getOpenFileName(None, 'Import File')[0]
1424+
# Create filter string from accepted extensions
1425+
filter_parts = []
1426+
for ext in acceptedExtensions():
1427+
filter_parts.append(f"*{ext}")
1428+
1429+
# Combine all extensions into a single filter
1430+
file_filter = f"Import Files ({';'.join(filter_parts)})"
1431+
1432+
importPath, _ = QtWidgets.QFileDialog.getOpenFileName(
1433+
None,
1434+
'Import File',
1435+
"",
1436+
file_filter
1437+
)
14211438
# logger.info(f'importPath:{importPath}')
14221439
if importPath == '':
14231440
return None
14241441
else:
1442+
# assuming path is acceptable
14251443
importPath = path
14261444

14271445
logger.info(f"importing New channel")
@@ -1439,6 +1457,14 @@ def loadInNewChannel(self, path:Optional[str] = None) -> int | None:
14391457
return newChannelNum
14401458
else:
14411459
logger.warning(f"import new channel failed -->> show dialog")
1460+
1461+
# Show warning dialog to user
1462+
existingShape = self.getStack().getMetadata().shape
1463+
QtWidgets.QMessageBox.warning(
1464+
None, # parent widget
1465+
"Import Failed", # title
1466+
f"Import failed. The image pixels need to match existing shape {existingShape}} but got shape (x,y,z)" # message
1467+
)
14421468

14431469
def _old_swapChannels(self, srcChannel, destChannel):
14441470
""" Call mapmanagercore to swap channels

src/pymapmanager/timeseriesCore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def importChannels(self, importPath:str, time:int) -> int | None:
352352
None: If the import failed.
353353
"""
354354

355-
logger.warning(f'abb imageImport importPath {importPath} time:{time}')
355+
# logger.warning(f'abb imageImport importPath {importPath} time:{time}')
356356
channelNum = self._fullMap.loader.importChannel(importPath, time)
357357
if channelNum is not None:
358358
return channelNum

0 commit comments

Comments
 (0)