コード例 #1
0
ファイル: GraphicsView.py プロジェクト: benoit-pierre/pyobjc
    def drawRect_(self, rect):
        myBounds = self.bounds()
        NSDrawLightBezel(myBounds, myBounds) # AppKit Function
        clipRect = NSBezierPath.bezierPathWithRect_(NSInsetRect(myBounds, 2.0, 2.0))
        clipRect.addClip()

        # Draw graphics
        graphicsArray = self.graphics()
        if graphicsArray:
            for graphic in graphicsArray:
                graphicDrawingBounds = graphic.drawingBounds()
                if NSIntersectsRect(rect, graphicDrawingBounds):
                    graphic.drawInView_(self)

        # Draw a red box around items in the current selection.
        # Selection should be handled by the graphic, but this is a
        # shortcut simply for display.

        currentSelectionIndexes = self.selectionIndexes() # ist das wir ein Array im Indezes?
        if currentSelectionIndexes != None:
            path = NSBezierPath.bezierPath()
            index = currentSelectionIndexes.firstIndex()
            while index != NSNotFound:
                graphicDrawingBounds = graphicsArray[index].drawingBounds()
                if NSIntersectsRect(rect, graphicDrawingBounds):
                    path.appendBezierPathWithRect_(graphicDrawingBounds)
                index = currentSelectionIndexes.indexGreaterThanIndex_(index)

            NSColor.redColor().set()
            path.setLineWidth_(1.5)
            path.stroke()
コード例 #2
0
ファイル: GraphicsView.py プロジェクト: rongilson/pyobjc
    def drawRect_(self, rect):
        myBounds = self.bounds()
        NSDrawLightBezel(myBounds, myBounds)  # AppKit Function
        clipRect = NSBezierPath.bezierPathWithRect_(NSInsetRect(myBounds, 2.0, 2.0))
        clipRect.addClip()

        # Draw graphics
        graphicsArray = self.graphics()
        if graphicsArray:
            for graphic in graphicsArray:
                graphicDrawingBounds = graphic.drawingBounds()
                if NSIntersectsRect(rect, graphicDrawingBounds):
                    graphic.drawInView_(self)

        # Draw a red box around items in the current selection.
        # Selection should be handled by the graphic, but this is a
        # shortcut simply for display.

        currentSelectionIndexes = (
            self.selectionIndexes()
        )  # ist das wir ein Array im Indezes?
        if currentSelectionIndexes is not None:
            path = NSBezierPath.bezierPath()
            index = currentSelectionIndexes.firstIndex()
            while index != NSNotFound:
                graphicDrawingBounds = graphicsArray[index].drawingBounds()
                if NSIntersectsRect(rect, graphicDrawingBounds):
                    path.appendBezierPathWithRect_(graphicDrawingBounds)
                index = currentSelectionIndexes.indexGreaterThanIndex_(index)

            NSColor.redColor().set()
            path.setLineWidth_(1.5)
            path.stroke()
コード例 #3
0
ファイル: osx.py プロジェクト: benpawle/Dialect-Bot
    def drawRect_(self, rect):
        fill_rect = self.frame().copy()
        fill_rect.origin = CGPointZero

        NSColor.colorWithWhite_alpha_(0.3, 1.0).set()

        if self.is_down:
            fill_rect.size.height *= 0.8

        NSRectFill(fill_rect)
コード例 #4
0
ファイル: osx.py プロジェクト: DJLectr0/tingbot-python
    def drawRect_(self, rect):
        fill_rect = self.frame().copy()
        fill_rect.origin = CGPointZero

        NSColor.colorWithWhite_alpha_(0.3, 1.0).set()

        if self.is_down:
            fill_rect.size.height *= 0.8

        NSRectFill(fill_rect)
コード例 #5
0
 def initWithFrame_(self, frame):
     self.backgroundColor = NSColor.blackColor()
     self.graphColor = NSColor.whiteColor()
     self.maxRssiColor = self.graphColor.colorWithAlphaComponent_(0.8)
     self._last_ts = None
     self._last_display = None
     self._rssi_values = []
     self._max_rssi = 0
     self._capture = None
     self._retained_samples = self.RETAINED_SAMPLES_START
     self._filtered_value_per_second = self.SAMPLEERATE
     return super(LaptimerView, self).initWithFrame_(frame)
