Skip to content

Commit

Permalink
add argument setting dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
yconst committed Aug 29, 2023
1 parent 7de0d92 commit 6e53727
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
3 changes: 2 additions & 1 deletion studio/Python/tinymovr/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
)
from tinymovr.gui.widgets import (
OurQTreeWidget,
IconComboBoxWidget
IconComboBoxWidget,
ArgumentInputDialog
)
from tinymovr.gui.worker import Worker
from tinymovr.gui.window import MainWindow
Expand Down
49 changes: 48 additions & 1 deletion studio/Python/tinymovr/gui/widgets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
from PySide6 import QtGui
from PySide6.QtGui import QPixmap
from PySide6.QtWidgets import QWidget, QTreeWidget, QHBoxLayout, QLabel, QComboBox
from PySide6.QtWidgets import (
QWidget,
QTreeWidget,
QHBoxLayout,
QLabel,
QComboBox,
QDialog,
QVBoxLayout,
QLabel,
QLineEdit,
QPushButton,
QFormLayout,
)

from tinymovr.gui.helpers import load_pixmap


class OurQTreeWidget(QTreeWidget):
def __init__(self, parent=None):
super().__init__(parent)
Expand Down Expand Up @@ -45,3 +59,36 @@ def __init__(self, icon_path, parent=None):
layout.addWidget(self.combo)

self.setLayout(layout)


class ArgumentInputDialog(QDialog):
def __init__(self, arguments, parent=None):
super(ArgumentInputDialog, self).__init__(parent)
self.arguments = arguments
self.inputs = {}

layout = QFormLayout(self)

# For each argument, create a label and input line edit
for arg in arguments:
label = QLabel(f"{arg.name} ({arg.dtype.nickname}):")
line_edit = QLineEdit(self)
layout.addRow(label, line_edit)
self.inputs[arg.name] = line_edit

# Add Ok and Cancel buttons
button_layout = QVBoxLayout()
ok_button = QPushButton("Ok", self)
ok_button.clicked.connect(self.accept)
cancel_button = QPushButton("Cancel", self)
cancel_button.clicked.connect(self.reject)
button_layout.addWidget(ok_button)
button_layout.addWidget(cancel_button)

layout.addRow(button_layout)
self.setLayout(layout)

def get_values(self):
return {
arg_name: line_edit.text() for arg_name, line_edit in self.inputs.items()
}
33 changes: 27 additions & 6 deletions studio/Python/tinymovr/gui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from PySide6.QtCore import Signal
from PySide6.QtWidgets import (
QMainWindow,
QDialog,
QMenu,
QMenuBar,
QWidget,
Expand All @@ -34,7 +35,7 @@
QLabel,
QTreeWidgetItem,
QPushButton,
QMessageBox
QMessageBox,
)
from pint.errors import UndefinedUnitError
from PySide6.QtGui import QAction
Expand All @@ -48,6 +49,7 @@
Worker,
OurQTreeWidget,
IconComboBoxWidget,
ArgumentInputDialog,
format_value,
load_icon,
display_file_open_dialog,
Expand All @@ -58,7 +60,6 @@


class MainWindow(QMainWindow):

TreeItemCheckedSignal = Signal(dict)

def __init__(self, app, arguments):
Expand Down Expand Up @@ -306,7 +307,22 @@ def attrs_updated(self, data):

@QtCore.Slot()
def f_call_clicked(self, f):
f()
args = []

# Check if the function has any arguments
if f.arguments:
dialog = ArgumentInputDialog(f.arguments, self)
if dialog.exec_() == QDialog.Accepted:
input_values = dialog.get_values()
args = [input_values[arg.name] for arg in f.arguments]
else:
return # User cancelled, stop the entire process

# Convert arguments as required using pint
args = [get_registry()(arg) for arg in args]

# Call the function with the collected arguments
f(*args)
if "reload_data" in f.meta and f.meta["reload_data"]:
self.worker.reset()

Expand Down Expand Up @@ -353,7 +369,12 @@ def delete_graphs(self):
self.delete_graph_by_attr_name(attr_name)

def show_about_box(self):
version_str = (pkg_resources.require("tinymovr")[0].version)
version_str = pkg_resources.require("tinymovr")[0].version
app_str = "{} {}".format(app_name, version_str)
QMessageBox.about(self, "About Tinymovr", "{}\nhttps://tinymovr.com\n\nCat Sleeping Icon by Denis Sazhin from Noun Project".format(app_str))

QMessageBox.about(
self,
"About Tinymovr",
"{}\nhttps://tinymovr.com\n\nCat Sleeping Icon by Denis Sazhin from Noun Project".format(
app_str
),
)

0 comments on commit 6e53727

Please sign in to comment.