123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #!/usr/bin/env python3
- # Copyright © 2024 Noah Vogt <noah@noahvogt.com>
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- # pylint: disable=invalid-name
- import subprocess
- import sys
- import colorama
- from kivy.app import App
- from kivy.uix.gridlayout import GridLayout
- from kivy.utils import get_color_from_hex
- from kivy.config import Config as kvConfig
- from util import log, error_exit_gui
- from config import get_config_path, ConfigLoader, Config
- from ui import AutoResizeButton
- class VulcanBoardApp(App):
- def build(self):
- self.icon = "icon.jpg"
- config_loader = ConfigLoader(get_config_path())
- config = config_loader.get_config() # pyright: ignore
- if isinstance(config, str):
- error_exit_gui(config)
- else:
- config: Config = config
- self.Borderless = config.borderless
- kvConfig.set("kivy", "window_icon", "icon.ico")
- button_map = {
- (btn["position"][0], btn["position"][1]): btn
- for btn in config.buttons
- }
- layout = GridLayout(
- cols=config.columns,
- rows=config.rows,
- spacing=config.spacing,
- padding=config.padding,
- )
- # Populate grid with buttons and placeholders
- for row in range(config.rows):
- for col in range(config.columns):
- defined_button = button_map.get((row, col))
- if defined_button:
- btn = AutoResizeButton(
- text=defined_button.get("txt", ""),
- background_color=get_color_from_hex(
- defined_button.get("bg_color", "aaaaff")
- ),
- color=get_color_from_hex(
- defined_button.get("fg_color", "ffffff")
- ),
- halign="center",
- valign="middle",
- background_normal="",
- )
- cmd = defined_button.get("cmd", "")
- # pylint: disable=no-member
- btn.bind( # pyright: ignore
- on_release=lambda _, cmd=cmd: self.execute_command_async(
- cmd
- )
- )
- else:
- btn = AutoResizeButton(
- background_color=get_color_from_hex("cccccc"),
- )
- layout.add_widget(btn)
- return layout
- def config_error_exit(self, popup):
- popup.dismiss()
- sys.exit(1)
- def execute_command_async(self, cmd):
- if cmd:
- try:
- subprocess.Popen( # pylint: disable=consider-using-with
- cmd, shell=True
- )
- log(f"Executed command: {cmd}")
- except Exception as e:
- log(f"Error executing command: {e}", color="yellow")
- if __name__ == "__main__":
- colorama.init()
- VulcanBoardApp().run()
|