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()
# 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')
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
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")
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) b_attr = propertyListFromPythonCollection( {
def init(self): self = super(ApplicationDelegate, self).init() self.colors = [NSColor.blackColor(), NSColor.redColor(), NSColor.greenColor()] return self