Exemple #1
0
    def resizeSubviewsWithOldSize_(self, oldSize):
        frame = self.frame()
        height = NSHeight(frame) - 2 * self.border

        expandCount = 0
        minimumWidth = 2 * self.border
        for view in self.subviews():
            if view in self.expandingViews:
                expandCount += 1
            else:
                minimumWidth += NSWidth(view.frame())
            minimumWidth += self.spacing

        expandedWidth= 0
        if expandCount > 0:
            expandedWidth = int((NSWidth(frame) - minimumWidth) / expandCount)

        x = self.border
        for view in self.subviews():
            rect = view.frame()
            if not view.isKindOfClass_(NSTextField.class__()):
                rect.origin.y = self.border
                rect.size.height = height
            else:
                rect.origin.y = self.border + (height - NSHeight(rect)) / 2
            rect.origin.x = x
            if view in self.expandingViews:
                rect.size.width = expandedWidth

            view.setFrame_(rect)
            x += NSWidth(rect) + self.spacing
Exemple #2
0
    def didAddSubview_(self, subview):
        minimumWidth = self.spacing * (self.subviews().count()-1) + self.border*2
        expandCount = 0
        for view in self.subviews():
            if view in self.expandingViews:
                expandCount += 1
            else:
                minimumWidth += NSWidth(view.frame())

        frame = self.frame()
        if NSWidth(frame) != minimumWidth:
            frame.size.width = minimumWidth
            self.setFrame_(frame)
Exemple #3
0
    def drawRect_(self, rect):

        NSColor.whiteColor().set()
        NSBezierPath.fillRect_(rect)

        if Glyphs.font is None:
            return

        if not Glyphs.font.selectedLayers:
            return

        glyphToRotate = None
        try:
            glyphToRotate = Glyphs.font.selectedLayers[0]
        except:
            print(traceback.format_exc())

        if glyphToRotate is None:
            return

        try:
            previewPath = glyphToRotate.completeBezierPath

            rotationFactor = self.wrapper._rotationFactor
            Width = NSWidth(self.frame())
            Height = NSHeight(self.frame())

            scaleFactor = 0.666666 / (glyphToRotate.parent.parent.upm /
                                      min(Width, Height))

            ## scaling and zeroing the glyph
            #------------------------
            transform = NSAffineTransform.transform()
            transform.scaleBy_(scaleFactor)
            bounds = glyphToRotate.bounds
            transform.translateXBy_yBy_(-NSMidX(bounds), -NSMidY(bounds))
            previewPath.transformUsingAffineTransform_(transform)

            ## rotation
            #------------------------
            transform = NSAffineTransform.transform()
            transform.rotateByDegrees_(rotationFactor)
            previewPath.transformUsingAffineTransform_(transform)

            ## positioning to the middle of the viewport
            #------------------------
            transform = NSAffineTransform.transform()
            transform.translateXBy_yBy_(Width / 2, Height / 2 - 8)
            previewPath.transformUsingAffineTransform_(transform)

            ## fill path
            #------------------------
            NSColor.blackColor().set()
            previewPath.fill()

        except:
            print(traceback.format_exc())
    def rearrange(self):
        if not self.items:
            return

        frame = self.frame()
        x = 5
        h = NSHeight(frame)

        if len(self.items) * MIN_TAB_WIDTH > NSWidth(frame) - 15 - 20:
            # some tabs don't fit, show what we can
            self.fitTabCount = max(
                int(NSWidth(frame) - 15 - 40) / MIN_TAB_WIDTH, 1)
            tab_width = int(NSWidth(frame) - 15 - 40) / self.fitTabCount

            self.leftButton.setFrame_(NSMakeRect(0, 3, 24, 20))
            self.rightButton.setFrame_(
                NSMakeRect(NSWidth(frame) - 31, 3, 24, 20))
            self.leftButton.setHidden_(False)
            self.rightButton.setHidden_(False)

            x += 20
            for item in self.items[self.firstVisible:self.firstVisible +
                                   self.fitTabCount]:
                item.setHidden_(False)
                item.setFrame_(NSMakeRect(x, 2, tab_width, h))
                x += tab_width

            for item in self.items[self.firstVisible + self.fitTabCount:]:
                item.setHidden_(True)

            for item in self.items[:self.firstVisible]:
                item.setHidden_(True)

        else:
            self.leftButton.setHidden_(True)
            self.rightButton.setHidden_(True)

            tab_width = min(TAB_WIDTH, (NSWidth(frame) - 15) / len(self.items))
            for item in self.items:
                w = tab_width
                item.setFrame_(NSMakeRect(x, 2, w, h))
                item.setHidden_(False)
                x += w
Exemple #5
0
    def mouseDragged_(self, event):
        if self.cropRectangle and self.dragPos:
            p = self.convertPoint_fromView_(event.locationInWindow(), None)
            dx = self.dragPos.x - p.x
            dy = self.dragPos.y - p.y

            newRect = NSMakeRect(self.initialPos.x - dx,
                                 self.initialPos.y - dy,
                                 NSWidth(self.cropRectangle),
                                 NSHeight(self.cropRectangle))
            if NSMinX(newRect) < 0:
                newRect.origin.x = 0
            if NSMinY(newRect) < 0:
                newRect.origin.y = 0
            if NSMaxX(newRect) > NSWidth(self.frame()):
                newRect.origin.x = NSWidth(self.frame()) - NSWidth(newRect)
            if NSMaxY(newRect) > NSHeight(self.frame()):
                newRect.origin.y = NSHeight(self.frame()) - NSHeight(newRect)
            self.cropRectangle = newRect
            self.setNeedsDisplay_(True)
Exemple #6
0
    def getCropped(self):
        image = self.image()

        cropped = NSImage.alloc().initWithSize_(self.cropRectangle.size)
        cropped.lockFocus()

        image.drawInRect_fromRect_operation_fraction_(
            NSMakeRect(0, 0, NSWidth(self.cropRectangle),
                       NSHeight(self.cropRectangle)), self.cropRectangle,
            NSCompositeCopy, 1.0)
        cropped.unlockFocus()
        return cropped
    def resizeWithOldSuperviewSize_(self, oldSize):
        sview = self.enclosingScrollView()
        frame = self.frame()

        if sview:
            width = sview.contentSize().width
        else:
            width = NSWidth(frame) - 2 * self.border

        expandCount = 0
        minimumHeight = self.minimumHeight()
        for view in self.subviews():
            if hasattr(view, "expand"):
                expandCount += 1

        expandedHeight = 0
        if expandCount > 0:
            expandedHeight = (NSHeight(frame) - minimumHeight) / expandCount

        y = self.border
        for view in self.subviews():
            rect = view.frame()
            # position NightVolumeOption to the right of Inbound Ringtone view
            if type(view) is NightVolumeOption:
                rect.origin.x = 230
                rect.origin.y = self.border
            else:
                rect.origin.x = self.border
                rect.origin.y = y
                y += NSHeight(rect) + self.spacing

            rect.size.width = width
            if hasattr(view, "expand"):
                rect.size.height = expandedHeight

            view.setFrame_(rect)

        if sview:
            frame.size.width = sview.contentSize().width

        frame.size.height = minimumHeight

        self.setFrame_(frame)
Exemple #8
0
    def insertItemView_before_(self, view, before):

        # check if its already in
        for child in self.subviews():
            if child == view:
                return

        frame = view.frame()
        frame.origin.y = 0
        frame.size.width = NSWidth(self.frame())
        view.setFrame_(frame)
        if before is None:
            self.addSubview_(view)
        else:
            self.addSubview_positioned_relativeTo_(view, NSWindowBelow, before)

        frame = self.frame()
        frame.size.height = self.minimumHeight()
        self.setFrame_(frame)

        self.relayout()
    def makeDragImage(self):
        if self.delegate is None:
            return

        image = NSImage.alloc().initWithSize_(self.frame().size)
        image.lockFocus()

        frame = self.frame()
        frame.origin = NSZeroPoint
        rect = NSInsetRect(frame, 1.5, 1.5)

        if self.conferencing and not self.draggedOut:
            NSColor.selectedControlColor().colorWithAlphaComponent_(0.7).set()
        else:
            NSColor.whiteColor().colorWithAlphaComponent_(0.7).set()
        path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
            rect, 5.0, 5.0)
        path.fill()

        if self.selected:
            path.setLineWidth_(3)
            NSColor.grayColor().set()
        else:
            path.setLineWidth_(1)
            NSColor.grayColor().set()
        path.stroke()

        NSColor.blackColor().set()
        point = NSMakePoint(8, NSMaxY(frame) - 20)
        uri = format_identity_to_string(
            self.delegate.sessionController.remoteIdentity,
            check_contact=False,
            format='compact')
        NSString.stringWithString_(uri).drawAtPoint_withAttributes_(
            point,
            NSDictionary.dictionaryWithObjectsAndKeys_(
                NSFont.boldSystemFontOfSize_(12), NSFontAttributeName))
        point = NSMakePoint(8, 6)
        if self.conferencing:
            NSString.stringWithString_(
                NSLocalizedString(
                    "Drop outside to remove from conference",
                    "Audio status label")).drawAtPoint_withAttributes_(
                        point,
                        NSDictionary.dictionaryWithObjectsAndKeys_(
                            NSFont.systemFontOfSize_(10), NSFontAttributeName))
        else:
            audio_sessions = [
                sess.hasStreamOfType("audio")
                for sess in NSApp.delegate().contactsWindowController.
                sessionControllersManager.sessionControllers
            ]
            if self.delegate.transferEnabled:
                text = NSLocalizedString(
                    "Drop this over a session or contact", "Audio status label"
                ) if len(audio_sessions) > 1 else NSLocalizedString(
                    "Drop this over a contact to transfer",
                    "Audio status label")
            else:
                text = NSLocalizedString(
                    "Drop this over a session to conference",
                    "Audio status label")
            NSString.stringWithString_(text).drawAtPoint_withAttributes_(
                point,
                NSDictionary.dictionaryWithObjectsAndKeys_(
                    NSFont.systemFontOfSize_(10), NSFontAttributeName))

        icon = NSImage.imageNamed_("NSEveryone")
        rect = frame
        s = icon.size()
        p = NSMakePoint(
            NSWidth(rect) - s.width - 8, rect.size.height - s.height - 8)
        r = NSMakeRect(0, 0, s.width, s.height)
        icon.drawAtPoint_fromRect_operation_fraction_(p, r,
                                                      NSCompositeSourceOver,
                                                      0.5)

        image.unlockFocus()
        return image
Exemple #10
0
    def drawRect_(self, rect):
        self.wrapper._backColour.set()
        NSBezierPath.fillRect_(rect)
        sizes = [
            8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 24, 28, 32, 36, 48, 60, 72,
            90, 120
        ]
        lineSpace = 8
        tab = 30
        w = NSWidth(self.frame())
        h = NSHeight(self.frame())
        glyphNames = self.wrapper._glyphsList
        insIndex = self.wrapper._instanceIndex
        if insIndex == 0:
            font = Glyphs.font
            m = font.selectedFontMaster
        else:
            instance = Glyphs.font.instances[insIndex - 1]
            font = self.wrapper.instances.get(instance.name)
            if font is None:
                font = instance.interpolatedFont
                self.wrapper.instances[instance.name] = font
            m = font.masters[0]
        fullPath = NSBezierPath.alloc().init()
        advance = 0
        self.wrapper._foreColour.set()

        try:
            for i, glyphName in enumerate(glyphNames):

                glyph = self.glyphForName(glyphName, font)
                if glyph:
                    layer = glyph.layers[m.id]

                    layerPath = layer.completeBezierPath
                    kernValue = 0
                    # kerning check
                    if i + 1 < len(glyphNames):
                        nextGlyphName = glyphNames[i + 1]
                        nextGlyph = self.glyphForName(nextGlyphName, font)
                        if nextGlyph:
                            nextLayer = nextGlyph.layers[m.id]
                            if nextLayer:
                                kernValue = getKernValue(layer, nextLayer)
                                if kernValue > 10000:
                                    kernValue = 0

                    transform = NSAffineTransform.transform()
                    transform.translateXBy_yBy_(advance, 0)
                    layerPath.transformUsingAffineTransform_(transform)
                    advance += layer.width + kernValue

                    fullPath.appendBezierPath_(layerPath)
        except:
            print(traceback.format_exc())

        if fullPath is None:
            return

        try:
            sSum = 0
            upm = float(font.upm)
            for i, s in enumerate(sizes):
                sSum += s + s / 4
                transform = NSAffineTransform.transform()
                transform.scaleBy_(s / upm)
                transform.translateXBy_yBy_(tab * upm / s,
                                            (h - s - sSum) * upm / s)
                self.drawText(str(s), self.wrapper._foreColour, 10,
                              h - s - sSum - 2)
                fullPath.transformUsingAffineTransform_(transform)
                fullPath.fill()
                transform.invert()
                fullPath.transformUsingAffineTransform_(transform)
        except StandardError:
            print(traceback.format_exc())
    def drawHashMarksAndLabelsInRect_(self, rect):
        bounds = self.bounds()
        view = self.clientView()

        rulerBackgroundColor = self.rulerBackgroundColor()
        if rulerBackgroundColor is not None:
            rulerBackgroundColor.set()
            NSRectFill(bounds)

        if not isinstance(view, NSTextView):
            return

        layoutManager = view.layoutManager()
        container = view.textContainer()
        text = view.string()
        nullRange = NSMakeRange(NSNotFound, 0)
        yinset = view.textContainerInset().height
        visibleRect = self.scrollView().contentView().bounds()
        textAttributes = self.textAttributes()

        lines = self.lineIndices()

        glyphRange = layoutManager.glyphRangeForBoundingRect_inTextContainer_(
            visibleRect, container)
        _range = layoutManager.characterRangeForGlyphRange_actualGlyphRange_(
            glyphRange, None)[0]
        _range.length += 1

        count = len(lines)
        index = 0

        lineNumber = self.lineNumberForCharacterIndex_inText_(
            _range.location, text)

        for line in range(lineNumber, count):
            index = lines[line]
            if NSLocationInRange(index, _range):
                rects, rectCount = layoutManager.rectArrayForCharacterRange_withinSelectedCharacterRange_inTextContainer_rectCount_(
                    NSMakeRange(index, 0), nullRange, container, None)
                if rectCount > 0:
                    ypos = yinset + NSMinY(rects[0]) - NSMinY(visibleRect)
                    labelText = NSString.stringWithString_("%s" % (line + 1))
                    stringSize = labelText.sizeWithAttributes_(textAttributes)

                    x = NSWidth(bounds) - stringSize.width - self.RULER_MARGIN
                    y = ypos + (NSHeight(rects[0]) - stringSize.height) / 2.0
                    w = NSWidth(bounds) - self.RULER_MARGIN * 2.0
                    h = NSHeight(rects[0])

                    labelText.drawInRect_withAttributes_(
                        NSMakeRect(x, y, w, h), textAttributes)

            if index > NSMaxRange(_range):
                break

        path = NSBezierPath.bezierPath()
        path.moveToPoint_(
            (bounds.origin.x + bounds.size.width, bounds.origin.y))
        path.lineToPoint_((bounds.origin.x + bounds.size.width,
                           bounds.origin.y + bounds.size.height))
        NSColor.grayColor().set()
        path.stroke()