コード例 #1
0
 def drawRect_(self, rect):
     if self.inLiveResize():
         self._recalcSize()
     from random import random
     NSColor.redColor().set()
     NSRectFill(self.bounds())
     width, height = self.frame()[1]
     w = width / 5
     h = height / 5
     for xI in range(5):
         for yI in range(5):
             x = xI * w
             y = height - (yI * h) - h
             r = ((x, y), (w, h))
             NSColor.colorWithDeviceRed_green_blue_alpha_(random(), random(), random(), 1.0).set()
             NSRectFill(r)
コード例 #2
0
ファイル: testAll.py プロジェクト: typesupply/vanilla
 def drawRect_(self, rect):
     if self.inLiveResize():
         self._recalcSize()
     from random import random
     NSColor.redColor().set()
     NSRectFill(self.bounds())
     width, height = self.frame()[1]
     w = width / 5
     h = height / 5
     for xI in range(5):
         for yI in range(5):
             x = xI * w
             y = height - (yI * h) - h
             r = ((x, y), (w, h))
             NSColor.colorWithDeviceRed_green_blue_alpha_(random(), random(), random(), 1.0).set()
             NSRectFill(r)
コード例 #3
0
ファイル: testAll.py プロジェクト: behnam/typefacet
    def __init__(self, drawGrid=False):
        self.w = Window((600, 500), "", minSize=(300, 250))

        grp = Group((0, 0, 0, 0))
        grp.button = Button((10, 10, -10, 20), "Toggle", self.buttonCallback)

        self.view1 = TestSplitSubview((0, 0, 0, 0), NSColor.redColor())
        paneDescriptions2 = [
            dict(view=self.view1, canCollapse=True, size=50, identifier="pane1"),
            dict(view=grp, identifier="pane2"),
            dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.greenColor()), minSize=50, identifier="pane3"),
            dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.yellowColor()), identifier="pane4"),
        ]
        self.nestedSplit = SplitView((0, 0, 0, 0), paneDescriptions2, isVertical=True)
        paneDescriptions1 = [
            dict(view=self.nestedSplit, identifier="pane5"),
            dict(
                view=TestSplitSubview((0, 0, 0, 0), NSColor.magentaColor()),
                minSize=100,
                size=100,
                canCollapse=True,
                identifier="pane6",
            ),
        ]
        self.w.splitView = SplitView((10, 10, -10, -10), paneDescriptions1, isVertical=False)

        if drawGrid:
            self.drawGrid()
        self.w.open()
コード例 #4
0
ファイル: copy_glyphs.py プロジェクト: davelab6/copyGlyphs
 def __init__(self):
     self.doMarkGlyphs = 0
     self.doOverwrite = 1
     self.sourceFontList = AllFonts()
     self.destinationFontList = AllFonts()
     self.source_font = self.sourceFontList[0]
     self.destination_fonts = None
     self.glyphs = None
     self.mark = NSColor.redColor()
     
     ## create a window
     self.w = Window((700, 500), "Copy Glyphs", minSize=(700, 500))
     self.w.sourceTitle = TextBox((15, 20, 200, 20), "Source Font:")
     self.w.sourceFont = PopUpButton((15, 42, -410, 20), [f.info.familyName + ' ' + f.info.styleName for f in self.sourceFontList], callback=self.sourceCallback)
     self.w.glyphs = GlyphCollectionView((16, 70, -410, -65), initialMode="list", enableDelete=False, allowDrag=False, selectionCallback=self.glyphCallback)
     self._sortGlyphs(self.source_font)
     self.w.desTitle = TextBox((-400, 20, 200, 20), "Destination Fonts:")
     self.w.destinationFonts = FontList((-400, 42, -15, -115), self.destinationFontList, selectionCallback=self.desCallback)
     self.w.overwrite = CheckBox((-395, -105, 130, 22), "Overwrite glyphs", callback=self.overwriteCallback, value=self.doOverwrite)
     self.w.markGlyphs = CheckBox((-395, -84, 100, 22), "Mark Glyphs", callback=self.markCallback, value=self.doMarkGlyphs)
     self.w.copyButton = Button((-115, -40, 100, 20), 'Copy Glyphs', callback=self.copyCallback)
     self.w.line = HorizontalLine((10, -50, -10, 1))
     self._updateDest()
     ## open the window
     self.w.open()
