🔍 Code Extractor

class Scrollmenu

Maturity: 57

A horizontal scroll menu component that displays a series of clickable icons representing different stages of a pathology workflow, built using Panel's ReactiveHTML for enhanced CSS customization.

File:
/tf/active/vicechatdev/resources/py2html.py
Lines:
21 - 86
Complexity:
moderate

Purpose

This class creates an interactive navigation menu for a pathology laboratory workflow system. It displays nine stages (Delivery, Registration, Grossing, Embedding, Sectioning, Staining, Scanning, Assessment, Report) as clickable icons. When an icon is clicked, the component updates its 'selected' parameter to reflect the current stage. Each stage icon can have its CSS class dynamically controlled through corresponding parameters, allowing for visual state changes (e.g., highlighting active stages). The component is designed to work within Panel applications and uses ReactiveHTML to provide better CSS control than standard Python-based Panel components.

Source Code

class Scrollmenu(ReactiveHTML):
    """
    A horizontal scroll menu of our images, using ReactiveHTML instead of python for improved CSS freedom.
    
    Attributes
    ----------
    _template : str
        The HTML string. The onclick ${} links to a python function
        
    Parameters
    ----------
    delivery : param.String
        css class for delivery icon
    """
    
    selected = param.String()
    
    delivery = param.String()
    registration = param.String()
    grossing = param.String()
    embedding = param.String()
    sectioning = param.String()
    staining = param.String()
    scanning = param.String()
    assessment = param.String()
    report = param.String()
    
    _template = """
<div class="scrollmenu">
  <div class="wrapper"><img id="Delivery" class="${delivery}" src="./custom_static/images/Delivery.png" onclick="${_delivery_click}" style="width:60px !important;"/></div>
  <div class="wrapper"><img id="Registration" class="${registration}" src="./custom_static/images/Registration.png" onclick="${_registration_click}"/></div>
  <div class="wrapper"><img id="Grossing" class="${grossing}" src="./custom_static/images/Grossing.png" onclick="${_grossing_click}" style="width:70px !important;"/></div>
  <div class="wrapper"><img id="Embedding" class="${embedding}" src="./custom_static/images/Embedding.png" onclick="${_embedding_click}"/></div>
  <div class="wrapper"><img id="Sectioning" class="${sectioning}" src="./custom_static/images/Sectioning.png" onclick="${_sectioning_click}"/></div>
  <div class="wrapper"><img id="Staining" class="${staining}" src="./custom_static/images/Staining.png" onclick="${_staining_click}"/></div>
  <div class="wrapper"><img id="Scanning" class="${scanning}" src="./custom_static/images/Scanning.png" onclick="${_scanning_click}"/></div>
  <div class="wrapper"><img id="Assessment" class="${assessment}" src="./custom_static/images/Assessment.png" onclick="${_assessment_click}" style="width:50px !important;"/></div>
  <div class="wrapper"><img id="Report" class="${report}" src="./custom_static/images/Report.png" onclick="${_report_click}" style="width:50px !important;"/></div>
</div>
    """
    def _delivery_click(self, event):
        self.selected = 'Delivery'

    def _registration_click(self, event):
        self.selected='Registration'
        
    def _grossing_click(self, event):
        self.selected = 'Grossing'
    
    def _embedding_click(self, event):
        self.selected = 'Embedding'
        
    def _sectioning_click(self, event):
        self.selected = 'Sectioning'
        
    def _staining_click(self, event):
        self.selected = 'Staining'
        
    def _scanning_click(self, event):
        self.selected = 'Scanning'
    
    def _assessment_click(self, event):
        self.selected = 'Assessment'
        
    def _report_click(self, event):
        self.selected = 'Report'

Parameters

Name Type Default Kind
bases ReactiveHTML -

Parameter Details

delivery: CSS class name to apply to the Delivery icon, allowing dynamic styling based on state (e.g., 'active', 'completed', 'disabled')

