Skip to content

Commit

Permalink
loader and home docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aelefebv committed Oct 3, 2024
1 parent 6db7b38 commit 6467da5
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
44 changes: 44 additions & 0 deletions nellie_napari/nellie_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,43 @@


class Home(QWidget):
"""
The Home screen for the Nellie application, displayed in the napari viewer.
It provides options to start using the application, navigate to the file selection tab, and take screenshots.
Attributes
----------
viewer : napari.viewer.Viewer
The napari viewer instance.
nellie : object
Reference to the main Nellie object containing image processing pipelines and functions.
layout : QVBoxLayout
The vertical layout to organize the widgets on the home screen.
start_button : QPushButton
Button to start the application and navigate to the file selection tab.
screenshot_button : QPushButton
Button to take a screenshot of the current napari viewer canvas.
Methods
-------
__init__(napari_viewer, nellie, parent=None)
Initializes the home screen with a logo, title, description, and navigation buttons.
screenshot(event=None)
Takes a screenshot of the napari viewer and saves it to a specified folder.
"""
def __init__(self, napari_viewer: 'napari.viewer.Viewer', nellie, parent=None):
"""
Initializes the Home screen with a logo, title, description, and buttons for navigation and screenshot functionality.
Parameters
----------
napari_viewer : napari.viewer.Viewer
Reference to the napari viewer instance.
nellie : object
Reference to the main Nellie object containing image processing pipelines and functions.
parent : QWidget, optional
Optional parent widget (default is None).
"""
super().__init__(parent)
self.nellie = nellie
self.viewer = napari_viewer
Expand Down Expand Up @@ -72,6 +108,14 @@ def __init__(self, napari_viewer: 'napari.viewer.Viewer', nellie, parent=None):
self.layout.addWidget(self.screenshot_button, alignment=Qt.AlignCenter)

def screenshot(self, event=None):
"""
Takes a screenshot of the napari viewer and saves it as a PNG file in a specified folder.
Parameters
----------
event : optional
An event object, if triggered by a key binding or button click (default is None).
"""
if self.nellie.im_info is None:
show_info("No file selected, cannot take screenshot")
return
Expand Down
69 changes: 69 additions & 0 deletions nellie_napari/nellie_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,54 @@


class NellieLoader(QTabWidget):
"""
The main loader class for managing the different stages of the Nellie pipeline within the napari viewer. This class
provides a tabbed interface for file selection, processing, visualization, analysis, and settings management.
Attributes
----------
home : Home
The home tab instance, providing an overview of the Nellie pipeline.
file_select : NellieFileSelect
The file selection tab instance, allowing users to select and validate image files.
processor : NellieProcessor
The image processing tab instance, where users can process images through the Nellie pipeline.
visualizer : NellieVisualizer
The visualization tab instance, where processed images can be visualized.
analyzer : NellieAnalysis
The analysis tab instance, enabling users to analyze processed image data.
settings : Settings
The settings tab instance, allowing users to configure various settings for the Nellie pipeline.
home_tab, file_select_tab, processor_tab, visualizer_tab, analysis_tab, settings_tab : int
Integer values representing the index of the respective tabs.
im_info : ImInfo or None
Contains metadata and information about the selected image file.
im_info_list : list of ImInfo or None
A list of ImInfo objects when batch processing is enabled (multiple files).
Methods
-------
add_tabs()
Adds the individual tabs to the widget.
reset()
Resets the state of the loader, removing and reinitializing all tabs.
on_tab_change(index)
Slot that is triggered when the user changes the tab.
go_process()
Initializes and enables the processing and visualization tabs for image processing.
"""
def __init__(self, napari_viewer: 'napari.viewer.Viewer', parent=None):
"""
Initializes the NellieLoader class, creating instances of the individual tabs for home, file selection,
processing, visualization, analysis, and settings.
Parameters
----------
napari_viewer : napari.viewer.Viewer
Reference to the napari viewer instance.
parent : QWidget, optional
Optional parent widget (default is None).
"""
super().__init__(parent)
self.home = Home(napari_viewer, self)
self.file_select = NellieFileSelect(napari_viewer, self)
Expand All @@ -33,6 +80,11 @@ def __init__(self, napari_viewer: 'napari.viewer.Viewer', parent=None):
self.im_info_list = None

def add_tabs(self):
"""
Adds the individual tabs for Home, File validation, Process, Visualize, Analyze, and Settings.
Initially disables the Process, Visualize, and Analyze tabs until they are needed.
"""
...
self.home_tab = self.addTab(self.home, "Home")
self.file_select_tab = self.addTab(self.file_select, "File validation")
self.processor_tab = self.addTab(self.processor, "Process")
Expand All @@ -45,6 +97,10 @@ def add_tabs(self):
self.setTabEnabled(self.analysis_tab, False)

def reset(self):
"""
Resets the state of the loader, reinitializing all tabs. This method is typically called when the user
wants to start a new session with a fresh file selection and settings.
"""
self.setCurrentIndex(self.home_tab)

# needs to be in reverse order
Expand All @@ -66,6 +122,15 @@ def reset(self):
self.im_info_list = None

def on_tab_change(self, index):
"""
Event handler that is triggered when the user changes the active tab. Initializes the Analyze or Visualize
tabs if they are selected for the first time, and always initializes the Settings tab.
Parameters
----------
index : int
The index of the newly selected tab.
"""
if index == self.analysis_tab: # Check if the Analyze tab is selected
if not self.analyzer.initialized:
show_info("Initializing analysis tab")
Expand All @@ -77,6 +142,10 @@ def on_tab_change(self, index):
self.settings.post_init()

def go_process(self):
"""
Prepares the image(s) for processing and visualization. This method is called after a file has been selected
and validated. It enables the Process and Visualize tabs and initializes them.
"""
if self.file_select.batch_fileinfo_list is None:
self.im_info = self.file_select.im_info
else:
Expand Down

0 comments on commit 6467da5

Please sign in to comment.