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()
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()
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()
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()
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
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()
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()
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)
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
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
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)
def init(self): self = super(ApplicationDelegate, self).init() self.colors = [NSColor.blackColor(), NSColor.redColor(), NSColor.greenColor()] return self
def transformedValue_(self, aDate): if aDate is None: return None if aDate.timeIntervalSinceNow() < 0: return NSColor.redColor() return NSColor.blackColor()