clan-app: Finish flash view. clan-cli: Flash cli now verifies if language and keymap are valid.

This commit is contained in:
Qubasa
2024-08-02 17:51:45 +02:00
parent e2bdf22f78
commit f1d124dabd
27 changed files with 556 additions and 202 deletions

View File

@@ -4,6 +4,8 @@ import gi
gi.require_version("Gtk", "4.0")
import logging
from pathlib import Path
from typing import Any
from clan_cli.api import ErrorDataClass, SuccessDataClass
from clan_cli.api.directory import FileRequest
@@ -17,7 +19,7 @@ log = logging.getLogger(__name__)
# This implements the abstract function open_file with one argument, file_request,
# which is a FileRequest object and returns a string or None.
class open_file(
ImplFunc[[FileRequest, str], SuccessDataClass[str | None] | ErrorDataClass]
ImplFunc[[FileRequest, str], SuccessDataClass[list[str] | None] | ErrorDataClass]
):
def __init__(self) -> None:
super().__init__()
@@ -27,7 +29,7 @@ class open_file(
try:
gfile = file_dialog.open_finish(task)
if gfile:
selected_path = gfile.get_path()
selected_path = [gfile.get_path()]
self.returns(
SuccessDataClass(
op_key=op_key, data=selected_path, status="success"
@@ -36,11 +38,26 @@ class open_file(
except Exception as e:
print(f"Error getting selected file or directory: {e}")
def on_file_select_multiple(
file_dialog: Gtk.FileDialog, task: Gio.Task
) -> None:
try:
gfiles: Any = file_dialog.open_multiple_finish(task)
if gfiles:
selected_paths = [gfile.get_path() for gfile in gfiles]
self.returns(
SuccessDataClass(
op_key=op_key, data=selected_paths, status="success"
)
)
except Exception as e:
print(f"Error getting selected files: {e}")
def on_folder_select(file_dialog: Gtk.FileDialog, task: Gio.Task) -> None:
try:
gfile = file_dialog.select_folder_finish(task)
if gfile:
selected_path = gfile.get_path()
selected_path = [gfile.get_path()]
self.returns(
SuccessDataClass(
op_key=op_key, data=selected_path, status="success"
@@ -53,7 +70,7 @@ class open_file(
try:
gfile = file_dialog.save_finish(task)
if gfile:
selected_path = gfile.get_path()
selected_path = [gfile.get_path()]
self.returns(
SuccessDataClass(
op_key=op_key, data=selected_path, status="success"
@@ -90,9 +107,21 @@ class open_file(
filters.append(file_filters)
dialog.set_filters(filters)
if file_request.initial_file:
p = Path(file_request.initial_file).expanduser()
f = Gio.File.new_for_path(str(p))
dialog.set_initial_file(f)
if file_request.initial_folder:
p = Path(file_request.initial_folder).expanduser()
f = Gio.File.new_for_path(str(p))
dialog.set_initial_folder(f)
# if select_folder
if file_request.mode == "select_folder":
dialog.select_folder(callback=on_folder_select)
if file_request.mode == "open_multiple_files":
dialog.open_multiple(callback=on_file_select_multiple)
elif file_request.mode == "open_file":
dialog.open(callback=on_file_select)
elif file_request.mode == "save":

View File

@@ -1,4 +1,5 @@
import logging
import os
import gi
from clan_cli.api import API
@@ -47,3 +48,4 @@ class MainWindow(Adw.ApplicationWindow):
def on_destroy(self, source: "Adw.ApplicationWindow") -> None:
log.debug("Destroying Adw.ApplicationWindow")
os._exit(0)