Coverage for graphica/gui/panels/__init__.py: 93.3%
22 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-12 16:38 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-12 16:38 +0000
1"""画面の欄をまとめる部品(gui/panels/*.py)と、PlotterApp に部品の名前を出す窓口。
3欄のウィジェットと状態はタブが持ち、部品は欄の読み書き・処理・信号の配線を持つ。PlotterApp は各部品の EXPOSED_NAMES を
4同じ名前の属性として出し、読み書きを部品へ回す(テスト・メニュー・ほかの部品が今までの名前で使うため。monkeypatch も部品に届く)。
5"""
6from graphica.gui.panels.axis_settings import AxisSettingsPanel
7from graphica.gui.panels.dataset_tree import DatasetTreePanel
9__all__ = ["PANEL_CLASSES", "create_panels", "expose_panel_names"]
11PANEL_CLASSES = {
12 "axis_settings": AxisSettingsPanel,
13 "dataset_tree": DatasetTreePanel,
14}
17def create_panels(app):
18 return {key: panel_class(app) for key, panel_class in PANEL_CLASSES.items()}
21class _PanelName:
22 """PlotterApp の属性として、部品の同じ名前の属性を読み書きする。"""
24 def __init__(self, panel_key, name):
25 self._panel_key = panel_key
26 self._name = name
28 def __get__(self, app, owner=None):
29 if app is None:
30 # クラスから引いたとき(メニューの表の検査など)は、部品のクラスの同じ名前を返す
31 return getattr(PANEL_CLASSES[self._panel_key], self._name, self)
32 return getattr(app.panels[self._panel_key], self._name)
34 def __set__(self, app, value):
35 setattr(app.panels[self._panel_key], self._name, value)
38def expose_panel_names(app_class):
39 for key, panel_class in PANEL_CLASSES.items():
40 for name in panel_class.EXPOSED_NAMES:
41 if any(name in klass.__dict__ for klass in app_class.__mro__): 41 ↛ 42line 41 didn't jump to line 42 because the condition on line 41 was never true
42 raise TypeError(f"{app_class.__name__}.{name} は部品 {key} の名前とぶつかる")
43 setattr(app_class, name, _PanelName(key, name))