Esempio n. 1
0
 def __init__(self, font, size):
     self._max_size = NSMakeSize(sys.float_info.max, sys.float_info.max)
     self._options = 1 << 3 # NSStringDrawingOptions.NSStringDrawingUsesDeiceMetrics
         # https://developer.apple.com/documentation/uikit/nsstringdrawingoptions?language=objc
     if font == "<System>":
         nsfont = NSFont.systemFontOfSize_(size)
     else:
         nsfont = NSFont.fontWithName_size_(font, size)
     self._attributes = NSMutableDictionary.dictionary()
     self._attributes.setObject_forKey_(nsfont, NSFontAttributeName)
     
     self._terminator = '1'
     self._terminator_width = self._measure(self._terminator)
Esempio n. 2
0
def attr_string_fits_in_rect(attr_string, rect):
    height = attr_string.boundingRectWithSize_options_(
        NSMakeSize(rect.size.width, 99999),
        NSStringDrawingUsesLineFragmentOrigin).size.height
    return height <= rect.size.height
Esempio n. 3
0
center = NSUserNotificationCenter.defaultUserNotificationCenter()
notification = NSUserNotification.alloc().init()

notification.setTitle_(title)
notification.setSubtitle_(subtitle)
notification.setInformativeText_(message)

# To-Do: Data allocation currently doesn't work in Catalina
if mac_ver()[0] != "10.15":
    if cover is not None:  # the song has an embedded cover image
        data = NSData.alloc().initWithBytes_length_(cover, len(cover))
        image_rep = NSBitmapImageRep.alloc().initWithData_(data)

        # CGImageGetWidth started returning bogus values in macOS 10.14 ->
        # Use Pillow to extract the image dimensions
        size = NSMakeSize(*Image.open(BytesIO(cover)).size)

        image = NSImage.alloc().initWithSize_(size)
        image.addRepresentation_(image_rep)
        if env.itunes_style_notification:

            notification.setValue_forKey_(image, "_identityImage")
        else:
            notification.setValue_forKey_(
                NSImage.alloc().initByReferencingFile_(str(env.app_icon)),
                "_identityImage",
            )
            notification.setContentImage_(image)
    else:  # song has no cover image, show an icon
        notification.setValue_forKey_(
            NSImage.alloc().initByReferencingFile_(str(env.app_icon)),
Esempio n. 4
0
 def size(self, width, height):
     size = NSMakeSize(float(width), float(height))
     self.window.setContentSize_(size)
Esempio n. 5
0
    message += ' – %s' % status["album"]

if "date" in status and status["date"].isnumeric():
    message += " (%s)" % status["date"]

center = NSUserNotificationCenter.defaultUserNotificationCenter()
notification = NSUserNotification.alloc().init()

notification.setTitle_(title)
notification.setSubtitle_(subtitle)
notification.setInformativeText_(message)

if cover:  # the song has an embedded cover image
    data = NSData.alloc().initWithBytes_length_(cover, len(cover))
    image_rep = NSBitmapImageRep.alloc().initWithData_(data)
    size = NSMakeSize(CGImageGetWidth(image_rep), CGImageGetHeight(image_rep))
    image = NSImage.alloc().initWithSize_(size)
    image.addRepresentation_(image_rep)
    if config.itunes_style_notification:
        notification.setValue_forKey_(image, "_identityImage")
    else:
        notification.setValue_forKey_(
            NSImage.alloc().initByReferencingFile_(config.app_icon),
            "_identityImage")
        notification.setContentImage_(image)
else:  # song has no cover image, show an icon
    notification.setValue_forKey_(
        NSImage.alloc().initByReferencingFile_(config.app_icon),
        "_identityImage")

if config.display_mode == 1: