Skip to content

Commit 600d71f

Browse files
committed
Add visit creation option in TUI
1 parent 42984f1 commit 600d71f

File tree

3 files changed

+103
-2
lines changed

3 files changed

+103
-2
lines changed

src/murfey/client/tui/app.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
MainScreen,
2626
ProcessingForm,
2727
SessionSelection,
28+
VisitCreation,
2829
VisitSelection,
2930
WaitingScreen,
3031
determine_default_destination,
@@ -682,8 +683,12 @@ async def on_mount(self) -> None:
682683
exisiting_sessions = requests.get(
683684
f"{self._environment.url.geturl()}/sessions"
684685
).json()
685-
self.install_screen(VisitSelection(self.visits), "visit-select-screen")
686-
self.push_screen("visit-select-screen")
686+
if self.visits:
687+
self.install_screen(VisitSelection(self.visits), "visit-select-screen")
688+
self.push_screen("visit-select-screen")
689+
else:
690+
self.install_screen(VisitCreation(), "visit-creation-screen")
691+
self.push_screen("visit-creation-screen")
687692
if exisiting_sessions:
688693
self.install_screen(
689694
SessionSelection(

src/murfey/client/tui/controller.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ SessionSelection {
4646
border: hidden;
4747
}
4848

49+
VisitCreation {
50+
layout: grid;
51+
grid-size: 2;
52+
border: hidden;
53+
}
54+
4955
VisitSelection {
5056
layout: grid;
5157
grid-size: 4;
@@ -235,6 +241,22 @@ RadioSet {
235241
background: darkslateblue;
236242
}
237243

244+
.btn-visit-create {
245+
width: 100%;
246+
height: 90fr;
247+
column-span: 2;
248+
background: teal;
249+
border: solid black;
250+
}
251+
252+
.btn-visit-create:hover {
253+
background: purple;
254+
}
255+
256+
.btn-visit-create:focus {
257+
background: darkslateblue;
258+
}
259+
238260
.btn-session {
239261
width: 100%;
240262
height: 20%;
@@ -468,6 +490,16 @@ RadioSet {
468490
background: black;
469491
}
470492

493+
.input-visit-name {
494+
width: 100%;
495+
height: 100%;
496+
column-span: 2;
497+
row-span: 1;
498+
content-align: left middle;
499+
text-style: bold;
500+
background: blueviolet;
501+
}
502+
471503
#log_book {
472504
width: 100%;
473505
height: 100%;

src/murfey/client/tui/screens.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,70 @@ def on_button_pressed(self, event: Button.Pressed):
760760
self.app.push_screen("upstream-downloads")
761761

762762

763+
class VisitCreation(Screen):
764+
visit_name: reactive[str] = reactive("")
765+
766+
def __init__(self, *args, **kwargs):
767+
super().__init__(*args, **kwargs)
768+
769+
def compose(self):
770+
yield Input(placeholder="Visit name", classes="input-visit-name")
771+
yield Button("Create visit", classes="btn-visit-create")
772+
773+
def on_input_changed(self, event):
774+
self.visit_name = event.value
775+
776+
def on_button_pressed(self, event: Button.Pressed):
777+
text = str(self.visit_name)
778+
self.app._visit = text
779+
self.app._environment.visit = text
780+
response = requests.post(
781+
f"{self.app._environment.url.geturl()}/visits/{text}",
782+
json={"id": self.app._environment.client_id},
783+
)
784+
log.info(f"Posted visit registration: {response.status_code}")
785+
machine_data = requests.get(
786+
f"{self.app._environment.url.geturl()}/machine"
787+
).json()
788+
789+
self.app.install_screen(
790+
DirectorySelection(
791+
[
792+
p[0]
793+
for p in machine_data.get("data_directories", {}).items()
794+
if p[1] == "detector" and Path(p[0]).exists()
795+
]
796+
),
797+
"directory-select",
798+
)
799+
self.app.pop_screen()
800+
801+
if machine_data.get("gain_reference_directory"):
802+
self.app.install_screen(
803+
GainReference(
804+
determine_gain_ref(Path(machine_data["gain_reference_directory"])),
805+
True,
806+
),
807+
"gain-ref-select",
808+
)
809+
self.app.push_screen("gain-ref-select")
810+
else:
811+
if self._switch_status:
812+
self.app.push_screen("directory-select")
813+
else:
814+
self.app.install_screen(LaunchScreen(basepath=Path("./")), "launcher")
815+
self.app.push_screen("launcher")
816+
817+
if machine_data.get("upstream_data_directories"):
818+
upstream_downloads = requests.get(
819+
f"{self.app._environment.url.geturl()}/sessions/{self.app._environment.murfey_session}/upstream_visits"
820+
).json()
821+
self.app.install_screen(
822+
UpstreamDownloads(upstream_downloads), "upstream-downloads"
823+
)
824+
self.app.push_screen("upstream-downloads")
825+
826+
763827
class UpstreamDownloads(Screen):
764828
def __init__(self, connected_visits: Dict[str, Path], *args, **kwargs):
765829
super().__init__(*args, **kwargs)

0 commit comments

Comments
 (0)