コード例 #5
0
    def __init__(self):
        self.color = "#FF0000"
        self.w = vanilla.Window((500, 600),
                                "MathShape Exporter",
                                minSize=(300, 200))
        self.w.preview = HTMLView((0, 0, -0, -200))
        self.w.exportButton = vanilla.Button((-150, -30, -10, 20),
                                             "Export",
                                             callback=self.cbExport)
        self.w.previewButton = vanilla.Button((10, -30, -160, 20),
                                              "Preview",
                                              callback=self.cbMakePreview)

        valueWidth = 50
        columnDescriptions = [
            dict(title="Glyphname", key="name", width=100),
            dict(title="Width", key="width"),
            dict(title="Bounds", key="bounds", width=100),
        ]
        self.w.l = vanilla.List((0, -200, -0, -60),
                                self.wrapGlyphs(),
                                columnDescriptions=columnDescriptions)
        self.w.t = vanilla.TextBox((40, -53, -5, 20),
                                   "FontName",
                                   sizeStyle="small")
        self.w.clr = vanilla.ColorWell((10, -55, 20, 20),
                                       callback=self.cbColor,
                                       color=NSColor.redColor())
        self.update()
        self.w.open()
コード例 #6
0
def linearGradient(startPoint=None, endPoint=None, colors=None, locations=None):
	global currentGradient
	global currentFillColor
	if colors is None:
		colors = [NSColor.greenColor(), NSColor.redColor()]
	if locations is None:
		locations = [i / float(len(colors)-1) for i in range(len(colors))]
	currentGradient = ("linear", startPoint, endPoint, colors, locations)
	currentFillColor = None
コード例 #7
0
        def drawRect_(self, rect):
            try:
                NSColor.whiteColor().set()
                NSRectFill(self.bounds())
                NSColor.blackColor().setFill()
                p = NSBezierPath.bezierPath()
                xcursor = 0
                ycursor = 0
                for i, g in enumerate(self.glyphs):
                    layer = g.layers[0]
                    if i > 0:
                        # Do anchor correction here
                        prevlayer = self.glyphs[i - 1].layers[0]
                        entry = prevlayer.anchors["entry"]
                        exit = layer.anchors["exit"]
                        if entry and exit:
                            diffX = entry.position.x - exit.position.x
                            diffY = entry.position.y - exit.position.y
                            xcursor = xcursor + diffX
                            ycursor = ycursor + diffY
                        else:
                            NSColor.redColor().setFill()
                    else:
                        xcursor = xcursor - layer.bounds.origin.x
                    thisPath = NSBezierPath.bezierPath()
                    thisPath.appendBezierPath_(layer.completeBezierPath)
                    t = NSAffineTransform.transform()
                    t.translateXBy_yBy_(xcursor,
                                        -layer.master.descender + ycursor)
                    thisPath.transformUsingAffineTransform_(t)
                    p.appendBezierPath_(thisPath)

                t = NSAffineTransform.transform()
                if xcursor > 0:
                    master = self.glyphs[0].layers[0].master
                    vscale = self.bounds().size.height / (master.ascender -
                                                          master.descender)
                    hscale = self.bounds().size.width / xcursor
                    t.scaleBy_(min(hscale, vscale))
                    p.transformUsingAffineTransform_(t)
                p.fill()
            except Exception as e:
                print("Oops!", sys.exc_info()[0], "occured.")
                traceback.print_exc(file=sys.stdout)
コード例 #8
0
 def check_signature_matcher(self, obj):
     regex       = obj.stringValue()
     feedback    = self.customSignatureMatcherFeedback
     try:
         re.compile(regex)
         feedback.setColor_(NSColor.greenColor())
         feedback.setToolTip_("")
     except re.error, e:
         feedback.setColor_(NSColor.redColor())
         feedback.setToolTip_(str(e))
コード例 #9
0
 def check_signature_matcher(self, obj):
     regex       = obj.stringValue()
     feedback    = self.customSignatureMatcherFeedback
     try:
         re.compile(regex)
         feedback.setColor_(NSColor.greenColor())
         feedback.setToolTip_("")
     except re.error, e:
         feedback.setColor_(NSColor.redColor())
         feedback.setToolTip_(str(e))
