Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies = [
"copick[all]>=1.5.0",
"zarr<3",
"numpy>=1.21.0",
"superqt"
]
authors = [
{name = "Utz H. Ermel", email = "utz@ermel.me"},
Expand Down
6 changes: 3 additions & 3 deletions src/copick_shared_ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__version__ = "0.1.1"

# Core components
from .core import (
from copick_shared_ui.core import (
AbstractImageInterface,
AbstractInfoSessionInterface,
AbstractSessionInterface,
Expand All @@ -15,10 +15,10 @@
)

# UI components
from .ui.edit_object_types_dialog import ColorButton, EditObjectTypesDialog
from copick_shared_ui.ui.edit_object_types_dialog import ColorButton, EditObjectTypesDialog

# Utilities
from .util.validation import generate_smart_copy_name, get_invalid_characters, validate_copick_name
from copick_shared_ui.util.validation import generate_smart_copy_name, get_invalid_characters, validate_copick_name

__all__ = [
# Core interfaces and caching
Expand Down
4 changes: 2 additions & 2 deletions src/copick_shared_ui/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Core shared components for copick UI."""

from .models import (
from copick_shared_ui.core.models import (
AbstractImageInterface,
AbstractInfoSessionInterface,
AbstractSessionInterface,
AbstractThemeInterface,
AbstractWorkerInterface,
)
from .thumbnail_cache import ThumbnailCache, get_global_cache, set_global_cache_config
from copick_shared_ui.core.thumbnail_cache import ThumbnailCache, get_global_cache, set_global_cache_config

__all__ = [
"AbstractImageInterface",
Expand Down
48 changes: 39 additions & 9 deletions src/copick_shared_ui/core/image_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Any, Optional

from .thumbnail_cache import ImageInterface
from copick_shared_ui.core.thumbnail_cache import ImageInterface


class QtImageInterface(ImageInterface):
Expand Down Expand Up @@ -30,6 +30,7 @@ def _setup_qt(self) -> None:
self._QPixmap = QPixmap
self._qt_available = True
except ImportError:
print("❌ No Qt interface available")
self._qt_available = False

def save_image(self, image: Any, path: str, format: str = "PNG") -> bool:
Expand All @@ -43,14 +44,24 @@ def save_image(self, image: Any, path: str, format: str = "PNG") -> bool:
Returns:
True if successful, False otherwise
"""
if not self._qt_available or not image:
if not self._qt_available:
print("❌ Qt not available for save operation")
return False

if not image:
print("❌ No image provided for save operation")
return False

try:
# QPixmap has a save method
return image.save(path, format)
result = image.save(path, format)

return result
except Exception as e:
print(f"Error saving image: {e}")
print(f"❌ Error saving image: {e}")
import traceback

print(f"❌ Stack trace: {traceback.format_exc()}")
return False

def load_image(self, path: str) -> Optional[Any]:
Expand All @@ -63,13 +74,24 @@ def load_image(self, path: str) -> Optional[Any]:
QPixmap object if successful, None otherwise
"""
if not self._qt_available:
print("❌ Qt not available for load operation")
return None

try:
from pathlib import Path

pixmap = self._QPixmap(path)
return pixmap if not pixmap.isNull() else None

if pixmap:
is_null = pixmap.isNull()
return pixmap if not is_null else None
else:
return None
except Exception as e:
print(f"Error loading image: {e}")
print(f"❌ Error loading image: {e}")
import traceback

print(f"❌ Stack trace: {traceback.format_exc()}")
return None

def is_valid_image(self, image: Any) -> bool:
Expand All @@ -81,13 +103,21 @@ def is_valid_image(self, image: Any) -> bool:
Returns:
True if valid, False otherwise
"""
if not self._qt_available or not image:
if not self._qt_available:
print("❌ Qt not available for validation")
return False

if not image:
print("❌ No image provided for validation")
return False

try:
# QPixmap has isNull method
return not image.isNull()
except Exception:
is_null = image.isNull()
is_valid = not is_null
return is_valid
except Exception as e:
print(f"❌ Error validating image: {e}")
return False


Expand Down
2 changes: 1 addition & 1 deletion src/copick_shared_ui/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def create_pixmap_from_array(self, array: Any) -> Any:
return None

@abstractmethod
def scale_pixmap(self, pixmap: Any, size: tuple, smooth: bool = True) -> Any:
def scale_pixmap(self, pixmap: Any, size: tuple, smooth: bool = False) -> Any:
"""Scale a pixmap to the specified size."""
pass

Expand Down
Loading