コード例 #6
0
ファイル: osx.py プロジェクト: benpawle/Dialect-Bot
    def image_window(self):
        rect = NSRect()
        rect.origin = self.screen_window.frame().origin
        rect.size.width = 470
        rect.size.height = 353

        view_rect = rect
        view_rect.origin = CGPointZero

        image_view = BackgroundImageView.alloc().initWithFrame_(view_rect)
        image = NSImage.alloc().initWithContentsOfFile_(
            os.path.join(os.path.dirname(__file__), 'bot.png'))
        image_view.setImage_(image)

        content_view = NSView.alloc().initWithFrame_(view_rect)

        for button in self.buttons:
            content_view.addSubview_(button)

        content_view.addSubview_(image_view)

        image_window = NSWindow.alloc(
        ).initWithContentRect_styleMask_backing_defer_(rect, 0, 2, False)

        image_window.setContentView_(content_view)
        image_window.setOpaque_(False)
        image_window.setBackgroundColor_(NSColor.clearColor())
        image_window.setHasShadow_(True)
        image_window.setMovableByWindowBackground_(True)

        image_window.setReleasedWhenClosed_(False)

        return image_window
コード例 #7
0
ファイル: osx.py プロジェクト: DJLectr0/tingbot-python
    def image_window(self):
        rect = NSRect()
        rect.origin = self.screen_window.frame().origin
        rect.size.width = 470
        rect.size.height = 353

        view_rect = rect
        view_rect.origin = CGPointZero

        image_view = BackgroundImageView.alloc().initWithFrame_(view_rect)
        image = NSImage.alloc().initWithContentsOfFile_(os.path.join(os.path.dirname(__file__), 'bot.png'))
        image_view.setImage_(image)

        content_view = NSView.alloc().initWithFrame_(view_rect)

        for button in self.buttons:
            content_view.addSubview_(button)

        content_view.addSubview_(image_view)

        image_window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
            rect,
            0,
            2,
            False)

        image_window.setContentView_(content_view)
        image_window.setOpaque_(False)
        image_window.setBackgroundColor_(NSColor.clearColor())
        image_window.setHasShadow_(True)
        image_window.setMovableByWindowBackground_(True)

        image_window.setReleasedWhenClosed_(False)

        return image_window
コード例 #8
0
    def arrangeObjects_(self, objects):
        "Filtering is not yet connected in IB!"
        # XXX: This doesn't work yet, so disable
        if self.shouldFilter:
            self.shouldFilter = False

        if not self.shouldFilter:
            return super(GraphicsArrayController,
                         self).arrangeObjects_(objects)

        if self.filterColor is None:
            self.filterColor = NSColor.blackColor().colorUsingColorSpaceName_(
                NSCalibratedRGBColorSpace)

        filterHue = self.filterColor.hueComponent()
        filteredObjects = []
        for item in objects:
            hue = item.color.hueComponent()
            if ((fabs(hue - filterHue) < 0.05)
                    or (fabs(hue - filterHue) > 0.95)
                    or (item is self.newCircle)):
                filteredObjects.append(item)
                self.newCircle = None
        return super(GraphicsArrayController,
                     self).arrangeObjects_(filteredObjects)
コード例 #9
0
ファイル: Circle.py プロジェクト: benoit-pierre/pyobjc
    def drawInView_(self, aView):
        # ignore aView here for simplicity...
        (xLoc, yLoc, radius, shadowOffset, shadowAngle) = (self.xLoc, self.yLoc, self.radius, self.shadowOffset, self.shadowAngle)

        circleBounds = NSMakeRect(xLoc-radius, yLoc-radius, radius*2, radius*2)

        # draw shadow if we'll see it
        shadow = NSShadow.alloc().init()
        if shadowOffset > 0.00001:
            shadowXOffset = sin(shadowAngle)*shadowOffset
            shadowYOffset = cos(shadowAngle)*shadowOffset
            shadow.setShadowOffset_(NSMakeSize(shadowXOffset,shadowYOffset))
            shadow.setShadowBlurRadius_(shadowOffset)
            shadow.set()

        # draw circle
        circle = NSBezierPath.bezierPathWithOvalInRect_(circleBounds)
        myColor = self.color
        if myColor is None:
            myColor = NSColor.redColor()
        myColor.set()
        circle.fill()

        shadow.setShadowColor_(None)
        shadow.set()
