-
Notifications
You must be signed in to change notification settings - Fork 605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add exec button to py panels #5119
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1370,6 +1370,43 @@ def to_json(self): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class OperatorExecutionButtonView(Button): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Represents an operator execution button in a :class:`View`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Examples:: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import fiftyone.operators.types as types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
operatorButtonView = types.OperatorExecutionButtonView( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
icon="expand_more", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
operator="execute_custom_operator", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
params={"key": "value"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label="Execute", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description="Executes the specified operator", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
inputs = types.Object() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
inputs.view("operator_btn", operatorButtonView) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
icon (str): an icon for the button. Defaults to "expand_more" if not provided. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label (str): a label for the button. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description (str): a description for the button. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
title (str): a tooltip title for the button. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
operator (str): the name of the operator to execute when the button is clicked. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
params (dict): the parameters to pass to the operator. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
prompt (str): a prompt for the operation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
disabled (bool): whether the button is disabled. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def __init__(self, **kwargs): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if "operator" not in kwargs or not isinstance(kwargs["operator"], str): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"The 'operator' parameter of type str is required." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
super().__init__(**kwargs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1402
to
+1407
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Define explicit Explicitly defining parameters in the Proposed change: -def __init__(self, **kwargs):
+def __init__(
+ self,
+ operator: str,
+ icon: str = "expand_more",
+ label: Optional[str] = None,
+ description: Optional[str] = None,
+ title: Optional[str] = None,
+ params: Optional[dict] = None,
+ prompt: bool = False,
+ disabled: bool = False,
+ **kwargs,
+):
if not isinstance(operator, str):
raise ValueError("The 'operator' parameter of type str is required.")
- super().__init__(**kwargs)
+ super().__init__(
+ operator=operator,
+ icon=icon,
+ label=label,
+ description=description,
+ title=title,
+ params=params,
+ prompt=prompt,
+ disabled=disabled,
+ **kwargs,
+ ) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class OneOfView(View): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"""Displays one of the given :class:`View` instances. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct parameter types and defaults in the docstring
There are discrepancies between the docstring and the method implementation:
prompt
parameter is documented as(str)
but should be(bool)
.icon
defaults to"expand_more"
) are not reflected in the code.Suggested fix:
Update the docstring to accurately reflect parameter types and default values.
Additionally, align the default values in the code with those specified in the docstring.