Пример #1
0
    def __init__(self, drawGrid=False):
        self.w = Window((350, 20), "Toolbar Test", minSize=(250, 20))

        customView = NSSegmentedControl.alloc().initWithFrame_(
            ((0, 0), (100, 30)))
        cell = customView.cell()
        cell.setTrackingMode_(NSSegmentSwitchTrackingSelectOne)
        cell.setSegmentCount_(2)
        cell.setImage_forSegment_(NSCursor.arrowCursor().image(), 0)
        cell.setImage_forSegment_(NSCursor.crosshairCursor().image(), 1)
        customView.sizeToFit()

        toolbarItems = [
            {
                "itemIdentifier": "Test Item One",
                "label": "Test One",
                "imagePath": iconPath,
                "imageNamed": iconName,
                "callback": self.basicCallback
            },
            {
                "itemIdentifier": "Test Item Two",
                "label": "Test Two",
                "imagePath": iconPath,
                "imageNamed": iconName,
                "callback": self.basicCallback
            },
            {
                "itemIdentifier": "Test Item Three",
                "imagePath": iconPath,
                "imageNamed": iconName,
                "callback": self.basicCallback
            },
            {
                "itemIdentifier": "Test Item Four",
                "label": "Test Four",
                "view": customView,
                "callback": self.basicCallback
            },
            {
                "itemIdentifier": NSToolbarPrintItemIdentifier,
                "visibleByDefault": False
            },
            {
                "itemIdentifier": NSToolbarFlexibleSpaceItemIdentifier
            },
            {
                "itemIdentifier": NSToolbarCustomizeToolbarItemIdentifier
            },
        ]

        self.w.addToolbar("Vanilla Test Toolbar", toolbarItems=toolbarItems)

        self.w.open()
Пример #2
0
    def mouseDown_(self, event):

        printB("mouseDown",  event  ,only=mouse_event_info+general_event_info)

        clickLocation = self.convertPoint_fromView_(event.locationInWindow(),
                                                    None)
        itemHit = self.isPointInItem_(clickLocation)
        if itemHit:
            self.dragging = True
            self.lastDragLocation = clickLocation
            NSCursor.closedHandCursor().push()
Пример #3
0
    def makeCursor(self):
        try:
            Scale = Glyphs.font.currentTab.scale
            if abs(Scale - self.lastScale) < 0.001:
                return
            # x, y = 100, 100
            x, y, circleCursorColor = self.getCursorSize()
            # print("__getCursorSize", x, y, circleCursorColor)
            if x > 0 and y > 0:
                ImageSize = NSMakeSize(math.ceil(x * Scale),
                                       math.ceil(y * Scale))
                # print(math.ceil(x * Scale), math.ceil(y * Scale))
                circleCursorImage = NSImage.alloc().initWithSize_(ImageSize)
                circleCursorImage.lockFocus()
                rect = NSMakeRect(0, 0, x * Scale, y * Scale)
                # circleCursorColor = 0.5, 0.5, 0.5, 0.9
                NSColor.colorWithCalibratedRed_green_blue_alpha_(
                    *circleCursorColor).set()
                NSBezierPath.bezierPathWithOvalInRect_(rect).fill()

                try:
                    fontSize = 18
                    fontAttributes = {
                        #NSFontAttributeName: NSFont.labelFontOfSize_(10.0),
                        NSFontAttributeName:
                        NSFont.systemFontOfSize_weight_(fontSize, 0.0),
                        NSForegroundColorAttributeName:
                        NSColor.blackColor()
                    }
                    displayText = NSAttributedString.alloc(
                    ).initWithString_attributes_(
                        self.getCursorType(circleCursorColor), fontAttributes)
                    textAlignment = 4  # top left: 6, top center: 7, top right: 8, center left: 3, center center: 4, center right: 5, bottom left: 0, bottom center: 1, bottom right: 2
                    #font = layer.parent.parent
                    displayText.drawAtPoint_alignment_(
                        NSMakePoint(0 + x * Scale / 2, 0 + y * Scale / 2),
                        textAlignment)
                except:
                    print(traceback.format_exc())

                circleCursorImage.unlockFocus()
                self.circleCursor = NSCursor.alloc().initWithImage_hotSpot_(
                    circleCursorImage, NSMakePoint(x / 2 * Scale,
                                                   y / 2 * Scale))
                try:
                    if self.editViewController().graphicView().cursor(
                    ) != self.circleCursor:
                        self.editViewController().graphicView().setCursor_(
                            self.circleCursor)
                except:
                    pass
        except Exception as e:
            print(traceback.format_exc())