コード例 #10
0
ファイル: Circle.py プロジェクト: rongilson/pyobjc
    def drawInView_(self, aView):
        # ignore aView here for simplicity...
        (xLoc, yLoc, radius, shadowOffset, shadowAngle) = (
            self.xLoc,
            self.yLoc,
            self.radius,
            self.shadowOffset,
            self.shadowAngle,
        )

        circleBounds = NSMakeRect(xLoc - radius, yLoc - radius, radius * 2,
                                  radius * 2)

        # draw shadow if we'll see it
        shadow = NSShadow.alloc().init()
        if shadowOffset > 0.00001:
            shadowXOffset = sin(shadowAngle) * shadowOffset
            shadowYOffset = cos(shadowAngle) * shadowOffset
            shadow.setShadowOffset_(NSMakeSize(shadowXOffset, shadowYOffset))
            shadow.setShadowBlurRadius_(shadowOffset)
            shadow.set()

        # draw circle
        circle = NSBezierPath.bezierPathWithOvalInRect_(circleBounds)
        myColor = self.color
        if myColor is None:
            myColor = NSColor.redColor()
        myColor.set()
        circle.fill()

        shadow.setShadowColor_(None)
        shadow.set()
コード例 #11
0
 def awakeFromNib(self):
     self.setFont_(NSFont.userFixedPitchFontOfSize_(10))
     self.p_colors = {
         "stderr": NSColor.redColor(),
         "stdout": NSColor.blueColor(),
         "code": NSColor.blackColor(),
     }
     self.setHistoryLength_(50)
     self.setHistoryView_(0)
     self.setInteracting_(False)
     self.setAutoScroll_(True)
     self.setSingleLineInteraction_(False)
     self.p_history = [""]
     self.p_input_callbacks = []
     self.p_input_lines = []
     self.setupTextView()
     self.interpreter.connect()
コード例 #12
0
 def awakeFromNib(self):
     self = super(PyInterpreter, self).init()
     self._font = NSFont.userFixedPitchFontOfSize_(10)
     self._stderrColor = NSColor.redColor()
     self._stdoutColor = NSColor.blueColor()
     self._codeColor = NSColor.blackColor()
     self._historyLength = 50
     self._history = [""]
     self._historyView = 0
     self._characterIndexForInput = 0
     self._stdin = PseudoUTF8Input(self._nestedRunLoopReaderUntilEOLchars_)
     # self._stdin = PseudoUTF8Input(self.readStdin)
     self._stderr = PseudoUTF8Output(self.writeStderr_)
     self._stdout = PseudoUTF8Output(self.writeStdout_)
     self._isInteracting = False
     self._console = AsyncInteractiveConsole()
     self._interp = self._console.asyncinteract(write=self.writeCode_).next
     self._autoscroll = True
     self.applicationDidFinishLaunching_(None)
コード例 #13
0
ファイル: Circle.py プロジェクト: benoit-pierre/pyobjc
    def init(self):
        self = super(Circle, self).init()
        if self is None:
            return None

        self.color = NSColor.redColor()
        self.xLoc = 15.0
        self.yLoc = 15.0
        self.radius = 15.0
        return self
コード例 #14
0
ファイル: Circle.py プロジェクト: rongilson/pyobjc
    def init(self):
        self = super(Circle, self).init()
        if self is None:
            return None

        self.color = NSColor.redColor()
        self.xLoc = 15.0
        self.yLoc = 15.0
        self.radius = 15.0
        return self
コード例 #15
0
 def initWithFrame_(self, frame):
     self.color = NSColor.blackColor()
     self.pixel_buffer = numpy.zeros((256, 256), numpy.uint8)
     self.blob = numpy.zeros((16, 16), numpy.uint8)
     self.blob += 16
     self.t = .0
     self.now = time.time()
     self.xfac = 3.5
     self.yfac = 2.5
     return super(ApplicationView, self).initWithFrame_(frame)
