-
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 all commits
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 |
---|---|---|
|
@@ -1241,6 +1241,20 @@ export class ToastView extends View { | |
} | ||
} | ||
|
||
/** | ||
* Operator class for rendering a execution button. | ||
*/ | ||
|
||
class OperatorExecutionButtonView extends View { | ||
constructor(options: ViewProps) { | ||
super(options); | ||
this.name = "OperatorExecutionButtonView"; | ||
} | ||
static fromJSON(json) { | ||
return new OperatorExecutionButtonView(json); | ||
} | ||
} | ||
|
||
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. Add OperatorExecutionButtonView to VIEWS constant. The new view class needs to be added to the VIEWS constant to support proper JSON deserialization through the viewFromJSON function. const VIEWS = {
View,
InferredView,
Form,
ReadOnlyView,
// ... other views
PillBadgeView,
ModalView,
ToastView,
+ OperatorExecutionButtonView,
};
|
||
/** | ||
* Places where you can have your operator placement rendered. | ||
*/ | ||
|
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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1392
to
+1399
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. Correct parameter types and defaults in the docstring There are discrepancies between the docstring and the method implementation:
Suggested fix: Update the docstring to accurately reflect parameter types and default values. Args:
icon (str, optional): an icon for the button. Defaults to "expand_more".
label (str, optional): a label for the button.
description (str, optional): a description for the button.
title (str, optional): a tooltip title for the button.
operator (str): the name of the operator to execute when the button is clicked.
params (dict, optional): the parameters to pass to the operator.
- prompt (str): a prompt for the operation.
+ prompt (bool, optional): whether to prompt the user before executing the operator.
disabled (bool, optional): whether the button is disabled. Additionally, align the default values in the code with those specified in the docstring.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Export the OperatorExecutionButtonView class.
The class should be exported to make it available for use in other modules, following the pattern of other view classes in this file.
📝 Committable suggestion