101 lines
3.1 KiB
Python
101 lines
3.1 KiB
Python
"""
|
|
Filename: terminal.py
|
|
Description: Terminal window for FLARES
|
|
|
|
Author: Tyler de Zeeuw
|
|
License: GPL-3.0
|
|
"""
|
|
|
|
from PySide6.QtWidgets import QWidget, QVBoxLayout, QTextEdit, QLineEdit
|
|
from PySide6.QtCore import Qt
|
|
|
|
from src.shared.shareddata import API_URL, API_URL_SECONDARY, APP_NAME, CURRENT_VERSION, PLATFORM_NAME
|
|
from src.window.about import AboutWindow
|
|
from updater import LocalPendingUpdateCheckThread, UpdateManager
|
|
|
|
|
|
class TerminalWindow(QWidget):
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent, Qt.WindowType.Window)
|
|
self.setWindowTitle(f"Terminal - {APP_NAME.upper()}")
|
|
self.resize(320, 180)
|
|
self.output_area = QTextEdit()
|
|
self.output_area.setReadOnly(True)
|
|
|
|
self.input_line = QLineEdit()
|
|
self.input_line.returnPressed.connect(self.handle_command)
|
|
|
|
layout = QVBoxLayout()
|
|
layout.addWidget(self.output_area)
|
|
layout.addWidget(self.input_line)
|
|
self.setLayout(layout)
|
|
|
|
self.commands = {
|
|
"hello": self.cmd_hello,
|
|
"help": self.cmd_help,
|
|
"version": self.cmd_version,
|
|
"about": self.cmd_about,
|
|
"update": self.cmd_update,
|
|
}
|
|
|
|
self.output_area.append(f"Welcome to {APP_NAME.upper()}. You are running version {CURRENT_VERSION}.")
|
|
self.output_area.append("Type 'help' for a list of available commands.\n")
|
|
|
|
self.input_line.setFocus()
|
|
|
|
|
|
def handle_command(self):
|
|
command_text = self.input_line.text()
|
|
self.input_line.clear()
|
|
|
|
self.output_area.append(f"> {command_text}")
|
|
parts = command_text.strip().split()
|
|
if not parts:
|
|
return
|
|
|
|
command_name = parts[0]
|
|
args = parts[1:]
|
|
|
|
func = self.commands.get(command_name)
|
|
if func:
|
|
try:
|
|
result = func(*args)
|
|
if result:
|
|
self.output_area.append(str(result))
|
|
except Exception as e:
|
|
self.output_area.append(f"[Error] {e}")
|
|
else:
|
|
self.output_area.append(f"[Unknown command] '{command_name}'")
|
|
|
|
|
|
def cmd_hello(self, *args):
|
|
return "Hello from the terminal!"
|
|
|
|
def cmd_help(self, *args):
|
|
return f"Available commands: {', '.join(self.commands.keys())}"
|
|
|
|
def cmd_version(self, *args):
|
|
return f"{APP_NAME.upper()} is running version {CURRENT_VERSION}."
|
|
|
|
def cmd_about(self, *args):
|
|
self.about = AboutWindow(self)
|
|
self.about.show()
|
|
|
|
def cmd_update(self, *args):
|
|
main_win = self.parent()
|
|
if main_win is None:
|
|
return "[Error] Main window context not found."
|
|
|
|
self.updater = UpdateManager(
|
|
main_window=main_win,
|
|
api_url=API_URL,
|
|
api_url_sec=API_URL_SECONDARY,
|
|
current_version=CURRENT_VERSION,
|
|
platform_name=PLATFORM_NAME,
|
|
platform_suffix="-" + PLATFORM_NAME,
|
|
app_name=APP_NAME
|
|
)
|
|
self.output_area.append("Checking for updates...")
|
|
|
|
self.updater.manual_check_for_updates()
|
|
return "See status bar for update information." |