Debian Codegraph @

DisplayCAL/mscms_wrapper.py

raw
1 """Wrapper for WCS API calls."""
2
3 from __future__ import annotations
4
5 import ctypes
6 import sys
7 from ctypes import (
8 POINTER,
9 WINFUNCTYPE,
10 Structure,
11 WinError,
12 c_wchar_p,
13 create_unicode_buffer,
14 wstring_at,
15 )
16 from ctypes.wintypes import BOOL, DWORD, LPWSTR
17 from typing import Any, Callable
18
19 if sys.version_info >= (3, 11):
20 from typing import Self
21 else:
22 from typing_extensions import Self
23
24 from DisplayCAL.mscms_types import (
25 COLORPROFILESUBTYPE,
26 COLORPROFILETYPE,
27 WCS_PROF_SCOPE,
28 dwDeviceClass,
29 dwFieldsUsed,
30 )
31
32 # mscms calls used:
33 # + WcsAssociateColorProfileWithDevice
34 # + WcsDisassociateColorProfileFromDevice
35 # + WcsEnumColorProfiles
36 # + WcsEnumColorProfilesSize
37 # + WcsGetCalibrationManagementState
38 # + WcsSetCalibrationManagementState
39 # + WcsGetDefaultColorProfile (leaks)
40 # + WcsGetDefaultColorProfileSize (leaks)
41 # + WcsGetUsePerUserProfiles (leaks)
42 # + WcsSetUsePerUserProfiles
43
44 dwResolutionArray = DWORD * 2 # noqa: N816
45 dwAttributesArray = DWORD * 2 # noqa: N816
46 WCS_PROF_SCOPE_t = DWORD
47 COLORPROFILETYPE_t = DWORD
48 COLORPROFILESUBTYPE_t = DWORD
49 PCWSTR = c_wchar_p
50
51 ENUM_TYPE_VERSION = DWORD(0x0300) # Profile enumeration marker
52 WIN_ERRNO_SUCCESS = 0
53 WIN_ERRNO_PROFILE_NOT_ASSOCIATED = 2015
54
55
56 class ENUMTYPEW(Structure):
57 """The ENUMTYPEW structure specifies the criteria for enumerating color profiles."""
58
59 _fields_ = [
60 ("dwSize", DWORD), # size of structure
61 ("dwVersion", DWORD), # should be equal to ENUM_TYPE_VERSION
62 (
63 "dwFields",
64 DWORD,
65 ), # indicates which fields in this structure are being used.
66 # Can be set to any combination of the dwFieldsUsed enum.
67 ("pDeviceName", LPWSTR),
68 ("dwMediaType", DWORD),
69 ("dwDitheringMode", DWORD),
70 ("dwResolution", dwResolutionArray),
71 ("dwCMMType", DWORD),
72 ("dwClass", DWORD),
73 ("dwDataColorSpace", DWORD),
74 ("dwConnectionSpace", DWORD),
75 ("dwSignature", DWORD),
76 ("dwPlatform", DWORD),
77 ("dwProfileFlags", DWORD),
78 ("dwManufacturer", DWORD),
79 ("dwModel", DWORD),
80 ("dwAttributes", dwAttributesArray),
81 ("dwRenderingIntent", DWORD),
82 ("dwCreator", DWORD),
83 ("dwDeviceClass", DWORD),
84 ]
85
86 def __init__(self) -> None:
87 self.dwSize = ctypes.sizeof(ENUMTYPEW)
88 self.dwVersion = ENUM_TYPE_VERSION
89
90 @classmethod
91 def create_monitor_profile_filter(
92 cls, device_key: str, device_class: dwDeviceClass = dwDeviceClass.CLASS_MONITOR
93 ) -> Self:
94 """Create an ENUMTYPEW structure for monitor profile filtering.
95
96 This is used for profile enumeration for a monitor device.
97
98 Args:
99 device_key (str): Device key of the monitor device for which to
100 filter.
101 device_class (dwDeviceClass, optional): The class of the device.
102 Defaults to dwDeviceClass.CLASS_MONITOR.
103
104 Returns:
105 ENUMTYPEW: An initialized ENUMTYPEW structure for monitor profile
106 filtering.
107 """
108 enum_desc = cls()
109 enum_desc.dwDeviceClass = device_class
110 enum_desc.pDeviceName = device_key
111 enum_desc.dwFields = dwFieldsUsed.ET_DEVICECLASS | dwFieldsUsed.ET_DEVICENAME
112 return enum_desc
113
114
115 def _errcheck_simple_bool(result: Any, func: Callable[..., Any], args: Any) -> Any: # noqa: ANN401
116 if not result:
117 raise WinError()
118 return result
119
120
121 def _errcheck_args_ret(result: Any, func: Callable[..., Any], args: Any) -> Any: # noqa: ANN401
122 errno = ctypes.GetLastError()
123 if not result and errno != WIN_ERRNO_SUCCESS:
124 raise WinError(errno)
125 return args
126
127
128 def _wrap_wcsAssociateColorProfileWithDevice() -> Callable[..., Any]: # noqa: ANN401, N802
129 proto = WINFUNCTYPE(BOOL, WCS_PROF_SCOPE_t, LPWSTR, LPWSTR)
130 paramflags = (
131 (1, "scope"),
132 (1, "pProfileName"),
133 (1, "pDeviceName"),
134 )
135
136 associate_color_profile_with_device = proto(
137 ("WcsAssociateColorProfileWithDevice", ctypes.windll.mscms),
138 paramflags,
139 )
140 associate_color_profile_with_device.errcheck = _errcheck_simple_bool
141 return associate_color_profile_with_device
142
143
144 def _wrap_wcsDisassociateColorProfileFromDevice() -> Callable[..., Any]: # noqa: N802
145 proto = WINFUNCTYPE(BOOL, WCS_PROF_SCOPE_t, LPWSTR, LPWSTR)
146 paramflags = (
147 (1, "scope"),
148 (1, "pProfileName"),
149 (1, "pDeviceName"),
150 )
151 disassociate_color_profile_from_device = proto(
152 ("WcsDisassociateColorProfileFromDevice", ctypes.windll.mscms),
153 paramflags,
154 )
155 disassociate_color_profile_from_device.errcheck = _errcheck_simple_bool
156 return disassociate_color_profile_from_device
157
158
159 def _wrap_wcsEnumColorProfiles() -> Callable[..., Any]: # noqa: N802
160 proto = WINFUNCTYPE(
161 BOOL, WCS_PROF_SCOPE_t, POINTER(ENUMTYPEW), LPWSTR, DWORD, POINTER(DWORD)
162 )
163 paramflags = (
164 (1, "scope"),
165 (1, "pEnumRecord"),
166 (3, "pBuffer"),
167 (1, "dwSize"),
168 (2, "pnProfiles", DWORD(0)),
169 )
170
171 enum_color_profiles = proto(
172 ("WcsEnumColorProfiles", ctypes.windll.mscms), paramflags
173 )
174 enum_color_profiles.errcheck = _errcheck_args_ret
175 return enum_color_profiles
176
177
178 def _wrap_wcsEnumColorProfilesSize() -> Callable[..., Any]: # noqa: N802
179 proto = WINFUNCTYPE(BOOL, WCS_PROF_SCOPE_t, POINTER(ENUMTYPEW), POINTER(DWORD))
180 paramflags = (
181 (1, "scope"),
182 (1, "pEnumRecord"),
183 (2, "pdwSize", DWORD(0)),
184 )
185 get_enum_color_profiles_size = proto(
186 ("WcsEnumColorProfilesSize", ctypes.windll.mscms), paramflags
187 )
188 get_enum_color_profiles_size.errcheck = _errcheck_args_ret
189 return get_enum_color_profiles_size
190
191
192 def _wrap_wcsGetCalibrationManagementState() -> Callable[..., Any]: # noqa: N802
193 proto = WINFUNCTYPE(BOOL, POINTER(BOOL))
194 paramflags = ((2, "pbIsEnabled", BOOL(False)),)
195 get_calibration_management_state = proto(
196 ("WcsGetCalibrationManagementState", ctypes.windll.mscms),
197 paramflags,
198 )
199 get_calibration_management_state.errcheck = _errcheck_args_ret
200 return get_calibration_management_state
201
202
203 def _wrap_wcsSetCalibrationManagementState() -> Callable[..., Any]: # noqa: N802
204 proto = WINFUNCTYPE(BOOL, BOOL)
205 paramflags = ((1, "pbIsEnabled"),)
206 set_calibration_management_state = proto(
207 ("WcsSetCalibrationManagementState", ctypes.windll.mscms),
208 paramflags,
209 )
210 set_calibration_management_state.errcheck = _errcheck_simple_bool
211 return set_calibration_management_state
212
213
214 def _wrap_wcsGetDefaultColorProfile() -> Callable[..., Any]: # noqa: N802
215 proto = WINFUNCTYPE(
216 BOOL,
217 WCS_PROF_SCOPE_t,
218 PCWSTR,
219 COLORPROFILETYPE_t,
220 COLORPROFILESUBTYPE_t,
221 DWORD,
222 DWORD,
223 LPWSTR,
224 )
225 paramflags = (
226 (1, "scope"),
227 (1, "pDeviceName"),
228 (1, "cptColorProfileType"),
229 (1, "cpstColorProfileSubType"),
230 (1, "dwProfileID"),
231 (1, "cbProfileName"),
232 (3, "pProfileName"),
233 )
234 get_default_color_profile = proto(
235 ("WcsGetDefaultColorProfile", ctypes.windll.mscms), paramflags
236 )
237 get_default_color_profile.errcheck = _errcheck_args_ret
238 return get_default_color_profile
239
240
241 def _wrap_wcsGetDefaultColorProfileSize() -> Callable[..., Any]: # noqa: N802
242 proto = WINFUNCTYPE(
243 BOOL,
244 WCS_PROF_SCOPE_t,
245 PCWSTR,
246 COLORPROFILETYPE_t,
247 COLORPROFILESUBTYPE_t,
248 DWORD,
249 POINTER(DWORD),
250 )
251 paramflags = (
252 (1, "scope"),
253 (1, "pDeviceName"),
254 (1, "cptColorProfileType"),
255 (1, "cpstColorProfileSubType"),
256 (1, "dwProfileID"),
257 (2, "pcbProfileName", DWORD(0)),
258 )
259 get_default_color_profile_size = proto(
260 ("WcsGetDefaultColorProfileSize", ctypes.windll.mscms),
261 paramflags,
262 )
263 get_default_color_profile_size.errcheck = _errcheck_args_ret
264 return get_default_color_profile_size
265
266
267 def _wrap_wcsSetDefaultColorProfile() -> Callable[..., Any]: # noqa: N802
268 proto = WINFUNCTYPE(
269 BOOL,
270 WCS_PROF_SCOPE_t,
271 PCWSTR,
272 COLORPROFILETYPE_t,
273 COLORPROFILESUBTYPE_t,
274 DWORD,
275 LPWSTR,
276 )
277 paramflags = (
278 (1, "scope"),
279 (1, "pDeviceName"),
280 (1, "cptColorProfileType"),
281 (1, "cpstColorProfileSubType"),
282 (1, "dwProfileID"),
283 (1, "pProfileName"),
284 )
285 set_default_color_profile = proto(
286 ("WcsSetDefaultColorProfile", ctypes.windll.mscms), paramflags
287 )
288 set_default_color_profile.errcheck = _errcheck_simple_bool
289 return set_default_color_profile
290
291
292 def _wrap_wcsGetUsePerUserProfiles() -> Callable[..., Any]: # noqa: N802
293 proto = WINFUNCTYPE(BOOL, LPWSTR, DWORD, POINTER(BOOL))
294 paramflags = (
295 (1, "pDeviceName"),
296 (1, "dwDeviceClass"),
297 (2, "pUsePerUserProfiles", BOOL(False)),
298 )
299 get_use_per_user_profiles = proto(
300 ("WcsGetUsePerUserProfiles", ctypes.windll.mscms),
301 paramflags,
302 )
303 get_use_per_user_profiles.errcheck = _errcheck_args_ret
304 return get_use_per_user_profiles
305
306
307 def _wrap_wcsSetUsePerUserProfiles() -> Callable[..., Any]: # noqa: N802
308 set_use_per_user_proto = WINFUNCTYPE(BOOL, LPWSTR, DWORD, BOOL)
309 set_use_per_user_paramflags = (
310 (1, "pDeviceName"),
311 (1, "dwDeviceClass"),
312 (1, "pUsePerUserProfiles"),
313 )
314 set_use_per_user_profiles = set_use_per_user_proto(
315 ("WcsSetUsePerUserProfiles", ctypes.windll.mscms),
316 set_use_per_user_paramflags,
317 )
318 set_use_per_user_profiles.errcheck = _errcheck_simple_bool
319 return set_use_per_user_profiles
320
321
322 class WCS:
323 """Wrapper for WCS API calls."""
324
325 def __init__(self) -> None:
326 self._wcsAssociateColorProfileWithDevice = (
327 _wrap_wcsAssociateColorProfileWithDevice()
328 )
329 self._wcsDisassociateColorProfileFromDevice = (
330 _wrap_wcsDisassociateColorProfileFromDevice()
331 )
332 self._wcsEnumColorProfiles = _wrap_wcsEnumColorProfiles()
333 self._wcsEnumColorProfilesSize = _wrap_wcsEnumColorProfilesSize()
334 self._wcsGetCalibrationManagementState = (
335 _wrap_wcsGetCalibrationManagementState()
336 )
337 self._wcsSetCalibrationManagementState = (
338 _wrap_wcsSetCalibrationManagementState()
339 )
340 self._wcsGetDefaultColorProfile = _wrap_wcsGetDefaultColorProfile()
341 self._wcsGetDefaultColorProfileSize = _wrap_wcsGetDefaultColorProfileSize()
342 self._wcsSetDefaultColorProfile = _wrap_wcsSetDefaultColorProfile()
343 self._wcsGetUsePerUserProfiles = _wrap_wcsGetUsePerUserProfiles()
344 self._wcsSetUsePerUserProfiles = _wrap_wcsSetUsePerUserProfiles()
345
346 def AssociateColorProfileWithDevice( # noqa: N802
347 self, scope: WCS_PROF_SCOPE, profile_name: str, device_key: str
348 ) -> None:
349 """Associate a specified WCS color profile with a specified device.
350
351 This API does not support "advanced color" profiles for HDR monitors
352
353 Note: this API makes the added profile also be the default one
354
355 Args:
356 scope (WCS_PROF_SCOPE): The scope of this profile management
357 operation, which could be system-wide or for the current user.
358 profile_name (str): File name of the profile to associate.
359 device_key (str): Device key of the device with which to
360 associate the profile.
361
362 Raises:
363 OSError: If a Win API error occurs.
364 """
365 self._wcsAssociateColorProfileWithDevice(scope, profile_name, device_key)
366
367 def DisassociateColorProfileFromDevice( # noqa: N802
368 self, scope: WCS_PROF_SCOPE, profile_name: str, device_key: str
369 ) -> None:
370 """Disassociate a specified WCS color profile from a specified device.
371
372 This API does not support "advanced color" profiles for HDR monitors.
373
374 Note: very unreliable due to quirks, the actual result should be
375 double-checked with profile listing
376
377 Args:
378 scope (WCS_PROF_SCOPE): The scope of this profile management
379 operation, which could be system-wide or for the current user.
380 profile_name (str): File name of the profile to disassociate.
381 device_key (str): Device key of the device from which to
382 disassociate the profile.
383
384 Raises:
385 OSError: If a Win API error occurs (apart from the ones caught
386 during handling its quirks).
387 """
388 try:
389 self._wcsDisassociateColorProfileFromDevice(scope, profile_name, device_key)
390 except OSError as e:
391 # quirks: very very quirky: either returns error with errno success
392 # or errno profile not associated with device. Why? Because Windows,
393 # that's why.
394 if e.winerror not in (WIN_ERRNO_SUCCESS, WIN_ERRNO_PROFILE_NOT_ASSOCIATED):
395 raise
396
397 def EnumColorProfiles( # noqa: N802
398 self, scope: WCS_PROF_SCOPE, enum_record: ENUMTYPEW, prof_size: int
399 ) -> list[str]:
400 """Enumerate color profiles associated with any device, in the specified scope.
401
402 This API does not support "advanced color" profiles for HDR monitors
403
404 Args:
405 scope (WCS_PROF_SCOPE): The scope of this profile management
406 operation, which could be system-wide or for the current user.
407 enum_record (ENUMTYPEW): Structure specifying the enumeration
408 criteria.
409 prof_size (int): Size, in bytes, of the buffer that is needed to
410 enumerate color profiles.
411
412 Raises:
413 ValueError: On parsing errors.
414 OSError: If a Win API error occurs.
415
416 Returns:
417 list[str]: Array of profile names.
418 """
419 wchar_size = ctypes.sizeof(ctypes.c_wchar)
420 char_count = max(1, (prof_size + wchar_size - 1) // wchar_size)
421 buf = create_unicode_buffer(char_count)
422 profiles, p_num = self._wcsEnumColorProfiles(scope, enum_record, buf, prof_size)
423 if p_num == 0:
424 return []
425 prof_arr = wstring_at(profiles, char_count).strip("\x00").split("\x00")
426 if len(prof_arr) != p_num:
427 raise ValueError(
428 "Parsing error: profile number mismatch: "
429 f"reported {p_num} != {len(prof_arr)} got"
430 )
431 return prof_arr
432
433 def EnumColorProfilesSize( # noqa: N802
434 self, scope: WCS_PROF_SCOPE, enum_record: ENUMTYPEW
435 ) -> int:
436 """Get the size in bytes of the buffer needed to enumerate color profiles.
437
438 This API does not support "advanced color" profiles for HDR monitors
439
440 Args:
441 scope (WCS_PROF_SCOPE): The scope of this profile management
442 operation, which could be system-wide or for the current user.
443 enum_record (ENUMTYPEW): Structure specifying the enumeration criteria.
444
445 Raises:
446 OSError: In case of Win API errors.
447
448 Returns:
449 int: Size, in bytes, of the buffer that is needed to enumerate
450 color profiles.
451 """
452 return self._wcsEnumColorProfilesSize(scope, enum_record)
453
454 def GetCalibrationManagementState(self) -> bool: # noqa: N802
455 """Check if system management of the display calibration state is enabled.
456
457 Raises:
458 OSError: If a Win API error occurs.
459
460 Returns:
461 bool: True if system management of the display calibration state is
462 enabled; otherwise False.
463 """
464 return bool(self._wcsGetCalibrationManagementState())
465
466 def SetCalibrationManagementState(self, new_state: bool) -> None: # noqa: N802
467 """Enable or disable system management of the display calibration state.
468
469 Args:
470 new_state (bool): True to enable system management of the display
471 calibration state. False to disable system management of the
472 display calibration state.
473
474 Raises:
475 OSError: If a Win API error occurs.
476 """
477 self._wcsSetCalibrationManagementState(new_state)
478
479 def GetDefaultColorProfile( # noqa: N802
480 self,
481 scope: WCS_PROF_SCOPE,
482 device_key: str,
483 prof_size: int,
484 c_prof_type: COLORPROFILETYPE = COLORPROFILETYPE.CPT_ICC,
485 c_prof_subtype: COLORPROFILESUBTYPE = COLORPROFILESUBTYPE.CPST_NONE,
486 profile_id: int = 0,
487 ) -> str:
488 """Get the default color profile for a device.
489
490 This API does not support "advanced color" profiles for HDR monitors.
491 Note: if HDR enabled on a device causes OSError
492
493 Args:
494 scope (WCS_PROF_SCOPE): The scope of this profile management
495 operation, which could be system-wide or for the current user.
496 device_key (str): Device key of the device for which the default
497 color profile is obtained. If None, a device-independent
498 default profile is obtained.
499 prof_size (int): Size, in bytes, of the buffer that is sufficient
500 to contain the profile name.
501 c_prof_type (COLORPROFILETYPE, optional): Value specifying the
502 color profile type. Defaults to COLORPROFILETYPE.CPT_ICC.
503 c_prof_subtype (COLORPROFILESUBTYPE, optional): Value specifying
504 the color profile subtype. Defaults to
505 COLORPROFILESUBTYPE.CPST_NONE.
506 profile_id (int, optional): ID of the color space that the color
507 profile represents. Defaults to 0.
508
509 Raises:
510 OSError: In case of Win API errors.
511
512 Returns:
513 str: The name of the default color profile for a device.
514 """
515 wchar_size = ctypes.sizeof(ctypes.c_wchar)
516 char_count = max(1, (prof_size + wchar_size - 1) // wchar_size)
517 buf = create_unicode_buffer(char_count)
518 self._wcsGetDefaultColorProfile(
519 scope, device_key, c_prof_type, c_prof_subtype, profile_id, prof_size, buf
520 )
521 return buf.value
522
523 def GetDefaultColorProfileSize( # noqa: N802
524 self,
525 scope: WCS_PROF_SCOPE,
526 device_key: str,
527 c_prof_type: COLORPROFILETYPE = COLORPROFILETYPE.CPT_ICC,
528 c_prof_subtype: COLORPROFILESUBTYPE = COLORPROFILESUBTYPE.CPST_NONE,
529 profile_id: int = 0,
530 ) -> int:
531 """Get the size in bytes of the default color profile name for a device.
532
533 This API does not support "advanced color" profiles for HDR monitors.
534 Note: if HDR enabled on a device returns 0.
535
536 Args:
537 scope (WCS_PROF_SCOPE): The scope of this profile management
538 operation, which could be system-wide or for the current user.
539 device_key (str): Device key of the device for which the default
540 color profile is obtained. If None, a device-independent
541 default profile is obtained.
542 c_prof_type (COLORPROFILETYPE, optional): Value specifying the
543 color profile type. Defaults to COLORPROFILETYPE.CPT_ICC.
544 c_prof_subtype (COLORPROFILESUBTYPE, optional): Value specifying
545 the color profile subtype. Defaults to COLORPROFILESUBTYPE.CPST_NONE.
546 profile_id (int, optional): ID of the color space that the color
547 profile represents. Defaults to 0.
548
549 Raises:
550 OSError: If a Win API error occurs.
551
552 Returns:
553 int: size, in bytes, of the buffer that is sufficient to contain
554 profile name.
555 """
556 return self._wcsGetDefaultColorProfileSize(
557 scope, device_key, c_prof_type, c_prof_subtype, profile_id
558 )
559
560 def SetDefaultColorProfile( # noqa: N802
561 self,
562 scope: WCS_PROF_SCOPE,
563 device_key: str,
564 profile_name: str,
565 c_prof_type: COLORPROFILETYPE = COLORPROFILETYPE.CPT_ICC,
566 c_prof_subtype: COLORPROFILESUBTYPE = COLORPROFILESUBTYPE.CPST_NONE,
567 profile_id: int = 0,
568 ) -> None:
569 """Set the default color profile for the specified device.
570
571 This API does not support "advanced color" profiles for HDR monitors.
572
573 Args:
574 scope (WCS_PROF_SCOPE): The scope of this profile management
575 operation, which could be system-wide or for the current user.
576 device_key (str): Device key of the device for which the default
577 color profile is to be set. If None, a device-independent
578 default profile is set.
579 profile_name (str): File name of the profile.
580 c_prof_type (COLORPROFILETYPE, optional): Value specifying the
581 color profile type. Defaults to COLORPROFILETYPE.CPT_ICC.
582 c_prof_subtype (COLORPROFILESUBTYPE, optional): Value specifying
583 the color profile subtype. Defaults to
584 COLORPROFILESUBTYPE.CPST_NONE.
585 profile_id (int, optional): ID of the color space that the color
586 profile represents. Defaults to 0.
587
588 Raises:
589 OSError: If a Win API error occurs.
590 """
591 self._wcsSetDefaultColorProfile(
592 scope, device_key, c_prof_type, c_prof_subtype, profile_id, profile_name
593 )
594
595 def GetUsePerUserProfiles( # noqa: N802
596 self, device_key: str, device_class: dwDeviceClass = dwDeviceClass.CLASS_MONITOR
597 ) -> bool:
598 """Determine if per-user profile association is enabled for the device.
599
600 Args:
601 device_key (str): Device key of the device.
602 device_class (dwDeviceClass, optional): The class of the device.
603 Defaults to dwDeviceClass.CLASS_MONITOR.
604
605 Raises:
606 OSError: If a Win API error occurs.
607
608 Returns:
609 bool: True if the user chose to use a per-user profile association
610 list for the specified device; otherwise False
611 """
612 return bool(self._wcsGetUsePerUserProfiles(device_key, device_class))
613
614 def SetUsePerUserProfiles( # noqa: N802
615 self,
616 device_key: str,
617 new_state: bool,
618 device_class: dwDeviceClass = dwDeviceClass.CLASS_MONITOR,
619 ) -> None:
620 """Enable or disable per-user profile association for the specified device.
621
622 Args:
623 device_key (str): Device key of the device.
624 new_state (bool): True if the user wants to use a per-user profile
625 association list for the specified device; otherwise False.
626 device_class (dwDeviceClass, optional): The class of the device.
627 Defaults to dwDeviceClass.CLASS_MONITOR.
628
629 Raises:
630 OSError: If a Win API error occurs.
631 """
632 self._wcsSetUsePerUserProfiles(device_key, device_class, new_state)
633
634 def getDeviceColorProfileList( # noqa: N802
635 self,
636 scope: WCS_PROF_SCOPE,
637 device_key: str,
638 device_class: dwDeviceClass = dwDeviceClass.CLASS_MONITOR,
639 ) -> list[str]:
640 """Higher abstraction level function to get color profile list for a device.
641
642 Also dodges the issue with serialization of some ctypes structures in
643 multiprocess context.
644
645 Args:
646 scope (WCS_PROF_SCOPE): The scope of this profile management
647 operation, which could be system-wide or for the current user.
648 device_key (str): Device key of the device.
649 device_class (dwDeviceClass, optional): The class of the device.
650 Defaults to dwDeviceClass.CLASS_MONITOR.
651
652 Raises:
653 OSError: If a Win API error occurs.
654 ValueError: If a parsing error occurs.
655
656 Returns:
657 list[str]: array of color profile names
658 """
659 enum_record = ENUMTYPEW.create_monitor_profile_filter(device_key)
660 size = self.EnumColorProfilesSize(scope, enum_record)
661 return self.EnumColorProfiles(scope, enum_record, size)