コード例 #16
0
ファイル: PyInterpreter.py プロジェクト: benoit-pierre/pyobjc
 def awakeFromNib(self):
     self = super(PyInterpreter, self).init()
     self._font = NSFont.userFixedPitchFontOfSize_(10)
     self._stderrColor = NSColor.redColor()
     self._stdoutColor = NSColor.blueColor()
     self._codeColor = NSColor.blackColor()
     self._historyLength = 50
     self._history = ['']
     self._historyView = 0
     self._characterIndexForInput = 0
     self._stdin = PseudoUTF8Input(self._nestedRunLoopReaderUntilEOLchars_)
     #self._stdin = PseudoUTF8Input(self.readStdin)
     self._stderr = PseudoUTF8Output(self.writeStderr_)
     self._stdout = PseudoUTF8Output(self.writeStdout_)
     self._isInteracting = False
     self._console = AsyncInteractiveConsole()
     self._interp = partial(next, self._console.asyncinteract(
         write=self.writeCode_,
     ))
     self._autoscroll = True
コード例 #17
0
ファイル: multi-breaks.py プロジェクト: namuan/multi-breaks
    def set_title(self, title):
        self.title = title

        if title is not None:
            # This is hacky, but works
            # https://github.com/jaredks/rumps/issues/30
            fg_color = NSColor.systemOrangeColor()
            bg_color = NSColor.darkGrayColor()

            font = NSFont.menuBarFontOfSize_(0)
            attributes = propertyListFromPythonCollection(
                {
                    NSForegroundColorAttributeName: fg_color,
                    NSBackgroundColorAttributeName: bg_color,
                    NSFontAttributeName: font,
                },
                conversionHelper=lambda x: x,
            )
            string = NSAttributedString.alloc().initWithString_attributes_(
                " " + title, attributes)
            self._nsapp.nsstatusitem.setAttributedTitle_(string)
コード例 #18
0
 def transformedValue_(self, priority):
     if priority is None:
         return NSColor.blackColor()
     elif 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()
コード例 #19
0
    def newObject(self):
        "Randomize attributes of new circles so we get a pretty display"
        self.newCircle = super(GraphicsArrayController, self).newObject()
        radius = 5.0 + 15.0 * random()
        self.newCircle.radius = radius

        height = self.graphicsView.bounds().size.height
        width = self.graphicsView.bounds().size.width

        xOffset = 10.0 + (height - 20.0) * random()
        yOffset = 10.0 + (width - 20.0) * random()

        self.newCircle.xLoc = xOffset
        self.newCircle.yLoc = height - yOffset

        color = NSColor.colorWithCalibratedHue_saturation_brightness_alpha_(
            random(), (0.5 + random() / 2.0), (0.333 + random() / 3.0), 1.0)

        self.newCircle.color = color
        return self.newCircle
コード例 #20
0
    def arrangeObjects_(self, objects):
        "Filtering is not yet connected in IB!"
        # XXX: This doesn't work yet, so disable
        if self.shouldFilter:
            self.shouldFilter = False

        if not self.shouldFilter:
            return super(GraphicsArrayController, self).arrangeObjects_(objects)

        if self.filterColor is None:
            self.filterColor = NSColor.blackColor().colorUsingColorSpaceName_(NSCalibratedRGBColorSpace)

        filterHue = self.filterColor.hueComponent()
        filteredObjects = []
        for item in objects:
            hue = item.color.hueComponent()
            if ((fabs(hue - filterHue) < 0.05) or
                (fabs(hue - filterHue) > 0.95) or
                (item is self.newCircle)):
                filteredObjects.append(item)
                self.newCircle = None
        return super(GraphicsArrayController, self).arrangeObjects_(filteredObjects)
コード例 #21
0
    def newObject(self):
        "Randomize attributes of new circles so we get a pretty display"
        self.newCircle = super(GraphicsArrayController, self).newObject()
        radius = 5.0 + 15.0 * random()
        self.newCircle.radius = radius

        height = self.graphicsView.bounds().size.height
        width  = self.graphicsView.bounds().size.width

        xOffset = 10.0 + (height - 20.0) * random()
        yOffset = 10.0 + (width - 20.0) * random()

        self.newCircle.xLoc = xOffset
        self.newCircle.yLoc = height - yOffset

        color = NSColor.colorWithCalibratedHue_saturation_brightness_alpha_(
            random(),
            (0.5 + random() / 2.0),
            (0.333 + random() / 3.0),
            1.0)

        self.newCircle.color = color
        return self.newCircle
