Skip to content

Commit

Permalink
Add a button for copying model config to clipboard (#1433)
Browse files Browse the repository at this point in the history
* Add shortcur for export_analysis_current

* Fix the linting issue

* Add the button without copy method'

* Add button for copying model config to clipboard

* Fix linting by reformatting

* Use Qtpy for clipboard rather than pyperclip

* Pretty print model config json to clipboard and fix missing command

* Fix the overwriting problem for dict object

* Delete unnecessary print statement

* Add a few comments & Remove unnecessary variables & remove unused function
  • Loading branch information
KevinZ0217 authored Aug 9, 2023
1 parent 2611e7d commit ad7529e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
31 changes: 27 additions & 4 deletions sleap/gui/learning/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from qtpy import QtWidgets, QtCore

import json

# List of fields which should show list of skeleton nodes
NODE_LIST_FIELDS = [
Expand Down Expand Up @@ -85,6 +86,9 @@ def __init__(

# Layout for buttons
buttons = QtWidgets.QDialogButtonBox()
self.copy_button = buttons.addButton(
"Copy to clipboard", QtWidgets.QDialogButtonBox.ActionRole
)
self.save_button = buttons.addButton(
"Save configuration files...", QtWidgets.QDialogButtonBox.ActionRole
)
Expand All @@ -94,6 +98,7 @@ def __init__(
self.cancel_button = buttons.addButton(QtWidgets.QDialogButtonBox.Cancel)
self.run_button = buttons.addButton("Run", QtWidgets.QDialogButtonBox.ApplyRole)

self.copy_button.setToolTip("Copy configuration to the clipboard")
self.save_button.setToolTip("Save scripts and configuration to run pipeline.")
self.export_button.setToolTip(
"Export data, configuration, and scripts for remote training and inference."
Expand Down Expand Up @@ -140,6 +145,7 @@ def __init__(
self.connect_signals()

# Connect actions for buttons
self.copy_button.clicked.connect(self.copy)
self.save_button.clicked.connect(self.save)
self.export_button.clicked.connect(self.export_package)
self.cancel_button.clicked.connect(self.reject)
Expand Down Expand Up @@ -674,10 +680,6 @@ def view_datagen(self):
datagen.show_datagen_preview(self.labels, config_info_list)
self.hide()

def on_button_click(self, button):
if button == self.save_button:
self.save()

def run(self):
"""Run with current dialog settings."""

Expand Down Expand Up @@ -717,6 +719,27 @@ def run(self):
win.setWindowTitle("Inference Results")
win.exec_()

def copy(self):
"""Copy scripts and configs to clipboard"""

# Get all info from dialog
pipeline_form_data = self.pipeline_form_widget.get_form_data()
config_info_list = self.get_every_head_config_data(pipeline_form_data)
pipeline_form_data = json.dumps(pipeline_form_data, indent=2)

# Format information for each tab in dialog
output = [pipeline_form_data]
for config_info in config_info_list:
config_info = config_info.config.to_json()
config_info = json.loads(config_info)
config_info = json.dumps(config_info, indent=2)
output.append(config_info)
output = "\n".join(output)

# Set the clipboard text
clipboard = QtWidgets.QApplication.clipboard()
clipboard.setText(output)

def save(
self, output_dir: Optional[str] = None, labels_filename: Optional[str] = None
):
Expand Down
1 change: 0 additions & 1 deletion sleap/gui/learning/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ def write_pipeline_files(
)
# And join them into a single call to inference
inference_script += " ".join(cli_args) + "\n"

# Setup job params
only_suggested_frames = False
if type(item_for_inference) == DatasetItemForInference:
Expand Down

0 comments on commit ad7529e

Please sign in to comment.