Пример #1
0
 def mouseDown_(self, event):
     if self.cropRectangle:
         p = self.convertPoint_fromView_(event.locationInWindow(), None)
         if p.x > NSMinX(self.cropRectangle) and p.x < NSMaxX(self.cropRectangle) and\
            p.y > NSMinY(self.cropRectangle) and p.y < NSMaxY(self.cropRectangle):
             self.dragPos = p
             self.initialPos = self.cropRectangle.origin
    def draggedItem_event_(self, sender, event):
        p = sender.convertPoint_fromView_(event.locationInWindow(), None)
        dx = self.dragPos.x - p.x
        dy = self.dragPos.y - p.y

        frame = sender.frame()

        if abs(dy) > 25 or self.dragWindow:
            if not self.dragWindow:
                self.dragWindow = self.createDragWindowForTab_(sender)
                self.dragWindow.makeKeyAndOrderFront_(None)
                self.draggedOut = True
                sender.setDraggedOut_(True)
            pos = NSEvent.mouseLocation()
            pos.x -= self.dragPos.x
            pos.y -= self.dragPos.y
            self.dragWindow.setFrameOrigin_(pos)

            if abs(dy) < 25 and p.x > NSMinX(frame) and p.x < NSMaxX(frame):
                self.dragWindow.close()
                self.dragWindow = None
                self.draggedOut = False
                sender.setDraggedOut_(False)
            else:
                return

        frame.origin.x -= dx
        sender.setFrame_(frame)

        self.reorderByPosition_(sender)
Пример #3
0
 def drawDividerInRect_(self, rect):
     NSSplitView.drawDividerInRect_(self, rect)
     if self.text:
         point = NSMakePoint(
             NSMaxX(rect) -
             self.text.sizeWithAttributes_(self.attributes).width - 10,
             rect.origin.y)
         self.text.drawAtPoint_withAttributes_(point, self.attributes)
def getMargins(layer, y):
	startPoint = NSMakePoint(NSMinX(layer.bounds) - 1, y)
	endPoint = NSMakePoint(NSMaxX(layer.bounds) + 1, y)

	result = layer.calculateIntersectionsStartPoint_endPoint_(startPoint, endPoint)
	count = len(result)
	if (count <= 2):
		return (None, None)

	left = 1
	right = count - 2
	return (result[left].pointValue().x, result[right].pointValue().x)
def totalMarginList(layer,minY,maxY,angle,minYref,maxYref):
# totalMarginList(layer,minY,maxY,angle,minYref,maxYref)
	#the list of margins
	y = minY
	listL = []
	listR = []

	#calculate default depth, otherwise measurement is None
	#calculate paralelogram extremes
	origin=NSMinX(layer.bounds)
	endpointx=NSMaxX(layer.bounds)
	endpointy=NSMaxY(layer.bounds)

	#calculate paralelogram top left
	xpos=triangle(angle,endpointy)+origin
	#paralelogram top side width
	slantWidth=(endpointx-xpos)
	#default depth
	dfltDepth=slantWidth

	#result will be false if all the measured margins are emtpy (no outlines in reference zone)
	result=False

	while y <= maxY:
		lpos, rpos = getMargins(layer, y)

		#get the default margin measure at a given y position
		slantPosL=origin+triangle(angle,y)+dfltDepth
		slantPosR=origin+triangle(angle,y)

		if lpos is not None:
			listL.append(NSMakePoint(lpos, y))
			if minYref<=y<=maxYref:
				result=True
		else:
			listL.append(NSMakePoint(slantPosL, y))

		if rpos is not None:
			listR.append(NSMakePoint(rpos, y))
			if minYref<=y<=maxYref:
				result=True
		else:
			listR.append(NSMakePoint(slantPosR, y))

		y += paramFreq

	#if no measurements are taken, returns false and will abort in main function
	if result:
		return listL, listR
	else:
		return False,False
Пример #6
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)
    placement = NSMakePoint(x, prop * result[1].y + (1 - prop) * (result[0].y))
    return score, placement


if shouldHaveExit(Layer) and not "exit" in Layer.anchors:
    bestScore = 99999
    bestPoint = None
    for potX in range(int(NSMinX(Layer.bounds)), 100):
        score, placement = doTrial("exit", potX)
        if score:
            print("Score for %i is %f" % (potX, score))
            if score < bestScore:
                bestScore = score
                bestPoint = placement
    Layer.anchors['exit'] = GSAnchor("exit")
    Layer.anchors["exit"].position = bestPoint

if shouldHaveEntry(Layer) and not "entry" in Layer.anchors:
    bestScore = 99999
    bestPoint = None
    for potX in range(int(NSMaxX(Layer.bounds) + 100),
                      int(NSMaxX(Layer.bounds)) - 100, -1):
        score, placement = doTrial("entry", potX)
        if score:
            print("Score for %i is %f" % (potX, score))
            if score < bestScore:
                bestScore = score
                bestPoint = placement
    Layer.anchors['entry'] = GSAnchor("entry")
    Layer.anchors["entry"].position = bestPoint
Пример #8
0
def __GSElement__get_box__(self):
    rect = self.bounds
    return (NSMinX(rect), NSMinY(rect), NSMaxX(rect), NSMaxY(rect))
Пример #9
0
 def _get_box(self):
     bounds = self._layer.bounds
     bounds = (int(round(NSMinX(bounds))), int(round(NSMinY(bounds))),
               int(round(NSMaxX(bounds))), int(round(NSMaxY(bounds))))
     return bounds