Created
June 19, 2014 12:48
-
-
Save fsi-jens/3ef12361015f84cbc418 to your computer and use it in GitHub Desktop.
Demo script to trigger a bug using drag and drop in vanilla/RoboFont
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vanilla | |
from Cocoa import NSColorPboardType | |
from AppKit import NSColor | |
from defconAppKit.windows.baseWindow import BaseWindowController | |
class DDWindow(BaseWindowController): | |
def __init__(self): | |
self.color = "#000000" | |
layer_columns = [ | |
{"title": "Index", | |
#"cell": vanilla.CheckBoxListCell(), | |
"width": 45, | |
"editable": True}, | |
{"title": "Color", | |
#"cell": vanilla.CheckBoxListCell(), | |
"width": 45, | |
"editable": True}, | |
{"title": "Layer Glyph", | |
"typingSensitive": True, | |
"editable": True}, | |
] | |
layer_drop_settings = { | |
"type": NSColorPboardType, | |
"allowDropBetweenRows": False, | |
"allowDropOnRow": True, | |
"callback": self._callback_layer_drop, | |
} | |
self.w = vanilla.Window((200, 204), "Bug Demo") | |
self.w.colorChooser = vanilla.ColorWell((10, 10, 40, 22), | |
color=self.getNSColor(self.color), | |
) | |
self.w.color_label = vanilla.TextBox((60, 13, 120, 20), "Drag color onto list", sizeStyle="small") | |
self.w.layer_list = vanilla.List((10, 42, -10, 150), | |
[{"Index": 0, "Color": "foo", "Layer Glyph": "bar"}, | |
{"Index": 1, "Color": "#123", "Layer Glyph": "aringacute"}], | |
columnDescriptions=layer_columns, | |
drawFocusRing=True, | |
enableDelete=True, | |
allowsMultipleSelection=False, | |
otherApplicationDropSettings=layer_drop_settings, | |
) | |
self.setUpBaseWindowBehavior() | |
self.w.open() | |
"""example dropinfo: | |
Something was dropped on the layer list: | |
{'rowIndex': 0, 'source': <objective-c class NSColorPanel at 0x7fff72b29ef0>, 'data': { | |
"$archiver" = NSKeyedArchiver; | |
"$objects" = ( | |
"$null", | |
{ | |
"$class" = "<CFKeyedArchiverUID 0x608000c2d220 [0x7fff70e30f00]>{value = 2}"; | |
NSColorSpace = 1; | |
NSRGB = <30203020 3000>; | |
}, | |
{ | |
"$classes" = ( | |
NSColor, | |
NSObject | |
); | |
"$classname" = NSColor; | |
} | |
); | |
"$top" = { | |
root = "<CFKeyedArchiverUID 0x608000c33260 [0x7fff70e30f00]>{value = 1}"; | |
}; | |
"$version" = 100000; | |
}, 'dropOnRow': False, 'isProposal': True} | |
""" | |
def _callback_layer_drop(self, sender=None, dropInfo=None): | |
if dropInfo["isProposal"]: | |
# TODO: check if drop is acceptable | |
return True | |
else: | |
print "DEBUG: dropped color on row %i" % dropInfo["rowIndex"] | |
# TODO: accept the drop (actually do something) | |
print dropInfo | |
return True | |
def getNSColor(self, hexrgba): | |
# return NSColor for r, g, b, a tuple | |
r, g, b, a = self.getTupleColor(hexrgba) | |
return NSColor.colorWithCalibratedRed_green_blue_alpha_(r, g, b, a) | |
def getTupleColor(self, hexrgba, opacity_factor=1): | |
r = float(int(hexrgba[1:3], 16)) / 255 | |
g = float(int(hexrgba[3:5], 16)) / 255 | |
b = float(int(hexrgba[5:7], 16)) / 255 | |
if len(hexrgba) == 9: | |
a = float(int(hexrgba[7:9], 16)) / 255 * opacity_factor | |
else: | |
a = opacity_factor | |
return (r, g, b, a) | |
if __name__ == "__main__": | |
OpenWindow(DDWindow) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment