def _setup_ui_dialogs(self): # This needs to be here otherwise we can't install the dialog if 'STOQ_TEST_MODE' in os.environ: return log.debug('providing graphical notification dialogs') from stoqlib.gui.base.dialogs import DialogSystemNotifier from stoqlib.lib.interfaces import ISystemNotifier from kiwi.component import provide_utility provide_utility(ISystemNotifier, DialogSystemNotifier(), replace=True) import gtk from kiwi.environ import environ from kiwi.ui.pixbufutils import pixbuf_from_string data = environ.get_resource_string( 'stoq', 'pixmaps', 'stoq-stock-app-24x24.png') gtk.window_set_default_icon(pixbuf_from_string(data)) if platform.system() == 'Darwin': from AppKit import NSApplication, NSData, NSImage bytes = environ.get_resource_string( 'stoq', 'pixmaps', 'stoq-stock-app-48x48.png') data = NSData.alloc().initWithBytes_length_(bytes, len(bytes)) icon = NSImage.alloc().initWithData_(data) app = NSApplication.sharedApplication() app.setApplicationIconImage_(icon)
def _setup_ui_dialogs(self): # This needs to be here otherwise we can't install the dialog if 'STOQ_TEST_MODE' in os.environ: return log.debug('providing graphical notification dialogs') from stoqlib.gui.base.dialogs import DialogSystemNotifier from stoqlib.lib.interfaces import ISystemNotifier from kiwi.component import provide_utility provide_utility(ISystemNotifier, DialogSystemNotifier(), replace=True) from gi.repository import Gtk from kiwi.environ import environ from kiwi.ui.pixbufutils import pixbuf_from_string data = environ.get_resource_string('stoq', 'pixmaps', 'stoq-stock-app-24x24.png') Gtk.Window.set_default_icon(pixbuf_from_string(data)) if platform.system() == 'Darwin': from AppKit import NSApplication, NSData, NSImage bytes = environ.get_resource_string('stoq', 'pixmaps', 'stoq-stock-app-48x48.png') data = NSData.alloc().initWithBytes_length_(bytes, len(bytes)) icon = NSImage.alloc().initWithData_(data) app = NSApplication.sharedApplication() app.setApplicationIconImage_(icon)
def _setup_ui_dialogs(self): # This needs to be here otherwise we can't install the dialog if 'STOQ_TEST_MODE' in os.environ: return log.debug('providing graphical notification dialogs') from stoqlib.gui.base.dialogs import DialogSystemNotifier from stoqlib.lib.interfaces import ISystemNotifier from kiwi.component import provide_utility provide_utility(ISystemNotifier, DialogSystemNotifier(), replace=True) from gi.repository import Gtk from kiwi.environ import environ from stoqlib.gui.stockicons import STOQ_LAUNCHER Gtk.Window.set_default_icon_name(STOQ_LAUNCHER) if platform.system() == 'Darwin': from AppKit import NSApplication, NSData, NSImage # FIXME: This should be a 48x48 icon data = environ.get_resource_string('stoq', 'pixmaps', 'hicolor', '24x24', 'actions', 'stoq-launcher.png') data = NSData.alloc().initWithBytes_length_(data, len(data)) icon = NSImage.alloc().initWithData_(data) app = NSApplication.sharedApplication() app.setApplicationIconImage_(icon)
def do_play(self): if self.playing or not self.queue: return self.playing = True sample = self.queue[0] del self.queue[0] self.impl = NSSound.alloc() data = NSData.alloc().initWithBytes_length_(sample, len(sample)) self.impl.initWithData_(data) self.impl.setDelegate_(self) self.impl.play()
def play_sound_darwin(self, wav_file_as_byte_array): from AppKit import NSSound from AppKit import NSObject from AppKit import NSData nssound = NSSound.alloc() data = NSData.alloc().initWithBytes_length_(wav_file_as_byte_array, len(wav_file_as_byte_array)) nssound.initWithData_(data) nssound.setDelegate_(self) if (not nssound): raise IOError('Unable to load sound.') nssound.play()
def save_image_to_clipboard(self, url): pb = NSPasteboard.generalPasteboard() pb.clearContents() if url.startswith('http'): img = Image.open(urllib.request.urlopen(url)) else: img = Image.open(url) img_bytes = io.BytesIO() img.save(img_bytes, format='PNG') imgNsData = NSData.alloc().initWithBytes_length_( img_bytes.getvalue(), img_bytes.tell()) imgNsImage = NSImage.alloc().initWithData_(imgNsData) array = NSArray.arrayWithObject_(imgNsImage) pb.writeObjects_(array) return
def _setup_ui_dialogs(self): # This needs to be here otherwise we can't install the dialog if 'STOQ_TEST_MODE' in os.environ: return log.debug('providing graphical notification dialogs') from stoqlib.gui.base.dialogs import DialogSystemNotifier from stoqlib.lib.interfaces import ISystemNotifier from kiwi.component import provide_utility provide_utility(ISystemNotifier, DialogSystemNotifier(), replace=True) from gi.repository import Gtk from kiwi.environ import environ from stoqlib.gui.stockicons import STOQ_LAUNCHER Gtk.Window.set_default_icon_name(STOQ_LAUNCHER) if platform.system() == 'Darwin': from AppKit import NSApplication, NSData, NSImage # FIXME: This should be a 48x48 icon data = environ.get_resource_string( 'stoq', 'pixmaps', 'hicolor', '24x24', 'actions', 'stoq-launcher.png') data = NSData.alloc().initWithBytes_length_(data, len(data)) icon = NSImage.alloc().initWithData_(data) app = NSApplication.sharedApplication() app.setApplicationIconImage_(icon)
def Data(s): return NSData.alloc().initWithBytes_length_(s, len(s))
if "album" in status: 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 no metadata is found, use filename instead if not subtitle or not message: filename = Path(status["file"]).name subtitle = filename 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",