コード例 #10
0
ファイル: main3.py プロジェクト: shikil/PyInterpreter
 def applicationDidFinishLaunching_(self, aNotification):
     d = {'StderrColor': NSArchiver.archivedDataWithRootObject_(NSColor.redColor()),
          'StdoutColor': NSArchiver.archivedDataWithRootObject_(NSColor.blueColor()),
          'CodeColor': NSArchiver.archivedDataWithRootObject_(NSColor.blackColor()),
          }
     defaults = NSUserDefaults.standardUserDefaults()
     defaults.registerDefaults_(d)
     self.textView.setFont_(self.font())
     self._stderrColor = NSUnarchiver.unarchiveObjectWithData_(defaults['StderrColor'])
     self._stdoutColor = NSUnarchiver.unarchiveObjectWithData_(defaults['StdoutColor'])
     self._codeColor = NSUnarchiver.unarchiveObjectWithData_(defaults['CodeColor'])
     self._executeWithRedirectedIO_args_kwds_(self._interp, (), {})
コード例 #11
0
def linearGradient(startPoint=None,
                   endPoint=None,
                   colors=None,
                   locations=None):
    global currentGradient
    global currentFillColor
    if colors is None:
        colors = [NSColor.greenColor(), NSColor.redColor()]
    if locations is None:
        locations = [i / float(len(colors) - 1) for i in range(len(colors))]
    currentGradient = ("linear", startPoint, endPoint, colors, locations)
    currentFillColor = None
コード例 #12
0
ファイル: testAll.py プロジェクト: justvanrossum/vanilla
    def __init__(self, drawGrid=False):
        self.w = Window((450, 350), "View Test", minSize=(350, 300))

        self.w.tabs = Tabs((10, 10, 220, 120), ["Small", "Mini"])
        self.w.tabs[0].tabs = Tabs((10, 10, -10, -10), ["One", "Two", "Three"],
                                   sizeStyle="small")
        self.w.tabs[1].tabs = Tabs((10, 10, -10, -10), ["One", "Two", "Three"],
                                   sizeStyle="mini")

        self.w.box = Box((10, 140, 220, 70), "Box")
        self.w.box.box = Box((10, 10, -10, -10))

        self.scrollViewNSView = TestCustomNSView.alloc().initWithFrame_(
            ((0, 0), (500, 500)))
        self.w.scrollView = ScrollView((240, 10, 200, 200),
                                       self.scrollViewNSView,
                                       backgroundColor=NSColor.redColor())

        self.splitViewNSView1 = TestCustomNSView.alloc().initWithFrame_(
            ((0, 0), (0, 0)))
        self.splitViewNSView2 = TestCustomNSView.alloc().initWithFrame_(
            ((0, 0), (0, 0)))
        view1 = ScrollView((0, 0, 0, 50),
                           self.splitViewNSView1,
                           autohidesScrollers=True,
                           backgroundColor=NSColor.redColor())
        view2 = ScrollView((0, 0, 0, -10),
                           self.splitViewNSView2,
                           autohidesScrollers=True,
                           backgroundColor=NSColor.redColor())
        paneDescriptions = [
            dict(view=view1, identifier="view1"),
            dict(view=view2, identifier="view2"),
        ]
        self.w.splitView = SplitView((10, 220, -10, -10), paneDescriptions)

        if drawGrid:
            self.drawGrid()

        self.w.open()
コード例 #13
0
    def foreground(self, layer):
        try:
            self.mouse_position = self.editViewController().graphicView(
            ).getActiveLocation_(Glyphs.currentEvent())
        except:
            # self.logToConsole("foreground: mouse_position: %s" % str(e))
            self.mouse_position = None
            return

        if self.mouse_position is not None:
            # Draw a preview circle at the mouse position
            x, y = self.mouse_position
            rect = NSMakeRect(x - self.pen_size / 2,
                              y - self.pen_size * self.pixel_ratio / 2,
                              self.pen_size, self.pen_size * self.pixel_ratio)
            path = NSBezierPath.bezierPathWithOvalInRect_(rect)
            path.setLineWidth_(1)
            if self.erase:
                NSColor.redColor().set()
            else:
                NSColor.lightGrayColor().set()
            path.stroke()
コード例 #14
0
 def transformedValue_(self, priority):
     if priority > 4:
         return NSColor.redColor()
     elif priority > 3:
         return NSColor.orangeColor()
     elif priority > 2:
         return NSColor.blueColor()
     elif priority > 1:
         return NSColor.greenColor()
     elif priority > 0:
         return NSColor.brownColor()
     else:
         return NSColor.blackColor()