registration: CSS class name to apply to the Registration icon for dynamic styling

grossing: CSS class name to apply to the Grossing icon for dynamic styling

embedding: CSS class name to apply to the Embedding icon for dynamic styling

sectioning: CSS class name to apply to the Sectioning icon for dynamic styling

staining: CSS class name to apply to the Staining icon for dynamic styling

scanning: CSS class name to apply to the Scanning icon for dynamic styling

assessment: CSS class name to apply to the Assessment icon for dynamic styling

report: CSS class name to apply to the Report icon for dynamic styling

Return Value

Instantiation returns a Scrollmenu object that inherits from ReactiveHTML. The object renders as an HTML component with a horizontal scrollable menu of icons. The 'selected' attribute returns a string indicating which stage was last clicked (one of: 'Delivery', 'Registration', 'Grossing', 'Embedding', 'Sectioning', 'Staining', 'Scanning', 'Assessment', 'Report'). Click handler methods (_delivery_click, etc.) do not return values but update the 'selected' parameter as a side effect.

Class Interface

Methods

_delivery_click(self, event) -> None

Purpose: Internal click handler that sets the selected parameter to 'Delivery' when the Delivery icon is clicked

Parameters:

  • event: Click event object passed by the ReactiveHTML framework containing event details

Returns: None - updates the 'selected' parameter as a side effect

_registration_click(self, event) -> None

Purpose: Internal click handler that sets the selected parameter to 'Registration' when the Registration icon is clicked

Parameters:

  • event: Click event object passed by the ReactiveHTML framework

Returns: None - updates the 'selected' parameter as a side effect

_grossing_click(self, event) -> None

Purpose: Internal click handler that sets the selected parameter to 'Grossing' when the Grossing icon is clicked

Parameters:

  • event: Click event object passed by the ReactiveHTML framework

Returns: None - updates the 'selected' parameter as a side effect

_embedding_click(self, event) -> None

Purpose: Internal click handler that sets the selected parameter to 'Embedding' when the Embedding icon is clicked

Parameters:

  • event: Click event object passed by the ReactiveHTML framework

Returns: None - updates the 'selected' parameter as a side effect

_sectioning_click(self, event) -> None

Purpose: Internal click handler that sets the selected parameter to 'Sectioning' when the Sectioning icon is clicked

Parameters:

  • event: Click event object passed by the ReactiveHTML framework

Returns: None - updates the 'selected' parameter as a side effect

_staining_click(self, event) -> None

Purpose: Internal click handler that sets the selected parameter to 'Staining' when the Staining icon is clicked

Parameters:

  • event: Click event object passed by the ReactiveHTML framework

Returns: None - updates the 'selected' parameter as a side effect

_scanning_click(self, event) -> None

Purpose: Internal click handler that sets the selected parameter to 'Scanning' when the Scanning icon is clicked

Parameters:

  • event: Click event object passed by the ReactiveHTML framework

Returns: None - updates the 'selected' parameter as a side effect

_assessment_click(self, event) -> None

Purpose: Internal click handler that sets the selected parameter to 'Assessment' when the Assessment icon is clicked

Parameters:

  • event: Click event object passed by the ReactiveHTML framework

Returns: None - updates the 'selected' parameter as a side effect

_report_click(self, event) -> None

Purpose: Internal click handler that sets the selected parameter to 'Report' when the Report icon is clicked

Parameters:

  • event: Click event object passed by the ReactiveHTML framework

Returns: None - updates the 'selected' parameter as a side effect

Attributes

Name Type Description Scope
selected param.String Stores the name of the currently selected workflow stage. Updated when any icon is clicked. Can be one of: 'Delivery', 'Registration', 'Grossing', 'Embedding', 'Sectioning', 'Staining', 'Scanning', 'Assessment', 'Report' class
delivery param.String CSS class name applied to the Delivery icon element, allowing dynamic styling based on state class
registration param.String CSS class name applied to the Registration icon element, allowing dynamic styling based on state class
grossing param.String CSS class name applied to the Grossing icon element, allowing dynamic styling based on state class
embedding param.String CSS class name applied to the Embedding icon element, allowing dynamic styling based on state class
sectioning param.String CSS class name applied to the Sectioning icon element, allowing dynamic styling based on state class
staining param.String CSS class name applied to the Staining icon element, allowing dynamic styling based on state class
scanning param.String CSS class name applied to the Scanning icon element, allowing dynamic styling based on state class
assessment param.String CSS class name applied to the Assessment icon element, allowing dynamic styling based on state class
report param.String CSS class name applied to the Report icon element, allowing dynamic styling based on state class
_template str HTML template string defining the structure and layout of the scroll menu. Contains placeholders for parameter values and onclick event handlers that link to Python methods class

Dependencies

  • param
  • panel

Required Imports

import param
import panel as pn
from panel.reactive import ReactiveHTML

Usage Example

import panel as pn
from panel.reactive import ReactiveHTML
import param

# Initialize Panel
pn.extension()

# Instantiate the Scrollmenu
menu = Scrollmenu(
    delivery='active',
    registration='inactive',
    grossing='inactive',
    embedding='inactive',
    sectioning='inactive',
    staining='inactive',
    scanning='inactive',
    assessment='inactive',
    report='inactive'
)

# Watch for selection changes
def on_selection_change(event):
    print(f'Selected stage: {event.new}')
    # Update CSS classes based on selection
    for stage in ['delivery', 'registration', 'grossing', 'embedding', 'sectioning', 'staining', 'scanning', 'assessment', 'report']:
        setattr(menu, stage, 'active' if event.new.lower() == stage else 'inactive')

menu.param.watch(on_selection_change, 'selected')

# Display in a Panel app
app = pn.template.FastListTemplate(
    title='Pathology Workflow',
    main=[menu]
)
app.servable()

Best Practices

  • Always initialize Panel with pn.extension() before instantiating this class
  • Ensure all required image files exist in the './custom_static/images/' directory before rendering
  • Use the param.watch() method to observe changes to the 'selected' parameter and react to user clicks
  • Set appropriate CSS classes for each stage parameter to provide visual feedback (e.g., 'active', 'completed', 'disabled')
  • The component is stateful - the 'selected' parameter persists the last clicked stage
  • Click handlers are internal methods (prefixed with _) and should not be called directly
  • CSS classes should be defined in your application's stylesheet to control the appearance of icons in different states
  • The component uses ReactiveHTML, so changes to parameters automatically trigger re-rendering of affected elements
  • Consider implementing validation logic to ensure only valid workflow transitions are allowed
  • The 'selected' parameter can be set programmatically to change the active stage without user interaction

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class Toolbar 57.5% similar

    A reactive HTML toolbar component that displays social media links and a settings button, tracking the number of clicks on the settings icon.

    From: /tf/active/vicechatdev/resources/py2html.py
  • class Study_progress_v1 53.5% similar

    A Panel ReactiveHTML component that displays study progress as a visual taskbar with completed and pending items represented by SVG icons.

    From: /tf/active/vicechatdev/resources/py2html.py
  • class Clickable_header 53.4% similar

    A clickable header component that displays text as a hyperlink and tracks the number of times it has been clicked.

    From: /tf/active/vicechatdev/resources/py2html.py
  • class Inbox 53.2% similar

    A reactive HTML component that displays a mailbox/notification icon with a badge indicator and tracks user clicks.

    From: /tf/active/vicechatdev/resources/py2html.py
  • class Study_progress 53.1% similar

    A Panel ReactiveHTML component that displays study progress as a visual taskbar with completed and pending items represented by SVG icons.

    From: /tf/active/vicechatdev/resources/.ipynb_checkpoints/py2html-checkpoint.py
← Back to Browse