コード例 #1
0
    def cropAndAddImage(self, path):
        try:
            image = NSImage.alloc().initWithContentsOfFile_(path)
        except:
            NSRunAlertPanel(NSLocalizedString("Camera Capture Error", "Window title"), NSLocalizedString("%s is not a valid image", "Label") % path, NSLocalizedString("OK", "Button title"), None, None)
            return

        rect = NSZeroRect.copy()
        rect.size = image.size()
        curSize = self.cropWindow.frame().size
        if rect.size.width > curSize.width or rect.size.height > curSize.height:
            self.cropWindowImage.setFrame_(rect)
        self.cropOriginalImage = image.copy()
        self.cropWindowImage.setImage_(image)

        if NSApp.runModalForWindow_(self.cropWindow) == NSOKButton:
            dt = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
            image = self.cropWindowImage.getCropped()

            tiff_data = image.TIFFRepresentation()

            #path = self.storage_folder + "/photo%s.tiff" % dt
            #tiff_data.writeToFile_atomically_(path, False)

            path = self.storage_folder + "/photo%s.png" % dt
            bitmap_data = NSBitmapImageRep.alloc().initWithData_(tiff_data)
            png_data = bitmap_data.representationUsingType_properties_(NSPNGFileType, None)
            data = png_data.bytes().tobytes()
            with open(path, 'w') as f:
                f.write(data)

            self.cropWindow.orderOut_(None)
            self.refreshLibrary()
        else:
            self.cropWindow.orderOut_(None)
コード例 #2
0
    def cropAndAddImage(self, path):
        try:
            image = NSImage.alloc().initWithContentsOfFile_(path)
        except:
            NSRunAlertPanel(
                NSLocalizedString("Camera Capture Error", "Window title"),
                NSLocalizedString("%s is not a valid image", "Label") % path,
                NSLocalizedString("OK", "Button title"), None, None)
            return

        rect = NSZeroRect.copy()
        rect.size = image.size()
        curSize = self.cropWindow.frame().size
        if rect.size.width > curSize.width or rect.size.height > curSize.height:
            self.cropWindowImage.setFrame_(rect)
        self.cropOriginalImage = image.copy()
        self.cropWindowImage.setImage_(image)

        if NSApp.runModalForWindow_(self.cropWindow) == NSOKButton:
            dt = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
            image = self.cropWindowImage.getCropped()

            path = self.storage_folder + "/photo%s.png" % dt
            jpg_data = NSBitmapImageRep.alloc().initWithData_(
                image.
                TIFFRepresentation()).representationUsingType_properties_(
                    NSJPEGFileType, {NSImageCompressionFactor: 0.9})
            data = jpg_data.bytes().tobytes()
            with open(path, 'wb') as f:
                f.write(data)

            self.cropWindow.orderOut_(None)
            self.refreshLibrary()
        else:
            self.cropWindow.orderOut_(None)
コード例 #3
0
ファイル: PhotoPicker.py プロジェクト: uditha-atukorala/blink
    def cropAndAddImage(self, path):
        try:
            image = NSImage.alloc().initWithContentsOfFile_(path)
        except:
            NSRunAlertPanel(NSLocalizedString("Camera Capture Error", "Window title"), NSLocalizedString("%s is not a valid image" % path, "Alert panel label"), NSLocalizedString("OK", "Button title"), None, None)
            return

        rect = NSZeroRect.copy()
        rect.size = image.size()
        curSize = self.cropWindow.frame().size
        if rect.size.width > curSize.width or rect.size.height > curSize.height:
            self.cropWindowImage.setFrame_(rect)
        self.cropOriginalImage = image.copy()
        self.cropWindowImage.setImage_(image)

        if NSApp.runModalForWindow_(self.cropWindow) == NSOKButton:
            path = ApplicationData.get('photos')
            dt = datetime.datetime.now().strftime("%Y%m%d%H%M%S")

            image = self.cropWindowImage.getCropped()
            path = path+"/photo%s.tiff"%dt
            image.TIFFRepresentation().writeToFile_atomically_(path, False)

            self.cropWindow.orderOut_(None)

            self.refreshLibrary()
        else:
            self.cropWindow.orderOut_(None)
