def Show(self, show=True):
     if show:
         self.show_controls()
         if hasattr(self, "measure_darken_background_cb"):
             self.measure_darken_background_cb.SetValue(
                 bool(int(getcfg("measure.darken_background"))))
         if self.Parent and hasattr(self.Parent, "display_ctrl"):
             display_no = self.Parent.display_ctrl.GetSelection()
         else:
             display_no = getcfg('display.number') - 1
         if display_no < 0 or display_no > wx.Display.GetCount() - 1:
             display_no = 0
         else:
             display_no = get_display_number(display_no)
         x, y = wx.Display(display_no).Geometry[:2]
         self.SetPosition((x, y))  # place measure frame on correct display
         self.place_n_zoom(
             *floatlist(getcfg("dimensions.measureframe").split(",")))
         self.display_no = wx.Display.GetFromWindow(self)
     elif self.IsShownOnScreen():
         setcfg("dimensions.measureframe", self.get_dimensions())
         if self.Parent and hasattr(self.Parent, "get_set_display"):
             self.Parent.get_set_display()
     if isinstance(self, wx.Dialog):
         if show:
             self.ShowModal()
         else:
             if self.IsModal():
                 self.EndModal(wx.ID_OK)
             else:
                 wx.Dialog.Hide(self)
     else:
         wx.Frame.Show(self, show)
Beispiel #2
0
 def OnMove(self, event=None):
     if self.IsShownOnScreen() and not self.IsMaximized() and not \
        self.IsIconized():
         x, y = self.GetScreenPosition()
         setcfg("position.scripting.x", x)
         setcfg("position.scripting.y", y)
     if event:
         event.Skip()
Beispiel #3
0
 def OnSize(self, event=None):
     if self.IsShownOnScreen() and not self.IsMaximized() and not \
        self.IsIconized():
         w, h = self.ClientSize
         setcfg("size.scripting.w", w)
         setcfg("size.scripting.h", h)
     if event:
         event.Skip()
 def mr_set_filebrowse_paths(self):
     for which in ("simulation", "devlink", "output"):
         self.set_profile_ctrl_path(which)
     chart = getcfg("measurement_report.chart")
     if not chart or not os.path.isfile(chart):
         chart = config.defaults["measurement_report.chart"]
         setcfg("measurement_report.chart", chart)
     self.mr_set_testchart(chart, load=False)
 def OnMove(self, event):
     if self.IsShownOnScreen() and not self.IsIconized() and \
        (not self.GetParent() or
         not self.GetParent().IsShownOnScreen()):
         prev_x = getcfg("position.progress.x")
         prev_y = getcfg("position.progress.y")
         x, y = self.GetScreenPosition()
         if x != prev_x or y != prev_y:
             setcfg("position.progress.x", x)
             setcfg("position.progress.y", y)
 def set_simulate_whitepoint(self, set_whitepoint_simulate_relative=False):
     sim_profile = self.get_simulation_profile()
     is_prtr_profile = sim_profile and sim_profile.profileClass == "prtr"
     if set_whitepoint_simulate_relative:
         setcfg(
             "measurement_report.whitepoint.simulate",
             int(not getattr(self, "chart_white", None)
                 or not "RGB" in self.fields_ctrl.Items or is_prtr_profile))
     setcfg("measurement_report.whitepoint.simulate.relative",
            int("LAB" in self.fields_ctrl.Items or is_prtr_profile))
 def mr_black_output_offset_ctrl_handler(self, event):
     if event.GetId() == self.mr_black_output_offset_intctrl.GetId():
         self.mr_black_output_offset_ctrl.SetValue(
             self.mr_black_output_offset_intctrl.GetValue())
     else:
         self.mr_black_output_offset_intctrl.SetValue(
             self.mr_black_output_offset_ctrl.GetValue())
     v = self.mr_black_output_offset_ctrl.GetValue() / 100.0
     if v != getcfg("measurement_report.trc_output_offset"):
         setcfg("measurement_report.trc_output_offset", v)
         self.mr_update_trc_control()
 def move_handler(self, event):
     if not self.IsShownOnScreen():
         return
     display_no, geometry, client_area = self.get_display()
     if display_no != self.display_no:
         self.display_no = display_no
         if config.is_virtual_display():
             return
         # Translate from wx display index to Argyll display index
         n = get_argyll_display_number(geometry)
         if n is not None:
             # Save Argyll display index to configuration
             setcfg("display.number", n + 1)
 def zoommax_handler(self, event):
     if debug: safe_print("[D] measureframe_zoommax_handler")
     display_client_rect = self.get_display()[2]
     if debug: safe_print("[D]  display_client_rect:", display_client_rect)
     display_client_size = display_client_rect[2:]
     if debug: safe_print("[D]  display_client_size:", display_client_size)
     size = self.GetSize()
     if debug: safe_print(" size:", size)
     if max(size) >= max(display_client_size) - 50:
         dim = getcfg("dimensions.measureframe.unzoomed")
         self.place_n_zoom(*floatlist(dim.split(",")))
     else:
         setcfg("dimensions.measureframe.unzoomed", self.get_dimensions())
         self.place_n_zoom(x=.5, y=.5, scale=50.0)
 def mr_trc_gamma_ctrl_handler(self, event):
     try:
         v = float(self.mr_trc_gamma_ctrl.GetValue().replace(",", "."))
         if (v < config.valid_ranges["measurement_report.trc_gamma"][0] or v
                 > config.valid_ranges["measurement_report.trc_gamma"][1]):
             raise ValueError()
     except ValueError:
         wx.Bell()
         self.mr_trc_gamma_ctrl.SetValue(
             str(getcfg("measurement_report.trc_gamma")))
     else:
         if str(v) != self.mr_trc_gamma_ctrl.GetValue():
             self.mr_trc_gamma_ctrl.SetValue(str(v))
         if v != getcfg("measurement_report.trc_gamma"):
             setcfg("measurement_report.trc_gamma", v)
             self.mr_update_trc_control()
             self.mr_show_trc_controls()
     event.Skip()
 def OnClose(self, event=None):
     if (self.IsShownOnScreen() and not self.IsMaximized()
             and not self.IsIconized()):
         x, y = self.GetScreenPosition()
         setcfg("position.reportframe.x", x)
         setcfg("position.reportframe.y", y)
         setcfg("size.reportframe.w", self.ClientSize[0])
         setcfg("size.reportframe.h", self.ClientSize[1])
     config.writecfg()
     if event:
         event.Skip()
 def chart_btn_handler(self, event):
     if self.Parent:
         parent = self.Parent
     else:
         parent = self
     chart = getcfg("measurement_report.chart")
     if not hasattr(parent, "tcframe"):
         parent.tcframe = TestchartEditor(
             parent,
             path=chart,
             cfg="measurement_report.chart",
             parent_set_chart_methodname="mr_set_testchart")
     elif (not hasattr(parent.tcframe, "ti1")
           or chart != parent.tcframe.ti1.filename):
         parent.tcframe.tc_load_cfg_from_ti1(None, chart,
                                             "measurement_report.chart",
                                             "mr_set_testchart")
     setcfg("tc.show", 1)
     parent.tcframe.Show()
     parent.tcframe.Raise()
 def measure_darken_background_ctrl_handler(self, event):
     if self.measure_darken_background_cb.GetValue() and \
        getcfg("measure.darken_background.show_warning"):
         dlg = ConfirmDialog(self,
                             msg=lang.getstr("measure.darken_background."
                                             "warning"),
                             ok=lang.getstr("ok"),
                             cancel=lang.getstr("cancel"),
                             bitmap=geticon(32, "dialog-warning"))
         chk = wx.CheckBox(dlg, -1, lang.getstr("dialog.do_not_show_again"))
         dlg.Bind(wx.EVT_CHECKBOX,
                  self.measure_darken_background_warning_handler,
                  id=chk.GetId())
         dlg.sizer3.Add(chk, flag=wx.TOP | wx.ALIGN_LEFT, border=12)
         dlg.sizer0.SetSizeHints(dlg)
         dlg.sizer0.Layout()
         rslt = dlg.ShowModal()
         if rslt == wx.ID_CANCEL:
             self.measure_darken_background_cb.SetValue(False)
     setcfg("measure.darken_background",
            int(self.measure_darken_background_cb.GetValue()))
