• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10/pyobjc-45/2.5/pyobjc/pyobjc-framework-Quartz/Examples/Core Graphics/Quartz2DBasics/
1from Cocoa import *
2from UIHandling import *
3from PyObjCTools import NibClassBuilder
4import AppDrawing
5import math
6
7_drawingCommand = kCommandStrokedAndFilledRects
8_pdfDocument = None
9
10class MyView (NibClassBuilder.AutoBaseClass):
11    def drawRect_(self, rect):
12        context = NSGraphicsContext.currentContext().graphicsPort()
13        AppDrawing.myDispatchDrawing(context, _drawingCommand)
14
15    def setDrawCommand_(self, sender):
16        global _drawingCommand
17
18        newCommand = sender.tag()
19
20        if newCommand != _drawingCommand:
21            _drawingCommand = newCommand
22            self.setNeedsDisplay_(True)
23
24            self.currentMenuItem.setState_(NSOffState)
25	    self.currentMenuItem = sender;
26	    self.currentMenuItem.setState_(NSOnState)
27
28    def currentPrintableCommand(self):
29        # The best representation for printing or exporting
30        # when the current command caches using a bitmap context
31        # or a layer is to not do any caching.
32        if _drawingCommand == kCommandDoCGLayer:
33            return kCommandDoUncachedDrawing
34
35        return _drawingCommand
36
37    def print_(self, sender):
38        global _drawingCommand
39
40        savedDrawingCommand = _drawingCommand
41        _drawingCommand = self.currentPrintableCommand()
42        NSPrintOperation.printOperationWithView_(self).runOperation()
43        _drawingCommand = savedDrawingCommand
44
45    def knowsPageRange_(self, range):
46        return True, NSRange(1, 1)
47
48    def rectForPage_(self, page):
49        pi = NSPrintOperation.currentOperation().printInfo()
50        paperSize = pi.paperSize()
51        return NSMakeRect(0, 0, paperSize.width, paperSize.height)
52
53    def validateMenuItem_(self, menuItem):
54        if menuItem.tag() == _drawingCommand:
55            self.currentMenuItem = menuItem
56            menuItem.setState_(True)
57        else:
58            menuItem.setState_(False)
59
60	return True
61