コード例 #22
0
ファイル: radiobar.py プロジェクト: Am0rphous/RadioBar
    def set_title(self, title, color_list=None):
        self.title = title
        if color_list is None:
            color_list = self.default_color_list

        if title is not None:
            if self.truncate and len(title) > 40:
                title = title[:37] + '...'

            # This is hacky, but works
            # https://github.com/jaredks/rumps/issues/30
            color = NSColor.colorWithCalibratedRed_green_blue_alpha_(
                color_list[0] / 255, color_list[1] / 255, color_list[2] / 255,
                color_list[3])
            font = NSFont.menuBarFontOfSize_(0)
            attributes = propertyListFromPythonCollection(
                {
                    NSForegroundColorAttributeName: color,
                    NSFontAttributeName: font
                },
                conversionHelper=lambda x: x)
            string = NSAttributedString.alloc().initWithString_attributes_(
                ' ' + title, attributes)
            self._nsapp.nsstatusitem.setAttributedTitle_(string)
コード例 #23
0
 def init(self):
     self = super(ApplicationDelegate, self).init()
     self.colors = [NSColor.blackColor(), NSColor.redColor(), NSColor.greenColor()]
     return self
コード例 #24
0
ファイル: multi-breaks.py プロジェクト: namuan/multi-breaks
 def calibrated_color(self, red, green, blue, alpha=1):
     return NSColor.colorWithCalibratedRed_green_blue_alpha_(
         red / 255, green / 255, blue / 255, alpha)
コード例 #25
0
# -*- coding: utf-8 -*-
# Copyright: 2019, Diez B. Roggisch, Berlin . All rights reserved.
from objc import IBOutlet, python_method

from Cocoa import (
    NSTableRowView,
    NSColor,
)

from .common import Mode

MODE2COLOR = {
    None:
    NSColor.colorWithRed_green_blue_alpha_(0, 0, 0, 0),
    Mode.SPLASH_SCREEN:
    NSColor.colorWithRed_green_blue_alpha_(76 / 255, 6 / 255, 29 / 255, 1),
    Mode.SCANNER:
    NSColor.colorWithRed_green_blue_alpha_(180 / 255, 194 / 255, 146 / 255, 1),
    Mode.LAPTIMER:
    NSColor.colorWithRed_green_blue_alpha_(115 / 255, 111 / 255, 78 / 255, 1),
    Mode.SETTINGS:
    NSColor.colorWithRed_green_blue_alpha_(59 / 255, 57 / 255, 35 / 255, 1),
    Mode.DISCONNECTED:
    NSColor.colorWithRed_green_blue_alpha_(255 / 255, 57 / 255, 35 / 255, 1),
}


class Connected:
    def __init__(self):
        self._connections = []
コード例 #26
0
        fontSize = panelFont.pointSize()

        defaults = NSUserDefaultsController.sharedUserDefaultsController(
        ).values()
        defaults.setValue_forKey_(panelFont.fontName(), "FontName")
        defaults.setValue_forKey_(fontSize, "FontSize")


# Set up initial values for defaults:
# Create dictionary with keys and values for WordOfTheDay, FontName,
# FontSize, and FavoriteColor.  Mostly straightforward, but:
#
# Store the fontName of the font as the default; the textfield displays
# the font's displayName using a value transformer.
#
# The color must be archived -- you can't store NSColors directly in NSUserDefaults.
dictionary = {}
dictionary["WordOfTheDay"] = "Today"
systemFont = NSFont.systemFontOfSize_(NSFont.systemFontSize())
dictionary["FontName"] = systemFont.fontName()
dictionary["FontSize"] = systemFont.pointSize()
archivedColor = NSArchiver.archivedDataWithRootObject_(NSColor.greenColor())
dictionary["FavoriteColor"] = archivedColor
NSUserDefaultsController.sharedUserDefaultsController().setInitialValues_(
    dictionary)

# Create and register font name value transformer
transformer = FontNameToDisplayNameTransformer.alloc().init()
NSValueTransformer.setValueTransformer_forName_(
    transformer, "FontNameToDisplayNameTransformer")
コード例 #27
0
 def drawRect_(self, rect):
     f = self.frame()
     f.origin.x = f.origin.y = 0.0
     color = NSColor.blackColor()
     color.set()
     NSBezierPath.fillRect_(f)
コード例 #28
0
 def transformedValue_(self, aDate):
     if aDate is None:
         return None
     if aDate.timeIntervalSinceNow() < 0:
         return NSColor.redColor()
     return NSColor.blackColor()