コード例 #15
0
 def transformedValue_(self, priority):
     if priority > 4:
         return NSColor.redColor()
     elif priority > 3:
         return NSColor.orangeColor()
     elif priority > 2:
         return NSColor.blueColor()
     elif priority > 1:
         return NSColor.greenColor()
     elif priority > 0:
         return NSColor.brownColor()
     else:
         return NSColor.blackColor()
コード例 #16
0
ファイル: copy_glyphs.py プロジェクト: roboDocs/copyGlyphs
    def __init__(self):
        self.doMarkGlyphs = 0
        self.doOverwrite = 1
        self.sourceFontList = AllFonts()
        self.destinationFontList = AllFonts()
        self.source_font = self.sourceFontList[0]
        self.destination_fonts = None
        self.glyphs = None
        self.mark = NSColor.redColor()

        sl = []
        for f in self.sourceFontList:
            if f.info.familyName != None:
                fn = f.info.familyName
            else:
                fn = "None"
            if f.info.styleName != None:
                fs = f.info.styleName
            else:
                fs = "None"
            sl.append(fn+" "+fs)

        ## create a window
        self.w = Window((700, 500), "Copy Glyphs", minSize=(700, 500))
        self.w.sourceTitle = TextBox((15, 20, 200, 20), "Source Font:")
        self.w.sourceFont = PopUpButton((15, 42, -410, 20), sl, callback=self.sourceCallback)
        self.w.glyphs = GlyphCollectionView((16, 70, -410, -65), initialMode="list", enableDelete=False, allowDrag=False, selectionCallback=self.glyphCallback)
        self._sortGlyphs(self.source_font)
        self.w.desTitle = TextBox((-400, 20, 200, 20), "Destination Fonts:")
        self.w.destinationFonts = FontList((-400, 42, -15, -115), self.destinationFontList, selectionCallback=self.desCallback)
        self.w.overwrite = CheckBox((-395, -105, 130, 22), "Overwrite glyphs", callback=self.overwriteCallback, value=self.doOverwrite)
        self.w.markGlyphs = CheckBox((-395, -84, 100, 22), "Mark Glyphs", callback=self.markCallback, value=self.doMarkGlyphs)
        self.w.copyButton = Button((-115, -40, 100, 20), 'Copy Glyphs', callback=self.copyCallback)
        self.w.line = HorizontalLine((10, -50, -10, 1))
        self._checkSelection()
        self._updateDest()
        ## open the window
        self.w.open()
コード例 #17
0
    def drawRotationPreview(self, info):
        # draw preview glyph
        outline = self.getRotatedGlyph()
        pen = CocoaPen(None)
        self.w.color.get().set()
        outline.draw(pen)
        pen.path.setLineWidth_(info['scale'] * .5)
        pen.path.stroke()

        # draw crosshair
        ch_pen = CocoaPen(None)
        center_x = self.xValue
        center_y = self.yValue
        strokeColor = NSColor.redColor()
        strokeColor.set()
        ch_pen.moveTo((center_x - 10, center_y))
        ch_pen.lineTo((center_x + 10, center_y))
        ch_pen.endPath()
        ch_pen.moveTo((center_x, center_y - 10))
        ch_pen.lineTo((center_x, center_y + 10))
        ch_pen.endPath()
        ch_pen.path.setLineWidth_(info['scale'])
        ch_pen.path.stroke()
コード例 #18
0
    def __init__(self, drawGrid=False):
        self.w = Window((600, 500), "", minSize=(300, 250))

        grp = Group((0, 0, 0, 0))
        grp.button = Button((10, 10, -10, 20), "Toggle", self.buttonCallback)

        self.view1 = TestSplitSubview((0, 0, 0, 0), NSColor.redColor())
        paneDescriptions2 = [
            dict(view=self.view1, canCollapse=True, size=50, identifier="pane1"),
            dict(view=grp, identifier="pane2"),
            dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.greenColor()), minSize=50, identifier="pane3"),
            dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.yellowColor()), identifier="pane4"),
        ]
        self.nestedSplit = SplitView((0, 0, 0, 0), paneDescriptions2, isVertical=True)
        paneDescriptions1 = [
            dict(view=self.nestedSplit, identifier="pane5"),
            dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.magentaColor()), minSize=100, size=100, canCollapse=True, identifier="pane6"),
        ]
        self.w.splitView = SplitView((10, 10, -10, -10), paneDescriptions1, isVertical=False)

        if drawGrid:
            self.drawGrid()
        self.w.open()