コード例 #4
0
 def changeCropScale_(self, sender):
     scale = sender.doubleValue()
     size = self.cropOriginalImage.size()
     size.width = size.width * scale / 100.0
     size.height = size.height * scale / 100.0
     scaled = self.cropOriginalImage.copy()
     scaled.setScalesWhenResized_(True)
     scaled.setSize_(size)
     self.cropWindowImage.setImage_(scaled)
     frame = NSZeroRect.copy()
     frame.size = size
     self.cropWindowImage.setFrame_(frame)
コード例 #5
0
 def changeCropScale_(self, sender):
     scale = sender.doubleValue()
     size = self.cropOriginalImage.size()
     size.width = size.width * scale / 100.0
     size.height = size.height * scale / 100.0
     scaled = self.cropOriginalImage.copy()
     scaled.setScalesWhenResized_(True)
     scaled.setSize_(size)
     self.cropWindowImage.setImage_(scaled)
     frame = NSZeroRect.copy()
     frame.size = size
     self.cropWindowImage.setFrame_(frame)
コード例 #6
0
    def drawRect_(self, rect):
        r = self.bounds()
        r.size.width -= 0.5
        r.size.height += 4
        if self.draggedOut:
            NSColor.colorWithDeviceWhite_alpha_(0.4, 1.0).set()
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(r, 5, 5)
            path.fill()
        else:
            if self == self.switcher.activeItem():
                NSColor.controlColor().set()
            else:
                NSColor.colorWithDeviceWhite_alpha_(0.6, 1.0).set()
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(r, 5, 5)
            path.fill()
            NSColor.colorWithDeviceRed_green_blue_alpha_(0.3, 0.3, 0.3, 1.0).set()
            path.stroke()

        if self.badgeLabel and not self.mouseInside and not self.busyIndicator and not self.composing:
            # draw the number in redbadge indicator
            gradient = NSGradient.alloc().initWithStartingColor_endingColor_(
                          NSColor.colorWithDeviceRed_green_blue_alpha_(0.9, 0.2, 0.2, 1),
                          NSColor.colorWithDeviceRed_green_blue_alpha_(1.0, 0.2, 0.2, 1))
            size = self.badgeLabel.size()
            size.width += 4
            if size.width < 12:
                size.width = 12
            bez = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(NSMakeRect(3, 5, size.width, 12), 6, 6)
            gradient.drawInBezierPath_angle_(bez, 90+45)
            self.badgeLabel.drawInRect_(NSMakeRect(3, 5, size.width, 12))

        if not self.mouseInside and not self.busyIndicator and self.composing:
            rect = NSZeroRect.copy()
            rect.size = self.composeIcon.size()
            self.composeIcon.drawAtPoint_fromRect_operation_fraction_(NSMakePoint(1, 3), rect, NSCompositeSourceOver, 1)

        if not self.busyIndicator and self.screen_sharing_active:
            rect = NSZeroRect.copy()
            rect.size = self.screenIcon.size()
            self.screenIcon.drawAtPoint_fromRect_operation_fraction_(NSMakePoint(17, 3), rect, NSCompositeSourceOver, 1)

        if not self.draggedOut:
            shadow = NSShadow.alloc().init()
            shadow.setShadowOffset_(NSMakeSize(0, -1))
            if self == self.switcher.activeItem():
                shadow.setShadowColor_(NSColor.whiteColor())
            else:
                shadow.setShadowColor_(NSColor.colorWithDeviceWhite_alpha_(0.7, 1.0))
            para = NSParagraphStyle.defaultParagraphStyle().mutableCopy()
            para.setLineBreakMode_(NSLineBreakByTruncatingTail)
            para.setAlignment_(NSCenterTextAlignment)
            attribs = NSDictionary.dictionaryWithObjectsAndKeys_(NSFont.systemFontOfSize_(11), NSFontAttributeName,
                            shadow, NSShadowAttributeName,
                            para, NSParagraphStyleAttributeName)

            rect = self.bounds()
            rect.origin.y -= 3
            rect.origin.x += 20
            rect.origin.x = rect.origin.x + 12 if self.screen_sharing_active else rect.origin.x
            rect.size.width -= 46
            rect.size.width = rect.size.width - 12 if self.screen_sharing_active else rect.size.width
            self.label.drawInRect_withAttributes_(rect, attribs)
コード例 #7
0
    def drawRect_(self, rect):
        r = self.bounds()
        r.size.width -= 0.5
        r.size.height += 4
        if self.draggedOut:
            NSColor.colorWithDeviceWhite_alpha_(0.4, 1.0).set()
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                r, 5, 5)
            path.fill()
        else:
            if self == self.switcher.activeItem():
                NSColor.controlColor().set()
            else:
                NSColor.colorWithDeviceWhite_alpha_(0.6, 1.0).set()
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                r, 5, 5)
            path.fill()
            NSColor.colorWithDeviceRed_green_blue_alpha_(0.3, 0.3, 0.3,
                                                         1.0).set()
            path.stroke()

        if self.badgeLabel and not self.mouseInside and not self.busyIndicator and not self.composing:
            # draw the number in redbadge indicator
            gradient = NSGradient.alloc().initWithStartingColor_endingColor_(
                NSColor.colorWithDeviceRed_green_blue_alpha_(0.9, 0.2, 0.2, 1),
                NSColor.colorWithDeviceRed_green_blue_alpha_(1.0, 0.2, 0.2, 1))
            size = self.badgeLabel.size()
            size.width += 4
            if size.width < 12:
                size.width = 12
            bez = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                NSMakeRect(3, 5, size.width, 12), 6, 6)
            gradient.drawInBezierPath_angle_(bez, 90 + 45)
            self.badgeLabel.drawInRect_(NSMakeRect(3, 5, size.width, 12))

        if not self.mouseInside and not self.busyIndicator and self.composing:
            rect = NSZeroRect.copy()
            rect.size = self.composeIcon.size()
            self.composeIcon.drawAtPoint_fromRect_operation_fraction_(
                NSMakePoint(1, 3), rect, NSCompositeSourceOver, 1)

        if not self.busyIndicator and self.screen_sharing_active:
            rect = NSZeroRect.copy()
            rect.size = self.screenIcon.size()
            self.screenIcon.drawAtPoint_fromRect_operation_fraction_(
                NSMakePoint(17, 3), rect, NSCompositeSourceOver, 1)

        if not self.draggedOut:
            shadow = NSShadow.alloc().init()
            shadow.setShadowOffset_(NSMakeSize(0, -1))
            if self == self.switcher.activeItem():
                shadow.setShadowColor_(NSColor.whiteColor())
            else:
                shadow.setShadowColor_(
                    NSColor.colorWithDeviceWhite_alpha_(0.7, 1.0))
            para = NSParagraphStyle.defaultParagraphStyle().mutableCopy()
            para.setLineBreakMode_(NSLineBreakByTruncatingTail)
            para.setAlignment_(NSCenterTextAlignment)
            attribs = NSDictionary.dictionaryWithObjectsAndKeys_(
                NSFont.systemFontOfSize_(11), NSFontAttributeName, shadow,
                NSShadowAttributeName, para, NSParagraphStyleAttributeName)

            rect = self.bounds()
            rect.origin.y -= 3
            rect.origin.x += 20
            rect.origin.x = rect.origin.x + 12 if self.screen_sharing_active else rect.origin.x
            rect.size.width -= 46
            rect.size.width = rect.size.width - 12 if self.screen_sharing_active else rect.size.width
            self.label.drawInRect_withAttributes_(rect, attribs)