コード例 #29
0
    def drawRect_(self, rect):
        """
        Basic goals here:
        If either the angle or the offset has a "bad selection":
        then draw a gray rectangle, and that's it.
        Note: bad selection is set if there's a multiple selection
        but the "allows multiple selection" binding is NO.

        If there's a multiple selection for either angle or offset:
        then what you draw depends on what's multiple.

        - First, draw a white background to show all's OK.

        - If both are multiple, then draw a special symbol.

        - If offset is multiple, draw a line from the center of the view
        - to the edge at the shared angle.

        - If angle is multiple, draw a circle of radius the shared offset
        - centered in the view.

        If neither is multiple, draw a cross at the center of the view
        and a cross at distance 'offset' from the center at angle 'angle'
        """
        myBounds = self.bounds()
        if self.badSelectionForAngle or self.badSelectionForOffset:
            # "disable" and exit
            NSDrawDarkBezel(myBounds, myBounds)
            return
        # user can do something, so draw white background and
        # clip in anticipation of future drawing
        NSDrawLightBezel(myBounds, myBounds)
        clipRect = NSBezierPath.bezierPathWithRect_(
            NSInsetRect(myBounds, 2.0, 2.0))
        clipRect.addClip()

        if self.multipleSelectionForAngle or self.multipleSelectionForOffset:
            originOffsetX = myBounds.size.width / 2 + 0.5
            originOffsetY = myBounds.size.height / 2 + 0.5
            if self.multipleSelectionForAngle and self.multipleSelectionForOffset:
                # draw a diagonal line and circle to denote
                # multiple selections for angle and offset
                NSBezierPath.strokeLineFromPoint_toPoint_(
                    NSMakePoint(0, 0),
                    NSMakePoint(myBounds.size.width, myBounds.size.height),
                )
                circleBounds = NSMakeRect(originOffsetX - 5, originOffsetY - 5,
                                          10, 10)
                path = NSBezierPath.bezierPathWithOvalInRect_(circleBounds)
                path.stroke()
                return
            if self.multipleSelectionForOffset:
                # draw a line from center to a point outside
                # bounds in the direction specified by angle
                angleRadians = self.angle * (pi / 180.0)
                x = sin(angleRadians) * myBounds.size.width + originOffsetX
                y = cos(angleRadians) * myBounds.size.height + originOffsetX
                NSBezierPath.strokeLineFromPoint_toPoint_(
                    NSMakePoint(originOffsetX, originOffsetY),
                    NSMakePoint(x, y))
                return
            if self.multipleSelectionForAngle:
                # draw a circle with radius the shared offset
                # dont' draw radius < 1.0, else invisible
                drawRadius = self.offset
                if drawRadius < 1.0:
                    drawRadius = 1.0
                offsetBounds = NSMakeRect(
                    originOffsetX - drawRadius,
                    originOffsetY - drawRadius,
                    drawRadius * 2,
                    drawRadius * 2,
                )
                path = NSBezierPath.bezierPathWithOvalInRect_(offsetBounds)
                path.stroke()
                return
            # shouldn't get here
            return
        trans = NSAffineTransform.transform()
        trans.translateXBy_yBy_(myBounds.size.width / 2 + 0.5,
                                myBounds.size.height / 2 + 0.5)
        trans.concat()
        path = NSBezierPath.bezierPath()

        # draw + where shadow extends
        angleRadians = self.angle * (pi / 180.0)
        xOffset = sin(angleRadians) * self.offset
        yOffset = cos(angleRadians) * self.offset

        path.moveToPoint_(NSMakePoint(xOffset, yOffset - 5))
        path.lineToPoint_(NSMakePoint(xOffset, yOffset + 5))
        path.moveToPoint_(NSMakePoint(xOffset - 5, yOffset))
        path.lineToPoint_(NSMakePoint(xOffset + 5, yOffset))

        NSColor.lightGrayColor().set()
        path.setLineWidth_(1.5)
        path.stroke()

        # draw + in center of view
        path = NSBezierPath.bezierPath()

        path.moveToPoint_(NSMakePoint(0, -5))
        path.lineToPoint_(NSMakePoint(0, +5))
        path.moveToPoint_(NSMakePoint(-5, 0))
        path.lineToPoint_(NSMakePoint(+5, 0))

        NSColor.blackColor().set()
        path.setLineWidth_(1.0)
        path.stroke()
