• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10/pyobjc-45/2.6/pyobjc/pyobjc-framework-Cocoa/Examples/AppKit/CocoaBindings/GraphicsBindings/
1#
2#  GraphicsBindingsDocument.py
3#  GraphicsBindings
4#
5#  Converted by u.fiedler on feb 2005
6#  with great help from Bob Ippolito - Thank you Bob!
7#
8#  The original version was written in Objective-C by Malcolm Crawford
9#  http://homepage.mac.com/mmalc/CocoaExamples/controllers.html
10
11import objc
12from PyObjCTools import AppHelper
13
14from RadiansToDegreesTransformer import RadiansToDegreesTransformer
15from Cocoa import *
16
17class GraphicsBindingsDocument (NSDocument):
18    graphicsView = objc.IBOutlet()
19    shadowInspector = objc.IBOutlet()
20    graphicsController = objc.IBOutlet()
21    graphics = objc.ivar()
22
23    def init(self):
24        self = super(GraphicsBindingsDocument, self).init()
25        if self is None:
26            return None
27        self.graphics = [] # NSMutableArray.array()
28        self.bindings = []
29        return self
30
31    def windowNibName(self):
32        return "GraphicsBindingsDocument"
33
34    def makeBinding_fromObject_toObject_withKeyPath_options_(self, key, fromObject, toObject, withKeyPath, options):
35        self.bindings.append((fromObject, key))
36        fromObject.bind_toObject_withKeyPath_options_(key, toObject, withKeyPath, options)
37
38    def windowControllerDidLoadNib_(self, controller):
39        super(GraphicsBindingsDocument, self).windowControllerDidLoadNib_(controller)
40
41        # we can't do these in IB at the moment, as
42        # we don't have palette items for them
43
44        # allow the shadow inspector (joystick) to handle multiple selections
45        offsetOptions = { u"NSAllowsEditingMultipleValuesSelection" : True }
46        angleOptions = {
47            u"NSValueTransformerName" :  u"RadiansToDegreesTransformer",
48            u"NSAllowsEditingMultipleValuesSelection" : True,
49        }
50
51        BINDINGS = [
52            (u'graphics',  self.graphicsView, self.graphicsController, u'arrangedObjects', None),
53            (u'selectionIndexes', self.graphicsView, self.graphicsController, u'selectionIndexes', None),
54            (u'offset', self.shadowInspector, self.graphicsController, u'selection.shadowOffset', offsetOptions),
55            (u'angle', self.shadowInspector, self.graphicsController, u'selection.shadowAngle', angleOptions),
56        ]
57        for binding in BINDINGS:
58            self.makeBinding_fromObject_toObject_withKeyPath_options_(*binding)
59
60        # "fake" what should be set in IB if we had a palette...
61        self.shadowInspector.maxOffset = 15
62
63    def close(self):
64        while self.bindings:
65            obj, binding = self.bindings.pop()
66            obj.unbind_(binding)
67        super(GraphicsBindingsDocument, self).close()
68
69    def dataRepresentationOfType_(self, aType):
70        return NSKeyedArchiver.archivedDataWithRootObject_(self.graphics)
71
72    def loadDataRepresentation_ofType_(self, data, aType):
73        self.graphics = NSKeyedUnarchiver.unarchiveObjectWithData_(data)
74        return True
75
76vt = RadiansToDegreesTransformer.alloc().init()
77NSValueTransformer.setValueTransformer_forName_(vt, u"RadiansToDegreesTransformer")
78