コード例 #19
0
ファイル: testAll.py プロジェクト: justvanrossum/vanilla
    def __init__(self, drawGrid=False):
        self.w = Window((150, 180), "Misc. Test")

        self.w.spinner1 = ProgressSpinner((10, 10, 32, 32),
                                          sizeStyle="regular")
        self.w.spinner2 = ProgressSpinner((50, 10, 16, 16), sizeStyle="small")

        self.w.bar1 = ProgressBar((10, 50, -10, 16))
        self.w.bar2 = ProgressBar((10, 70, -10, 10),
                                  isIndeterminate=True,
                                  sizeStyle="small")

        self.w.progressStartButton = Button((10, 90, -10, 20),
                                            "Start Progress",
                                            callback=self.startProgress)

        self.w.colorWell = ColorWell((10, 130, -10, -10),
                                     callback=self.getCallback,
                                     color=NSColor.redColor())

        if drawGrid:
            self.drawGrid()

        self.w.open()
コード例 #20
0
	def drawRect_(self, rect): ## must be `drawRect_` - nothing else

		bounds = self.bounds()
		scaleFactor = self._scaleFactor
		thisUPM = self._upm * scaleFactor # = self._layer.parent.parent.upm
		rectX, rectY, rectWidth, rectHeight = 0, 0, thisUPM, thisUPM
		self.rect = rect


		# self._layer.drawInFrame_(bounds)  # used in Georgs GlyphView

		try:
			thisGlyph = self._layer.parent
			layerWidth = self._layer.width * scaleFactor
			descender = self._layer.glyphMetrics()[3] * scaleFactor
			
			# ## This order is important! Wont work the other way around.
			# try: # pre Glyphs 2.3
			# 	bezierPathOnly = self._layer.copy().bezierPath()  # Path Only
			# 	bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath() # Path & Components
			# except: # Glyphs 2.3
			# 	bezierPathOnly = self._layer.copy().bezierPath  # Path Only
			# 	bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath  # Path & Components

			## This order is important! Wont work the other way around.
			try: # Glyphs 2.3
				bezierPathOnly = self._layer.copy().bezierPath  # Path Only
				bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath  # Path & Components
			except: # Glyphs 2.4
				bezierPathOnly = self._layer.copy().bezierPath  # Path Only
				bezierPathWithComponents = self._layer.completeBezierPath  # Path & Components


			# Set the scale
			#--------------
			scale = NSAffineTransform.transform()
			scale.translateXBy_yBy_( rectWidth/2 - (layerWidth / 2.0) + self._margin/2, -descender + self._margin/2 )
			scale.scaleBy_( scaleFactor )

			if bezierPathWithComponents:
				bezierPathWithComponents.transformUsingAffineTransform_( scale )
			if bezierPathOnly:
				bezierPathOnly.transformUsingAffineTransform_( scale )

			# Draw components in gray
			#------------------------
			NSColor.darkGrayColor().set() # lightGrayColor
			bezierPathWithComponents.fill()
			
			
			# Draw only path in black
			#------------------------
			if thisGlyph.export:
				NSColor.blackColor().set()
				if bezierPathOnly:
					bezierPathOnly.fill()
			# Draw non-exported glyphs in orange
			#-----------------------------------
			else:
				NSColor.orangeColor().set()
				bezierPathWithComponents.fill()
			
			# AUTO-WIDTH LABEL
			#-----------------
			if self._layer.hasAlignedWidth():
				paragraphStyle = NSMutableParagraphStyle.alloc().init()
				paragraphStyle.setAlignment_(2) ## 0=L, 1=R, 2=C, 3=justified
				attributes = {}
				attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(10)
				attributes[NSForegroundColorAttributeName] = NSColor.lightGrayColor()
				attributes[NSParagraphStyleAttributeName] = paragraphStyle
				String = NSAttributedString.alloc().initWithString_attributes_("Auto-Width", attributes)
				# String.drawAtPoint_((rectWidth, 0))
				NSColor.redColor().set()
				# NSRectFill(((0, 0), (self.rect.size.width, 15)))
				String.drawInRect_(((0, 0), (self.rect.size.width, 15)))
		except:
			pass # print traceback.format_exc()
コード例 #21
0
ファイル: DotView.py プロジェクト: fruitsamples/PyObjC
 def initWithFrame_(self, frame):
     self.center = (50.0, 50.0)
     super(DotView, self).initWithFrame_(frame)
     self.radius = 10.0
     self.color = NSColor.redColor()
     return self
コード例 #22
0
ファイル: colors.py プロジェクト: PageBot/PageBotNano
greenColor = NSColor.greenColor()
lightGreenColor = getRGBA(75, 211, 154)
darkGreenColor = getRGBA(41, 120, 37)
lightestGrayColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
    0.98, 0.98, 0.98, 1)
lightestGreyColor = lightestGrayColor
lightGrayColor = NSColor.lightGrayColor()
lightGreyColor = lightGrayColor
magentaColor = NSColor.magentaColor()
orangeColor = NSColor.orangeColor()
lightOrangeColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
    0.98, 0.81, 0.32, 1)
purpleColor = NSColor.purpleColor()
opaquePurpleColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(
    1, 0, 1, 0.3)
redColor = NSColor.redColor()
opaqueRedColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 0, 0, 0.3)
whiteColor = NSColor.whiteColor()
opaqueWhiteColor = getRGBA(255, 255, 255, 0.5)
yellowColor = NSColor.yellowColor()

# Interface presets.

UIGray = getRGBA(31, 38, 46)
UIOpaqueGray = getRGBA(31, 38, 46, 0.5)
UIOpaqueGrey = UIOpaqueGray
UIGrey = UIGray
UILightGray = getRGBA(100, 121, 146)
UILightGrey = UILightGray
UIBlue = getRGBA(13, 48, 54)
UILightBlue = getRGBA(86, 196, 229)
コード例 #23
0
 def __init__(self):
     self.color = "#FF0000"
     self.w = vanilla.Window((500, 600), "LettError MathShape Exporter", minSize=(300,200))
     self.w.preview = HTMLView((0,0,-0, -200))
     self.w.exportButton = vanilla.Button((-150, -30, -10, 20), "Export", callback=self.cbExport)
     self.w.previewButton = vanilla.Button((10, -30, -160, 20), "Preview", callback=self.cbMakePreview)
     
     valueWidth = 50
     columnDescriptions = [
         dict(title="Glyphname", key="name", width=100),
         dict(title="Width", key="width"),
         dict(title="Bounds", key="bounds", width=100),
     ]
     self.w.l = vanilla.List((0,-200,-0,-60), self.wrapGlyphs(), columnDescriptions=columnDescriptions)
     self.w.t = vanilla.TextBox((40,-53,-5,20), "FontName", sizeStyle="small")
     self.w.clr = vanilla.ColorWell((10,-55, 20, 20), callback=self.cbColor, color=NSColor.redColor())
     self.update()
     self.w.open()
コード例 #24
0
ファイル: DotView.py プロジェクト: fruitsamples/PyObjC
 def initWithFrame_(self, frame):
     self.center = (50.0, 50.0)
     super(DotView, self).initWithFrame_(frame)
     self.radius = 10.0
     self.color = NSColor.redColor()
     return self
コード例 #25
0
ファイル: testAll.py プロジェクト: typesupply/vanilla
    def __init__(self, drawGrid=False):
        self.w = Window((450, 350), "View Test", minSize=(350, 300))

        self.w.tabs = Tabs((10, 10, 220, 120), ["Small", "Mini"])
        self.w.tabs[0].tabs = Tabs((10, 10, -10, -10), ["One", "Two", "Three"], sizeStyle="small")
        self.w.tabs[1].tabs = Tabs((10, 10, -10, -10), ["One", "Two", "Three"], sizeStyle="mini")

        self.w.box = Box((10, 140, 220, 70), "Box")
        self.w.box.box = Box((10, 10, -10, -10))

        self.scrollViewNSView = TestCustomNSView.alloc().initWithFrame_(((0, 0), (500, 500)))
        self.w.scrollView = ScrollView((240, 10, 200, 200), self.scrollViewNSView, backgroundColor=NSColor.redColor())

        self.splitViewNSView1 = TestCustomNSView.alloc().initWithFrame_(((0, 0), (0, 0)))
        self.splitViewNSView2 = TestCustomNSView.alloc().initWithFrame_(((0, 0), (0, 0)))
        view1 = ScrollView((0, 0, 0, 50), self.splitViewNSView1, autohidesScrollers=True, backgroundColor=NSColor.redColor())
        view2 = ScrollView((0, 0, 0, -10), self.splitViewNSView2, autohidesScrollers=True, backgroundColor=NSColor.redColor())
        paneDescriptions = [
            dict(view=view1, identifier="view1"),
            dict(view=view2, identifier="view2"),
        ]
        self.w.splitView = SplitView((10, 220, -10, -10), paneDescriptions)

        if drawGrid:
            self.drawGrid()

        self.w.open()
