def showWindow_(self, sender): width, height = 400,300 minWidth, minHeight = 100,100 maxWidth, maxHeight = 500,500 # max size of window = size of largest screen: for screen in NSScreen.screens(): screenSize = screen.visibleFrame().size maxWidth = max(int(screenSize.width), maxWidth) maxHeight = max(int(screenSize.height), maxHeight) w = FloatingWindow((width, height), self.name, minSize=(minWidth,minHeight), maxSize=(maxWidth,maxHeight)) w.center() window = w.getNSWindow() window.setTitlebarAppearsTransparent_(1) window.setStandardWindowTitleButtonsAlphaValue_(0.00001) window.setBackgroundColor_(NSColor.textBackgroundColor()) window.setAlphaValue_(0.9) window.setMovableByWindowBackground_(1) w.im = DYDraggingImageView((10,10,-10,-10), horizontalAlignment='center', verticalAlignment='center', scale='proportional') w.im.setImage(imageObject=self.icon) imview = w.im.getNSImageView() imview.setEditable_(True) imview.setFocusRingType_(NSFocusRingTypeNone) w.open() w.select()
def showWindow_(self, sender): width, height = 400, 300 minWidth, minHeight = 100, 100 maxWidth, maxHeight = 500, 500 # max size of window = size of largest screen: for screen in NSScreen.screens(): screenSize = screen.visibleFrame().size maxWidth = max(int(screenSize.width), maxWidth) maxHeight = max(int(screenSize.height), maxHeight) window = NSPanel.new() window.setMinSize_(NSMakeSize(minWidth, minHeight)) window.setStyleMask_(NSTitledWindowMask | NSUtilityWindowMask | NSResizableWindowMask | NSClosableWindowMask) window.setTitlebarAppearsTransparent_(1) window.setStandardWindowTitleButtonsAlphaValue_(0.00001) window.setBackgroundColor_(NSColor.textBackgroundColor()) window.setAlphaValue_(0.9) window.setMovableByWindowBackground_(1) if Glyphs.defaults[ "NSWindow Frame com.dyb.floatingImageFrame"] is not None: window.setFrameUsingName_("com.dyb.floatingImageFrame") else: window.setFrame_display_(NSMakeRect(0, 0, width, height), True) window.center() window.setFrameAutosaveName_("com.dyb.floatingImageFrame") window.setLevel_(NSFloatingWindowLevel) imview = DYDraggingImageView.alloc().initWithFrame_( window.contentView().frame()) imview.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable) imview.setEditable_(True) imview.setFocusRingType_(NSFocusRingTypeNone) imview.setImage_(self.icon) window.contentView().addSubview_(imview) window.makeKeyAndOrderFront_(self)
def drawRect_(self, rect): # self._layer.drawInFrame_(bounds) # used in Georgs GlyphView try: bounds = self.bounds() NSColor.textBackgroundColor().set() NSRectFill(bounds) scaleFactor = self._scaleFactor thisGlyph = self._layer.parent layerWidth = self._layer.width * scaleFactor descender = self._layer.glyphMetrics()[3] * scaleFactor ascender = self._layer.glyphMetrics()[1] * scaleFactor ## This order is important! Wont work the other way around. bezierPathOnly = self._layer.bezierPath # Path Only if bezierPathOnly is not None: bezierPathOnly = bezierPathOnly.copy() bezierPathWithComponents = self._layer.completeBezierPath # Path & Components bezierPathOpenWithComponents = self._layer.completeOpenBezierPath # Path & Components # Set the scale #-------------- scale = NSAffineTransform.transform() scale.translateXBy_yBy_((bounds.size.width - layerWidth) / 2.0, (bounds.size.height - ascender + descender) / 2.0 - descender) scale.scaleBy_(scaleFactor) # Draw only path in black #------------------------ if thisGlyph.export: pathColor = NSColor.textColor() componentColor = NSColor.secondaryLabelColor() else: pathColor = NSColor.orangeColor() componentColor = NSColor.orangeColor() if bezierPathWithComponents: bezierPathWithComponents.transformUsingAffineTransform_(scale) componentColor.set() # Draw components in gray bezierPathWithComponents.fill() if bezierPathOnly: pathColor.set() bezierPathOnly.transformUsingAffineTransform_(scale) bezierPathOnly.fill() if bezierPathOpenWithComponents: pathColor.set() bezierPathOpenWithComponents.transformUsingAffineTransform_(scale) bezierPathOpenWithComponents.stroke() # Draw non-exported glyphs in orange #----------------------------------- else: NSColor.orangeColor().set() bezierPathWithComponents.transformUsingAffineTransform_(scale) bezierPathWithComponents.fill() attributes = {} attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(14) attributes[NSForegroundColorAttributeName] = NSColor.secondaryLabelColor() thisLKG = thisGlyph.leftKerningGroup thisRKG = thisGlyph.rightKerningGroup if thisLKG is not None: String = NSAttributedString.alloc().initWithString_attributes_(thisLKG, attributes) String.drawAtPoint_alignment_((12, 5), 0) if thisRKG is not None: String = NSAttributedString.alloc().initWithString_attributes_(thisRKG, attributes) String.drawAtPoint_alignment_((bounds.size.width - 12, 5), 2) # AUTO-WIDTH LABEL #----------------- if self._layer.hasAlignedWidth(): attributes[NSForegroundColorAttributeName] = NSColor.lightGrayColor() attributes[NSFontAttributeName] = NSFont.systemFontOfSize_(11) String = NSAttributedString.alloc().initWithString_attributes_("Auto-Width", attributes) String.drawAtPoint_alignment_((bounds.size.width / 2.0, 5), 1) except: print(traceback.format_exc())