コード例 #30
0
 def transformedValue_(self, aDate):
     if aDate is None:
         return None
     if aDate.timeIntervalSinceNow() < 0:
         return NSColor.redColor()
     return NSColor.blackColor()
コード例 #31
0
import rumps
import speedtest as st
from AppKit import NSAttributedString
from PyObjCTools.Conversion import propertyListFromPythonCollection
from Cocoa import (NSFont, NSFontAttributeName, NSColor,
                   NSForegroundColorAttributeName)

font = NSFont.fontWithName_size_("Monaco", 11.0)
red = NSColor.redColor()
yellow = NSColor.yellowColor()
green = NSColor.greenColor()


class SpeedTestApp(object):
    def __init__(self):
        self.config = {
            "app_name": "SpeedTest",
            "start": "Check Speed",
            "interval": 1500
        }
        self.app = rumps.App(self.config["app_name"])
        self.timer = rumps.Timer(self.on_tick, 60)
        self.interval = self.config["interval"]
        self.set_up_menu()
        self.update_button = rumps.MenuItem(title=self.config["start"],
                                            callback=self.check_speed)
        self.app.menu = [self.update_button]

    def set_up_menu(self):
        self.timer.stop()
        self.timer.count = 0
コード例 #32
0
 def initWithFrame_(self, frame):
     self.backgroundColor = NSColor.blackColor()
     self.barColor = NSColor.whiteColor()
     self.channelValues = [0] * self.CHANNELS
     return super(ScanView, self).initWithFrame_(frame)
コード例 #33
0
import launchd
import rumps
import subprocess

from AppKit import NSAttributedString
from PyObjCTools.Conversion import propertyListFromPythonCollection
from Cocoa import (NSFont, NSFontAttributeName, NSColor,
                   NSForegroundColorAttributeName)
from launchd.cmd import launchctl

ICON_PATH = "../assets/[email protected]"
USER_AGENTS = os.path.expanduser('~/Library/LaunchAgents')

FONT = NSFont.fontWithName_size_("Hack Nerd Font", 14.0)
color = {
    "red": NSColor.redColor(),
    "blue": NSColor.blueColor(),
    "green": NSColor.greenColor()
}
r_attr = propertyListFromPythonCollection(
    {
        # NSFontAttributeName: FONT,
        NSForegroundColorAttributeName: color['red']
    },
    conversionHelper=lambda x: x)
g_attr = propertyListFromPythonCollection(
    {
        # NSFontAttributeName: FONT,
        NSForegroundColorAttributeName: color['green']
    },
    conversionHelper=lambda x: x)
