示例#1
0
    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)
示例#2
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)