Skip to content

Commit

Permalink
Merge pull request #138 from TimMonko/widget-layout-improvements
Browse files Browse the repository at this point in the history
APOC Widget layout improvements
  • Loading branch information
TimMonko authored Dec 23, 2024
2 parents c3833c8 + 3affa82 commit 04c922b
Showing 1 changed file with 37 additions and 23 deletions.
60 changes: 37 additions & 23 deletions src/napari_ndev/widgets/_apoc_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy as np
import pandas as pd
from magicclass.widgets import ScrollableContainer, TabbedContainer
from magicgui.widgets import (
CheckBox,
ComboBox,
Expand All @@ -21,7 +22,6 @@
SpinBox,
Table,
)
from qtpy.QtWidgets import QTabWidget

from napari import layers
from napari_ndev import helpers
Expand All @@ -30,7 +30,7 @@
import napari


class ApocContainer(Container):
class ApocContainer(ScrollableContainer):
"""
Container class for managing the ApocContainer widget in napari.
Expand Down Expand Up @@ -153,10 +153,11 @@ def __init__(
viewer: napari.viewer.Viewer = None,
# viewer = napari_viewer
):
super().__init__()
super().__init__(labels=False)
self.min_width = 600 # TODO: remove this hardcoded value
self._viewer = viewer if viewer is not None else None
self._lazy_imports()
self._initialize_widgets()
self._initialize_cl_container()
self._initialize_batch_container()
self._initialize_viewer_container()
self._initialize_custom_apoc_container()
Expand All @@ -174,7 +175,7 @@ def _filter_layers(self, layer_type):
return []
return [x for x in self._viewer.layers if isinstance(x, layer_type)]

def _initialize_widgets(self):
def _initialize_cl_container(self):
self._classifier_file = FileEdit(
label='Classifier File (.cl)',
mode='w',
Expand Down Expand Up @@ -238,6 +239,19 @@ def _initialize_widgets(self):
'A string in the form of ' "'filter1=radius1 filter2=radius2'."
),
)
self._cl_container = Container()
self._cl_container.extend(
[
self._classifier_file,
self._continue_training,
self._classifier_type,
self._max_depth,
self._num_trees,
self._positive_class_id,
self._predefined_features,
self._feature_string,
]
)

def _initialize_batch_container(self):
self._image_directory = FileEdit(label='Image Directory', mode='d')
Expand Down Expand Up @@ -274,7 +288,7 @@ def _initialize_batch_container(self):

self._progress_bar = ProgressBar(label='Progress:')

self._batch_container = Container(layout='vertical')
self._batch_container = Container(layout='vertical', label='Batch')
self._batch_container.extend(
[
self._image_directory,
Expand All @@ -301,9 +315,9 @@ def _initialize_viewer_container(self):
self._predict_image_layer = PushButton(
label='Predict using classifier on selected layers'
)
self._single_result_label = Label()
self._single_result_label = LineEdit()

self._viewer_container = Container(layout='vertical')
self._viewer_container = Container(layout='vertical', label='Viewer')
self._viewer_container.extend(
[
self._image_layers,
Expand All @@ -318,27 +332,27 @@ def _initialize_custom_apoc_container(self):
from napari_ndev import ApocFeatureStack

self._custom_apoc_container = ApocFeatureStack(viewer=self._viewer)
self._custom_apoc_container.label = 'Custom Feature Set'

def _setup_widget_layout(self):
# from napari_ndev import ApocFeatureStack
self.extend(
self.append(self._cl_container)

# tabs = QTabWidget()
# tabs.addTab(self._batch_container.native, 'Batch')
# tabs.addTab(self._viewer_container.native, 'Viewer')
# tabs.addTab(self._custom_apoc_container.native, 'Custom Feature Set')
# self.native.layout().addWidget(tabs)

tabs = TabbedContainer(label=None, labels=None)
tabs.extend(
[
self._classifier_file,
self._continue_training,
self._classifier_type,
self._positive_class_id,
self._max_depth,
self._num_trees,
self._predefined_features,
self._feature_string,
self._batch_container,
self._viewer_container,
self._custom_apoc_container,
]
)

tabs = QTabWidget()
tabs.addTab(self._batch_container.native, 'Batch')
tabs.addTab(self._viewer_container.native, 'Viewer')
tabs.addTab(self._custom_apoc_container.native, 'Custom Feature Set')
self.native.layout().addWidget(tabs)
self.extend([tabs])

def _connect_events(self):
self._image_directory.changed.connect(self._update_metadata_from_file)
Expand Down

0 comments on commit 04c922b

Please sign in to comment.