|
@@ -36,6 +36,12 @@ from config import (
|
|
Config,
|
|
Config,
|
|
get_state_from_id,
|
|
get_state_from_id,
|
|
get_state_id_from_exit_code,
|
|
get_state_id_from_exit_code,
|
|
|
|
+ contains_id,
|
|
|
|
+ DEFAULT_BUTTON_BG_COLOR,
|
|
|
|
+ DEFAULT_BUTTON_FG_COLOR,
|
|
|
|
+ EMPTY_BUTTON_BG_COLOR,
|
|
|
|
+ DEFAULT_STATE_ID,
|
|
|
|
+ ERROR_SINK_STATE_ID,
|
|
)
|
|
)
|
|
from ui import AutoResizeButton
|
|
from ui import AutoResizeButton
|
|
|
|
|
|
@@ -73,26 +79,29 @@ class VulcanBoardApp(App):
|
|
defined_button = button_map.get((row, col))
|
|
defined_button = button_map.get((row, col))
|
|
if defined_button:
|
|
if defined_button:
|
|
states = defined_button.get("states", [])
|
|
states = defined_button.get("states", [])
|
|
- print("STATES")
|
|
|
|
- print(states)
|
|
|
|
- state_id = [0]
|
|
|
|
|
|
+ state_id = [DEFAULT_STATE_ID]
|
|
state = get_state_from_id(states, state_id[0])
|
|
state = get_state_from_id(states, state_id[0])
|
|
- print("STATE")
|
|
|
|
- print(state)
|
|
|
|
|
|
|
|
btn = AutoResizeButton(
|
|
btn = AutoResizeButton(
|
|
text=state.get("txt", ""),
|
|
text=state.get("txt", ""),
|
|
background_color=get_color_from_hex(
|
|
background_color=get_color_from_hex(
|
|
- state.get("bg_color", "aaaaff")
|
|
|
|
|
|
+ state.get("bg_color", DEFAULT_BUTTON_BG_COLOR)
|
|
),
|
|
),
|
|
color=get_color_from_hex(
|
|
color=get_color_from_hex(
|
|
- state.get("fg_color", "ffffff")
|
|
|
|
|
|
+ state.get("fg_color", DEFAULT_BUTTON_FG_COLOR)
|
|
),
|
|
),
|
|
halign="center",
|
|
halign="center",
|
|
valign="middle",
|
|
valign="middle",
|
|
background_normal="",
|
|
background_normal="",
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ if defined_button.get("autostart", False):
|
|
|
|
+ self.async_task(
|
|
|
|
+ self.execute_command_async(
|
|
|
|
+ states, state_id, btn
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+
|
|
# pylint: disable=no-member
|
|
# pylint: disable=no-member
|
|
btn.bind( # pyright: ignore
|
|
btn.bind( # pyright: ignore
|
|
on_release=lambda btn_instance, states=states, state_id=state_id: self.async_task(
|
|
on_release=lambda btn_instance, states=states, state_id=state_id: self.async_task(
|
|
@@ -101,9 +110,12 @@ class VulcanBoardApp(App):
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
+
|
|
else:
|
|
else:
|
|
btn = AutoResizeButton(
|
|
btn = AutoResizeButton(
|
|
- background_color=get_color_from_hex("cccccc"),
|
|
|
|
|
|
+ background_color=get_color_from_hex(
|
|
|
|
+ EMPTY_BUTTON_BG_COLOR
|
|
|
|
+ ),
|
|
)
|
|
)
|
|
layout.add_widget(btn)
|
|
layout.add_widget(btn)
|
|
|
|
|
|
@@ -136,13 +148,15 @@ class VulcanBoardApp(App):
|
|
try:
|
|
try:
|
|
print(states[new_state_id]["cmd"])
|
|
print(states[new_state_id]["cmd"])
|
|
process = await asyncio.create_subprocess_shell(
|
|
process = await asyncio.create_subprocess_shell(
|
|
- states[new_state_id]["cmd"], shell=True
|
|
|
|
|
|
+ get_state_from_id(states, new_state_id)["cmd"], shell=True
|
|
)
|
|
)
|
|
exit_code = await process.wait()
|
|
exit_code = await process.wait()
|
|
print(f"EXIT {exit_code}")
|
|
print(f"EXIT {exit_code}")
|
|
- log(f"Executed command: {states[new_state_id]['cmd']}")
|
|
|
|
|
|
+ log(
|
|
|
|
+ f"Executed command: {get_state_from_id(states, new_state_id)['cmd']}"
|
|
|
|
+ )
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- exit_code = 1
|
|
|
|
|
|
+ exit_code = ERROR_SINK_STATE_ID
|
|
log(f"Error executing command: {e}", color="yellow")
|
|
log(f"Error executing command: {e}", color="yellow")
|
|
|
|
|
|
if len(states) != 1:
|
|
if len(states) != 1:
|
|
@@ -163,11 +177,11 @@ class VulcanBoardApp(App):
|
|
|
|
|
|
btn.text = state.get("txt", "")
|
|
btn.text = state.get("txt", "")
|
|
btn.background_color = get_color_from_hex(
|
|
btn.background_color = get_color_from_hex(
|
|
- state.get("bg_color", "cc0000")
|
|
|
|
|
|
+ state.get("bg_color", DEFAULT_BUTTON_BG_COLOR)
|
|
|
|
+ )
|
|
|
|
+ btn.color = get_color_from_hex(
|
|
|
|
+ state.get("fg_color", DEFAULT_BUTTON_FG_COLOR)
|
|
)
|
|
)
|
|
- # btn.foreground_color = get_color_from_hex(
|
|
|
|
- # state.get("bg_color", "cc0000")
|
|
|
|
- # )
|
|
|
|
|
|
|
|
|
|
|
|
def start_asyncio_loop():
|
|
def start_asyncio_loop():
|