Skip to content

Commit

Permalink
Dynamic key binding by check_action
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenhanQian committed Nov 20, 2024
1 parent 10eb1c8 commit dd92400
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "slurmui"
version = "1.1.7"
version = "1.1.8"
description = "Terminal UI for Slurm"
authors = [
{name = "Shenhan Qian", email = "[email protected]"}
Expand All @@ -13,7 +13,7 @@ classifiers = [
"Operating System :: OS Independent"
]
dependencies = [
"textual",
"textual>=0.61.0",
"pandas",
"pyperclip",
]
Expand Down
28 changes: 23 additions & 5 deletions slurmui/slurmui.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class SlurmUI(App):
BINDINGS = [
Binding("enter", "confirm", "Confirm", priority=True),
Binding("r", "refresh", "Refresh"),
Binding("q", "abort_quit", "Quit"),
Binding("s", "sort", "Sort"),
Binding("i", "copy_jobid", "Copy JobID"),
Binding("d", "stage_delete", "Delete job"),
Binding("q", "abort_quit", "Quit"),
Binding("d", "delete", "Delete job"),
Binding("g", "display_gpu", "GPU"),
Binding("l", "display_log", "Log"),
Binding("L", "copy_log_path", "Copy Log Path"),
Expand Down Expand Up @@ -77,6 +77,23 @@ def on_ready(self) -> None:
self.init_gpu_table()
self.switch_table_display("monitor")
self.init_squeue_table()

def check_action(self, action: str, parameters: tuple[object, ...]) -> bool | None:
"""Check if an action may run."""
# self.info_log.write(f"Action: {action}")
if action == "sort" and self.STAGE['action'] == 'log':
return False
elif action == "copy_jobid" and self.STAGE['action'] != 'monitor':
return False
elif action == "delete" and self.STAGE['action'] != 'monitor':
return False
elif action == "display_gpu" and self.STAGE['action'] != 'monitor':
return False
elif action == "display_log" and self.STAGE['action'] != 'monitor':
return False
elif action == "copy_log_path" and self.STAGE['action'] != 'monitor':
return False
return True

def auto_refresh(self):
self.action_refresh()
Expand Down Expand Up @@ -126,7 +143,7 @@ def action_copy_jobid(self):
except Exception as e:
self.info_log.write(str(e))

def action_stage_delete(self):
def action_delete(self):
if self.STAGE['action'] == "monitor":
try:
job_id, job_name = self._get_selected_job()
Expand Down Expand Up @@ -207,7 +224,7 @@ def update_title(self):
njobs = self.stats.get("njobs", 0)
njobs_running = self.stats.get("njobs_running", 0)

self.title = f"SlurmUI (v{importlib.metadata.version('slurmui')}) \t[Jobs: {njobs_running}/{njobs} | GPUs: {ngpus_avail}/{ngpus}]"
self.title = f"[Jobs: {njobs_running}/{njobs}] SlurmUI (v{importlib.metadata.version('slurmui')}) [GPUs: {ngpus_avail}/{ngpus}]"

def query_squeue(self, sort_column=None, sort_ascending=True):
squeue_df = get_squeue()
Expand Down Expand Up @@ -315,6 +332,7 @@ def _minimize_joblog_panel(self):
self.info_log.styles.max_height="20%"
self.info_log.can_focus = False
self.info_log.styles.border = ("heavy","grey")
self.info_log.focus()

self.job_log.styles.max_height="0%"
self.job_log.styles.border = ("none","grey")
Expand All @@ -325,11 +343,11 @@ def _maximize_joblog_panel(self):
self.squeue_table.styles.height="0%"

self.info_log.styles.max_height="0%"
self.info_log.can_focus = True
self.info_log.styles.border = ("none","grey")

self.job_log.styles.max_height="100%"
self.job_log.styles.border = ("heavy","grey")
self.job_log.focus()

@run_in_thread
def init_gpu_table(self, sort_column=None, sort_ascending=True):
Expand Down

0 comments on commit dd92400

Please sign in to comment.