コード例 #34
0
ファイル: JoystickView.py プロジェクト: benoit-pierre/pyobjc
    def drawRect_(self, rect):
        """
        Basic goals here:
        If either the angle or the offset has a "bad selection":
        then draw a gray rectangle, and that's it.
        Note: bad selection is set if there's a multiple selection
        but the "allows multiple selection" binding is NO.

        If there's a multiple selection for either angle or offset:
        then what you draw depends on what's multiple.

        - First, draw a white background to show all's OK.

        - If both are multiple, then draw a special symbol.

        - If offset is multiple, draw a line from the center of the view
        - to the edge at the shared angle.

        - If angle is multiple, draw a circle of radius the shared offset
        - centered in the view.

        If neither is multiple, draw a cross at the center of the view
        and a cross at distance 'offset' from the center at angle 'angle'
        """
        myBounds = self.bounds()
        if self.badSelectionForAngle or self.badSelectionForOffset:
            # "disable" and exit
            NSDrawDarkBezel(myBounds,myBounds);
            return;
        # user can do something, so draw white background and
        # clip in anticipation of future drawing
        NSDrawLightBezel(myBounds,myBounds)
        clipRect = NSBezierPath.bezierPathWithRect_(NSInsetRect(myBounds,2.0,2.0))
        clipRect.addClip()

        if self.multipleSelectionForAngle or self.multipleSelectionForOffset:
            originOffsetX = myBounds.size.width/2 + 0.5
            originOffsetY = myBounds.size.height/2 + 0.5
            if self.multipleSelectionForAngle and self.multipleSelectionForOffset:
                # draw a diagonal line and circle to denote
                # multiple selections for angle and offset
                NSBezierPath.strokeLineFromPoint_toPoint_(NSMakePoint(0,0), NSMakePoint(myBounds.size.width,myBounds.size.height))
                circleBounds = NSMakeRect(originOffsetX-5, originOffsetY-5, 10, 10)
                path = NSBezierPath.bezierPathWithOvalInRect_(circleBounds)
                path.stroke()
                return
            if self.multipleSelectionForOffset:
                # draw a line from center to a point outside
                # bounds in the direction specified by angle
                angleRadians = self.angle * (pi/180.0)
                x = sin(angleRadians) * myBounds.size.width + originOffsetX
                y = cos(angleRadians) * myBounds.size.height + originOffsetX
                NSBezierPath.strokeLineFromPoint_toPoint_(NSMakePoint(originOffsetX, originOffsetY),
                    NSMakePoint(x, y))
                return
            if self.multipleSelectionForAngle:
                # draw a circle with radius the shared offset
                # dont' draw radius < 1.0, else invisible
                drawRadius = self.offset
                if drawRadius < 1.0: drawRadius = 1.0
                offsetBounds = NSMakeRect(originOffsetX-drawRadius,
                         originOffsetY-drawRadius,
                         drawRadius*2, drawRadius*2)
                path = NSBezierPath.bezierPathWithOvalInRect_(offsetBounds)
                path.stroke()
                return
            # shouldn't get here
            return
        trans = NSAffineTransform.transform()
        trans.translateXBy_yBy_( myBounds.size.width/2 + 0.5, myBounds.size.height/2 + 0.5)
        trans.concat()
        path = NSBezierPath.bezierPath()

        # draw + where shadow extends
        angleRadians = self.angle * (pi/180.0)
        xOffset = sin(angleRadians) * self.offset
        yOffset = cos(angleRadians) * self.offset

        path.moveToPoint_(NSMakePoint(xOffset,yOffset-5))
        path.lineToPoint_(NSMakePoint(xOffset,yOffset+5))
        path.moveToPoint_(NSMakePoint(xOffset-5,yOffset))
        path.lineToPoint_(NSMakePoint(xOffset+5,yOffset))

        NSColor.lightGrayColor().set()
        path.setLineWidth_(1.5)
        path.stroke()

        # draw + in center of view
        path = NSBezierPath.bezierPath()

        path.moveToPoint_(NSMakePoint(0,-5))
        path.lineToPoint_(NSMakePoint(0,+5))
        path.moveToPoint_(NSMakePoint(-5,0))
        path.lineToPoint_(NSMakePoint(+5,0))

        NSColor.blackColor().set()
        path.setLineWidth_(1.0)
        path.stroke()
コード例 #35
0
        # Get and store details of selected font
        # Note: use fontName, not displayName.  The font name identifies the font to
        # the system, we use a value transformer to show the user the display name
        fontSize = panelFont.pointSize()

        defaults = NSUserDefaultsController.sharedUserDefaultsController().values()
        defaults.setValue_forKey_(panelFont.fontName(), "FontName")
        defaults.setValue_forKey_(fontSize, "FontSize")


# Set up initial values for defaults:
# Create dictionary with keys and values for WordOfTheDay, FontName,
# FontSize, and FavoriteColor.  Mostly straightforward, but:
#
# Store the fontName of the font as the default; the textfield displays
# the font's displayName using a value transformer.
#
# The color must be archived -- you can't store NSColors directly in NSUserDefaults.
dictionary = {}
dictionary['WordOfTheDay'] = 'Today'
systemFont = NSFont.systemFontOfSize_(NSFont.systemFontSize())
dictionary["FontName"] = systemFont.fontName()
dictionary["FontSize"] = systemFont.pointSize()
archivedColor = NSArchiver.archivedDataWithRootObject_(NSColor.greenColor())
dictionary['FavoriteColor'] = archivedColor
NSUserDefaultsController.sharedUserDefaultsController().setInitialValues_(dictionary)

# Create and register font name value transformer
transformer = FontNameToDisplayNameTransformer.alloc().init()
NSValueTransformer.setValueTransformer_forName_(transformer, 'FontNameToDisplayNameTransformer')
コード例 #36
0
 def drawRect_(self, rect):
     f = self.frame()
     f.origin.x = f.origin.y = 0.0
     color = NSColor.blackColor()
     color.set()
     NSBezierPath.fillRect_(f)