brkraw-viewer 0.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- brkraw_viewer/__init__.py +4 -0
- brkraw_viewer/apps/__init__.py +0 -0
- brkraw_viewer/apps/config.py +90 -0
- brkraw_viewer/apps/convert.py +1689 -0
- brkraw_viewer/apps/hooks.py +36 -0
- brkraw_viewer/apps/viewer.py +5316 -0
- brkraw_viewer/assets/icon.ico +0 -0
- brkraw_viewer/assets/icon.png +0 -0
- brkraw_viewer/frames/__init__.py +2 -0
- brkraw_viewer/frames/params_panel.py +80 -0
- brkraw_viewer/frames/viewer_canvas.py +340 -0
- brkraw_viewer/frames/viewer_config.py +101 -0
- brkraw_viewer/plugin.py +125 -0
- brkraw_viewer/registry.py +258 -0
- brkraw_viewer/snippets/context_map/basic.yaml +4 -0
- brkraw_viewer/snippets/context_map/enum-map.yaml +5 -0
- brkraw_viewer/snippets/rule/basic.yaml +10 -0
- brkraw_viewer/snippets/rule/when-contains.yaml +10 -0
- brkraw_viewer/snippets/spec/basic.yaml +5 -0
- brkraw_viewer/snippets/spec/list-source.yaml +5 -0
- brkraw_viewer/snippets/spec/with-default.yaml +5 -0
- brkraw_viewer/utils/__init__.py +2 -0
- brkraw_viewer/utils/orientation.py +17 -0
- brkraw_viewer-0.2.5.dist-info/METADATA +170 -0
- brkraw_viewer-0.2.5.dist-info/RECORD +28 -0
- brkraw_viewer-0.2.5.dist-info/WHEEL +5 -0
- brkraw_viewer-0.2.5.dist-info/entry_points.txt +2 -0
- brkraw_viewer-0.2.5.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import datetime as dt
|
|
4
|
+
import logging
|
|
5
|
+
import shutil
|
|
6
|
+
import tkinter as tk
|
|
7
|
+
from tkinter import messagebox, ttk
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from brkraw.core import config as config_core
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger("brkraw.viewer")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ConfigTabMixin:
|
|
16
|
+
_config_text: tk.Text
|
|
17
|
+
_config_path_var: tk.StringVar
|
|
18
|
+
|
|
19
|
+
def _build_config_tab(self, config_tab: ttk.Frame) -> None:
|
|
20
|
+
config_tab.columnconfigure(0, weight=1)
|
|
21
|
+
config_tab.rowconfigure(1, weight=1)
|
|
22
|
+
config_bar = ttk.Frame(config_tab, padding=(6, 6))
|
|
23
|
+
config_bar.grid(row=0, column=0, sticky="ew")
|
|
24
|
+
ttk.Button(config_bar, text="Save", command=self._save_config_text).pack(side=tk.LEFT)
|
|
25
|
+
ttk.Button(config_bar, text="Backup", command=self._backup_config_text).pack(side=tk.LEFT, padx=(6, 0))
|
|
26
|
+
ttk.Button(config_bar, text="Reset", command=self._reset_config_text).pack(side=tk.LEFT, padx=(6, 0))
|
|
27
|
+
self._config_path_var = tk.StringVar(value="")
|
|
28
|
+
ttk.Label(config_bar, textvariable=self._config_path_var).pack(side=tk.LEFT, padx=(12, 0))
|
|
29
|
+
|
|
30
|
+
config_body = ttk.Frame(config_tab, padding=(6, 6))
|
|
31
|
+
config_body.grid(row=1, column=0, sticky="nsew")
|
|
32
|
+
config_body.columnconfigure(0, weight=1)
|
|
33
|
+
config_body.rowconfigure(0, weight=1)
|
|
34
|
+
self._config_text = tk.Text(config_body, wrap="none")
|
|
35
|
+
self._config_text.grid(row=0, column=0, sticky="nsew")
|
|
36
|
+
config_scroll = ttk.Scrollbar(config_body, orient="vertical", command=self._config_text.yview)
|
|
37
|
+
config_scroll.grid(row=0, column=1, sticky="ns")
|
|
38
|
+
self._config_text.configure(yscrollcommand=config_scroll.set)
|
|
39
|
+
|
|
40
|
+
def _load_config_text(self) -> None:
|
|
41
|
+
try:
|
|
42
|
+
paths = config_core.ensure_initialized(root=None, create_config=True, exist_ok=True)
|
|
43
|
+
self._config_path_var.set(str(paths.config_file))
|
|
44
|
+
content = paths.config_file.read_text(encoding="utf-8")
|
|
45
|
+
except Exception as exc:
|
|
46
|
+
logger.error("Failed to load config.yaml: %s", exc, exc_info=logger.isEnabledFor(logging.DEBUG))
|
|
47
|
+
self._config_path_var.set("")
|
|
48
|
+
self._config_text.delete("1.0", tk.END)
|
|
49
|
+
self._config_text.insert(tk.END, f"# Failed to load config.yaml: {exc}\n")
|
|
50
|
+
return
|
|
51
|
+
self._config_text.delete("1.0", tk.END)
|
|
52
|
+
self._config_text.insert(tk.END, content)
|
|
53
|
+
|
|
54
|
+
def _save_config_text(self) -> None:
|
|
55
|
+
try:
|
|
56
|
+
paths = config_core.ensure_initialized(root=None, create_config=True, exist_ok=True)
|
|
57
|
+
self._config_path_var.set(str(paths.config_file))
|
|
58
|
+
text = self._config_text.get("1.0", tk.END)
|
|
59
|
+
paths.config_file.write_text(text, encoding="utf-8")
|
|
60
|
+
logger.info("Saved config.yaml: %s", paths.config_file)
|
|
61
|
+
except Exception as exc:
|
|
62
|
+
logger.error("Failed to save config.yaml: %s", exc, exc_info=logger.isEnabledFor(logging.DEBUG))
|
|
63
|
+
messagebox.showerror("Save error", f"Failed to save config.yaml:\n{exc}")
|
|
64
|
+
|
|
65
|
+
def _backup_config_text(self) -> None:
|
|
66
|
+
try:
|
|
67
|
+
paths = config_core.ensure_initialized(root=None, create_config=True, exist_ok=True)
|
|
68
|
+
config_path = paths.config_file
|
|
69
|
+
self._config_path_var.set(str(config_path))
|
|
70
|
+
if not config_path.exists():
|
|
71
|
+
messagebox.showwarning("Backup", f"Config file not found:\n{config_path}")
|
|
72
|
+
return
|
|
73
|
+
ts = dt.datetime.now().strftime("%Y%m%d-%H%M%S")
|
|
74
|
+
backup_path = Path(f"{config_path}.bak-{ts}")
|
|
75
|
+
shutil.copy2(config_path, backup_path)
|
|
76
|
+
logger.info("Backed up config.yaml: %s", backup_path)
|
|
77
|
+
messagebox.showinfo("Backup", f"Created backup:\n{backup_path}")
|
|
78
|
+
except Exception as exc:
|
|
79
|
+
logger.error("Failed to back up config.yaml: %s", exc, exc_info=logger.isEnabledFor(logging.DEBUG))
|
|
80
|
+
messagebox.showerror("Backup error", f"Failed to back up config.yaml:\n{exc}")
|
|
81
|
+
|
|
82
|
+
def _reset_config_text(self) -> None:
|
|
83
|
+
try:
|
|
84
|
+
config_core.reset_config(root=None)
|
|
85
|
+
logger.info("Reset config.yaml to defaults.")
|
|
86
|
+
except Exception as exc:
|
|
87
|
+
logger.error("Failed to reset config.yaml: %s", exc, exc_info=logger.isEnabledFor(logging.DEBUG))
|
|
88
|
+
messagebox.showerror("Reset error", f"Failed to reset config.yaml:\n{exc}")
|
|
89
|
+
return
|
|
90
|
+
self._load_config_text()
|