def classBundle(cls): framework = NSBundle.bundleForClass_(cls).bundlePath() if framework.startswith(SYSFRAMEWORKS_DIR): framework = framework[len(SYSFRAMEWORKS_DIR):] if framework.endswith('.framework'): framework = framework[:-len('.framework')] return framework
def init(self): """ Do all initializing here. """ try: # Settings, default values self.name = 'My File Format' self.icon = 'ExportIcon' self.toolbarPosition = 100 if hasattr(self, 'settings'): self.settings() # Dialog stuff # Initiate empty self.dialog here in case of Vanilla dialog, # where .dialog is not defined at the class’s root. if not hasattr(self, 'dialog'): self.dialog = None thisBundle = NSBundle.bundleForClass_(NSClassFromString(self.className())) self.toolbarIcon = NSImage.alloc().initWithContentsOfFile_(thisBundle.pathForImageResource_(self.icon)) self.toolbarIcon.setName_(self.icon) if hasattr(self, 'start'): self.start() except: self.logError(traceback.format_exc()) return self
def _frameworkForClass(className): """Return the name of the framework containing the class.""" try: cls = objc.lookUpClass(className) except objc.error: return "" path = NSBundle.bundleForClass_(cls).bundlePath() if path == "/System/Library/Frameworks/Foundation.framework": return "Foundation" elif path == "/System/Library/Frameworks/AppKit.framework": return "AppKit" else: return ""
def notdefLayer( self ): try: from Foundation import NSBundle, NSClassFromString, NSDictionary bundle = NSBundle.bundleForClass_(NSClassFromString("GSExportInstanceOperation")) if bundle: path = bundle.pathForResource_ofType_("notDef","plist") layerDict = NSDictionary.dictionaryWithContentsOfFile_(path) layer = GSLayer.alloc().initWithDict_format_(layerDict,1) return layer return None except Exception as e: import traceback print(traceback.format_exc()) self.logToConsole( "notdefLayer: %s" % str(e) ) return None
def init(self): """ By default, toolbar.pdf will be your tool icon. Use this for any initializations you need. """ try: self = objc.super(SelectTool, self).init() self.name = 'My Select Tool' self.toolbarPosition = 100 self._icon = 'toolbar.pdf' self.keyboardShortcut = None self.generalContextMenus = () # Inspector dialog stuff # Initiate self.inspectorDialogView here in case of Vanilla dialog, # where inspectorDialogView is not defined at the class’s root. if not hasattr(self, 'inspectorDialogView'): self.inspectorDialogView = None if hasattr(self, 'settings'): self.settings() try: if hasattr(self, "__file__"): path = self.__file__() Bundle = NSBundle.bundleWithPath_(path[:path.rfind("Contents/Resources/")]) else: Bundle = NSBundle.bundleForClass_(NSClassFromString(self.className())) if self._icon is not None: self.tool_bar_image = Bundle.imageForResource_(self._icon) self.tool_bar_image.setTemplate_(True) # Makes the icon blend in with the toolbar. except: self.logError(traceback.format_exc()) if hasattr(self, 'start'): self.start() return self except: self.logError(traceback.format_exc()) return objc.nil
def init(self): """ By default, toolbar.pdf will be your tool icon. Use this for any initializations you need. """ try: self = objc.super(SelectTool, self).init() self.name = 'My Select Tool' self.toolbarPosition = 100 self._icon = 'toolbar.pdf' self.keyboardShortcut = None self.generalContextMenus = () # Inspector dialog stuff # Initiate self.inspectorDialogView here in case of Vanilla dialog, # where inspectorDialogView is not defined at the class’s root. if not hasattr(self, 'inspectorDialogView'): self.inspectorDialogView = None if hasattr(self, 'settings'): self.settings() try: if hasattr(self, "__file__"): path = self.__file__() Bundle = NSBundle.bundleWithPath_(path[:path.rfind("Contents/Resources/")]) else: Bundle = NSBundle.bundleForClass_(NSClassFromString(self.className())); if self._icon != None: self.tool_bar_image = Bundle.imageForResource_(self._icon) self.tool_bar_image.setTemplate_(True) # Makes the icon blend in with the toolbar. except: self.logError(traceback.format_exc()) if hasattr(self, 'start'): self.start() return self except: self.logError(traceback.format_exc()) return objc.nil
def init(self): """ Do all initializing here. """ try: # Settings, default values self.name = 'My File Format' self.icon = 'ExportIcon' self.toolbarPosition = 100 if hasattr(self, 'settings'): self.settings() # Dialog stuff # Initiate empty self.dialog here in case of Vanilla dialog, # where .dialog is not defined at the class’s root. if not hasattr(self, 'dialog'): self.dialog = None if hasattr(self, "__file__"): path = self.__file__() thisBundle = NSBundle.bundleWithPath_(path[:path.rfind("Contents/Resources/")]) else: thisBundle = NSBundle.bundleForClass_(NSClassFromString(self.className())) self.toolbarIcon = NSImage.alloc().initWithContentsOfFile_(thisBundle.pathForImageResource_(self.icon)) # Using self.toolbarIconName() instead of self.icon to # make sure registered NSImage name is unique self.toolbarIcon.setName_(self.toolbarIconName()) if hasattr(self, 'start'): self.start() except: self.logError(traceback.format_exc()) return self
def webkit_version(self): return NSBundle.bundleForClass_(WKWebView).infoDictionary().get("CFBundleVersion").strip()
#MenuTitle: Move ogonek anchors to baseline intersection # -*- coding: utf-8 -*- __doc__=""" Moves all ogonek and _ogonek anchors to the rightmost intersection of the outline with the baseline. """ import math from Foundation import NSPoint, NSBundle thisFont = Glyphs.font # frontmost font thisFontMaster = thisFont.selectedFontMaster # active master listOfSelectedLayers = thisFont.selectedLayers # active layers of selected glyphs GLYPHSAPPVERSION = NSBundle.bundleForClass_(NSClassFromString("GSMenu")).infoDictionary().objectForKey_("CFBundleShortVersionString") GLYPHS_IS_OLD = GLYPHSAPPVERSION.startswith("1.") measurementTool = None if GLYPHS_IS_OLD: measurementTool = NSClassFromString("GlyphsToolMeasurement").alloc().init() def angle( firstPoint, secondPoint ): xDiff = firstPoint.x - secondPoint.x yDiff = firstPoint.y - secondPoint.y tangens = yDiff / xDiff angle = math.atan( tangens ) * 180.0 / math.pi return angle def sliceIntersections( thisLayer, startPoint, endPoint ): if measurementTool: return measurementTool.calculateIntersectionsForLayer_startPoint_endPoint_( thisLayer, startPoint, endPoint ) else: return thisLayer.calculateIntersectionsStartPoint_endPoint_( startPoint, endPoint )