Skip to content

Commit e4239a7

Browse files
authored
Merge pull request #180 from robotools/colorwellStyleArgument
Colorwell style argument
2 parents c8c4af6 + 85024e4 commit e4239a7

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

Lib/vanilla/vanillaBase.py

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class VanillaWarning(Warning): pass
3737
if platform.system() != "Darwin":
3838
macVersion = "0.0"
3939
osVersionCurrent = version(macVersion)
40+
osVersion13_0 = version("13.0")
4041
osVersion12_0 = version("12.0")
4142
osVersion10_16 = version("10.16") # macOS11 Big Sur seems to be 10.16
4243
osVersion10_15 = version("10.15")

Lib/vanilla/vanillaColorWell.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
from AppKit import NSColorWell, NSColorPanel
2-
from vanilla.vanillaBase import VanillaBaseObject
2+
from vanilla.vanillaBase import VanillaBaseObject, osVersionCurrent, osVersion13_0
3+
4+
if osVersionCurrent >= osVersion13_0:
5+
from AppKit import NSColorWellStyleDefault, NSColorWellStyleMinimal, NSColorWellStyleExpanded
6+
7+
colorWellStyleMap = dict(
8+
default=NSColorWellStyleDefault,
9+
minimal=NSColorWellStyleMinimal,
10+
expanded=NSColorWellStyleExpanded
11+
)
12+
13+
else:
14+
colorWellStyleMap = dict()
315

416

517
class ColorWell(VanillaBaseObject):
@@ -38,17 +50,32 @@ def colorWellEdit(self, sender):
3850
**color** A `NSColor`_ object. If *None* is given, the color shown will
3951
be white.
4052
53+
**colorWellStyle** A string representing the desired color well style. The options are:
54+
55+
+------------+
56+
| "default" |
57+
+------------+
58+
| "minimal" |
59+
+------------+
60+
| "expanded" |
61+
+------------+
62+
4163
.. _NSColor: https://developer.apple.com/documentation/appkit/nscolor?language=objc
4264
"""
4365

4466
nsColorWellClass = NSColorWell
4567

46-
def __init__(self, posSize, callback=None, color=None):
68+
def __init__(self, posSize, callback=None, color=None, colorWellStyle=None):
4769
self._setupView(self.nsColorWellClass, posSize, callback=callback)
4870
if color is not None:
4971
self._nsObject.setColor_(color)
5072
colorPanel = NSColorPanel.sharedColorPanel()
5173
colorPanel.setShowsAlpha_(True)
74+
if osVersionCurrent >= osVersion13_0:
75+
# https://developer.apple.com/documentation/appkit/nscolorwell/3955203-colorwellstyle?language=objc
76+
nsColorWellStyle = colorWellStyleMap.get(colorWellStyle)
77+
if nsColorWellStyle is not None:
78+
colorPanel.setColorWellStyle_(nsColorWellStyle)
5279

5380
def getNSColorWell(self):
5481
"""

Lib/vanilla/vanillaList2.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1301,11 +1301,15 @@ class ColorWellList2Cell(ColorWell):
13011301

13021302
def __init__(self,
13031303
editable=False,
1304-
callback=None
1304+
callback=None,
1305+
colorWellStyle=None
13051306
):
1307+
if colorWellStyle is None:
1308+
colorWellStyle = "minimal"
13061309
super().__init__(
13071310
"auto",
1308-
callback=callback
1311+
callback=callback,
1312+
colorWellStyle=colorWellStyle
13091313
)
13101314
colorWell = self.getNSColorWell()
13111315
self.enable(editable)

0 commit comments

Comments
 (0)