def image_window(self): rect = NSRect() rect.origin = self.screen_window.frame().origin rect.size.width = 470 rect.size.height = 353 view_rect = rect view_rect.origin = CGPointZero image_view = BackgroundImageView.alloc().initWithFrame_(view_rect) image = NSImage.alloc().initWithContentsOfFile_(os.path.join(os.path.dirname(__file__), 'bot.png')) image_view.setImage_(image) content_view = NSView.alloc().initWithFrame_(view_rect) for button in self.buttons: content_view.addSubview_(button) content_view.addSubview_(image_view) image_window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_( rect, 0, 2, False) image_window.setContentView_(content_view) image_window.setOpaque_(False) image_window.setBackgroundColor_(NSColor.clearColor()) image_window.setHasShadow_(True) image_window.setMovableByWindowBackground_(True) image_window.setReleasedWhenClosed_(False) return image_window
def image_window(self): rect = NSRect() rect.origin = self.screen_window.frame().origin rect.size.width = 470 rect.size.height = 353 view_rect = rect view_rect.origin = CGPointZero image_view = BackgroundImageView.alloc().initWithFrame_(view_rect) image = NSImage.alloc().initWithContentsOfFile_( os.path.join(os.path.dirname(__file__), 'bot.png')) image_view.setImage_(image) content_view = NSView.alloc().initWithFrame_(view_rect) for button in self.buttons: content_view.addSubview_(button) content_view.addSubview_(image_view) image_window = NSWindow.alloc( ).initWithContentRect_styleMask_backing_defer_(rect, 0, 2, False) image_window.setContentView_(content_view) image_window.setOpaque_(False) image_window.setBackgroundColor_(NSColor.clearColor()) image_window.setHasShadow_(True) image_window.setMovableByWindowBackground_(True) image_window.setReleasedWhenClosed_(False) return image_window
def overlay(src, overlay, dest): """Create image ``dest`` by putting ``overlay`` on top of ``src``. Args: src (str): Path to source image. overlay (str): Path to overlay image. dest (str): Path to save combined image to. """ src = NSImage.alloc().initWithContentsOfFile_(src) overlay = NSImage.alloc().initWithContentsOfFile_(overlay) img = NSImage.alloc().initWithSize_(src.size()) img.lockFocus() rect = (0, 0), src.size() src.drawInRect_(rect) overlay.drawInRect_(rect) img.unlockFocus() rep = NSBitmapImageRep.imageRepWithData_(img.TIFFRepresentation()) data = rep.representationUsingType_properties_(NSPNGFileType, {}) data.writeToFile_atomically_(dest, False)
def set_icon(self, file_name): try: from Cocoa import NSImage, NSWorkspace path = (sys._MEIPASS + "/icon.icns/icon.icns") if hasattr( sys, "_MEIPASS") else "icon.icns" img = NSImage.alloc().initWithContentsOfFile_(str(path)) NSWorkspace.sharedWorkspace().setIcon_forFile_options_( img, str(file_name), 0) except ModuleNotFoundError: pass #silent fail writing icon
def image_from_buffer(self): buf = buffer(self.pixel_buffer) width, height = self.pixel_buffer.shape planes = (buf, None, None, None, None) brep = NSBitmapImageRep.alloc().initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_( planes, width, height, 8, 1, False, True, NSCalibratedWhiteColorSpace, width, 0 ) img = NSImage.alloc().initWithSize_((width, height)) img.addRepresentation_(brep) return img
def initWithFrame_window_(self, frame, window): self = super(TitlelessHostView, self).initWithFrame_(frame) if self is None: return self.trackingArea = None resources_dir = get_resources_dir() if hasattr(build_number, 'frozen') else u'images/setupwizard/mac' overlay_path = os.path.join(resources_dir, 'traffic-light.tiff') self.customLights = [] self.closeLight = None for b in window.controlButtons: pos = self.convertPoint_fromView_(b.frame().origin, b.superview()) image = NSImage.alloc().initWithContentsOfFile_(overlay_path) imageview = NSImageView.alloc().initWithFrame_(NSMakeRect(pos.x, pos.y - 1, b.frame().size.width, b.frame().size.height)) imageview.setImage_(image) self.addSubview_(imageview) self.customLights.append(imageview) if b != window.closeButton: imageview.setAlphaValue_(0.3) else: self.closeLight = imageview return self