Пример #4
0
    def __init__(self, drawGrid=False):
        self.w = Window((350, 20), "Toolbar Test", minSize=(250, 20))

        customView = NSSegmentedControl.alloc().initWithFrame_(((0, 0), (100, 30)))
        cell = customView.cell()
        cell.setTrackingMode_(NSSegmentSwitchTrackingSelectOne)
        cell.setSegmentCount_(2)
        cell.setImage_forSegment_(NSCursor.arrowCursor().image(), 0)
        cell.setImage_forSegment_(NSCursor.crosshairCursor().image(), 1)
        customView.sizeToFit()

        toolbarItems = [
            {"itemIdentifier": "Test Item One",
             "label": "Test One",
             "imagePath": iconPath,
             "imageNamed": iconName,
             "callback": self.basicCallback},
            {"itemIdentifier": "Test Item Two",
             "label": "Test Two",
             "imagePath": iconPath,
             "imageNamed": iconName,
             "callback": self.basicCallback},
            {"itemIdentifier": "Test Item Three",
             "imagePath": iconPath,
             "imageNamed": iconName,
             "callback": self.basicCallback},
            {"itemIdentifier": "Test Item Four",
             "label": "Test Four",
             "view": customView,
             "callback": self.basicCallback},
            {"itemIdentifier": NSToolbarPrintItemIdentifier, "visibleByDefault": False},
            {"itemIdentifier": NSToolbarFlexibleSpaceItemIdentifier},
            {"itemIdentifier": NSToolbarCustomizeToolbarItemIdentifier},
        ]

        self.w.addToolbar("Vanilla Test Toolbar", toolbarItems=toolbarItems)

        self.w.open()
Пример #5
0
	def makeCursor(self):
		try:
			Scale = Glyphs.font.currentTab.scale
			if abs(Scale - self.lastScale) < 0.001:
				return
			# x, y = 100, 100
			x, y, circleCursorColor = self.getCursorSize()
			# print "__getCursorSize", x, y, circleCursorColor


			if x > 0 and y > 0:
				ImageSize = NSMakeSize(math.ceil(x * Scale), math.ceil(y * Scale))
				# print math.ceil(x * Scale), math.ceil(y * Scale)
				circleCursorImage = NSImage.alloc().initWithSize_(ImageSize)
				circleCursorImage.lockFocus()
				rect = NSMakeRect(0, 0, x * Scale, y * Scale)
				# circleCursorColor = 0.5, 0.5, 0.5, 0.9
				NSColor.colorWithCalibratedRed_green_blue_alpha_( *circleCursorColor ).set()
				NSBezierPath.bezierPathWithOvalInRect_(rect).fill()

				try:
					fontSize = 18
					fontAttributes = {
						#NSFontAttributeName: NSFont.labelFontOfSize_(10.0),
						NSFontAttributeName: NSFont.systemFontOfSize_weight_(fontSize,0.0),
						NSForegroundColorAttributeName: NSColor.blackColor()
					}
					displayText = NSAttributedString.alloc().initWithString_attributes_( self.getCursorType(circleCursorColor), fontAttributes)
					textAlignment = 4 # top left: 6, top center: 7, top right: 8, center left: 3, center center: 4, center right: 5, bottom left: 0, bottom center: 1, bottom right: 2
					#font = layer.parent.parent
					displayText.drawAtPoint_alignment_(NSMakePoint(0 + x * Scale / 2, 0 + y * Scale / 2 ), textAlignment)
				except:
					print traceback.format_exc()

				circleCursorImage.unlockFocus()
				self.circleCursor = NSCursor.alloc().initWithImage_hotSpot_(circleCursorImage, NSMakePoint(x / 2 * Scale, y / 2 * Scale))
				try:
					if self.editViewController().graphicView().cursor() != self.circleCursor:
						self.editViewController().graphicView().setCursor_(self.circleCursor) 
				except:
					pass
		except Exception as e:
			print traceback.format_exc()
Пример #6
0
def _make_empty_cursor():
    global _empty_cursor
    if not _empty_cursor:
        from AppKit import NSCursor, NSImage, NSBitmapImageRep, NSDeviceRGBColorSpace
        from GUI import Cursor
        import sys
        if sys.version_info >= (3, 0):
            b = bytes([0])
        else:
            b = "\x00"
        d = b * 1024
        ns_bitmap = NSBitmapImageRep.alloc().\
         initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_\
         ((d, d, d, d, d), 16, 16, 8, 4, True, False, NSDeviceRGBColorSpace, 64, 32)
        ns_image = NSImage.alloc().initWithSize_((16, 16))
        ns_image.addRepresentation_(ns_bitmap)
        ns_cursor = NSCursor.alloc().initWithImage_hotSpot_(ns_image, (0, 0))
        _empty_cursor = Cursor._from_ns_cursor(ns_cursor)
        _empty_cursor._data = d
    return _empty_cursor
