Skip to content

Commit 95dc687

Browse files
SIM RFC: Add runtime installer ui (UBC-Thunderbots#3572)
* Add runtime installer modal and button to open * Add list of selectable runtimes, install button callback gets all selected * Fix typo * Add comment for function * Only fetch list of runtimes when modal is opened * [pre-commit.ci lite] apply automatic fixes * Add GL prefix to runtime installer modal * Import qtwidget classes directly * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 5819bb8 commit 95dc687

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

src/software/thunderscope/gl/widgets/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ load("@thunderscope_deps//:requirements.bzl", "requirement")
22

33
package(default_visibility = ["//visibility:public"])
44

5+
py_library(
6+
name = "gl_runtime_installer",
7+
srcs = ["gl_runtime_installer.py"],
8+
deps = [
9+
requirement("pyqtgraph"),
10+
],
11+
)
12+
513
py_library(
614
name = "gl_toolbar",
715
srcs = ["gl_toolbar.py"],
@@ -33,6 +41,7 @@ py_library(
3341
name = "gl_gamecontroller_toolbar",
3442
srcs = ["gl_gamecontroller_toolbar.py"],
3543
deps = [
44+
":gl_runtime_installer",
3645
":gl_toolbar",
3746
"//proto:import_all_protos",
3847
"//software/networking:ssl_proto_communication",

src/software/thunderscope/gl/widgets/gl_gamecontroller_toolbar.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import webbrowser
77
from software.thunderscope.gl.widgets.gl_toolbar import GLToolbar
88
from software.thunderscope.proto_unix_io import ProtoUnixIO
9+
from software.thunderscope.gl.widgets.gl_runtime_installer import (
10+
GLRuntimeInstallerDialog,
11+
)
912
import qtawesome as qta
1013

1114

@@ -95,6 +98,13 @@ def __init__(
9598
display_text="Open GC",
9699
)
97100

101+
self.runtime_installer_button = self.__setup_icon_button(
102+
qta.icon("mdi6.download"),
103+
"Opens a runtime installer modal",
104+
self.__open_runtime_installer_dialog,
105+
display_text="Install Runtimes",
106+
)
107+
98108
# disable the normal start button when no play is selected
99109
self.normal_start_enabled = True
100110
self.__toggle_normal_start_button()
@@ -110,6 +120,8 @@ def __init__(
110120
self.__add_separator(self.layout())
111121
self.layout().addWidget(self.gc_browser_button)
112122
self.layout().addStretch()
123+
self.__add_separator(self.layout())
124+
self.layout().addWidget(self.runtime_installer_button)
113125

114126
@override
115127
def refresh(self) -> None:
@@ -248,3 +260,12 @@ def __send_gc_command(self, command: Command.Type, team: Team) -> None:
248260
"""
249261
command = ManualGCCommand(manual_command=Command(type=command, for_team=team))
250262
self.proto_unix_io.send_proto(ManualGCCommand, command)
263+
264+
def __open_runtime_installer_dialog(self):
265+
"""Opens the runtime installer modal, initializing if first time"""
266+
if not hasattr(self, "runtime_installer_dialog"):
267+
self.runtime_installer_dialog = GLRuntimeInstallerDialog(
268+
parent=self.parent()
269+
)
270+
271+
self.runtime_installer_dialog.show()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from pyqtgraph.Qt.QtWidgets import (
2+
QDialog,
3+
QWidget,
4+
QPushButton,
5+
QListWidget,
6+
QAbstractItemView,
7+
QVBoxLayout,
8+
)
9+
10+
11+
class GLRuntimeInstallerDialog(QDialog):
12+
"""Modal that displays selectable list of runtimes to install"""
13+
14+
def __init__(self, parent: QWidget):
15+
"""Initializes runtime installer modal, fetching a list of installable
16+
runtimes and adding to a selectable list
17+
18+
:param parent: the modal's parent
19+
"""
20+
super().__init__(parent)
21+
22+
# TODO (#3559): get list of runtimes from GET request
23+
runtimes = [f"runtime_{i}" for i in range(10)]
24+
25+
self.setWindowTitle("Install runtimes")
26+
self.setModal(True)
27+
self.setMinimumWidth(400)
28+
29+
install_button = QPushButton("Install")
30+
install_button.clicked.connect(self.__install_selected_runtimes)
31+
32+
runtime_select_list = QListWidget()
33+
runtime_select_list.setSelectionMode(
34+
QAbstractItemView.SelectionMode.MultiSelection
35+
)
36+
runtime_select_list.setFixedHeight(200)
37+
runtime_select_list.addItems(runtimes)
38+
39+
self.runtime_select_list = runtime_select_list
40+
41+
layout = QVBoxLayout(self)
42+
layout.addWidget(runtime_select_list)
43+
layout.addWidget(install_button)
44+
45+
def __install_selected_runtimes(self) -> None:
46+
"""Installs all runtimes that are currently selected"""
47+
selected_items = self.runtime_select_list.selectedItems()
48+
selected_runtimes = [item.text() for item in selected_items]
49+
50+
# TODO (#3559): actually install the list of runtimes
51+
print("Installing:", selected_runtimes)
52+
53+
self.close()

0 commit comments

Comments
 (0)