Debian Codegraph @

DisplayCAL/wx_report_frame.py

raw
1 """Measurement report creation window for DisplayCAL.
2
3 It allows users to configure test charts, profiles, and various settings for
4 generating measurement reports. The module integrates with wxPython for the
5 graphical interface and supports handling ICC profiles, test charts, and
6 rendering intents.
7 """
8
9 import math
10 import os
11 from time import gmtime, strftime
12
13 from wx import xrc
14
15 from DisplayCAL import (
16 config,
17 worker,
18 xh_bitmapctrls,
19 xh_fancytext,
20 xh_filebrowsebutton,
21 xh_hstretchstatbmp,
22 )
23 from DisplayCAL import localization as lang
24 from DisplayCAL.cgats import (
25 CGATS,
26 CGATSInvalidError,
27 CGATSInvalidOperationError,
28 CGATSKeyError,
29 CGATSTypeError,
30 CGATSValueError,
31 )
32 from DisplayCAL.config import (
33 get_data_path,
34 getcfg,
35 hascfg,
36 setcfg,
37 )
38 from DisplayCAL.icc_profile import (
39 CurveType,
40 ICCProfile,
41 ICCProfileInvalidError,
42 LUT16Type,
43 XYZType,
44 )
45 from DisplayCAL.meta import NAME as APPNAME
46 from DisplayCAL.util_list import natsort_key_factory
47 from DisplayCAL.worker import Error, get_current_profile_path, show_result_dialog
48 from DisplayCAL.wx_fixes import TempXmlResource
49 from DisplayCAL.wx_testchart_editor import TestchartEditor
50 from DisplayCAL.wx_windows import BaseApp, BaseFrame, FileDrop, wx
51
52
53 class ReportFrame(BaseFrame):
54 """Measurement report creation window."""
55
56 def __init__(self, parent=None):
57 BaseFrame.__init__(self, parent, -1, lang.getstr("measurement_report"))
58 self.Bind(wx.EVT_CLOSE, self.OnClose)
59
60 self.SetIcons(config.get_icon_bundle([256, 48, 32, 16], APPNAME))
61
62 self.XYZbpin = None
63 self.XYZbpout = None
64
65 res = TempXmlResource(get_data_path(os.path.join("xrc", "report.xrc")))
66 res.InsertHandler(xh_fancytext.StaticFancyTextCtrlXmlHandler())
67 res.InsertHandler(xh_filebrowsebutton.FileBrowseButtonWithHistoryXmlHandler())
68 res.InsertHandler(xh_hstretchstatbmp.HStretchStaticBitmapXmlHandler())
69 res.InsertHandler(xh_bitmapctrls.BitmapButton())
70 res.InsertHandler(xh_bitmapctrls.StaticBitmap())
71 self.panel = res.LoadPanel(self, "panel")
72
73 self.Sizer = wx.BoxSizer(wx.VERTICAL)
74 self.Sizer.Add(self.panel, 1, flag=wx.EXPAND)
75
76 self.set_child_ctrls_as_attrs(self)
77
78 self.measurement_report_btn = wx.Button(self.panel, -1, lang.getstr("measure"))
79 self.panel.Sizer.Insert(
80 2,
81 self.measurement_report_btn,
82 flag=wx.RIGHT | wx.BOTTOM | wx.ALIGN_RIGHT,
83 border=16,
84 )
85
86 self.worker = worker.Worker(self)
87 self.worker.set_argyll_version("xicclu")
88
89 BaseFrame.setup_language(self)
90 self.mr_setup_language()
91 self.mr_init_controls()
92 self.mr_update_controls()
93 self.mr_init_frame()
94
95 def mr_init_controls(self):
96 """Initialize controls for the measurement report frame."""
97 for which in (
98 "chart",
99 "simulation_profile",
100 "devlink_profile",
101 "output_profile",
102 ):
103 ctrl = xrc.XRCCTRL(self, f"{which}_ctrl")
104 setattr(self, f"{which}_ctrl", ctrl)
105 ctrl.changeCallback = getattr(self, f"{which}_ctrl_handler")
106 if which not in ("devlink_profile", "output_profile"):
107 wildcard = r"\.(cie|ti1|ti3)$" if which == "chart" else r"\.(icc|icm)$"
108 history = []
109 if which == "simulation_profile":
110 standard_profiles = config.get_standard_profiles(True)
111 basenames = []
112 for path in standard_profiles:
113 basename = os.path.basename(path)
114 if basename not in basenames:
115 basenames.append(basename)
116 history.append(path)
117 else:
118 paths = get_data_path("ref", wildcard) or []
119 for path in paths:
120 basepath, ext = os.path.splitext(path)
121 if os.getenv("XDG_SESSION_TYPE") == "wayland" and (
122 ext.lower() != ".ti1"
123 or os.path.basename(path) == "ccxx.ti1"
124 ):
125 # When the number of items in a dropdown popup menu
126 # exceeds the available display client area height,
127 # the popup menu gets shown at weird positions or
128 # not at all under Wayland. Work-around this wx bug
129 # by truncating the choices. Yuck. Also see:
130 # FileBrowseBitmapButtonWithChoiceHistory.SetHistory
131 continue
132 if not (
133 path.lower().endswith(".ti2") and f"{basepath}.cie" in paths
134 ):
135 history.append(path)
136 natsort_key = natsort_key_factory()
137 history = sorted(
138 history, key=lambda path: natsort_key(os.path.basename(path))
139 )
140 ctrl.SetHistory(history)
141 ctrl.SetMaxFontSize(11)
142 # Drop targets
143 handler = getattr(self, f"{which}_drop_handler")
144 if which.endswith("_profile"):
145 drophandlers = {".icc": handler, ".icm": handler}
146 else:
147 drophandlers = {
148 ".cgats": handler,
149 ".cie": handler,
150 ".ti1": handler,
151 ".ti2": handler,
152 ".ti3": handler,
153 ".txt": handler,
154 }
155 ctrl.SetDropTarget(FileDrop(self, drophandlers))
156
157 # Bind event handlers
158 self.fields_ctrl.Bind(wx.EVT_CHOICE, self.fields_ctrl_handler)
159 self.chart_btn.Bind(wx.EVT_BUTTON, self.chart_btn_handler)
160 self.simulation_profile_cb.Bind(
161 wx.EVT_CHECKBOX, self.use_simulation_profile_ctrl_handler
162 )
163 self.use_simulation_profile_as_output_cb.Bind(
164 wx.EVT_CHECKBOX, self.use_simulation_profile_as_output_handler
165 )
166 self.enable_3dlut_cb.Bind(wx.EVT_CHECKBOX, self.enable_3dlut_handler)
167 self.apply_none_ctrl.Bind(wx.EVT_RADIOBUTTON, self.apply_trc_ctrl_handler)
168 self.apply_black_offset_ctrl.Bind(
169 wx.EVT_RADIOBUTTON, self.apply_trc_ctrl_handler
170 )
171 self.apply_trc_ctrl.Bind(wx.EVT_RADIOBUTTON, self.apply_trc_ctrl_handler)
172 self.mr_trc_ctrl.Bind(wx.EVT_CHOICE, self.mr_trc_ctrl_handler)
173 self.mr_trc_gamma_ctrl.Bind(wx.EVT_COMBOBOX, self.mr_trc_gamma_ctrl_handler)
174 self.mr_trc_gamma_ctrl.Bind(wx.EVT_KILL_FOCUS, self.mr_trc_gamma_ctrl_handler)
175 self.mr_trc_gamma_type_ctrl.Bind(
176 wx.EVT_CHOICE, self.mr_trc_gamma_type_ctrl_handler
177 )
178 self.mr_black_output_offset_ctrl.Bind(
179 wx.EVT_SLIDER, self.mr_black_output_offset_ctrl_handler
180 )
181 self.mr_black_output_offset_intctrl.Bind(
182 wx.EVT_TEXT, self.mr_black_output_offset_ctrl_handler
183 )
184 self.simulate_whitepoint_cb.Bind(
185 wx.EVT_CHECKBOX, self.simulate_whitepoint_ctrl_handler
186 )
187 self.simulate_whitepoint_relative_cb.Bind(
188 wx.EVT_CHECKBOX, self.simulate_whitepoint_relative_ctrl_handler
189 )
190 self.devlink_profile_cb.Bind(
191 wx.EVT_CHECKBOX, self.use_devlink_profile_ctrl_handler
192 )
193 self.output_profile_current_btn.Bind(
194 wx.EVT_BUTTON, self.output_profile_current_ctrl_handler
195 )
196
197 def mr_init_frame(self):
198 """Initialize the measurement report frame with default settings and layout."""
199 self.measurement_report_btn.SetDefault()
200
201 self.update_layout()
202
203 config.DEFAULTS.update(
204 {
205 "position.reportframe.x": self.GetDisplay().ClientArea[0] + 40,
206 "position.reportframe.y": self.GetDisplay().ClientArea[1] + 60,
207 "size.reportframe.w": self.ClientSize[0],
208 "size.reportframe.h": self.ClientSize[1],
209 }
210 )
211
212 if (
213 hascfg("position.reportframe.x")
214 and hascfg("position.reportframe.y")
215 and hascfg("size.reportframe.w")
216 and hascfg("size.reportframe.h")
217 ):
218 self.SetSaneGeometry(
219 int(getcfg("position.reportframe.x")),
220 int(getcfg("position.reportframe.y")),
221 int(getcfg("size.reportframe.w")),
222 int(getcfg("size.reportframe.h")),
223 )
224 else:
225 self.Center()
226
227 def OnClose(self, event=None):
228 """Handle the close event for the measurement report frame.
229
230 Args:
231 event (wx.Event, optional): The event that triggered the close.
232 """
233 if self.IsShownOnScreen() and not self.IsMaximized() and not self.IsIconized():
234 x, y = self.GetScreenPosition()
235 setcfg("position.reportframe.x", x)
236 setcfg("position.reportframe.y", y)
237 setcfg("size.reportframe.w", self.ClientSize[0])
238 setcfg("size.reportframe.h", self.ClientSize[1])
239 config.writecfg()
240 if event:
241 event.Skip()
242
243 def apply_trc_ctrl_handler(self, event):
244 """Handle changes to the TRC application control.
245
246 Args:
247 event (wx.Event): The event that triggered this handler.
248 """
249 v = self.apply_trc_ctrl.GetValue()
250 setcfg("measurement_report.apply_trc", int(v))
251 setcfg(
252 "measurement_report.apply_black_offset",
253 int(self.apply_black_offset_ctrl.GetValue()),
254 )
255 self.mr_update_main_controls()
256
257 def mr_black_output_offset_ctrl_handler(self, event):
258 """Handle changes to the black output offset control.
259
260 Args:
261 event (wx.Event): The event that triggered this handler.
262 """
263 if event.GetId() == self.mr_black_output_offset_intctrl.GetId():
264 self.mr_black_output_offset_ctrl.SetValue(
265 self.mr_black_output_offset_intctrl.GetValue()
266 )
267 else:
268 self.mr_black_output_offset_intctrl.SetValue(
269 self.mr_black_output_offset_ctrl.GetValue()
270 )
271 v = self.mr_black_output_offset_ctrl.GetValue() / 100.0
272 if v != getcfg("measurement_report.trc_output_offset"):
273 setcfg("measurement_report.trc_output_offset", v)
274 self.mr_update_trc_control()
275 # self.mr_show_trc_controls()
276
277 def mr_trc_gamma_ctrl_handler(self, event):
278 """Handle changes to the TRC gamma control.
279
280 Args:
281 event (wx.Event): The event that triggered this handler.
282 """
283 try:
284 v = float(self.mr_trc_gamma_ctrl.GetValue().replace(",", "."))
285 if (
286 v < config.VALID_RANGES["measurement_report.trc_gamma"][0]
287 or v > config.VALID_RANGES["measurement_report.trc_gamma"][1]
288 ):
289 raise ValueError
290 except ValueError:
291 wx.Bell()
292 self.mr_trc_gamma_ctrl.SetValue(str(getcfg("measurement_report.trc_gamma")))
293 else:
294 if str(v) != self.mr_trc_gamma_ctrl.GetValue():
295 self.mr_trc_gamma_ctrl.SetValue(str(v))
296 if v != getcfg("measurement_report.trc_gamma"):
297 setcfg("measurement_report.trc_gamma", v)
298 self.mr_update_trc_control()
299 self.mr_show_trc_controls()
300 event.Skip()
301
302 def mr_trc_ctrl_handler(self, event):
303 """Handle changes to the TRC control.
304
305 Args:
306 event (wx.Event): The event that triggered this handler.
307 """
308 self.Freeze()
309 if self.mr_trc_ctrl.GetSelection() == 1:
310 # BT.1886
311 setcfg("measurement_report.trc_gamma", 2.4)
312 setcfg("measurement_report.trc_gamma_type", "B")
313 setcfg("measurement_report.trc_output_offset", 0.0)
314 self.mr_update_trc_controls()
315 elif self.mr_trc_ctrl.GetSelection() == 0:
316 # Pure power gamma 2.2
317 setcfg("measurement_report.trc_gamma", 2.2)
318 setcfg("measurement_report.trc_gamma_type", "b")
319 setcfg("measurement_report.trc_output_offset", 1.0)
320 self.mr_update_trc_controls()
321 else:
322 # Custom
323 # Have to use CallAfter, otherwise only part of the text will
324 # be selected (wxPython bug?)
325 wx.CallAfter(self.mr_trc_gamma_ctrl.SetFocus)
326 wx.CallLater(1, self.mr_trc_gamma_ctrl.SelectAll)
327 self.mr_show_trc_controls()
328 self.Thaw()
329
330 def mr_trc_gamma_type_ctrl_handler(self, event):
331 """Handle changes to the TRC gamma type control.
332
333 Args:
334 event (wx.Event): The event that triggered this handler.
335 """
336 v = self.trc_gamma_types_ab[self.mr_trc_gamma_type_ctrl.GetSelection()]
337 if v != getcfg("measurement_report.trc_gamma_type"):
338 setcfg("measurement_report.trc_gamma_type", v)
339 self.mr_update_trc_control()
340 self.mr_show_trc_controls()
341
342 def chart_btn_handler(self, event):
343 """Open the test chart editor for the selected chart.
344
345 Args:
346 event (wx.Event): The event that triggered this handler.
347 """
348 parent = self.Parent if self.Parent else self
349 chart = getcfg("measurement_report.chart")
350 if not hasattr(parent, "tcframe"):
351 parent.tcframe = TestchartEditor(
352 parent,
353 path=chart,
354 cfg="measurement_report.chart",
355 parent_set_chart_methodname="mr_set_testchart",
356 )
357 elif not hasattr(parent.tcframe, "ti1") or chart != parent.tcframe.ti1.filename:
358 parent.tcframe.tc_load_cfg_from_ti1(
359 None, chart, "measurement_report.chart", "mr_set_testchart"
360 )
361 setcfg("tc.show", 1)
362 parent.tcframe.Show()
363 parent.tcframe.Raise()
364
365 def chart_ctrl_handler(self, event):
366 """Handle changes to the chart control.
367
368 Args:
369 event (wx.Event): The event that triggered this handler.
370 """
371 chart = self.chart_ctrl.GetPath()
372 values = []
373 try:
374 cgats = CGATS(chart)
375 except (
376 OSError,
377 CGATSInvalidError,
378 CGATSInvalidOperationError,
379 CGATSKeyError,
380 CGATSTypeError,
381 CGATSValueError,
382 ) as exception:
383 show_result_dialog(exception, self)
384 else:
385 data_format = cgats.queryv1("DATA_FORMAT")
386 accurate = cgats.queryv1("ACCURATE_EXPECTED_VALUES") == "true"
387 if data_format:
388 basename, ext = os.path.splitext(chart)
389 for column in data_format.values():
390 column_prefix = column.split(b"_")[0].decode("utf-8")
391 if (
392 column_prefix in ("CMYK", "LAB", "RGB", "XYZ")
393 and column_prefix not in values
394 and (
395 (
396 (ext.lower() == ".cie" or accurate)
397 and column_prefix in ("LAB", "XYZ")
398 )
399 or (
400 ext.lower() == ".ti1"
401 and column_prefix in ("CMYK", "RGB")
402 )
403 or (ext.lower() not in (".cie", ".ti1"))
404 )
405 ):
406 values.append(column_prefix)
407 if values:
408 self.panel.Freeze()
409 self.fields_ctrl.SetItems(values)
410 self.fields_ctrl.GetContainingSizer().Layout()
411 self.panel.Thaw()
412 _fields = getcfg("measurement_report.chart.fields")
413 if ext.lower() == ".ti1":
414 index = 0
415 elif "RGB" in values and ext.lower() != ".cie":
416 index = values.index("RGB")
417 elif "CMYK" in values:
418 index = values.index("CMYK")
419 elif "XYZ" in values:
420 index = values.index("XYZ")
421 elif "LAB" in values:
422 index = values.index("LAB")
423 else:
424 index = 0
425 self.fields_ctrl.SetSelection(index)
426 setcfg("measurement_report.chart", chart)
427 self.chart_patches_amount.Freeze()
428 self.chart_patches_amount.SetLabel(
429 str(cgats.queryv1("NUMBER_OF_SETS") or "")
430 )
431 self.update_estimated_measurement_time("chart")
432 self.chart_patches_amount.GetContainingSizer().Layout()
433 self.chart_patches_amount.Thaw()
434 self.chart_white = cgats.get_white_cie()
435 if not values:
436 if chart:
437 show_result_dialog(
438 lang.getstr(
439 "error.testchart.missing_fields",
440 (chart, f"RGB/CMYK {lang.getstr('or')} LAB/XYZ"),
441 ),
442 self,
443 )
444 self.chart_ctrl.SetPath(getcfg("measurement_report.chart"))
445 else:
446 self.chart_btn.Enable("RGB" in values)
447 parent = self.Parent if self.Parent else self
448 if (
449 event
450 and self.chart_btn.Enabled
451 and hasattr(parent, "tcframe")
452 and self.tcframe.IsShownOnScreen()
453 and (
454 not hasattr(parent.tcframe, "ti1")
455 or chart != parent.tcframe.ti1.filename
456 )
457 ):
458 parent.tcframe.tc_load_cfg_from_ti1(
459 None, chart, "measurement_report.chart", "mr_set_testchart"
460 )
461 self.fields_ctrl.Enable(self.fields_ctrl.GetCount() > 1)
462 self.fields_ctrl_handler(event)
463
464 def set_simulate_whitepoint(self, set_whitepoint_simulate_relative=False):
465 """Set the configuration for simulating whitepoint in measurement reports.
466
467 Args:
468 set_whitepoint_simulate_relative (bool): If True, sets the
469 'measurement_report.whitepoint.simulate.relative' configuration.
470 """
471 sim_profile = self.get_simulation_profile()
472 is_prtr_profile = sim_profile and sim_profile.profileClass == b"prtr"
473 if set_whitepoint_simulate_relative:
474 setcfg(
475 "measurement_report.whitepoint.simulate",
476 int(
477 not getattr(self, "chart_white", None)
478 or "RGB" not in self.fields_ctrl.Items
479 or is_prtr_profile
480 ),
481 )
482 setcfg(
483 "measurement_report.whitepoint.simulate.relative",
484 int("LAB" in self.fields_ctrl.Items or is_prtr_profile),
485 )
486
487 def chart_drop_handler(self, path):
488 """Handle dropping a chart file onto the control.
489
490 Args:
491 path (str): The file path of the dropped chart.
492 """
493 if not self.worker.is_working():
494 self.chart_ctrl.SetPath(path)
495 self.chart_ctrl_handler(True)
496
497 def devlink_profile_ctrl_handler(self, event):
498 """Handle changes to the devicelink profile control.
499
500 Args:
501 event (wx.Event): The event that triggered this handler.
502 """
503 self.set_profile("devlink")
504
505 def devlink_profile_drop_handler(self, path):
506 """Handle dropping a devicelink profile file onto the control.
507
508 Args:
509 path (str): The file path of the dropped devicelink profile.
510 """
511 if not self.worker.is_working():
512 self.devlink_profile_ctrl.SetPath(path)
513 self.set_profile("devlink")
514
515 def enable_3dlut_handler(self, event):
516 """Handle changes to the enable 3D LUT checkbox.
517
518 Args:
519 event (wx.Event): The event that triggered this handler.
520 """
521 setcfg("3dlut.enable", int(self.enable_3dlut_cb.GetValue()))
522 setcfg("measurement_report.use_devlink_profile", 0)
523 self.mr_update_main_controls()
524
525 def fields_ctrl_handler(self, event):
526 """Handle changes to the fields control.
527
528 Args:
529 event (wx.Event): The event that triggered this handler.
530 """
531 setcfg("measurement_report.chart.fields", self.fields_ctrl.GetStringSelection())
532 if event:
533 self.mr_update_main_controls(event)
534
535 def output_profile_ctrl_handler(self, event):
536 """Handle changes to the output profile control.
537
538 Args:
539 event (wx.Event): The event that triggered this handler.
540 """
541 self.set_profile("output")
542
543 def output_profile_current_ctrl_handler(self, event):
544 """Set the output profile control to the current profile path.
545
546 Args:
547 event (wx.Event): The event that triggered this handler.
548 """
549 profile_path = get_current_profile_path(True, True)
550 if profile_path and os.path.isfile(profile_path):
551 self.output_profile_ctrl.SetPath(profile_path)
552 self.set_profile("output")
553
554 def output_profile_drop_handler(self, path):
555 """Handle dropping an output profile file onto the control.
556
557 Args:
558 path (str): The file path of the dropped output profile.
559 """
560 if not self.worker.is_working():
561 self.output_profile_ctrl.SetPath(path)
562 self.set_profile("output")
563
564 def set_profile(self, which, profile_path=None, silent=False):
565 """Set the profile for the given type (simulation, devlink, or output).
566
567 Args:
568 which (str): The type of profile to set. Should be one of "simulation",
569 "devlink", or "output".
570 profile_path (str, optional): The path to the profile file. If None,
571 the current profile path will be used.
572 silent (bool): If True, suppresses UI updates and dialogs.
573
574 Returns:
575 ICCProfile or None: The set profile if successful, otherwise None.
576 """
577 path = getattr(self, f"{which}_profile_ctrl").GetPath()
578 if which == "output":
579 # if profile_path is None:
580 # profile_path = get_current_profile_path(True, True)
581 # self.output_profile_current_btn.Enable(
582 # self.output_profile_ctrl.IsShown() and
583 # bool(profile_path) and
584 # os.path.isfile(profile_path) and
585 # profile_path != path
586 # )
587 profile = config.get_current_profile(True)
588 path = profile.filename if profile else None
589 setcfg("measurement_report.output_profile", path)
590 XYZbpout = self.XYZbpout
591 # XYZbpout will be set to the blackpoint of the selected profile.
592 # This is used to determine if black output offset controls should
593 # be shown. Set a initial value slightly above zero so output
594 # offset controls are shown if the selected profile doesn't exist.
595 self.XYZbpout = [0.001, 0.001, 0.001]
596 else:
597 profile = None
598 if which == "input":
599 XYZbpin = self.XYZbpin
600 self.XYZbpin = [0, 0, 0]
601 if not path and not profile:
602 setattr(self, f"{which}_profile", None)
603 if not silent:
604 setcfg(f"measurement_report.{which}_profile", None)
605 self.mr_update_main_controls()
606 return None
607 if path and not os.path.isfile(path):
608 if not silent:
609 show_result_dialog(
610 Error(lang.getstr("file.missing", path)), parent=self
611 )
612 return None
613 if not profile:
614 try:
615 profile = ICCProfile(path)
616 except ICCProfileInvalidError:
617 if not silent:
618 show_result_dialog(
619 Error(f"{lang.getstr('profile.invalid')}\n{path}"),
620 parent=self,
621 )
622 except OSError as exception:
623 if not silent:
624 show_result_dialog(exception, parent=self)
625 if profile:
626 profile_path = profile.filename
627 if (
628 (
629 which == "simulation"
630 and (
631 profile.profileClass not in (b"mntr", b"prtr")
632 or profile.colorSpace not in (b"CMYK", b"RGB")
633 )
634 )
635 or (
636 which == "output"
637 and (
638 profile.profileClass != b"mntr" or profile.colorSpace != b"RGB"
639 )
640 )
641 or (which == "devlink" and profile.profileClass != b"link")
642 ):
643 show_result_dialog(
644 NotImplementedError(
645 lang.getstr(
646 "profile.unsupported",
647 (
648 profile.profileClass.decode("utf-8"),
649 profile.colorSpace.decode("utf-8"),
650 ),
651 )
652 ),
653 parent=self,
654 )
655 else:
656 if (
657 not getattr(self, f"{which}_profile", None)
658 or getattr(self, f"{which}_profile").filename != profile.filename
659 ):
660 # Profile selection has changed
661 if which == "simulation":
662 # Get profile blackpoint so we can check if it makes
663 # sense to show TRC type and output offset controls
664 try:
665 odata = self.worker.xicclu(profile, (0, 0, 0), pcs="x")
666 except Exception as exception:
667 show_result_dialog(exception, self)
668 self.set_profile_ctrl_path(which)
669 return None
670 else:
671 if len(odata) != 1 or len(odata[0]) != 3:
672 show_result_dialog(
673 f"Blackpoint is invalid: {odata}", self
674 )
675 self.set_profile_ctrl_path(which)
676 return None
677 self.XYZbpin = odata[0]
678 elif which == "output":
679 # Get profile blackpoint so we can check if input
680 # values would be clipped
681 try:
682 odata = self.worker.xicclu(profile, (0, 0, 0), pcs="x")
683 except Exception as exception:
684 show_result_dialog(exception, self)
685 self.set_profile_ctrl_path(which)
686 return None
687 else:
688 if len(odata) != 1 or len(odata[0]) != 3:
689 show_result_dialog(
690 f"Blackpoint is invalid: {odata}", self
691 )
692 self.set_profile_ctrl_path(which)
693 return None
694 if odata[0][1]:
695 # Got above zero blackpoint from lookup
696 self.XYZbpout = odata[0]
697 else:
698 # Got zero blackpoint from lookup.
699 # Try chardata instead.
700 XYZbp = profile.get_chardata_bkpt()
701 if XYZbp:
702 self.XYZbpout = XYZbp
703 else:
704 self.XYZbpout = [0, 0, 0]
705 # Profile selection has not changed
706 # Restore cached XYZbp values
707 elif which == "output":
708 self.XYZbpout = XYZbpout
709 elif which == "input":
710 self.XYZbpin = XYZbpin
711 setattr(self, f"{which}_profile", profile)
712 if not silent:
713 setcfg(
714 f"measurement_report.{which}_profile",
715 profile and profile_path,
716 )
717 if which == "simulation":
718 self.use_simulation_profile_ctrl_handler(None)
719 elif hasattr(self, "XYZbpin"):
720 self.mr_update_main_controls()
721 return profile
722 if path:
723 self.set_profile_ctrl_path(which)
724 return None
725
726 def set_profile_ctrl_path(self, which):
727 """Set the path for the profile control based on the current configuration.
728
729 Args:
730 which (str): The type of profile control to set the path for.
731 Should be one of "simulation", "devlink", or "output".
732 """
733 getattr(self, f"{which}_profile_ctrl").SetPath(
734 getcfg(f"measurement_report.{which}_profile")
735 )
736
737 def mr_setup_language(self):
738 """Set up language-specific strings and controls for the measurement report window.""" # noqa: E501
739 # Shared with main window
740
741 for which in (
742 "chart",
743 "simulation_profile",
744 "devlink_profile",
745 "output_profile",
746 ):
747 if which.endswith("_profile"):
748 wildcard = f"{lang.getstr('filetype.icc')}|*.icc;*.icm"
749 else:
750 wildcard = (
751 f"{lang.getstr('filetype.ti1_ti3_txt')}|"
752 "*.cgats;*.cie;*.ti1;*.ti2;*.ti3;*.txt"
753 )
754 msg = {
755 "chart": "measurement_report_choose_chart_or_reference",
756 "devlink_profile": "devicelink_profile",
757 "output_profile": "measurement_report_choose_profile",
758 }.get(which, which)
759 kwargs = {
760 "toolTip": lang.getstr(msg).rstrip(":"),
761 "dialogTitle": lang.getstr(msg),
762 "fileMask": wildcard,
763 }
764 ctrl = getattr(self, f"{which}_ctrl")
765 for name in kwargs:
766 value = kwargs[name]
767 setattr(ctrl, name, value)
768
769 items = [lang.getstr(item) for item in ("Gamma 2.2", "trc.rec1886", "custom")]
770 self.mr_trc_ctrl.SetItems(items)
771
772 self.trc_gamma_types_ab = {0: "b", 1: "B"}
773 self.trc_gamma_types_ba = {"b": 0, "B": 1}
774 self.mr_trc_gamma_type_ctrl.SetItems(
775 [lang.getstr("trc.type.relative"), lang.getstr("trc.type.absolute")]
776 )
777
778 def mr_show_trc_controls(self):
779 """Show or hide TRC controls based on the current configuration."""
780 shown = self.apply_trc_ctrl.IsShown()
781 enable6 = shown and bool(getcfg("measurement_report.apply_trc"))
782 show = shown and (
783 self.mr_trc_ctrl.GetSelection() == 2 or getcfg("show_advanced_options")
784 )
785 self.panel.Freeze()
786 self.mr_trc_ctrl.Enable(enable6)
787 self.mr_trc_ctrl.Show(shown)
788 self.mr_trc_gamma_label.Enable(enable6)
789 self.mr_trc_gamma_label.Show(show)
790 self.mr_trc_gamma_ctrl.Enable(enable6)
791 self.mr_trc_gamma_ctrl.Show(show)
792 self.mr_trc_gamma_type_ctrl.Enable(enable6)
793 self.mr_black_output_offset_label.Enable(enable6 and self.XYZbpout > [0, 0, 0])
794 self.mr_black_output_offset_label.Show(show and self.XYZbpout > [0, 0, 0])
795 self.mr_black_output_offset_ctrl.Enable(enable6 and self.XYZbpout > [0, 0, 0])
796 self.mr_black_output_offset_ctrl.Show(show and self.XYZbpout > [0, 0, 0])
797 self.mr_black_output_offset_intctrl.Enable(
798 enable6 and self.XYZbpout > [0, 0, 0]
799 )
800 self.mr_black_output_offset_intctrl.Show(show and self.XYZbpout > [0, 0, 0])
801 self.mr_black_output_offset_intctrl_label.Enable(
802 enable6 and self.XYZbpout > [0, 0, 0]
803 )
804 self.mr_black_output_offset_intctrl_label.Show(
805 show and self.XYZbpout > [0, 0, 0]
806 )
807 self.mr_trc_gamma_type_ctrl.Show(show and self.XYZbpout > [0, 0, 0])
808 self.panel.Layout()
809 self.panel.Thaw()
810
811 def simulate_whitepoint_ctrl_handler(self, event):
812 """Handle changes to the simulate whitepoint checkbox.
813
814 Args:
815 event (wx.Event): Optional event that triggered the change.
816 """
817 v = self.simulate_whitepoint_cb.GetValue()
818 setcfg("measurement_report.whitepoint.simulate", int(v))
819 self.mr_update_main_controls()
820
821 def simulate_whitepoint_relative_ctrl_handler(self, event):
822 """Handle changes to the simulate whitepoint relative checkbox.
823
824 Args:
825 event (wx.Event): Optional event that triggered the change.
826 """
827 setcfg(
828 "measurement_report.whitepoint.simulate.relative",
829 int(self.simulate_whitepoint_relative_cb.GetValue()),
830 )
831
832 def simulation_profile_ctrl_handler(self, event):
833 """Handle changes to the simulation profile control.
834
835 Args:
836 event (wx.Event): Optional event that triggered the change.
837 """
838 self.set_profile("simulation")
839
840 def simulation_profile_drop_handler(self, path):
841 """Handle dropping a simulation profile file onto the control.
842
843 Args:
844 path (str): The file path of the dropped simulation profile.
845 """
846 if not self.worker.is_working():
847 self.simulation_profile_ctrl.SetPath(path)
848 self.set_profile("simulation")
849
850 def mr_set_filebrowse_paths(self):
851 """Set file browse paths for chart, simulation, devicelink and output profile controls.""" # noqa: E501
852 for which in ("simulation", "devlink", "output"):
853 self.set_profile_ctrl_path(which)
854 chart = getcfg("measurement_report.chart")
855 if not chart or not os.path.isfile(chart):
856 chart = config.DEFAULTS["measurement_report.chart"]
857 setcfg("measurement_report.chart", chart)
858 self.mr_set_testchart(chart, load=False)
859
860 def mr_update_controls(self, set_filebrowse_paths=True):
861 """Update controls with values from the configuration.
862
863 Args:
864 set_filebrowse_paths (bool): If True, sets the file browse paths
865 for the chart, simulation profile, devicelink profile, and
866 output profile controls.
867 """
868 self.panel.Freeze()
869 if set_filebrowse_paths:
870 self.mr_set_filebrowse_paths()
871 self.set_profile("simulation", silent=True)
872 self.mr_update_trc_controls()
873 self.set_profile("devlink", silent=True)
874 self.set_profile("output", silent=True)
875 self.chart_ctrl_handler(None)
876 self.use_simulation_profile_ctrl_handler(None, update_trc=False)
877 self.panel.Thaw()
878
879 def mr_update_trc_control(self):
880 """Update the TRC control based on the current configuration."""
881 if (
882 getcfg("measurement_report.trc_gamma_type") == "B"
883 and getcfg("measurement_report.trc_output_offset") == 0
884 and getcfg("measurement_report.trc_gamma") == 2.4
885 ):
886 self.mr_trc_ctrl.SetSelection(1) # BT.1886
887 elif (
888 getcfg("measurement_report.trc_gamma_type") == "b"
889 and getcfg("measurement_report.trc_output_offset") == 1
890 and getcfg("measurement_report.trc_gamma") == 2.2
891 ):
892 self.mr_trc_ctrl.SetSelection(0) # Pure power gamma 2.2
893 else:
894 self.mr_trc_ctrl.SetSelection(2) # Custom
895
896 def mr_update_trc_controls(self):
897 """Update TRC controls based on the current configuration."""
898 self.mr_update_trc_control()
899 self.mr_trc_gamma_ctrl.SetValue(str(getcfg("measurement_report.trc_gamma")))
900 self.mr_trc_gamma_type_ctrl.SetSelection(
901 self.trc_gamma_types_ba[getcfg("measurement_report.trc_gamma_type")]
902 )
903 outoffset = int(getcfg("measurement_report.trc_output_offset") * 100)
904 self.mr_black_output_offset_ctrl.SetValue(outoffset)
905 self.mr_black_output_offset_intctrl.SetValue(outoffset)
906
907 def mr_set_testchart(self, path, load=True):
908 """Set the test chart for the measurement report.
909
910 Args:
911 path (str): Path to the test chart file.
912 load (bool): If True, the chart will be loaded and the controls
913 updated.
914 """
915 self.chart_ctrl.SetPath(path)
916 if load:
917 self.chart_ctrl_handler(None)
918
919 def mr_update_main_controls(self, event=None):
920 """Update main controls based on the current configuration.
921
922 Args:
923 event: Optional event that triggered the update. If provided,
924 the whitepoint simulation will be set to True.
925 """
926 # print("MR update main ctrls")
927 self.panel.Freeze()
928 chart_has_white = bool(getattr(self, "chart_white", None))
929 color = getcfg("measurement_report.chart.fields")
930 sim_profile_color = (
931 getattr(self, "simulation_profile", None)
932 and self.simulation_profile.colorSpace
933 )
934 if isinstance(sim_profile_color, bytes):
935 sim_profile_color = sim_profile_color.decode("utf-8")
936 if getcfg("measurement_report.use_simulation_profile"):
937 setcfg(
938 "measurement_report.use_simulation_profile",
939 int(sim_profile_color == color),
940 )
941 self.simulation_profile_cb.Enable(sim_profile_color == color)
942 self.simulation_profile_cb.Show(color in ("CMYK", "RGB"))
943 enable1 = bool(getcfg("measurement_report.use_simulation_profile"))
944 # print(enable1)
945 enable2 = sim_profile_color == "RGB" and bool(
946 getcfg("measurement_report.use_simulation_profile_as_output")
947 )
948 self.simulation_profile_cb.SetValue(enable1)
949 self.simulation_profile_ctrl.Show(color in ("CMYK", "RGB"))
950 self.use_simulation_profile_as_output_cb.Show(
951 enable1 and sim_profile_color == "RGB"
952 )
953 self.use_simulation_profile_as_output_cb.SetValue(enable1 and enable2)
954 self.enable_3dlut_cb.Enable(enable1 and enable2)
955 self.enable_3dlut_cb.SetValue(
956 enable1 and enable2 and bool(getcfg("3dlut.enable"))
957 )
958 self.enable_3dlut_cb.Show(
959 enable1
960 and sim_profile_color == "RGB"
961 and config.get_display_name() in ("madVR", "Prisma")
962 )
963 enable5 = (
964 sim_profile_color == "RGB"
965 and isinstance(self.simulation_profile.tags.get("rXYZ"), XYZType)
966 and isinstance(self.simulation_profile.tags.get("gXYZ"), XYZType)
967 and isinstance(self.simulation_profile.tags.get("bXYZ"), XYZType)
968 and not isinstance(self.simulation_profile.tags.get("A2B0"), LUT16Type)
969 )
970 # print(enable5, self.XYZbpin, self.XYZbpout)
971 self.mr_trc_label.Show(enable1 and enable5)
972 self.apply_none_ctrl.Show(enable1 and enable5)
973 self.apply_none_ctrl.SetValue(
974 (
975 not getcfg("measurement_report.apply_black_offset")
976 and not getcfg("measurement_report.apply_trc")
977 )
978 or not enable5
979 )
980 self.apply_black_offset_ctrl.Show(enable1 and enable5)
981 self.apply_black_offset_ctrl.SetValue(
982 enable5 and bool(getcfg("measurement_report.apply_black_offset"))
983 )
984 self.apply_trc_ctrl.Show(enable1 and enable5)
985 self.apply_trc_ctrl.SetValue(
986 enable5 and bool(getcfg("measurement_report.apply_trc"))
987 )
988 enable6 = (
989 enable1
990 and enable5
991 and bool(
992 getcfg("measurement_report.apply_trc")
993 or getcfg("measurement_report.apply_black_offset")
994 )
995 )
996 self.mr_show_trc_controls()
997 show = (
998 self.apply_none_ctrl.GetValue()
999 and enable1
1000 and enable5
1001 and self.XYZbpout > self.XYZbpin
1002 )
1003 self.input_value_clipping_bmp.Show(show)
1004 self.input_value_clipping_label.Show(show)
1005 if event:
1006 self.set_simulate_whitepoint(True)
1007 self.simulate_whitepoint_cb.Enable(
1008 (enable1 and not enable2) or (color in ("LAB", "XYZ") and chart_has_white)
1009 )
1010 enable3 = bool(getcfg("measurement_report.whitepoint.simulate"))
1011 self.simulate_whitepoint_cb.SetValue(
1012 ((enable1 and not enable2) or color in ("LAB", "XYZ")) and enable3
1013 )
1014 self.simulate_whitepoint_relative_cb.Enable(
1015 ((enable1 and not enable2) or color in ("LAB", "XYZ")) and enable3
1016 )
1017 self.simulate_whitepoint_relative_cb.SetValue(
1018 ((enable1 and not enable2) or color in ("LAB", "XYZ"))
1019 and enable3
1020 and bool(getcfg("measurement_report.whitepoint.simulate.relative"))
1021 )
1022 self.devlink_profile_cb.Show(enable1 and enable2)
1023 enable4 = bool(getcfg("measurement_report.use_devlink_profile"))
1024 self.devlink_profile_cb.SetValue(enable1 and enable2 and enable4)
1025 self.devlink_profile_ctrl.Enable(enable1 and enable2 and enable4)
1026 self.devlink_profile_ctrl.Show(enable1 and enable2)
1027 self.output_profile_label.Enable(
1028 (color in ("LAB", "RGB", "XYZ") or enable1)
1029 and (
1030 not enable1
1031 or not enable2
1032 or self.apply_trc_ctrl.GetValue()
1033 or self.apply_black_offset_ctrl.GetValue()
1034 )
1035 )
1036 self.output_profile_ctrl.Enable(
1037 (color in ("LAB", "RGB", "XYZ") or enable1)
1038 and (
1039 not enable1
1040 or not enable2
1041 or self.apply_trc_ctrl.GetValue()
1042 or self.apply_black_offset_ctrl.GetValue()
1043 )
1044 )
1045 output_profile = (
1046 (
1047 hasattr(self, "presets")
1048 and getcfg("measurement_report.output_profile") not in self.presets
1049 )
1050 or not hasattr(self, "presets")
1051 ) and bool(getattr(self, "output_profile", None))
1052 self.measurement_report_btn.Enable(
1053 (
1054 (
1055 enable1
1056 and enable2
1057 and (not enable6 or output_profile)
1058 and (
1059 not enable4
1060 or (
1061 bool(getcfg("measurement_report.devlink_profile"))
1062 and os.path.isfile(
1063 getcfg("measurement_report.devlink_profile")
1064 )
1065 )
1066 )
1067 )
1068 or (
1069 (
1070 (not enable1 and color in ("LAB", "RGB", "XYZ"))
1071 or (enable1 and sim_profile_color == color and not enable2)
1072 )
1073 and output_profile
1074 )
1075 )
1076 and bool(getcfg("measurement_report.chart"))
1077 and os.path.isfile(getcfg("measurement_report.chart"))
1078 )
1079 self.panel.Layout()
1080 self.panel.Thaw()
1081 if hasattr(self, "update_scrollbars"):
1082 self.update_scrollbars()
1083 self.calpanel.Layout()
1084 else:
1085 self.update_layout()
1086
1087 def update_estimated_measurement_time(self, which, patches=None):
1088 """Update the estimated measurement time shown.
1089
1090 Args:
1091 which (str): The type of measurement, e.g. "chart", "testchart".
1092 patches (int, optional): The number of patches to measure. If not
1093 provided, the value from the chart_patches_amount control is used.
1094 """
1095 integration_time = self.worker.get_instrument_features().get("integration_time")
1096 if integration_time:
1097 if which == "chart" and not patches:
1098 patches = int(self.chart_patches_amount.Label)
1099 opatches = patches
1100 # Scale integration time based on display technology
1101 tech = getcfg("display.technology").lower()
1102 if isinstance(tech, bytes):
1103 tech = tech.decode("utf-8")
1104 prop = [1, 1]
1105 if "plasma" in tech or "crt" in tech:
1106 prop[0] = 1.9
1107 elif "projector" in tech or "dlp" in tech:
1108 prop[0] = 2.2
1109 prop[1] = 2.2
1110 elif "oled" in tech:
1111 prop[0] = 2.2
1112 integration_time = [
1113 min(prop[i] * v, 20) for i, v in enumerate(integration_time)
1114 ]
1115 # Get time per patch (tpp)
1116 tpp = list(integration_time)
1117 if (
1118 "plasma" in tech
1119 or "crt" in tech
1120 or "projector" in tech
1121 or "dlp" in tech
1122 ) and self.worker.get_instrument_features().get("refresh"):
1123 # Not all instruments can measure refresh rate! Add .25 secs
1124 # for those who do if refresh mode is used.
1125 tpp = [v + 0.25 for v in tpp]
1126 if config.get_display_name() == "madVR":
1127 # madVR takes a tad longer
1128 tpp = [v + 0.45 for v in tpp]
1129 min_delay_s = 0.2
1130 if getcfg("measure.override_min_display_update_delay_ms"):
1131 # Add additional display update delay (zero at <= 200 ms)
1132 min_delay_ms = getcfg("measure.min_display_update_delay_ms")
1133 min_delay_s = max(min_delay_ms / 1000.0, min_delay_s)
1134 if getcfg("measure.override_display_settle_time_mult"):
1135 # We don't have access to display rise/fall time, so use this as
1136 # generic delay multiplier
1137 settle_mult = getcfg("measure.display_settle_time_mult")
1138 else:
1139 settle_mult = 1.0
1140 tpp = [v + min_delay_s + 0.145 * settle_mult for v in tpp]
1141 avg_delay = sum(tpp) / (8 / 3.0)
1142 seconds = avg_delay * patches
1143 oseconds = seconds
1144 if getcfg("drift_compensation.blacklevel"):
1145 # Assume black patch every 60 seconds
1146 seconds += math.ceil(oseconds / 60.0) * ((20 - tpp[0]) / 2.0 + tpp[0])
1147 # Assume black patch every n samples
1148 seconds += math.ceil(opatches / 40.0) * ((20 - tpp[0]) / 2.0 + tpp[0])
1149 if getcfg("drift_compensation.whitelevel"):
1150 # Assume white patch every 60 seconds
1151 seconds += math.ceil(oseconds / 60.0) * tpp[1]
1152 # Assume white patch every n samples
1153 seconds += math.ceil(opatches / 40.0) * tpp[1]
1154 if (
1155 which in ("testchart", "chart")
1156 and getcfg("testchart.patch_sequence")
1157 != "optimize_display_response_delay"
1158 ):
1159 # Roughly 650s patch response delay per 1000 patches
1160 # reduced by roughly 1 / 1.75 through optimization.
1161 seconds -= 0.65 / 1.75 * patches
1162 seconds += 0.65 * patches
1163 if (
1164 getcfg("patterngenerator.ffp_insertion")
1165 and hasattr(self, "ffp_insertion")
1166 and self.ffp_insertion.IsShown()
1167 ):
1168 interval = getcfg("patterngenerator.ffp_insertion.interval")
1169 duration = getcfg("patterngenerator.ffp_insertion.duration")
1170 if getcfg("measure.override_min_display_update_delay_ms"):
1171 dur = getcfg("measure.min_display_update_delay_ms") / 1000.0
1172 else:
1173 dur = 0
1174 ffp_delay = max(0.8 - dur, 0)
1175 seconds += seconds / max(interval, avg_delay) * (duration + ffp_delay)
1176 timestamp = gmtime(seconds)
1177 hours = int(strftime("%H", timestamp))
1178 minutes = int(strftime("%M", timestamp))
1179 minutes += math.ceil(int(strftime("%S", timestamp)) / 60.0)
1180 if minutes > 59:
1181 minutes = 0
1182 hours += 1
1183 else:
1184 hours, minutes = "--", "--"
1185 getattr(self, f"{which}_meas_time").Label = lang.getstr(
1186 "estimated_measurement_time", (hours, minutes)
1187 )
1188 # Show visual warning by coloring the text if measurement is going to
1189 # take a long time. Display and instrument stability and repeatability
1190 # may be an issue over such long periods of time.
1191 if hours != "--" and hours > 7:
1192 # Warning color "red"
1193 color = "#FF3300"
1194 elif hours != "--" and hours > 3:
1195 # Warning color "orange"
1196 color = "#F07F00"
1197 else:
1198 # Default text color
1199 color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
1200 getattr(self, f"{which}_meas_time").ForegroundColour = color
1201
1202 def use_devlink_profile_ctrl_handler(self, event):
1203 """Handle use_devlink_profile checkbox.
1204
1205 Args:
1206 event (wx.Event): The event that triggered this handler.
1207 """
1208 setcfg("3dlut.enable", 0)
1209 setcfg(
1210 "measurement_report.use_devlink_profile",
1211 int(self.devlink_profile_cb.GetValue()),
1212 )
1213 self.mr_update_main_controls()
1214
1215 def get_simulation_profile(self):
1216 """Return simulation profile if enabled."""
1217 use_sim_profile = getcfg("measurement_report.use_simulation_profile")
1218 return use_sim_profile and getattr(self, "simulation_profile", None)
1219
1220 def use_simulation_profile_ctrl_handler(self, event, update_trc=True):
1221 """Handle use_simulation_profile checkbox.
1222
1223 Args:
1224 event (wx.Event): The event that triggered this handler.
1225 update_trc (bool): Whether to update TRC controls.
1226 """
1227 if event:
1228 setcfg(
1229 "measurement_report.use_simulation_profile",
1230 int(self.simulation_profile_cb.GetValue()),
1231 )
1232 sim_profile = self.get_simulation_profile()
1233 enable = False
1234 if sim_profile:
1235 self.set_simulate_whitepoint()
1236 if (
1237 "rTRC" in sim_profile.tags
1238 and "gTRC" in sim_profile.tags
1239 and "bTRC" in sim_profile.tags
1240 and sim_profile.tags.rTRC
1241 == sim_profile.tags.gTRC
1242 == sim_profile.tags.bTRC
1243 and isinstance(sim_profile.tags.rTRC, CurveType)
1244 ):
1245 tf = sim_profile.tags.rTRC.get_transfer_function(outoffset=1.0)
1246 if update_trc or self.XYZbpin == self.XYZbpout:
1247 # Use only BT.1886 black output offset or not
1248 setcfg(
1249 "measurement_report.apply_black_offset",
1250 int(
1251 tf[0][1] not in (-240, -709)
1252 and (not tf[0][0].startswith("Gamma") or tf[1] < 0.95)
1253 and self.XYZbpin != self.XYZbpout
1254 ),
1255 )
1256 if update_trc:
1257 # Use BT.1886 gamma mapping for SMPTE 240M / Rec. 709 TRC
1258 setcfg(
1259 "measurement_report.apply_trc",
1260 int(
1261 tf[0][1] in (-240, -709)
1262 or (tf[0][0].startswith("Gamma") and tf[1] >= 0.95)
1263 ),
1264 )
1265 # Set gamma to profile gamma if single gamma profile
1266 if tf[0][0].startswith("Gamma") and tf[1] >= 0.95:
1267 if not getcfg("measurement_report.trc_gamma.backup", False):
1268 # Backup current gamma
1269 setcfg(
1270 "measurement_report.trc_gamma.backup",
1271 getcfg("measurement_report.trc_gamma"),
1272 )
1273 setcfg("measurement_report.trc_gamma", round(tf[0][1], 2))
1274 # Restore previous gamma if not single gamma profile
1275 elif getcfg("measurement_report.trc_gamma.backup", False):
1276 setcfg(
1277 "measurement_report.trc_gamma",
1278 getcfg("measurement_report.trc_gamma.backup"),
1279 )
1280 setcfg("measurement_report.trc_gamma.backup", None)
1281 self.mr_update_trc_controls()
1282 enable = tf[0][1] not in (-240, -709) and self.XYZbpin != self.XYZbpout
1283 elif update_trc:
1284 enable = self.XYZbpin != self.XYZbpout
1285 setcfg("measurement_report.apply_black_offset", int(enable))
1286 setcfg("measurement_report.apply_trc", 0)
1287 self.apply_black_offset_ctrl.Enable(bool(sim_profile) and enable)
1288 self.mr_update_main_controls()
1289
1290 def use_simulation_profile_as_output_handler(self, event):
1291 """Handle use_simulation_profile_as_output checkbox.
1292
1293 Args:
1294 event (wx.Event): The event that triggered this handler.
1295 """
1296 setcfg(
1297 "measurement_report.use_simulation_profile_as_output",
1298 int(self.use_simulation_profile_as_output_cb.GetValue()),
1299 )
1300 self.mr_update_main_controls()
1301
1302
1303 if __name__ == "__main__":
1304 config.initcfg()
1305 lang.init()
1306 lang.update_defaults()
1307 app = BaseApp(0)
1308 app.TopWindow = ReportFrame()
1309 app.TopWindow.Show()
1310 app.MainLoop()