示例#1
0
    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)
示例#2
0
 def calibrated_color(self, red, green, blue, alpha=1):
     return NSColor.colorWithCalibratedRed_green_blue_alpha_(
         red / 255, green / 255, blue / 255, alpha)