Coverage for graphica/gui/ui_mode.py: 91.5%

41 statements  

« prev     ^ index     » next       coverage.py v7.17.5, created at 2026-11-25 19:22 +0000

1"""シンプル(Lite)とアドバンスド(Advanced)の表示の出し分け。 

2 

3部品は1組だけで、モードで見せる・隠すだけ。値には触らない(隠した設定もそのまま描かれ、保存される)。 

4どの部品をどちらのモードで出すかは MODE_ONLY_ELEMENTS の表で決める。見本は docs/dev/mockups/gui_redesign/。 

5""" 

6from graphica.core.i18n import tr 

7from graphica.gui import app_settings 

8 

9LITE = "lite" 

10ADVANCED = "advanced" 

11MODES = (LITE, ADVANCED) 

12 

13# 表示名(日本語は「シンプル / アドバンスド」。「ライト」はテーマのライトと紛らわしいので使わない) 

14MODE_LABELS = {LITE: "シンプル", ADVANCED: "アドバンスド"} 

15 

16# (タブの属性の名前(ドットで辿る), 出すモード)。ここに無い部品は両方のモードで出す 

17MODE_ONLY_ELEMENTS = ( 

18 # ステータスバー: 座標と、データセット・選択の数 

19 ("coordinate_label", ADVANCED), 

20 ("status_selection_label", ADVANCED), 

21 ("dataset_stats_advanced_row", ADVANCED), 

22 # グラフの道具: シンプルは左に縦のアイコン、アドバンスドはプロットの上に文字付き(同じ QAction) 

23 ("plot_tool_rail", LITE), 

24 ("plot_toolbar", ADVANCED), 

25 ("card_subplot_label", ADVANCED), 

26 ("card_minimap_button", ADVANCED), 

27 # プロパティ: シンプルは種類のタイルと「アドバンスドですべて表示」の案内、色の 16 進はアドバンスドだけ 

28 ("_plot_type_tiles_row", LITE), 

29 ("lite_more_box", LITE), 

30 ("color_picker_widget.hex_edit", ADVANCED), 

31 # グラフの下のパネル(データ表・フィット結果・残差・来歴・ログ) 

32 ("bottom_panel", ADVANCED), 

33 # 軸: 単位の換算と第2Y軸 

34 ("x_unit_section", ADVANCED), 

35 ("y2_axis_section", ADVANCED), 

36) 

37 

38# シンプルで隠すプロパティの行(欄の属性の名前。名前の欄も一緒に隠す)。種類などによる今の出し入れより強い 

39LITE_HIDDEN_PROPERTY_FIELDS = ( 

40 "use_secondary_y_checkbox", "x_err_col_combo", "y_err_col_combo", "nan_policy_combo", 

41 "ui.plot_type_combo", "alpha_slider", "ui.smoothing_checkbox", "smoothing_method_combo", 

42 "marker_fill_field", "marker_face_color_picker", "marker_edge_combo", "marker_edge_color_picker", 

43 "marker_edge_width_slider", "legend_label_edit", "hide_from_legend_checkbox", 

44) 

45# シンプルで出すプロパティの節(ほかの節は見出しごと隠す)。マーカーは形と大きさだけ(点の種類のときに出る) 

46LITE_PROPERTY_SECTIONS = ("data", "style", "marker") 

47 

48 

49# インスペクタのタブ(キー, 出すモード) 

50MODE_ONLY_INSPECTOR_PAGES = ( 

51 ("legend", ADVANCED), 

52) 

53 

54 

55def mode_label(mode): 

56 return tr(MODE_LABELS[mode]) 

57 

58 

59def initial_mode(settings): 

60 """保存したモード。無ければ、今までの利用者(スタートアップ画面を見たことがある)はアドバンスド、初めての人はシンプル。 

61 

62 更新した人の手元で項目が消えて見えないよう、決めた値はすぐ保存する。 

63 """ 

64 saved = app_settings.UI_MODE.read(settings) 

65 if saved in MODES: 

66 return saved 

67 mode = ADVANCED if app_settings.HAS_SHOWN_WELCOME.read(settings) else LITE 

68 app_settings.UI_MODE.write(settings, mode) 

69 return mode 

70 

71 

72def resolve(app, dotted_name): 

73 target = app 

74 for part in dotted_name.split("."): 

75 target = getattr(target, part, None) 

76 if target is None: 76 ↛ 77line 76 didn't jump to line 77 because the condition on line 76 was never true

77 return None 

78 return target 

79 

80 

81def apply_ui_mode(app, mode): 

82 """タブの部品をモードに合わせて見せる・隠す。値は変えない。""" 

83 if mode not in MODES: 

84 raise ValueError(f"知らないモード: {mode!r}") 

85 for dotted_name, only_in in MODE_ONLY_ELEMENTS: 

86 widget = resolve(app, dotted_name) 

87 if widget is not None: 87 ↛ 85line 87 didn't jump to line 85 because the condition on line 87 was always true

88 widget.setVisible(mode == only_in) 

89 inspector = getattr(app, 'inspector', None) 

90 if inspector is not None: 90 ↛ 93line 90 didn't jump to line 93 because the condition on line 90 was always true

91 for key, only_in in MODE_ONLY_INSPECTOR_PAGES: 

92 inspector.set_page_visible(key, mode == only_in) 

93 app.ui_mode = mode 

94 # プロパティの行は種類などの条件でも出し入れするので、条件を当て直してからモードで隠す 

95 property_panel = getattr(app, 'property_panel', None) 

96 if property_panel is not None: 96 ↛ exitline 96 didn't return from function 'apply_ui_mode' because the condition on line 96 was always true

97 property_panel.update_mode_visibility()