Coverage for graphica/gui/export_preview_panel.py: 97.4%
316 statements
« prev ^ index » next coverage.py v7.17.5, created at 2026-11-25 19:22 +0000
« prev ^ index » next coverage.py v7.17.5, created at 2026-11-25 19:22 +0000
1"""書き出しのプレビューのドック。設定を変えるたびに全サブプロットの完成形を描き直し、ここから保存とコピーもできる。
3一時的な MplCanvas に描くので、画面のキャンバスには触れない。
4"""
5import copy
6import io
7import os
8import logging
9import matplotlib as mpl
11from PySide6.QtCore import Qt, QTimer, QByteArray, QMimeData
12from PySide6.QtGui import QPixmap
13from PySide6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout,
14 QLabel, QComboBox, QCheckBox, QDoubleSpinBox, QSpinBox,
15 QPushButton, QApplication)
17from graphica.core.i18n import tr
18from graphica.gui import motion, notify
19from graphica.gui import dialog_dirs
20from graphica.gui.canvas import MplCanvas
21from graphica.core.plugin_api import get_plugin_api, get_registered_exporters
22from graphica.core.plugin_types import PluginExecutionError
23from graphica.gui.export_settings import (export_rc_params, is_croppable_format, outside_frame_cropped,
24 project_has_raster_gradient_fill)
25from graphica.gui.export_size import ExportSizeFields, confirm_output_size, preview_dpi, preview_too_large_text
26from graphica.gui.builders.property_sections import build_section
27from graphica.gui.widgets import ComboMirror, SegmentedControl
29logger = logging.getLogger(__name__)
31# 矢印の連打などで毎回重い描き直しが走らないよう、まとめるまでの待ち(ms)
32PREVIEW_DEBOUNCE_MS = 150
34# 学術誌の段組の幅(mm)。高さは図ごとに違うので決めない
35SIZE_PRESET_CUSTOM = "カスタム"
36JOURNAL_COLUMN_WIDTHS_MM = (
37 ("学術誌 単段 (85mm)", 85.0),
38 ("学術誌 1.5段 (114mm)", 114.0),
39 ("学術誌 2段 (170mm)", 170.0),
40)
41# 値は日本語の元の文字(書き出しの処理がそれで単位を見分ける)、見せるのは短い記号
42EXPORT_UNITS = (
43 ("ピクセル (px)", "px"), ("インチ (in)", "in"), ("センチメートル (cm)", "cm"), ("ミリメートル (mm)", "mm"),
44)
45MILLIMETRE_UNIT = "ミリメートル (mm)"
46COPY_FORMAT_SEGMENTS_WIDTH = 96
49def _with_hidden_owner(view, owner):
50 """見た目の部品と、隠した値の持ち主(コンボ)を1つの欄にまとめる。"""
51 field = QWidget()
52 layout = QHBoxLayout(field)
53 layout.setContentsMargins(0, 0, 0, 0)
54 layout.setSpacing(0)
55 layout.addWidget(view, 1)
56 owner.setParent(field)
57 owner.hide()
58 return field
61class ExportPreviewPanel(QWidget):
62 def __init__(self, main_window, parent=None):
63 super().__init__(parent)
64 self.main_window = main_window
65 self._current_pixmap = None
67 layout = QVBoxLayout(self)
68 # 左はほかのタブと同じ 16px。右は下のボタンの行が入るよう少し狭い
69 layout.setContentsMargins(16, 8, 14, 9)
70 layout.setSpacing(6)
72 # ほかのタブと同じ開閉できる節(名前の列の幅もそろう)
73 self._size_section = build_section(tr("大きさ"), opened=True, first=True)
74 self._options_section = build_section(tr("書き出し方"), opened=True)
75 form = self._size_section['form']
76 self.size_preset_combo = QComboBox()
77 self.size_preset_combo.addItem(tr(SIZE_PRESET_CUSTOM), None)
78 for label, width_mm in JOURNAL_COLUMN_WIDTHS_MM:
79 self.size_preset_combo.addItem(tr(label), width_mm)
80 self.size_preset_combo.setToolTip(tr("学術誌の段の幅に合わせる(単位はミリメートルになる)"))
81 form.addRow(tr("段幅"), self.size_preset_combo)
83 self.width_spinbox = QDoubleSpinBox()
84 self.width_spinbox.setRange(1, 10000)
85 self.width_spinbox.setDecimals(1)
86 self.width_spinbox.setValue(800)
87 form.addRow("幅", self.width_spinbox)
89 self.height_spinbox = QDoubleSpinBox()
90 self.height_spinbox.setRange(1, 10000)
91 self.height_spinbox.setDecimals(1)
92 self.height_spinbox.setValue(600)
93 form.addRow("高さ", self.height_spinbox)
95 self.unit_combo = QComboBox()
96 for unit, _short in EXPORT_UNITS:
97 self.unit_combo.addItem(tr(unit), unit)
98 # 単位は選択肢が少ないのでセグメントで見せる(値の持ち主はコンボのまま)
99 self.unit_segments = SegmentedControl()
100 for unit, short in EXPORT_UNITS:
101 self.unit_segments.addItem(short, unit, tr(unit))
102 form.addRow("単位", _with_hidden_owner(self.unit_segments, self.unit_combo))
104 self.dpi_spinbox = QSpinBox()
105 self.dpi_spinbox.setRange(50, 1200)
106 self.dpi_spinbox.setValue(150)
107 self.dpi_spinbox.setSuffix(" dpi")
108 form.addRow("解像度", self.dpi_spinbox)
110 self.output_size_label = QLabel()
111 self.output_size_label.setProperty("hint", True)
112 form.addRow(self.output_size_label)
113 # 単位のコンボの描き直しより先に換算が済むよう、ほかの通知をつなぐ前に作る
114 self._size_fields = ExportSizeFields(
115 self.width_spinbox, self.height_spinbox, self.unit_combo, self.dpi_spinbox, self.output_size_label)
117 form = self._options_section['form']
118 self.transparent_checkbox = QCheckBox("背景を透過")
119 self.transparent_checkbox.setChecked(True)
120 form.addRow(self.transparent_checkbox)
122 # ダークのまま書き出すと、透過した白い紙に明るい文字と目盛が乗って読めない図になる
123 self.light_colors_checkbox = QCheckBox(tr("ライト配色で書き出す"))
124 self.light_colors_checkbox.setChecked(True)
125 self.light_colors_checkbox.setToolTip(tr(
126 "ダークモードのときも、書き出し・コピー・印刷はライトの配色(白地に濃い文字)で描きます。"))
127 form.addRow(self.light_colors_checkbox)
129 # 「名前を付けてエクスポート」は画面の図をそのまま書き出すので、既定はそれと同じ範囲にする
130 self.visible_range_checkbox = QCheckBox("表示中の範囲で書き出す")
131 self.visible_range_checkbox.setChecked(True)
132 self.visible_range_checkbox.setToolTip("グラフの上でマウスで拡大・移動した範囲で書き出します。外すと、プロットのプロパティで決めた範囲(自動ならデータ全体)で書き出します。")
133 form.addRow(self.visible_range_checkbox)
135 self.svg_text_as_path_checkbox = QCheckBox("文字をアウトライン化する(SVG)")
136 self.svg_text_as_path_checkbox.setToolTip(
137 "SVG保存/コピー時、目盛の数字やラベルの文字をパス(輪郭線)として出力します。"
138 )
139 form.addRow(self.svg_text_as_path_checkbox)
141 self.crop_outside_frame_checkbox = QCheckBox("枠の外を切り落とす(SVG/PDF)")
142 self.crop_outside_frame_checkbox.setToolTip("SVG・PDF で、プロット枠の外にはみ出す線・点・塗りを削って書き出します(クリッピングマスクも使いません)。PowerPoint で「図形に変換」したときなどに、枠の外のデータが出てこなくなります。オフのときは枠の外のデータも残し、マスクで隠します。2D マップは削らずマスクで隠します。")
143 form.addRow(self.crop_outside_frame_checkbox)
145 # プレビューは応答を優先して常に間引いて描く。このチェックは保存とコピーだけに効く
146 # 解像度(dpi)の設定と取り違えられたので、「間引かない」ことを名前にする
147 self.full_resolution_checkbox = QCheckBox("データを間引かずに保存/コピー")
148 self.full_resolution_checkbox.setToolTip(
149 "「名前を付けて保存」「コピー」で、点数の多い Line(折れ線)データセットや 2D マップ(ヒートマップ/等高線)を、"
150 "画面表示用に間引かず全データ点で描きます(処理が遅くなる場合があります)。画像の解像度(dpi)とは別の設定です。常に描き直すプレビュー自体は、応答を優先して間引いたまま表示します。"
151 )
152 form.addRow(self.full_resolution_checkbox)
154 layout.addWidget(self._size_section['section'])
155 layout.addWidget(self._options_section['section'])
157 self.preview_label = QLabel("プレビューがここに表示されます")
158 self.preview_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
159 self.preview_label.setMinimumSize(200, 150)
160 self.preview_label.setObjectName("export_preview_frame")
161 self.preview_label.setWordWrap(True)
162 layout.addWidget(self.preview_label, 1)
164 button_row = QHBoxLayout()
165 # インスペクタは縦のスクロールバーの幅をいつも取っておくので、この行が入るように少し詰める
166 button_row.setSpacing(4)
167 # SVG はベクター画像を受け付けるアプリ(Illustrator、Inkscape など)に貼れる
168 self.copy_format_combo = QComboBox()
169 self.copy_format_combo.addItems(["PNG", "SVG"])
170 self.copy_format_segments = SegmentedControl()
171 for fmt in ("PNG", "SVG"):
172 self.copy_format_segments.addItem(fmt, fmt, tr("クリップボードにコピーする形式"))
173 self.copy_format_segments.setFixedWidth(COPY_FORMAT_SEGMENTS_WIDTH)
174 button_row.addWidget(_with_hidden_owner(self.copy_format_segments, self.copy_format_combo))
175 self.copy_format_mirror = ComboMirror(self.copy_format_segments, self.copy_format_combo)
177 self.copy_button = QPushButton("コピー")
178 self.copy_button.setToolTip("現在の設定でレンダリングした画像をクリップボードにコピーします")
179 self.copy_button.clicked.connect(self._on_copy_clicked)
180 button_row.addWidget(self.copy_button)
182 self.save_button = QPushButton("名前を付けて保存...")
183 self.save_button.setProperty("primaryButton", True)
184 self.save_button.clicked.connect(self._on_save_clicked)
185 button_row.addWidget(self.save_button)
186 layout.addLayout(button_row)
188 self.unit_mirror = ComboMirror(self.unit_segments, self.unit_combo)
189 self.size_preset_combo.currentIndexChanged.connect(self._on_size_preset_changed)
191 self.width_spinbox.valueChanged.connect(self.refresh_preview)
192 self.height_spinbox.valueChanged.connect(self.refresh_preview)
193 self.unit_combo.currentIndexChanged.connect(self.refresh_preview)
194 self.dpi_spinbox.valueChanged.connect(self.refresh_preview)
195 self.visible_range_checkbox.toggled.connect(self.refresh_preview)
196 self.light_colors_checkbox.toggled.connect(self.refresh_preview)
198 self._refresh_timer = QTimer(self)
199 self._refresh_timer.setSingleShot(True)
200 self._refresh_timer.setInterval(PREVIEW_DEBOUNCE_MS)
201 self._refresh_timer.timeout.connect(self._render_if_shown)
203 def section_forms(self):
204 return [self._size_section['form'], self._options_section['form']]
206 def _on_size_preset_changed(self, _index):
207 """「カスタム」なら入力した値をそのまま残す。単位を先に替える(今の幅がミリメートルに換算されてから入れ直す)。"""
208 width_mm = self.size_preset_combo.currentData()
209 if width_mm is None: 209 ↛ 210line 209 didn't jump to line 210 because the condition on line 209 was never true
210 return
211 self.unit_combo.setCurrentIndex(self.unit_combo.findData(MILLIMETRE_UNIT))
212 self.width_spinbox.setValue(width_mm)
214 def get_options(self):
215 """書き出しの設定(_calculate_size_in_inches で使える)。"""
216 return {
217 "width": self.width_spinbox.value(),
218 "height": self.height_spinbox.value(),
219 "unit": self.unit_combo.currentData(),
220 "dpi": self.dpi_spinbox.value(),
221 "transparent": self.transparent_checkbox.isChecked(),
222 "svg_text_as_path": self.svg_text_as_path_checkbox.isChecked(),
223 "crop_outside_frame": self.crop_outside_frame_checkbox.isChecked(),
224 "full_resolution": self.full_resolution_checkbox.isChecked(),
225 "visible_range": self.visible_range_checkbox.isChecked(),
226 }
228 def refresh_preview(self):
229 """少し待ってまとめて描く。隠れている間は描かない(表示したときに refresh_preview が呼ばれる)。"""
230 if not self.isVisible():
231 return
232 self._refresh_timer.start()
234 def _render_if_shown(self):
235 """実際に見えているときだけ描く。プロパティとタブで並べたドックは、後ろのタブでも isVisible() が真のままなので、
236 見えている領域で確かめる(前に出たときはドックの visibilityChanged から refresh_preview が呼ばれる)。"""
237 if self.isVisible() and not self.visibleRegion().isEmpty():
238 self._render_preview()
240 def _render_preview(self):
241 options = self.get_options()
242 width_in, height_in = self.main_window._calculate_size_in_inches(options)
243 if width_in <= 0 or height_in <= 0:
244 return
246 # 書き出しの解像度のまま描いてから縮めると、大きな図や高い解像度で固まる。欄に合う解像度で描く
247 dpi = preview_dpi(width_in, height_in, options["dpi"],
248 self.preview_label.width(), self.preview_label.height())
249 if dpi is None:
250 self._current_pixmap = None
251 self.preview_label.setPixmap(QPixmap())
252 self.preview_label.setText(preview_too_large_text(width_in, height_in, options["dpi"]))
253 return
254 pixmap = self._render_full_figure_pixmap(width_in, height_in, dpi)
255 self._current_pixmap = pixmap
256 if pixmap is None or pixmap.isNull():
257 self.preview_label.setPixmap(QPixmap())
258 self.preview_label.setText("プレビューを生成できませんでした\n(データセットがないか、設定を確認してください)")
259 return
260 self.preview_label.setText("")
261 self.preview_label.setPixmap(
262 pixmap.scaled(self.preview_label.size(),
263 Qt.AspectRatioMode.KeepAspectRatio,
264 Qt.TransformationMode.SmoothTransformation)
265 )
267 def resizeEvent(self, event):
268 super().resizeEvent(event)
269 if self._current_pixmap is not None and not self._current_pixmap.isNull():
270 self.preview_label.setPixmap(
271 self._current_pixmap.scaled(self.preview_label.size(),
272 Qt.AspectRatioMode.KeepAspectRatio,
273 Qt.TransformationMode.SmoothTransformation)
274 )
275 # 欄に合わせた解像度で描いているので、欄が描いた画像より大きくなったら描き直す
276 if (self._current_pixmap.width() < self.preview_label.width() 276 ↛ 278line 276 didn't jump to line 278 because the condition on line 276 was never true
277 and self._current_pixmap.height() < self.preview_label.height()):
278 self.refresh_preview()
280 def _make_temp_canvas_for_full_figure(self, width_in, height_in, dpi, full_resolution=False):
281 """全サブプロットを描いた一時的な MplCanvas。描けるものが無ければ None。
283 full_resolution=True は間引かない。常に描き直すプレビューでは False、保存とコピーでだけ設定の値を渡す。
284 """
285 mw = self.main_window
286 layout_mode = getattr(mw.project, 'layout_mode', 'grid')
287 if layout_mode == 'free':
288 rows, cols = 0, 0
289 if not mw.project.all_plot_settings: 289 ↛ 297line 289 didn't jump to line 297 because the condition on line 289 was always true
290 return None
291 else:
292 rows = mw.subplot_rows_spinbox.value()
293 cols = mw.subplot_cols_spinbox.value()
294 if rows * cols == 0:
295 return None
297 temp_canvas = MplCanvas(width=width_in, height=height_in, dpi=dpi)
298 temp_canvas.dark_mode = mw.output_dark_mode()
299 if self.visible_range_checkbox.isChecked():
300 # 当て直すときに設定と合わない範囲を消すので、画面の記録を写して渡す
301 temp_canvas.view_overrides = copy.deepcopy(mw.canvas.view_overrides)
302 temp_canvas.redraw_all(
303 mw.project.datasets, rows, cols, mw.project.all_plot_settings, layout_mode=layout_mode,
304 panel_labels_enabled=mw.project.panel_labels_enabled,
305 full_resolution=full_resolution,
306 )
307 return temp_canvas
309 def _render_full_figure_pixmap(self, width_in, height_in, dpi):
310 """画面のプレビュー用。常に不透明で描く(透過は保存とコピーのときだけ選べる)。"""
311 try:
312 temp_canvas = self._make_temp_canvas_for_full_figure(width_in, height_in, dpi)
313 if temp_canvas is None:
314 return None
315 try:
316 buf = io.BytesIO()
317 temp_canvas.fig.savefig(
318 buf, format='png', dpi=dpi, bbox_inches='tight',
319 facecolor=temp_canvas.fig.get_facecolor()
320 )
321 buf.seek(0)
322 pixmap = QPixmap()
323 pixmap.loadFromData(buf.read())
324 buf.close()
325 return pixmap
326 finally:
327 temp_canvas.deleteLater()
328 except Exception:
329 logger.exception("エクスポートプレビューの生成に失敗しました。")
330 return None
332 def _render_full_figure_bytes(self, width_in, height_in, dpi, fmt, transparent, svg_text_as_path=False,
333 full_resolution=False, crop_outside_frame=False):
334 """'png' か 'svg' で書いたバイト列(保存とコピーで共有)。"""
335 try:
336 temp_canvas = self._make_temp_canvas_for_full_figure(width_in, height_in, dpi, full_resolution=full_resolution)
337 if temp_canvas is None:
338 return None
339 try:
340 buf = io.BytesIO()
341 save_kwargs = {'format': fmt, 'bbox_inches': 'tight', 'transparent': transparent}
342 if fmt != 'svg':
343 save_kwargs['dpi'] = dpi
344 with mpl.rc_context(export_rc_params(fmt, svg_text_as_path)), outside_frame_cropped(temp_canvas.fig, crop_outside_frame and is_croppable_format(fmt)):
345 temp_canvas.fig.savefig(buf, **save_kwargs)
346 buf.seek(0)
347 data = buf.read()
348 buf.close()
349 return data
350 finally:
351 temp_canvas.deleteLater()
352 except Exception:
353 logger.exception("エクスポートプレビューのレンダリングに失敗しました(形式: %s)。", fmt)
354 return None
356 def _on_copy_clicked(self):
357 options = self.get_options()
358 width_in, height_in = self.main_window._calculate_size_in_inches(options)
359 if width_in <= 0 or height_in <= 0:
360 notify.warning(self, "コピーエラー", "コピーする画像がありません。")
361 return
362 if not confirm_output_size(self, width_in, height_in, options["dpi"]):
363 return
365 if self.copy_format_combo.currentText() == "SVG":
366 svg_bytes = self._render_full_figure_bytes(
367 width_in, height_in, options["dpi"], fmt='svg', transparent=options["transparent"],
368 svg_text_as_path=options["svg_text_as_path"], full_resolution=options["full_resolution"],
369 crop_outside_frame=options["crop_outside_frame"]
370 )
371 if svg_bytes is None:
372 notify.warning(self, "コピーエラー", "コピーする画像がありません。")
373 return
374 mime_data = QMimeData()
375 mime_data.setData("image/svg+xml", QByteArray(svg_bytes))
376 # SVG だけでは Word や PowerPoint が貼り付けられないので、PNG も同じ QMimeData に載せる。
377 # その PNG は透過にしない(macOS のクリップボードはアルファを引き継がず、貼ると真っ黒になる)
378 png_fallback_bytes = self._render_full_figure_bytes(
379 width_in, height_in, options["dpi"], fmt='png', transparent=False,
380 full_resolution=options["full_resolution"]
381 )
382 if png_fallback_bytes is not None: 382 ↛ 387line 382 didn't jump to line 387 because the condition on line 382 was always true
383 fallback_pixmap = QPixmap()
384 fallback_pixmap.loadFromData(png_fallback_bytes)
385 if not fallback_pixmap.isNull(): 385 ↛ 387line 385 didn't jump to line 387 because the condition on line 385 was always true
386 mime_data.setImageData(fallback_pixmap.toImage())
387 QApplication.clipboard().setMimeData(mime_data)
388 self.main_window.statusBar().showMessage("プレビュー画像をSVG形式でクリップボードにコピーしました", 3000)
389 motion.toast(self.main_window, tr("コピーしました"))
390 else:
391 # 上と同じ理由で透過にしない
392 png_bytes = self._render_full_figure_bytes(
393 width_in, height_in, options["dpi"], fmt='png', transparent=False,
394 full_resolution=options["full_resolution"]
395 )
396 if png_bytes is None:
397 notify.warning(self, "コピーエラー", "コピーする画像がありません。")
398 return
399 pixmap = QPixmap()
400 pixmap.loadFromData(png_bytes)
401 QApplication.clipboard().setPixmap(pixmap)
402 self.main_window.statusBar().showMessage("プレビュー画像をクリップボードにコピーしました", 3000)
403 motion.toast(self.main_window, tr("コピーしました"))
405 def _on_save_clicked(self):
406 self.save_to_chosen_file()
408 def save_to_chosen_file(self):
409 """保存先を聞いて、このタブの設定で書き出す(メニューと上部バーの「エクスポート」もここを通る)。
411 形式は拡張子で決める。プラグインの書き出しの拡張子なら、その writer に図を渡す。
412 """
413 mw = self.main_window
414 options = self.get_options()
415 width_in, height_in = mw._calculate_size_in_inches(options)
417 layout_mode = getattr(mw.project, 'layout_mode', 'grid')
418 if layout_mode == 'free':
419 if not mw.project.all_plot_settings: 419 ↛ 429line 419 didn't jump to line 429 because the condition on line 419 was always true
420 notify.warning(self, "保存エラー", "有効なプロットがありません。")
421 return
422 else:
423 rows = mw.subplot_rows_spinbox.value()
424 cols = mw.subplot_cols_spinbox.value()
425 if rows * cols == 0:
426 notify.warning(self, "保存エラー", "有効なプロットがありません。")
427 return
428 # PDF・SVG でも、一時的な図をこの解像度で描いてから保存する
429 if not confirm_output_size(self, width_in, height_in, options["dpi"]):
430 return
432 filter_parts = ["PNG (*.png)", "PDF (*.pdf)", "SVG (*.svg)"]
433 filter_parts += [f"{exp.format_name} (*{exp.extension})" for exp in get_registered_exporters()]
434 file_path, _ = dialog_dirs.get_save_file_name(
435 mw, dialog_dirs.EXPORT, "プロットを保存", dialog_dirs.project_stem(mw), ";;".join(filter_parts),
436 preferred_dir=dialog_dirs.output_dir(mw)
437 )
438 if not file_path:
439 return
441 file_ext = os.path.splitext(file_path)[1].lower()
442 # グラデーションの塗りはベクター形式でもラスタで埋め込まれる。書き出しは続け、知らせるだけ
443 if file_ext in ('.svg', '.pdf') and project_has_raster_gradient_fill(mw.project):
444 notify.warning(
445 mw, "ベクター出力時の注意",
446 "グラデーション塗りが有効なデータセットが含まれています。\n"
447 "この部分は画像(ラスタ)として埋め込まれるため、拡大すると"
448 "他の要素のようにはくっきり表示されません。\n\n"
449 "エクスポートは続行します。"
450 )
452 temp_canvas = self._make_temp_canvas_for_full_figure(
453 width_in, height_in, options["dpi"], full_resolution=options["full_resolution"]
454 )
455 if temp_canvas is None:
456 notify.warning(self, "保存エラー", "有効なプロットがありません。")
457 return
458 try:
459 api = get_plugin_api()
460 exporter = api.get_exporter_for_extension(file_ext) if api is not None else None
461 if exporter is not None:
462 try:
463 exporter.writer(temp_canvas.fig, file_path)
464 except Exception as e:
465 raise PluginExecutionError(
466 exporter.name, f"「{file_path}」への書き出しに失敗しました: {e}") from e
467 else:
468 save_kwargs = {'transparent': options["transparent"], 'bbox_inches': 'tight'}
469 if file_ext not in ('.pdf', '.svg'):
470 save_kwargs['dpi'] = options["dpi"]
471 crop = options.get("crop_outside_frame", False) and is_croppable_format(file_ext)
472 with mpl.rc_context(export_rc_params(file_ext, options.get("svg_text_as_path", False))), outside_frame_cropped(temp_canvas.fig, crop):
473 temp_canvas.fig.savefig(file_path, **save_kwargs)
474 mw.statusBar().showMessage(f"保存しました: {file_path}", 3000)
475 motion.toast(mw, tr("書き出しました"))
476 except Exception as e:
477 logger.exception("エクスポートに失敗しました。")
478 notify.warning(mw, "保存エラー", f"エクスポート中にエラーが発生しました:\n{e}")
479 finally:
480 temp_canvas.deleteLater()