Пример #7
0
def _make_empty_cursor():
    global _empty_cursor
    if not _empty_cursor:
        from AppKit import NSCursor, NSImage, NSBitmapImageRep, NSDeviceRGBColorSpace
        from GUI import Cursor
        import sys
        if sys.version_info >= (3, 0):
            b = bytes([0])
        else:
            b = "\x00"
        d = b * 1024
        ns_bitmap = NSBitmapImageRep.alloc().\
            initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_\
            ((d, d, d, d, d), 16, 16, 8, 4, True, False, NSDeviceRGBColorSpace, 64, 32)
        ns_image = NSImage.alloc().initWithSize_((16, 16))
        ns_image.addRepresentation_(ns_bitmap)
        ns_cursor = NSCursor.alloc().initWithImage_hotSpot_(ns_image, (0, 0))
        _empty_cursor = Cursor._from_ns_cursor(ns_cursor)
        _empty_cursor._data = d
    return _empty_cursor
Пример #8
0
 def _init_from_image_and_hotspot(self, image, hotspot):
     #print "Cursor._init_from_image_and_hotspot:", image, hotspot ###
     ns_image = image._ns_image.copy()
     ns_image.setFlipped_(False)
     self._ns_cursor = NSCursor.alloc().initWithImage_hotSpot_(
         ns_image, hotspot)
Пример #9
0
 def _init_from_image_and_hotspot(self, image, hotspot):
     #print "Cursor._init_from_image_and_hotspot:", image, hotspot ###
     ns_image = image._ns_image.copy()
     ns_image.setFlipped_(False)
     self._ns_cursor = NSCursor.alloc().initWithImage_hotSpot_(
         ns_image, hotspot)
Пример #10
0
            b = bytes([0])
        else:
            b = "\x00"
        d = b * 1024
        ns_bitmap = NSBitmapImageRep.alloc().\
         initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_\
         ((d, d, d, d, d), 16, 16, 8, 4, True, False, NSDeviceRGBColorSpace, 64, 32)
        ns_image = NSImage.alloc().initWithSize_((16, 16))
        ns_image.addRepresentation_(ns_bitmap)
        ns_cursor = NSCursor.alloc().initWithImage_hotSpot_(ns_image, (0, 0))
        _empty_cursor = Cursor._from_ns_cursor(ns_cursor)
        _empty_cursor._data = d
    return _empty_cursor


arrow = Cursor._from_ns_cursor(NSCursor.arrowCursor())
ibeam = Cursor._from_ns_cursor(NSCursor.IBeamCursor())
crosshair = Cursor._from_ns_cursor(NSCursor.crosshairCursor())
fist = Cursor._from_ns_cursor(NSCursor.closedHandCursor())
hand = Cursor._from_ns_cursor(NSCursor.openHandCursor())
finger = Cursor._from_ns_cursor(NSCursor.pointingHandCursor())
invisible = _make_empty_cursor()

mac_poof = Cursor._from_ns_cursor(NSCursor.disappearingItemCursor())

del NSCursor
del Cursor
del _make_empty_cursor


def empty_cursor():
Пример #11
0
        if sys.version_info >= (3, 0):
            b = bytes([0])
        else:
            b = "\x00"
        d = b * 1024
        ns_bitmap = NSBitmapImageRep.alloc().\
            initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_\
            ((d, d, d, d, d), 16, 16, 8, 4, True, False, NSDeviceRGBColorSpace, 64, 32)
        ns_image = NSImage.alloc().initWithSize_((16, 16))
        ns_image.addRepresentation_(ns_bitmap)
        ns_cursor = NSCursor.alloc().initWithImage_hotSpot_(ns_image, (0, 0))
        _empty_cursor = Cursor._from_ns_cursor(ns_cursor)
        _empty_cursor._data = d
    return _empty_cursor

arrow = Cursor._from_ns_cursor(NSCursor.arrowCursor())
ibeam = Cursor._from_ns_cursor(NSCursor.IBeamCursor())
crosshair = Cursor._from_ns_cursor(NSCursor.crosshairCursor())
fist = Cursor._from_ns_cursor(NSCursor.closedHandCursor())
hand = Cursor._from_ns_cursor(NSCursor.openHandCursor())
finger = Cursor._from_ns_cursor(NSCursor.pointingHandCursor())
invisible = _make_empty_cursor()

mac_poof = Cursor._from_ns_cursor(NSCursor.disappearingItemCursor())

del NSCursor
del Cursor
del _make_empty_cursor

def empty_cursor():
    return invisible