Beispiel #14
0
Datei: syt.py Projekt: j-som/syt
def main():
    root = TkinterDnD.Tk()
    root.withdraw()
    root.title(u"翻译工具")
    viewtool.center_window(root, 650, 680)
    # tv.pack(anchor = tk.W)
    # pv.pack(anchor = tk.W)
    tabframe = views.TabsView(master=root)
    tabframe.pack(anchor=tk.W)
    tabs = {
        u'翻译': views.TransView,
        u'提取': views.PickView,
        u'更新': views.UpdateView,
        u'繁体': views.TwView,
        u'工具': views.ToolsView
    }
    for tabname in tabs:
        tabframe.add(tabname, tabs[tabname])
    logpanel = views.LogPanel(root)
    logpanel.pack(expand=True, fill=tk.BOTH)
    sytlog.log_panel = logpanel
    # tk.Button(master=root, text="test",command = lambda:logpanel.print("hahaha")).pack()
    with open('config.json', 'r', encoding='UTF-8') as f:
        cfg = json.load(f)
        config.setcfg(cfg)
        menu = tk.Menu(root)
        item = tk.Menu(menu, tearoff=False)
        v = tk.StringVar(value=config.CN)
        config.choose(config.CN)
        for vsn, vsncfg in cfg.items():
            item.add_radiobutton(label=vsncfg['name'],
                                 value=vsn,
                                 variable=v,
                                 command=lambda: config.choose(v.get()))
        menu.add_cascade(label=u"版本", menu=item)
        root.config(menu=menu)
    # logpanel.dnd_bind()
    root.update_idletasks()
    root.deiconify()
    root.mainloop()
 def use_devlink_profile_ctrl_handler(self, event):
     setcfg("3dlut.enable", 0)
     setcfg("measurement_report.use_devlink_profile",
            int(self.devlink_profile_cb.GetValue()))
     self.mr_update_main_controls()
