Coverage for paintmaskanimator/main_window_view_preview.py: 81%

79 statements  

« prev     ^ index     » next       coverage.py v7.17.0, created at 2026-11-02 04:50 +0000

1"""キャンバス下の表示チェック; owned by ``MainWindow`` as ``window.view_preview``. 

2 

3ブラックチェック(背景以外を黒シルエット表示)・隣接色分け・チャンネル表示・ 

4露光量を、キャンバスの下のバーにまとめる。どれも画面の見え方だけを変え、 

5画素データや書き出しには影響しない。計算は :mod:`view_preview` と 

6``PaintCanvas.view_layer_image`` が持ち、ここはボタンと設定の同期だけを持つ。 

7 

8A collaborator rather than a mixin -- see ``main_window_export.py`` for why. 

9""" 

10from __future__ import annotations 

11 

12from typing import TYPE_CHECKING 

13 

14from PySide6.QtCore import QSignalBlocker 

15 

16from . import preferences, view_preview 

17from .i18n import tr 

18 

19if TYPE_CHECKING: 

20 from .main_window import MainWindow 

21 

22 

23def channel_labels(): 

24 """チャンネル表示の選択肢 ``(値, 表示名)``。呼び出し時に翻訳する。""" 

25 return ( 

26 (view_preview.CHANNEL_RGB, tr("RGB")), 

27 (view_preview.CHANNEL_RED, tr("赤")), 

28 (view_preview.CHANNEL_GREEN, tr("緑")), 

29 (view_preview.CHANNEL_BLUE, tr("青")), 

30 (view_preview.CHANNEL_ALPHA, tr("アルファ")), 

31 ) 

32 

33 

34class ViewPreviewController: 

35 """Owned by ``MainWindow`` as ``window.view_preview``.""" 

36 

37 def __init__(self, window: "MainWindow"): 

38 self.window = window 

39 # 露光量のボタンで 0 に戻す前の値。もう一度押すとこの値に戻す(AE と同じ)。 

40 self._last_exposure = 1.0 

41 

42 @property 

43 def _settings(self): 

44 return self.window.canvas.view_preview 

45 

46 # ------------------------------------------------------------------ 

47 # 隣接色分け 

48 # ------------------------------------------------------------------ 

49 def set_map_colors(self, checked): 

50 self.window.canvas.set_view_preview(map_colors=bool(checked)) 

51 self.sync() 

52 

53 def set_flip_horizontal(self, checked): 

54 self.window.canvas.flip_horizontal = bool(checked) 

55 self.window.canvas.update() 

56 

57 def set_flip_vertical(self, checked): 

58 self.window.canvas.flip_vertical = bool(checked) 

59 self.window.canvas.update() 

60 

61 def toggle_map_colors(self): 

62 self.set_map_colors(not self._settings.map_colors) 

63 

64 def set_palette(self, colors): 

65 """隣接色分けの仮の色を変えて保存する(環境設定から)。""" 

66 preferences.set_map_palette(colors) 

67 self.window.canvas.set_view_preview(palette=preferences.map_palette()) 

68 

69 # ------------------------------------------------------------------ 

70 # チャンネル 

71 # ------------------------------------------------------------------ 

72 def set_channel(self, channel): 

73 if channel not in view_preview.CHANNELS: 73 ↛ 74line 73 didn't jump to line 74 because the condition on line 73 was never true

74 channel = view_preview.CHANNEL_RGB 

75 # もう一度同じチャンネルを選んだら RGB に戻す(AE の Alt+1〜4 と同じ)。 

76 if channel == self._settings.channel and channel != view_preview.CHANNEL_RGB: 

77 channel = view_preview.CHANNEL_RGB 

78 self.window.canvas.set_view_preview(channel=channel) 

79 self.sync() 

80 

81 def _channel_chosen(self, index): 

82 combo = self.window.channel_combo 

83 self.window.canvas.set_view_preview(channel=combo.itemData(index)) 

84 self.sync() 

85 

86 # ------------------------------------------------------------------ 

87 # 露光量 

88 # ------------------------------------------------------------------ 

89 def set_exposure(self, value): 

90 value = view_preview.clamp_exposure(value) 

91 if abs(value) > 1e-9: 91 ↛ 93line 91 didn't jump to line 93 because the condition on line 91 was always true

92 self._last_exposure = value 

93 self.window.canvas.set_view_preview(exposure=value) 

94 self.sync() 

95 

96 def toggle_exposure(self): 

97 """露光量を 0 に戻す。0 のときは、直前に使っていた値に戻す。""" 

98 if abs(self._settings.exposure) > 1e-9: 

99 self.window.canvas.set_view_preview(exposure=0.0) 

100 self.sync() 

101 else: 

102 self.set_exposure(self._last_exposure) 

103 

104 # ------------------------------------------------------------------ 

105 # ボタンとメニューの表示を、今の設定に合わせる 

106 # ------------------------------------------------------------------ 

107 def sync(self): 

108 window = self.window 

109 settings = self._settings 

110 button = getattr(window, "map_colors_button", None) 

111 if button is not None: 111 ↛ 114line 111 didn't jump to line 114 because the condition on line 111 was always true

112 with QSignalBlocker(button): 

113 button.setChecked(settings.map_colors) 

114 action = getattr(window, "a_preview_map", None) 

115 if action is not None: 115 ↛ 118line 115 didn't jump to line 118 because the condition on line 115 was always true

116 with QSignalBlocker(action): 

117 action.setChecked(settings.map_colors) 

118 combo = getattr(window, "channel_combo", None) 

119 if combo is not None: 119 ↛ 122line 119 didn't jump to line 122 because the condition on line 119 was always true

120 with QSignalBlocker(combo): 

121 combo.setChannel(settings.channel) 

122 control = getattr(window, "exposure_control", None) 

123 if control is not None: 123 ↛ 126line 123 didn't jump to line 126 because the condition on line 123 was always true

124 with QSignalBlocker(control.spin): 

125 control.setValue(settings.exposure) 

126 button = getattr(window, "exposure_button", None) 

127 if button is not None: 127 ↛ exitline 127 didn't return from function 'sync' because the condition on line 127 was always true

128 with QSignalBlocker(button): 

129 button.setChecked(abs(settings.exposure) > 1e-9) 

130 

131 def sync_black_check(self, checked): 

132 button = getattr(self.window, "black_check_button", None) 

133 if button is not None: 133 ↛ exitline 133 didn't return from function 'sync_black_check' because the condition on line 133 was always true

134 with QSignalBlocker(button): 

135 button.setChecked(bool(checked)) 

136 

137 

138__all__ = ["ViewPreviewController", "channel_labels"]