コード例 #26
0
ファイル: preview.py プロジェクト: davelab6/Kernkraft
	def drawRect_(self, rect): ## needs to be `drawRect_` -- nothing else

		bounds = self.bounds()

		# thisUPM = self._layer.parent.parent.upm
		scaleFactor = self._scaleFactor
		thisUPM = self._upm * scaleFactor
		rectX, rectY, rectWidth, rectHeight = 0, 0, thisUPM, thisUPM
		self.rect = rect

		# self._layer.drawInFrame_(bounds)  # used in Georgs GlyphView


		try:
			layerWidth = self._layer.width * scaleFactor
			descender = self._layer.glyphMetrics()[3] * scaleFactor
			
			## this order is important! Wont work the other way around
			try: # pre Glyphs 2.3
				bezierPathOnly = self._layer.copy().bezierPath()  # Path Only
				bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath() # Path & Components				
			except: # Glyphs 2.3
				bezierPathOnly = self._layer.copy().bezierPath  # Path Only
				bezierPathWithComponents = self._layer.copyDecomposedLayer().bezierPath  # Path & Components			

				

			scale = NSAffineTransform.transform()
			scale.translateXBy_yBy_( rectWidth/2 - (layerWidth / 2.0) + self._margin/2, -descender + self._margin/2 )
			scale.scaleBy_( scaleFactor )

			if bezierPathWithComponents:
				bezierPathWithComponents.transformUsingAffineTransform_( scale )
			if bezierPathOnly:
				bezierPathOnly.transformUsingAffineTransform_( scale )

			## DRAW COMPONENTS IN GRAY
			NSColor.darkGrayColor().set() # lightGrayColor
			bezierPathWithComponents.fill()
			
			## CHANGE COLOR FOR NON-EXPORTED GLYPHS
			thisGlyph = self._layer.parent
			if thisGlyph.export:
				NSColor.blackColor().set()

				## DRAW ONLY PATH IN BLACK
				if bezierPathOnly:
					bezierPathOnly.fill()
			else:
				NSColor.orangeColor().set()
				bezierPathWithComponents.fill()
			
			# print self.bounds()

			## AUTO-WIDTH LABEL
			if self._layer.hasAlignedWidth():
				paragraphStyle = NSMutableParagraphStyle.alloc().init()
				paragraphStyle.setAlignment_(2) ## 0=L, 1=R, 2=C, 3=justified
				attributes = {}
				attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(10)
				attributes[NSForegroundColorAttributeName] = NSColor.lightGrayColor()
				attributes[NSParagraphStyleAttributeName] = paragraphStyle
				String = NSAttributedString.alloc().initWithString_attributes_("Auto-Width", attributes)
				# String.drawAtPoint_((rectWidth, 0))
				NSColor.redColor().set()
				# NSRectFill(((0, 0), (self.rect.size.width, 15)))
				String.drawInRect_(((0, 0), (self.rect.size.width, 15)))
		except:
			# pass
			print traceback.format_exc()
コード例 #27
0
ファイル: testAll.py プロジェクト: typesupply/vanilla
    def __init__(self, drawGrid=False):
        self.w = Window((150, 180), "Misc. Test")

        self.w.spinner1 = ProgressSpinner((10, 10, 32, 32), sizeStyle="regular")
        self.w.spinner2 = ProgressSpinner((50, 10, 16, 16), sizeStyle="small")

        self.w.bar1 = ProgressBar((10, 50, -10, 16))
        self.w.bar2 = ProgressBar((10, 70, -10, 10), isIndeterminate=True, sizeStyle="small")

        self.w.progressStartButton = Button((10, 90, -10, 20), "Start Progress", callback=self.startProgress)

        self.w.colorWell = ColorWell((10, 130, -10, -10), callback=self.getCallback, color=NSColor.redColor())

        if drawGrid:
            self.drawGrid()

        self.w.open()