Beispiel #16
0
 def parse_txt(self, txt):
     if not txt:
         return
     self.logger.info("%r" % txt)
     if "Setting up the instrument" in txt:
         self.Pulse(lang.getstr("instrument.initializing"))
     if "Spot read failed" in txt:
         self.last_error = txt
     if "Result is XYZ:" in txt:
         # Result is XYZ: d.dddddd d.dddddd d.dddddd, D50 Lab: d.dddddd d.dddddd d.dddddd
         #							CCT = ddddK (Delta E d.dddddd)
         # Closest Planckian temperature = ddddK (Delta E d.dddddd)
         # Closest Daylight temperature  = ddddK (Delta E d.dddddd)
         XYZ = re.search("XYZ:\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)", txt)
         self.results[self.index].append(
             {"XYZ": [float(value) for value in XYZ.groups()]})
         self.last_error = None
     loci = {"t": "Daylight", "T": "Planckian"}
     for locus in list(loci.values()):
         if locus in txt:
             CT = re.search(
                 "Closest\s+%s\s+temperature\s+=\s+(\d+)K" % locus, txt,
                 re.I)
             self.results[self.index][-1]["C%sT" % locus[0]] = int(
                 CT.groups()[0])
     if "key to take a reading" in txt and not self.last_error:
         safe_print("%s: Got 'key to take a reading'" % appname)
         if not self.is_measuring:
             self.enable_buttons()
             return
         if len(self.results[self.index]) < len(self.colors):
             # Take readings at 5 different brightness levels per swatch
             safe_print("%s: About to take next reading" % appname)
             self.measure()
         else:
             self.is_measuring = False
             self.show_cursor()
             self.enable_buttons()
             self.buttons[self.index].Show()
             self.buttons[self.index].SetFocus()
             self.buttons[self.index].SetBitmap(
                 getbitmap("theme/icons/16x16/checkmark"))
             self.panels[self.index].SetBackgroundColour(BGCOLOUR)
             self.panels[self.index].Refresh()
             self.panels[self.index].Update()
             if len(self.results) == self.rows * self.cols:
                 # All swatches have been measured, show results
                 # Let the user choose a location for the results html
                 display_no, geometry, client_area = self.get_display()
                 # Translate from wx display index to Argyll display index
                 geometry = "%i, %i, %ix%i" % tuple(geometry)
                 for i, display in enumerate(getcfg("displays")):
                     if display.find("@ " + geometry) > -1:
                         safe_print("Found display %s at index %i" %
                                    (display, i))
                         break
                 display = display.replace(" [PRIMARY]", "")
                 defaultFile = "Uniformity Check %s — %s — %s" % (
                     appversion, re.sub(r"[\\/:*?\"<>|]+", "_", display),
                     strftime("%Y-%m-%d %H-%M.html"))
                 defaultDir = get_verified_path(
                     None,
                     os.path.join(getcfg("profile.save_path"),
                                  defaultFile))[0]
                 dlg = wx.FileDialog(self,
                                     lang.getstr("save_as"),
                                     defaultDir,
                                     defaultFile,
                                     wildcard=lang.getstr("filetype.html") +
                                     "|*.html;*.htm",
                                     style=wx.SAVE | wx.FD_OVERWRITE_PROMPT)
                 dlg.Center(wx.BOTH)
                 result = dlg.ShowModal()
                 if result == wx.ID_OK:
                     path = dlg.GetPath()
                     if not waccess(path, os.W_OK):
                         from worker import show_result_dialog
                         show_result_dialog(
                             Error(
                                 lang.getstr("error.access_denied.write",
                                             path)), self)
                         return
                     save_path = os.path.splitext(path)[0] + ".html"
                     setcfg("last_filedialog_path", save_path)
                 dlg.Destroy()
                 if result != wx.ID_OK:
                     return
                 locus = loci.get(getcfg("whitepoint.colortemp.locus"))
                 try:
                     report.create(
                         save_path, {
                             "${REPORT_VERSION}": appversion,
                             "${DISPLAY}": display,
                             "${DATETIME}": strftime("%Y-%m-%d %H:%M:%S"),
                             "${ROWS}": str(self.rows),
                             "${COLS}": str(self.cols),
                             "${RESULTS}": str(self.results),
                             "${LOCUS}": locus
                         }, getcfg("report.pack_js"), "uniformity")
                 except (IOError, OSError) as exception:
                     from worker import show_result_dialog
                     show_result_dialog(exception, self)
                 else:
                     launch_file(save_path)
             if getcfg("uniformity.measure.continuous"):
                 self.measure(event=Event(self.buttons[self.index]))
