def _setCallback(self, callback): if callback is not None: self._target = VanillaCallbackWrapper(callback) delegate = self._nsObject.delegate() if delegate is None: self._delegate = delegate = VanillaTabsDelegate.alloc().init() self._nsObject.setDelegate_(delegate) delegate._target = self._target
def _setCallback(self, callback): if callback is not None: self._target = VanillaCallbackWrapper(callback) delegate = self._textView.delegate() if delegate is None: self._textViewDelegate = delegate = self.delegateClass.alloc( ).init() self._textView.setDelegate_(delegate) delegate._target = self._target
def selectFontCallback(self, sender): fm = NSFontManager.sharedFontManager() fm.setSelectedFont_isMultiple_(getFontDefault("PyDEFont", fallbackFont), False) fm.orderFrontFontPanel_(sender) fp = fm.fontPanel_(False) self._fontCallbackWrapper = VanillaCallbackWrapper(self._selectFontCallback) fm.setTarget_(self._fontCallbackWrapper) fm.setAction_("action:")
def _createToolbarItem(self, itemData): itemIdentifier = itemData.get("itemIdentifier") if itemIdentifier is None: raise VanillaError( "toolbar item data must contain a unique itemIdentifier string" ) if itemIdentifier in self._toolbarItems: raise VanillaError("toolbar itemIdentifier is not unique: %r" % itemIdentifier) if itemIdentifier not in self._toolbarAllowedItemIdentifiers: self._toolbarAllowedItemIdentifiers.append(itemIdentifier) if itemData.get("visibleByDefault", True): self._toolbarDefaultItemIdentifiers.append(itemIdentifier) if itemIdentifier.startswith("NS"): # no need to create an actual item for a standard Cocoa toolbar item return label = itemData.get("label") paletteLabel = itemData.get("paletteLabel", label) toolTip = itemData.get("toolTip", label) imagePath = itemData.get("imagePath") imageNamed = itemData.get("imageNamed") imageObject = itemData.get("imageObject") view = itemData.get("view") callback = itemData.get("callback", None) # create the NSImage if needed if imagePath is not None: image = NSImage.alloc().initWithContentsOfFile_(imagePath) elif imageNamed is not None: image = NSImage.imageNamed_(imageNamed) elif imageObject is not None: image = imageObject else: image = None toolbarItem = NSToolbarItem.alloc().initWithItemIdentifier_( itemIdentifier) toolbarItem.setLabel_(label) toolbarItem.setPaletteLabel_(paletteLabel) toolbarItem.setToolTip_(toolTip) if image is not None: toolbarItem.setImage_(image) elif view is not None: toolbarItem.setView_(view) toolbarItem.setMinSize_(view.frame().size) toolbarItem.setMaxSize_(view.frame().size) if callback is not None: target = VanillaCallbackWrapper(callback) toolbarItem.setTarget_(target) toolbarItem.setAction_("action:") self._toolbarCallbackWrappers[itemIdentifier] = target if itemData.get("selectable", False): self._toolbarSelectableItemIdentifiers.append(itemIdentifier) self._toolbarItems[itemIdentifier] = toolbarItem
def __init__(self): # setup a callback nsobject wrapper self.__callbackWrapper = VanillaCallbackWrapper(self._myAction) # get the default notification center N = NSNotificationCenter.defaultCenter() # add observer for `PyDEUserDefaultChanged` (when a font/color changed in the Preferences) N.addObserver_selector_name_object_(self.__callbackWrapper, "action:", "PyDEUserDefaultChanged", None)
def __init__(self, connections): self.connections = connections columns = [{ "title": x, "editable": x != "Left Glyph", "width": 40 } for x in self.connections["colnames"]] columns[0]["width"] = 100 self.w = vanilla.Window((950, 600), "Nastaliq Editor", closable=True) self.w.LeftLabel = vanilla.TextBox((-200, 10, 200, 17), "", alignment="center") self.w.LeftButton = vanilla.Button((-200, 30, 30, 17), "<", callback=self.decrement) self.w.RightLabel = vanilla.TextBox((-170, 30, 140, 17), "", alignment="center") self.w.RightButton = vanilla.Button((-30, 30, 30, 17), ">", callback=self.increment) self.w.myList = vanilla.List( (0, 0, -200, -0), self.connections["rows"], columnDescriptions=columns, editCallback=self.editCallback, menuCallback=self.menuCallback, ) self.w.myList._clickTarget = VanillaCallbackWrapper(self.clickCallback) self.w.myList._tableView.setTarget_(self.w.myList._clickTarget) self.w.myList._tableView.setAction_("action:") self.w.CompileButton = vanilla.Button((-200, -20, 200, 17), "Compile", callback=self.compile) self.glyphView = GlyphView.alloc().init() self.glyphView.glyphs = [] self.glyphView.setFrame_(((0, 0), (400, 400))) self.w.scrollView = vanilla.ScrollView((-200, 50, 200, 400), self.glyphView) self.selectedPair = None self.inAdd = False self.w.open()