コード例 #28
0
    def drawTopOrBottom(self, bbox, defaultColor, zones, top, xHeight,
                        italicAngle):
        try:
            bboxOrigin = bbox.origin
            bboxSize = bbox.size
            left = bboxOrigin.x
            right = left + bboxSize.width
            middle = left + bboxSize.width / 2.0
            position = bboxOrigin.y

            surplus = 30.0
            scale = self.getScale()
            numberDistance = 25.0 / scale
            lineDistance = 10.0 / scale

            # adjust values for top/bottom:
            if top:
                position += bboxSize.height
                numberDistance -= 10.0 / scale
            else:
                numberDistance *= -1
                lineDistance *= -1

            # adjust values for italic angle:
            if italicAngle != 0.0:
                offset = (position - xHeight * 0.5) * math.tan(
                    italicAngle * math.pi / 180.0)
                left += offset
                right += offset
                middle += offset

            # draw it red if it is not inside a zone:
            drawColor = NSColor.redColor()
            for thisZone in zones:
                zoneBegin = thisZone[0]
                zoneEnd = zoneBegin + thisZone[1]
                zoneBottom = min((zoneBegin, zoneEnd))
                zoneTop = max((zoneBegin, zoneEnd))
                if position <= zoneTop and position >= zoneBottom:
                    drawColor = defaultColor

            # set line attributes:
            drawColor.set()
            storedLineWidth = NSBezierPath.defaultLineWidth()
            NSBezierPath.setDefaultLineWidth_(1.0 / scale)

            # draw horizontal line on canvas:
            leftPoint = NSPoint(left - surplus, position)
            rightPoint = NSPoint(right + surplus, position)
            NSBezierPath.strokeLineFromPoint_toPoint_(leftPoint, rightPoint)

            # draw vertical line on canvas:
            startPoint = NSPoint(middle, position)
            endPoint = NSPoint(middle, position + lineDistance)
            NSBezierPath.strokeLineFromPoint_toPoint_(startPoint, endPoint)

            # restore default line width:
            NSBezierPath.setDefaultLineWidth_(storedLineWidth)

            # draw number on canvas:
            self.drawTextAtPoint("%.1f" % position,
                                 NSPoint(middle, position + numberDistance),
                                 fontColor=drawColor)
        except Exception as e:
            self.logToConsole("drawBottom: %s" % str(e))
コード例 #29
0
      ui='Slider',
      args=dict(minValue=1,
                maxValue=21,
                value=9,
                tickMarkCount=11,
                stopOnTickMarks=True)),
 dict(name='starCols',
      ui='Slider',
      args=dict(minValue=1,
                maxValue=21,
                value=11,
                tickMarkCount=11,
                stopOnTickMarks=True)),
 dict(name='oddStripeColor',
      ui='ColorWell',
      args=dict(color=NSColor.redColor())),
 dict(name='evenStripeColor',
      ui='ColorWell',
      args=dict(color=NSColor.whiteColor())),
 dict(name='cantonColor',
      ui='ColorWell',
      args=dict(color=NSColor.blueColor())),
 dict(name='starColor',
      ui='ColorWell',
      args=dict(color=NSColor.whiteColor())),
 dict(name='jasperize',
      ui='Slider',
      args=dict(minValue=1,
                maxValue=6,
                value=1,
                tickMarkCount=6,
コード例 #30
0
ファイル: osx_panel.py プロジェクト: xoconusco/verano16
    def __init__(self, ns_color):
        self.ns_color = ns_color


Color.BLACK = Color(NSColor.blackColor())
Color.BLUE = Color(NSColor.blueColor())
Color.BROWN = Color(NSColor.brownColor())
Color.CYAN = Color(NSColor.cyanColor())
Color.DARK_GRAY = Color(NSColor.darkGrayColor())
Color.GRAY = Color(NSColor.grayColor())
Color.GREEN = Color(NSColor.greenColor())
Color.MAGENTA = Color(NSColor.magentaColor())
Color.ORANGE = Color(NSColor.orangeColor())
Color.PURPLE = Color(NSColor.purpleColor())
Color.RED = Color(NSColor.redColor())
Color.WHITE = Color(NSColor.whiteColor())
Color.YELLOW = Color(NSColor.yellowColor())


class Font:
    """ Text font """

    def __init__(self, name, size):
        self.ns_font = NSFont.fontWithName_size_(name, size)


class Sound:
    """ A system sound """

    def __init__(self, path):