Beispiel #17
0
def vrmlfile2x3dfile(vrmlpath=None,
                     x3dpath=None,
                     html=True,
                     embed=False,
                     view=False,
                     force=False,
                     cache=True,
                     worker=None,
                     gui=True):
    """ Convert VRML to HTML. Output is written to <vrmlfilename>.x3d.html
	unless you set x3dpath to desired output path, or False to be prompted
	for an output path. """
    while not vrmlpath or not os.path.isfile(vrmlpath):
        if not gui:
            if not vrmlpath or vrmlpath.startswith("--"):
                safe_print("No filename given.")
            else:
                safe_print("%r is not a file." % vrmlpath)
            return False
        if not wx.GetApp():
            app = BaseApp(0)
        defaultDir, defaultFile = config.get_verified_path("last_vrml_path")
        dlg = wx.FileDialog(None,
                            lang.getstr("file.select"),
                            defaultDir=defaultDir,
                            defaultFile=defaultFile,
                            wildcard=lang.getstr("filetype.vrml") +
                            "|*.vrml;*.vrml.gz;*.wrl.gz;*.wrl;*.wrz",
                            style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        dlg.Center(wx.BOTH)
        result = dlg.ShowModal()
        vrmlpath = dlg.GetPath()
        dlg.Destroy()
        if result != wx.ID_OK:
            return
        config.setcfg("last_vrml_path", vrmlpath)
        config.writecfg(module="VRML-to-X3D-converter",
                        options=("last_vrml_path", ))
    filename, ext = os.path.splitext(vrmlpath)
    if x3dpath is None:
        x3dpath = filename + ".x3d"
    if x3dpath:
        dirname = os.path.dirname(x3dpath)
    while not x3dpath or not waccess(dirname, os.W_OK):
        if not gui:
            if not x3dpath:
                safe_print("No HTML output filename given.")
            else:
                safe_print("%r is not writable." % dirname)
            return False
        if not wx.GetApp():
            app = BaseApp(0)
        if x3dpath:
            defaultDir, defaultFile = os.path.split(x3dpath)
        else:
            defaultFile = os.path.basename(filename) + ".x3d"
        dlg = wx.FileDialog(None,
                            lang.getstr("error.access_denied.write", dirname),
                            defaultDir=defaultDir,
                            defaultFile=defaultFile,
                            wildcard=lang.getstr("filetype.x3d") + "|*.x3d",
                            style=wx.SAVE | wx.FD_OVERWRITE_PROMPT)
        dlg.Center(wx.BOTH)
        result = dlg.ShowModal()
        dlg.Destroy()
        if result != wx.ID_OK:
            return
        x3dpath = dlg.GetPath()
        dirname = os.path.dirname(x3dpath)
    vrmlpath, x3dpath = [safe_unicode(path) for path in (vrmlpath, x3dpath)]
    if sys.platform == "win32":
        vrmlpath = make_win32_compatible_long_path(vrmlpath)
        x3dpath = make_win32_compatible_long_path(x3dpath)
    if html:
        finalpath = x3dpath + ".html"
        if sys.platform == "win32":
            finalpath = make_win32_compatible_long_path(finalpath)
            x3dpath = finalpath[:-5]
    else:
        finalpath = x3dpath
    if worker:
        worker.clear_cmd_output()
        worker.start(
            lambda result: show_result_dialog(result,
                                              wx.GetApp().GetTopWindow())
            if isinstance(result, Exception
                          ) else result and view and launch_file(finalpath),
            x3dom.vrmlfile2x3dfile,
            wargs=(vrmlpath, x3dpath, html, embed, force, cache, worker),
            progress_title=lang.getstr("vrml_to_x3d_converter"),
            progress_start=1,
            resume=worker.progress_wnd
            and worker.progress_wnd.IsShownOnScreen(),
            fancy=False)
    else:
        result = x3dom.vrmlfile2x3dfile(vrmlpath, x3dpath, html, embed, force,
                                        cache, None)
        if not isinstance(result, Exception) and result:
            if view:
                launch_file(finalpath)
        else:
            return False
    return True
 def fields_ctrl_handler(self, event):
     setcfg("measurement_report.chart.fields",
            self.fields_ctrl.GetStringSelection())
     if event:
         self.mr_update_main_controls(event)
 def chart_ctrl_handler(self, event):
     chart = self.chart_ctrl.GetPath()
     values = []
     try:
         cgats = CGATS.CGATS(chart)
     except (IOError, CGATS.CGATSInvalidError,
             CGATS.CGATSInvalidOperationError, CGATS.CGATSKeyError,
             CGATS.CGATSTypeError, CGATS.CGATSValueError) as exception:
         show_result_dialog(exception, self)
     else:
         data_format = cgats.queryv1("DATA_FORMAT")
         accurate = cgats.queryv1("ACCURATE_EXPECTED_VALUES") == "true"
         if data_format:
             basename, ext = os.path.splitext(chart)
             for column in data_format.values():
                 column_prefix = column.split("_")[0]
                 if (column_prefix in ("CMYK", "LAB", "RGB", "XYZ")
                         and column_prefix not in values
                         and (((ext.lower() == ".cie" or accurate)
                               and column_prefix in ("LAB", "XYZ")) or
                              (ext.lower() == ".ti1"
                               and column_prefix in ("CMYK", "RGB")) or
                              (ext.lower() not in (".cie", ".ti1")))):
                     values.append(column_prefix)
             if values:
                 self.panel.Freeze()
                 self.fields_ctrl.SetItems(values)
                 self.fields_ctrl.GetContainingSizer().Layout()
                 self.panel.Thaw()
                 fields = getcfg("measurement_report.chart.fields")
                 if ext.lower() == ".ti1":
                     index = 0
                 elif "RGB" in values and not ext.lower() == ".cie":
                     index = values.index("RGB")
                 elif "CMYK" in values:
                     index = values.index("CMYK")
                 elif "XYZ" in values:
                     index = values.index("XYZ")
                 elif "LAB" in values:
                     index = values.index("LAB")
                 else:
                     index = 0
                 self.fields_ctrl.SetSelection(index)
                 setcfg("measurement_report.chart", chart)
                 self.chart_patches_amount.Freeze()
                 self.chart_patches_amount.SetLabel(
                     str(cgats.queryv1("NUMBER_OF_SETS") or ""))
                 self.update_estimated_measurement_time("chart")
                 self.chart_patches_amount.GetContainingSizer().Layout()
                 self.chart_patches_amount.Thaw()
                 self.chart_white = cgats.get_white_cie()
         if not values:
             if chart:
                 show_result_dialog(
                     lang.getstr("error.testchart.missing_fields",
                                 (chart, "RGB/CMYK %s LAB/XYZ" %
                                  lang.getstr("or"))), self)
             self.chart_ctrl.SetPath(getcfg("measurement_report.chart"))
         else:
             self.chart_btn.Enable("RGB" in values)
             if self.Parent:
                 parent = self.Parent
             else:
                 parent = self
             if (event and self.chart_btn.Enabled
                     and hasattr(parent, "tcframe")
                     and self.tcframe.IsShownOnScreen()
                     and (not hasattr(parent.tcframe, "ti1")
                          or chart != parent.tcframe.ti1.filename)):
                 parent.tcframe.tc_load_cfg_from_ti1(
                     None, chart, "measurement_report.chart",
                     "mr_set_testchart")
     self.fields_ctrl.Enable(self.fields_ctrl.GetCount() > 1)
     self.fields_ctrl_handler(event)
 def set_profile(self, which, profile_path=None, silent=False):
     path = getattr(self, "%s_profile_ctrl" % which).GetPath()
     if which == "output":
         ##if profile_path is None:
         ##profile_path = get_current_profile_path(True, True)
         ##self.output_profile_current_btn.Enable(self.output_profile_ctrl.IsShown() and
         ##bool(profile_path) and
         ##os.path.isfile(profile_path) and
         ##profile_path != path)
         profile = config.get_current_profile(True)
         if profile:
             path = profile.fileName
         else:
             path = None
         setcfg("measurement_report.output_profile", path)
         XYZbpout = self.XYZbpout
         # XYZbpout will be set to the blackpoint of the selected profile.
         # This is used to determine if black output offset controls should
         # be shown. Set a initial value slightly above zero so output
         # offset controls are shown if the selected profile doesn't exist.
         self.XYZbpout = [0.001, 0.001, 0.001]
     else:
         profile = None
         if which == "input":
             XYZbpin = self.XYZbpin
             self.XYZbpin = [0, 0, 0]
     if path or profile:
         if path and not os.path.isfile(path):
             if not silent:
                 show_result_dialog(Error(lang.getstr("file.missing",
                                                      path)),
                                    parent=self)
             return
         if not profile:
             try:
                 profile = ICCP.ICCProfile(path)
             except (IOError, ICCP.ICCProfileInvalidError):
                 if not silent:
                     show_result_dialog(Error(
                         lang.getstr("profile.invalid") + "\n" + path),
                                        parent=self)
             except IOError as exception:
                 if not silent:
                     show_result_dialog(exception, parent=self)
         if profile:
             profile_path = profile.fileName
             if ((which == "simulation" and
                  (profile.profileClass not in ("mntr", "prtr")
                   or profile.colorSpace not in ("CMYK", "RGB"))) or
                 (which == "output" and (profile.profileClass != "mntr"
                                         or profile.colorSpace != "RGB")) or
                 (which == "devlink" and profile.profileClass != "link")):
                 show_result_dialog(NotImplementedError(
                     lang.getstr(
                         "profile.unsupported",
                         (profile.profileClass, profile.colorSpace))),
                                    parent=self)
             else:
                 if (not getattr(self, which + "_profile", None)
                         or getattr(self, which + "_profile").fileName !=
                         profile.fileName):
                     # Profile selection has changed
                     if which == "simulation":
                         # Get profile blackpoint so we can check if it makes
                         # sense to show TRC type and output offset controls
                         try:
                             odata = self.worker.xicclu(profile, (0, 0, 0),
                                                        pcs="x")
                         except Exception as exception:
                             show_result_dialog(exception, self)
                             self.set_profile_ctrl_path(which)
                             return
                         else:
                             if len(odata) != 1 or len(odata[0]) != 3:
                                 show_result_dialog(
                                     "Blackpoint is invalid: %s" % odata,
                                     self)
                                 self.set_profile_ctrl_path(which)
                                 return
                             self.XYZbpin = odata[0]
                     elif which == "output":
                         # Get profile blackpoint so we can check if input
                         # values would be clipped
                         try:
                             odata = self.worker.xicclu(profile, (0, 0, 0),
                                                        pcs="x")
                         except Exception as exception:
                             show_result_dialog(exception, self)
                             self.set_profile_ctrl_path(which)
                             return
                         else:
                             if len(odata) != 1 or len(odata[0]) != 3:
                                 show_result_dialog(
                                     "Blackpoint is invalid: %s" % odata,
                                     self)
                                 self.set_profile_ctrl_path(which)
                                 return
                             if odata[0][1]:
                                 # Got above zero blackpoint from lookup
                                 self.XYZbpout = odata[0]
                             else:
                                 # Got zero blackpoint from lookup.
                                 # Try chardata instead.
                                 XYZbp = profile.get_chardata_bkpt()
                                 if XYZbp:
                                     self.XYZbpout = XYZbp
                                 else:
                                     self.XYZbpout = [0, 0, 0]
                 else:
                     # Profile selection has not changed
                     # Restore cached XYZbp values
                     if which == "output":
                         self.XYZbpout = XYZbpout
                     elif which == "input":
                         self.XYZbpin = XYZbpin
                 setattr(self, "%s_profile" % which, profile)
                 if not silent:
                     setcfg("measurement_report.%s_profile" % which, profile
                            and profile_path)
                     if which == "simulation":
                         self.use_simulation_profile_ctrl_handler(None)
                     elif hasattr(self, "XYZbpin"):
                         self.mr_update_main_controls()
                 return profile
         if path:
             self.set_profile_ctrl_path(which)
     else:
         setattr(self, "%s_profile" % which, None)
         if not silent:
             setcfg("measurement_report.%s_profile" % which, None)
             self.mr_update_main_controls()
    def place_n_zoom(self, x=None, y=None, scale=None):
        """
		Place and scale the window.
		
		x, y and scale need to be in Argyll coordinates (0.0...1.0)
		if given. Without arguments, they are read from the user 
		configuration.
		
		"""
        if debug: safe_print("[D] measureframe.place_n_zoom")
        if None in (x, y, scale):
            cur_x, cur_y, cur_scale = floatlist(
                self.get_dimensions().split(","))
            if x is None:
                x = cur_x
            if y is None:
                y = cur_y
            if scale is None:
                scale = cur_scale
        if scale > 50.0:  # Argyll max
            scale = 50
        if debug: safe_print(" x:", x)
        if debug: safe_print(" y:", y)
        if debug: safe_print(" scale:", scale)
        if debug:
            safe_print("[D]  scale_adjustment_factor:",
                       scale_adjustment_factor)
        scale /= scale_adjustment_factor
        if debug: safe_print("[D]  scale / scale_adjustment_factor:", scale)
        display = self.get_display(getcfg("display.number") - 1)
        display_client_rect = display[2]
        if debug: safe_print("[D]  display_client_rect:", display_client_rect)
        display_client_size = display_client_rect[2:]
        if debug: safe_print("[D]  display_client_size:", display_client_size)
        measureframe_min_size = [max(self.sizer.GetMinSize())] * 2
        if debug:
            safe_print("[D]  measureframe_min_size:", measureframe_min_size)
        default_measureframe_size = get_default_size()
        defaults["size.measureframe"] = default_measureframe_size
        size = [
            min(display_client_size[0], default_measureframe_size * scale),
            min(display_client_size[1], default_measureframe_size * scale)
        ]
        if measureframe_min_size[0] > size[0]:
            size = measureframe_min_size
        if size[0] > display_client_size[0]:
            size[0] = display_client_size[0]
        if size[1] > display_client_size[1]:
            size[1] = display_client_size[1]
        if max(size) >= max(display_client_size):
            scale = 50
        if debug: safe_print("[D]  measureframe_size:", size)
        if (sys.platform not in ("darwin", "win32")
                and os.getenv("XDG_SESSION_TYPE") != "wayland"
                and not os.getenv("XDG_CURRENT_DESKTOP", "").startswith("KDE")
                and hasattr(self, "MaxClientSize")):
            self.MaxClientSize = (-1, -1)
            self.MinClientSize = size
            self.ClientSize = size
            self.MaxClientSize = size
        else:
            self.SetMaxSize((-1, -1))
            self.SetMinSize(size)
            self.SetSize(size)
            self.SetMaxSize(size)
        display_rect = display[1]
        if debug: safe_print("[D]  display_rect:", display_rect)
        display_size = display_rect[2:]
        if debug: safe_print("[D]  display_size:", display_size)
        if sys.platform in ("darwin", "win32"):
            titlebar = 0  # size already includes window decorations
        else:
            titlebar = 25  # assume titlebar height of 25px
        measureframe_pos = [
            display_rect[0] + round((display_size[0] - size[0]) * x),
            display_rect[1] + round((display_size[1] - size[1]) * y) - titlebar
        ]
        if measureframe_pos[0] < display_client_rect[0]:
            measureframe_pos[0] = display_client_rect[0]
        if measureframe_pos[1] < display_client_rect[1]:
            measureframe_pos[1] = display_client_rect[1]
        if debug: safe_print("[D]  measureframe_pos:", measureframe_pos)
        setcfg("dimensions.measureframe", ",".join(strlist((x, y, scale))))
        self.SetPosition(measureframe_pos)
 def simulate_whitepoint_ctrl_handler(self, event):
     v = self.simulate_whitepoint_cb.GetValue()
     setcfg("measurement_report.whitepoint.simulate", int(v))
     self.mr_update_main_controls()
 def measure_darken_background_warning_handler(self, event):
     setcfg("measure.darken_background.show_warning",
            int(not event.GetEventObject().GetValue()))
 def use_simulation_profile_as_output_handler(self, event):
     setcfg("measurement_report.use_simulation_profile_as_output",
            int(self.use_simulation_profile_as_output_cb.GetValue()))
     self.mr_update_main_controls()
 def use_simulation_profile_ctrl_handler(self, event, update_trc=True):
     if event:
         setcfg("measurement_report.use_simulation_profile",
                int(self.simulation_profile_cb.GetValue()))
     sim_profile = self.get_simulation_profile()
     enable = False
     if sim_profile:
         self.set_simulate_whitepoint()
         if ("rTRC" in sim_profile.tags and "gTRC" in sim_profile.tags
                 and "bTRC" in sim_profile.tags and sim_profile.tags.rTRC ==
                 sim_profile.tags.gTRC == sim_profile.tags.bTRC
                 and isinstance(sim_profile.tags.rTRC, ICCP.CurveType)):
             tf = sim_profile.tags.rTRC.get_transfer_function(outoffset=1.0)
             if update_trc or self.XYZbpin == self.XYZbpout:
                 # Use only BT.1886 black output offset or not
                 setcfg(
                     "measurement_report.apply_black_offset",
                     int(tf[0][1] not in (-240, -709) and
                         (not tf[0][0].startswith("Gamma") or tf[1] < .95)
                         and self.XYZbpin != self.XYZbpout))
             if update_trc:
                 # Use BT.1886 gamma mapping for SMPTE 240M / Rec. 709 TRC
                 setcfg(
                     "measurement_report.apply_trc",
                     int(tf[0][1] in (-240, -709) or
                         (tf[0][0].startswith("Gamma") and tf[1] >= .95)))
                 # Set gamma to profile gamma if single gamma profile
                 if tf[0][0].startswith("Gamma") and tf[1] >= .95:
                     if not getcfg("measurement_report.trc_gamma.backup",
                                   False):
                         # Backup current gamma
                         setcfg("measurement_report.trc_gamma.backup",
                                getcfg("measurement_report.trc_gamma"))
                     setcfg("measurement_report.trc_gamma",
                            round(tf[0][1], 2))
                 # Restore previous gamma if not single gamma profile
                 elif getcfg("measurement_report.trc_gamma.backup", False):
                     setcfg("measurement_report.trc_gamma",
                            getcfg("measurement_report.trc_gamma.backup"))
                     setcfg("measurement_report.trc_gamma.backup", None)
             self.mr_update_trc_controls()
             enable = (tf[0][1] not in (-240, -709)
                       and self.XYZbpin != self.XYZbpout)
         elif update_trc:
             enable = self.XYZbpin != self.XYZbpout
             setcfg("measurement_report.apply_black_offset", int(enable))
             setcfg("measurement_report.apply_trc", 0)
     self.apply_black_offset_ctrl.Enable(bool(sim_profile) and enable)
     self.mr_update_main_controls()
 def mr_trc_gamma_type_ctrl_handler(self, event):
     v = self.trc_gamma_types_ab[self.mr_trc_gamma_type_ctrl.GetSelection()]
     if v != getcfg("measurement_report.trc_gamma_type"):
         setcfg("measurement_report.trc_gamma_type", v)
         self.mr_update_trc_control()
         self.mr_show_trc_controls()
 def simulate_whitepoint_relative_ctrl_handler(self, event):
     setcfg("measurement_report.whitepoint.simulate.relative",
            int(self.simulate_whitepoint_relative_cb.GetValue()))
 def measure_auto_ctrl_handler(self, event):
     auto = self.measure_auto_cb.GetValue()
     setcfg("untethered.measure.auto", int(auto))
 def measurement_play_sound_handler(self, event):
     setcfg("measurement.play_sound",
            int(not (bool(getcfg("measurement.play_sound")))))
     self.set_sound_on_off_btn_bitmap()
 def mr_update_main_controls(self, event=None):
     ##print "MR update main ctrls",
     self.panel.Freeze()
     chart_has_white = bool(getattr(self, "chart_white", None))
     color = getcfg("measurement_report.chart.fields")
     sim_profile_color = (getattr(self, "simulation_profile", None)
                          and self.simulation_profile.colorSpace)
     if getcfg("measurement_report.use_simulation_profile"):
         setcfg("measurement_report.use_simulation_profile",
                int(sim_profile_color == color))
     self.simulation_profile_cb.Enable(sim_profile_color == color)
     self.simulation_profile_cb.Show(color in ("CMYK", "RGB"))
     enable1 = bool(getcfg("measurement_report.use_simulation_profile"))
     ##print enable1,
     enable2 = (sim_profile_color == "RGB" and bool(
         getcfg("measurement_report.use_simulation_profile_as_output")))
     self.simulation_profile_cb.SetValue(enable1)
     self.simulation_profile_ctrl.Show(color in ("CMYK", "RGB"))
     self.use_simulation_profile_as_output_cb.Show(
         enable1 and sim_profile_color == "RGB")
     self.use_simulation_profile_as_output_cb.SetValue(enable1 and enable2)
     self.enable_3dlut_cb.Enable(enable1 and enable2)
     self.enable_3dlut_cb.SetValue(enable1 and enable2
                                   and bool(getcfg("3dlut.enable")))
     self.enable_3dlut_cb.Show(
         enable1 and sim_profile_color == "RGB"
         and config.get_display_name() in ("madVR", "Prisma"))
     enable5 = (sim_profile_color == "RGB" and isinstance(
         self.simulation_profile.tags.get("rXYZ"), ICCP.XYZType)
                and isinstance(self.simulation_profile.tags.get("gXYZ"),
                               ICCP.XYZType)
                and isinstance(self.simulation_profile.tags.get("bXYZ"),
                               ICCP.XYZType)
                and not isinstance(self.simulation_profile.tags.get("A2B0"),
                                   ICCP.LUT16Type))
     ##print enable5, self.XYZbpin, self.XYZbpout
     self.mr_trc_label.Show(enable1 and enable5)
     self.apply_none_ctrl.Show(enable1 and enable5)
     self.apply_none_ctrl.SetValue(
         (not getcfg("measurement_report.apply_black_offset")
          and not getcfg("measurement_report.apply_trc")) or not enable5)
     self.apply_black_offset_ctrl.Show(enable1 and enable5)
     self.apply_black_offset_ctrl.SetValue(
         enable5 and bool(getcfg("measurement_report.apply_black_offset")))
     self.apply_trc_ctrl.Show(enable1 and enable5)
     self.apply_trc_ctrl.SetValue(
         enable5 and bool(getcfg("measurement_report.apply_trc")))
     enable6 = (enable1 and enable5 and bool(
         getcfg("measurement_report.apply_trc")
         or getcfg("measurement_report.apply_black_offset")))
     self.mr_show_trc_controls()
     show = (self.apply_none_ctrl.GetValue() and enable1 and enable5
             and self.XYZbpout > self.XYZbpin)
     self.input_value_clipping_bmp.Show(show)
     self.input_value_clipping_label.Show(show)
     if event:
         self.set_simulate_whitepoint(True)
     self.simulate_whitepoint_cb.Enable(
         (enable1 and not enable2)
         or (color in ("LAB", "XYZ") and chart_has_white))
     enable3 = bool(getcfg("measurement_report.whitepoint.simulate"))
     self.simulate_whitepoint_cb.SetValue(
         ((enable1 and not enable2) or color in ("LAB", "XYZ")) and enable3)
     self.simulate_whitepoint_relative_cb.Enable(
         ((enable1 and not enable2) or color in ("LAB", "XYZ")) and enable3)
     self.simulate_whitepoint_relative_cb.SetValue(
         ((enable1 and not enable2) or color in ("LAB", "XYZ"))
         and enable3 and bool(
             getcfg("measurement_report.whitepoint.simulate.relative")))
     self.devlink_profile_cb.Show(enable1 and enable2)
     enable4 = bool(getcfg("measurement_report.use_devlink_profile"))
     self.devlink_profile_cb.SetValue(enable1 and enable2 and enable4)
     self.devlink_profile_ctrl.Enable(enable1 and enable2 and enable4)
     self.devlink_profile_ctrl.Show(enable1 and enable2)
     self.output_profile_label.Enable(
         (color in ("LAB", "RGB", "XYZ") or enable1)
         and (not enable1 or not enable2 or self.apply_trc_ctrl.GetValue()
              or self.apply_black_offset_ctrl.GetValue()))
     self.output_profile_ctrl.Enable(
         (color in ("LAB", "RGB", "XYZ") or enable1)
         and (not enable1 or not enable2 or self.apply_trc_ctrl.GetValue()
              or self.apply_black_offset_ctrl.GetValue()))
     output_profile = ((hasattr(self, "presets")
                        and getcfg("measurement_report.output_profile")
                        not in self.presets or not hasattr(self, "presets"))
                       and bool(getattr(self, "output_profile", None)))
     self.measurement_report_btn.Enable(
         ((enable1 and enable2 and (not enable6 or output_profile) and
           (not enable4 or
            (bool(getcfg("measurement_report.devlink_profile")) and
             os.path.isfile(getcfg("measurement_report.devlink_profile")))))
          or (((not enable1 and color in ("LAB", "RGB", "XYZ")) or
               (enable1 and sim_profile_color == color and not enable2))
              and output_profile))
         and bool(getcfg("measurement_report.chart"))
         and os.path.isfile(getcfg("measurement_report.chart")))
     self.panel.Layout()
     self.panel.Thaw()
     if hasattr(self, "update_scrollbars"):
         self.update_scrollbars()
         self.calpanel.Layout()
     else:
         self.update_layout()