def buildUI(self, attributes): if self._attributes == attributes: return self._attributes = attributes if hasattr(self.w, "ui"): del self.w.ui self.w.ui = ui = vanilla.Group((0, 0, -0, -0)) y = 10 labelSize = 100 gutter = 5 for attribute in self._attributes: uiElement = attribute["ui"] name = attribute["name"] args = dict(attribute.get("args", {})) if uiElement != "CheckBox": label = vanilla.TextBox((0, y + 2, labelSize - gutter, 19), "%s:" % name, alignment="right", sizeStyle="small") setattr(ui, "%sLabel" % name, label) else: args["title"] = name if uiElement not in ("ColorWell"): args["sizeStyle"] = "small" else: if "color" not in args: args["color"] = AppKit.NSColor.blackColor() attr = getattr(vanilla, uiElement)((labelSize, y, -10, 19), callback=self.changed, **args) setattr(ui, name, attr) y += 25 self.w.resize(250, y)
def buildPlacard(self): placardW = 65 placardH = 16 self.placard = vanilla.Group((0, 0, placardW, placardH)) self.placard.optionsButton = PlacardPopUpButton((0, 0, placardW, placardH), [], callback=self._placardDisplayOptionsCallback, sizeStyle="mini") self._populatePlacard()
def __init__(self, tool, event, view): self.tool = tool self.drawingChoices = [RECT_MODE, OVAL_MODE, COMPONENT_MODE] self.view = vanilla.Group((0, 0, 0, 0)) self.view.gridText = vanilla.TextBox((10, 12, 100, 22), "Pixel Size:") self.view.gridInput = vanilla.EditText((120, 10, -10, 22), self.tool.size, callback=self.gridInputCallback) self.view.drawingMode = vanilla.RadioGroup((10, 40, -10, 100), self.drawingChoices, isVertical=True, callback=self.drawingModeCallback) if self.tool.drawingMode in self.drawingChoices: self.view.drawingMode.set(self.drawingChoices.index(self.tool.drawingMode)) self.view.componentName = vanilla.EditText((120, 113, -10, 22), self.tool.componentName, callback=self.drawingModeCallback) self.view.componentName.show(self.tool.drawingMode == COMPONENT_MODE) self.view.useGrid = vanilla.CheckBox((11, 145, -10, 22), "Use Grid", value=self.tool.useGrid, callback=self.drawingModeCallback) nsView = self.view.getNSView() nsView.setFrame_(NSMakeRect(0, 0, 195, 175)) menu = NSMenu.alloc().init() settingsItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("doodle.guideView", None, "") settingsItem.setView_(nsView) menu.addItem_(settingsItem) NSMenu.popUpContextMenu_withEvent_forView_(menu, event, view)
def __init__(self, fonts): self.fonts = fonts self.w = vanilla.Window((1200, 600), minSize=(100, 100)) _, _, w_width, w_height = self.w.getPosSize() prev_height = w_height / 3 self.w.allFontsGroup = vanilla.Group((0, 0, -0, prev_height)) self.steps = len(self.fonts) step = w_width / self.steps for f_index, f in enumerate(self.fonts): x = step * f_index control = DrawPair((x, 0, step, -0)) self.kern_list = list(f.kerning.keys()) initial_pair = self.kern_list[0] kern_value = f.kerning.get(initial_pair, 0) repr_pair = get_repr_pair(f, initial_pair) repr_glyphs = [f[g_name] for g_name in repr_pair] control.setGlyphData_kerning(repr_glyphs, kern_value) setattr(self.w.allFontsGroup, 'pair_{}'.format(f_index), control) display_list = [', '.join(pair) for pair in self.kern_list] list_height = w_height - prev_height self.w.myList = vanilla.List( (0, -list_height, -0, -0), display_list, allowsMultipleSelection=False, selectionCallback=self.list_callback, ) self.w.bind('resize', self.resize_callback) self.w.open()
def buildUI(self, attributes, continuous): import vanilla if (self._attributes, self._continuous) == (attributes, continuous): return self._attributes = attributes self._continuous = continuous if hasattr(self.w, "ui"): del self.w.ui self.w.ui = ui = vanilla.Group((0, 0, -0, -0)) y = 10 labelSize = 100 gutter = 5 for attribute in self._attributes: uiElement = attribute["ui"] name = attribute["name"] args = dict(attribute.get("args", {})) height = 19 # adjust the height if a radioGroup is vertical if uiElement == "RadioGroup": if args.get("isVertical", True): height = height * len(args.get("titles", [""])) # create a label for every ui element except a checkbox if uiElement not in ("CheckBox", "Button"): # create the label view label = vanilla.TextBox((0, y + 2, labelSize - gutter, height), "%s:" % name, alignment="right", sizeStyle="small") # set the label view setattr(ui, "%sLabel" % name, label) else: if "title" not in args: args["title"] = name # check the provided args and add required keys if uiElement == "ColorWell": # a color well needs a color to be set # no size style if "color" not in args: args["color"] = AppKit.NSColor.blackColor() elif uiElement == "TextEditor": # different control height # no size style height = attribute.get("height", 75) else: # all other get a size style args["sizeStyle"] = "small" # add the callback if continuous: args["callback"] = self.changed # create the control view attr = getattr(vanilla, uiElement)((labelSize, y, -10, height), **args) # set the control view setattr(ui, name, attr) y += height + 6 if not continuous: # add button when the variable control is set to not continuous ui._continuousUpdateButton = vanilla.Button((labelSize, y, -10, height), "Update", callback=self.changed) y += height + 6 # resize the window according the provided ui elements self.w.resize(250, y)
def buildPlacard(self): placardW = 65 placardH = 16 self.placard = vanilla.Group((0, 0, placardW, placardH)) self.placard.optionsButton = PlacardPopUpButton( (0, 0, placardW, placardH), [], callback=self._placardDisplayOptionsCallback, sizeStyle="mini") self._populatePlacard() self.placard.optionsButton.getNSPopUpButton().menu( ).setAutoenablesItems_(False)
def __init__(self, posSize, text, callback=None): # there must be a callback as it triggers the creation of the delegate if callback is None: callback = self._fallbackCallback super(FeatureTextEditor, self).__init__(posSize, "", callback=callback) self._nsObject.setHasHorizontalScroller_(True) font = NSFont.fontWithName_size_("Monaco", 10) self._textView.setFont_(font) self._textView.setUsesFindPanel_(True) ## line numbers #ruler = DefconAppKitLineNumberView.alloc().init() #ruler.setClientView_(self._textView) #self._nsObject.setVerticalRulerView_(ruler) #self._nsObject.setHasHorizontalRuler_(False) #self._nsObject.setHasVerticalRuler_(True) #self._nsObject.setRulersVisible_(True) #notificationCenter = NSNotificationCenter.defaultCenter() #notificationCenter.addObserver_selector_name_object_( # ruler, "clientViewSelectionChanged:", NSTextViewDidChangeSelectionNotification, self._textView #) # colors self._mainColor = NSColor.blackColor() self._commentColor = NSColor.colorWithCalibratedWhite_alpha_(.6, 1) self._keywordColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( .8, 0, 0, 1) self._tokenColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( .8, .4, 0, 1) self._classNameColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0, .8, 1) self._includeColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( .8, 0, .8, 1) self._stringColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, .6, 0, 1) # build the placard placardW = 65 placardH = 16 self._placardJumps = [] self._placard = vanilla.Group((0, 0, placardW, placardH)) self._placard.featureJumpButton = PlacardPopUpButton( (0, 0, placardW, placardH), [], callback=self._placardFeatureSelectionCallback, sizeStyle="mini") self._nsObject.setPlacard_(self._placard.getNSView()) # registed for syntax coloring notifications self._programmaticallySettingText = False delegate = self._textViewDelegate delegate.vanillaWrapper = weakref.ref(self) notificationCenter = NSNotificationCenter.defaultCenter() notificationCenter.addObserver_selector_name_object_( self._textViewDelegate, "textStorageDidProcessEditing:", NSTextStorageDidProcessEditingNotification, self._textView.textStorage()) # set the text self.set(text)
def __init__(self, posSize, pointSize=100, rightToLeft=False, applyKerning=False, glyphColor=None, backgroundColor=None, alternateHighlightColor=None, autohideScrollers=True, showPointSizePlacard=False): if glyphColor is None: glyphColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0, 0, 1) if backgroundColor is None: backgroundColor = NSColor.whiteColor() if alternateHighlightColor is None: alternateHighlightColor = defaultAlternateHighlightColor self._applyKerning = applyKerning self._glyphLineView = self.glyphLineViewClass.alloc().init() self._glyphLineView.setPointSize_(pointSize) self._glyphLineView.setRightToLeft_(rightToLeft) self._glyphLineView.setGlyphColor_(glyphColor) self._glyphLineView.setBackgroundColor_(backgroundColor) self._glyphLineView.setAlternateHighlightColor_( alternateHighlightColor) self._glyphLineView.vanillaWrapper = weakref.ref(self) # don't autohide if the placard is to be visible. # bad things will happen if this is not the case. if showPointSizePlacard: autohideScrollers = False # setup the scroll view super(GlyphLineView, self).__init__(posSize, self._glyphLineView, autohidesScrollers=autohideScrollers, backgroundColor=backgroundColor) # placard if showPointSizePlacard: self._pointSizes = ["Auto"] + [str(i) for i in pointSizes] placardW = 55 placardH = 16 self._placard = vanilla.Group((0, 0, placardW, placardH)) self._placard.button = PlacardPopUpButton( (0, 0, placardW, placardH), self._pointSizes, callback=self._placardSelection, sizeStyle="mini") self.setPlacard(self._placard) pointSize = str(pointSize) if pointSize in self._pointSizes: index = self._pointSizes.index(pointSize) self._placard.button.set(index)
def __init__(self): self.w = vanilla.Window((400, 400), "Merz Playground", minSize=(200, 200)) self.w.getNSWindow().setFrameUsingName_(self.windowAutoSaveName) # Code # ---- self.codeGroup = vanilla.Group((0, 0, 0, 0)) self.codeEditor = self.codeGroup.codeEditor = CodeEditor( (0, 0, -0, -45)) self.runButton = self.codeGroup.runButton = vanilla.Button( (15, -35, -15, 20), "Run", callback=self.runCode) self.runButton.bind("r", ["command"]) self.outputEditor = OutPutEditor((0, 0, -0, -0), readOnly=True) paneDescriptions = [ dict(view=self.codeGroup, identifier="codeGroup", minSize=50, canCollapse=False), dict(view=self.outputEditor, identifier="outputEditor", size=100, minSize=50, canCollapse=False), ] self.codeSplitView = vanilla.SplitView((0, 0, 0, 0), paneDescriptions, isVertical=False) # Merz # ---- self.merzView = merz.MerzView((0, 0, 0, 0), backgroundColor=(1, 1, 1, 1)) # Splits # ------ paneDescriptions = [ dict(view=self.codeSplitView, identifier="codeSplitView", minSize=50, canCollapse=False), dict(view=self.merzView, identifier="merzView", minSize=50) ] self.w.splitView = vanilla.SplitView((0, 0, 0, 0), paneDescriptions) self.setUpBaseWindowBehavior() self.w.open()
def buildUI(self, attributes): if self._attributes == attributes: return self._attributes = attributes if hasattr(self.w, "ui"): del self.w.ui self.w.ui = ui = vanilla.Group((0, 0, -0, -0)) y = 10 labelSize = 100 gutter = 5 for attribute in self._attributes: uiElement = attribute["ui"] name = attribute["name"] args = dict(attribute.get("args", {})) height = 19 # create a label for every ui element except a checkbox if uiElement != "CheckBox": # create the label view label = vanilla.TextBox((0, y+2, labelSize-gutter, height), "%s:" % name, alignment="right", sizeStyle="small") # set the label view setattr(ui, "%sLabel" % name, label) else: args["title"] = name # check the provided args and add required keys if uiElement == "ColorWell": # a color well needs a color to be set # no size style if "color" not in args: args["color"] = AppKit.NSColor.blackColor() elif uiElement == "TextEditor": # different control height # no size style height = attribute.get("height", 75) else: # all other get a size style args["sizeStyle"] = "small" # create the control view attr = getattr(vanilla, uiElement)((labelSize, y, -10, height), callback=self.changed, **args) # set the control view setattr(ui, name, attr) y += height + 6 # resize the window according the provided ui elements self.w.resize(250, y)
def _setupPanes(self): self._identifierToPane = {} splitView = self.getNSSplitView() splitViewFrame = splitView.frame() mask = NSViewWidthSizable | NSViewHeightSizable for index, paneDescription in enumerate(self._paneDescriptions): # get the pane data view = paneDescription["view"] identifier = paneDescription["identifier"] size = paneDescription.get("size") minSize = paneDescription.get("minSize") maxSize = paneDescription.get("maxSize") canCollapse = paneDescription.get("canCollapse", True) resizeFlexibility = paneDescription.get("resizeFlexibility", True) # unwrap the view if necessary if isinstance(view, VanillaBaseObject): group = vanilla.Group((0, 0, -0, -0)) group.splitViewContentView = view view = group view._setFrame(splitViewFrame) view = view._nsObject view.setAutoresizingMask_(mask) # push all of the items into the description # so that we can reduce the get calls and # centralize the default values here. paneDescription["index"] = index paneDescription["nsView"] = view paneDescription["size"] = size paneDescription["minSize"] = minSize paneDescription["maxSize"] = maxSize paneDescription["canCollapse"] = canCollapse paneDescription[ "fixedSize"] = minSize is not None and minSize == maxSize if resizeFlexibility and paneDescription["fixedSize"]: resizeFlexibility = False paneDescription["resizeFlexibility"] = resizeFlexibility # store the view assert identifier is not None assert identifier not in self._identifierToPane self._identifierToPane[identifier] = paneDescription # add the subview splitView.addSubview_(view)
def __init__(self, parentWindow): self.parentWindow = parentWindow self.debug = False # Glyph and font data self.glyph = None self.LIBKEY = "com.andyclymer.zPosition" self.LIBKEYVIEW = "com.andyclymer.projectionViewOrientation" self.pointData = {} # dict of x,y,z for each pointID # Helper attributes self.holdChanges = False self.currentView = "front" self.enableProjection = False # Enable the buttons and save point data to the lib? # Window controls self.view = vanilla.Group((30, 30, 100, 100)) self.view.controlGroup = vanilla.Box((0, 0, 93, 94)) self.view.controlGroup.buttonFront = vanilla.SquareButton( (40, 5, 40, 40), "●", callback=self.rotateFront) self.view.controlGroup.buttonFront.enable(False) self.view.controlGroup.buttonSide = vanilla.SquareButton( (5, 5, 30, 40), "◑", callback=self.rotateSide) self.view.controlGroup.buttonSide.enable(False) self.view.controlGroup.buttonTop = vanilla.SquareButton( (40, 50, 40, 30), "◓", callback=self.rotateTop) self.view.controlGroup.buttonTop.enable(False) self.view.controlGroup.enableBox = vanilla.CheckBox( (13, -38, 25, 25), "", callback=self.enableDisableCallback) addObserver(self, "viewWillChangeGlyph", "viewWillChangeGlyph") addObserver(self, "viewDidChangeGlyph", "viewDidChangeGlyph") addObserver(self, "fontWillSave", "fontWillSave") addObserver(self, "fontDidSave", "fontDidSave") addObserver(self, "mouseUp", "mouseUp")
def __init__(self, glyph, construction, decompose): self.glyph = glyph width = 350 height = 120 editorWindow = CurrentGlyphWindow() (editorX, editorY, editorW, editorH), screen = getGlyphEditorRectAndScreen(editorWindow) x = editorX + ((editorW - width) / 2) y = editorY + ((editorH - height) / 2) self.w = StatusInteractivePopUpWindow((x, y, width, height), screen=screen) self.w.constructionEditor = vanilla.EditText( "auto", construction ) self.w.decomposeCheckBox = vanilla.CheckBox( "auto", "Decompose", value=decompose ) self.w.open() self.w.line = vanilla.HorizontalLine("auto") self.w.flex = vanilla.Group("auto") self.w.cancelButton = vanilla.Button( "auto", "Cancel", callback=self.cancelButtonCallback ) self.w.buildButton = vanilla.Button( "auto", "Build", callback=self.buildButtonCallback ) metrics = dict( margin=15, padding=10, buttonWidth=80 ) rules = [ "H:|-margin-[constructionEditor]-margin-|", "H:|-margin-[line]-margin-|", "H:|-margin-[decomposeCheckBox][flex(>=100)]-[cancelButton(==buttonWidth)]-padding-[buildButton(==buttonWidth)]-margin-|", "V:|" "-margin-" "[constructionEditor]" "-padding-" "[line]" "-padding-" "[decomposeCheckBox]" "-margin-" "|", "V:|" "-margin-" "[constructionEditor]" "-padding-" "[line]" "-padding-" "[flex]" "-margin-" "|", "V:|" "-margin-" "[constructionEditor]" "-padding-" "[line]" "-padding-" "[cancelButton]" "-margin-" "|", "V:|" "-margin-" "[constructionEditor]" "-padding-" "[line]" "-padding-" "[buildButton]" "-margin-" "|" ] self.w.addAutoPosSizeRules(rules, metrics) self.w.setDefaultButton(self.w.buildButton) self.w.cancelButton.bind(".", ["command"]) self.w.getNSWindow().makeFirstResponder_(self.w.constructionEditor.getNSTextField()) self.w.open()
def __init__(self, posSize, items, placardSortItems=[ dict(title="Sort by File Name", callback=fontFileNameSort), dict(title="Sort by Weight and Width", callback=fontWidthWeightSort), ], placardItems=[], **kwargs): # make default column descriptions if needed if not kwargs.get("columnDescriptions"): kwargs["columnDescriptions"] = [fontListFontNameColumnDescription] kwargs["showColumnTitles"] = False # set some defaults kwargs["autohidesScrollers"] = False # build the internal column reference self._keyToAttribute = {} self._orderedListKeys = [] self._wrappedListItems = {} for columnDescription in kwargs["columnDescriptions"]: title = columnDescription["title"] key = columnDescription.get("key", title) attribute = columnDescription["attribute"] self._keyToAttribute[key] = attribute self._orderedListKeys.append(key) # wrap the items items = [self._wrapFontForList(font) for font in items] # start the list super(FontList, self).__init__(posSize, items, **kwargs) # set the initial sort mode self._sortMode = None self._placardSortOptions = {} self._placardOptions = {} # placard if len(placardSortItems) + len(placardItems): # build the sort options if placardSortItems: self._sortMode = placardSortItems[0]["title"] for d in placardSortItems: title = d["title"] assert title.startswith("Sort by") self._placardSortOptions[title] = d["callback"] # build the other options if placardItems: for d in placardItems: self._placardOptions[d["title"]] = d["callback"] # build placardW = 65 placardH = 16 self._placard = vanilla.Group((0, 0, placardW, placardH)) # make a default item item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( "Options...", None, "") item.setHidden_(True) items = [item] # add the items items += [d["title"] for d in placardSortItems] items += [d["title"] for d in placardItems] self._placard.optionsButton = PlacardPopUpButton( (0, 0, placardW, placardH), items, callback=self._placardCallback, sizeStyle="mini") button = self._placard.optionsButton.getNSPopUpButton() button.setTitle_("Options...") self._nsObject.setPlacard_(self._placard.getNSView()) # update the sort self._updateSort()
def __init__(self, posSize, callback): self._callback = callback # put the controls group into a flipped group. # this will give better scroll behavior. width = posSize[2] - NSScroller.scrollerWidth() - 2 view = DefconAppKitTopAnchoredNSView.alloc().init() view.setFrame_(((0, 0), (width, 0))) # call the super super(OpenTypeControlsView, self).__init__(posSize, view, hasHorizontalScroller=False, drawsBackground=False) # build the view for the controls self._controlGroup = vanilla.Group((0, 0, width, 0)) view.addSubview_(self._controlGroup.getNSView()) # build the static controls top = 10 # mode self._controlGroup.modeTitle = vanilla.TextBox( (10, top, -10, 14), NSAttributedString.alloc().initWithString_attributes_( "DISPLAY MODE", titleControlAttributes), sizeStyle="small") top += 20 self._controlGroup.modeRadioGroup = vanilla.RadioGroup( (10, top, -10, 38), ["Glyph Preview", "Glyph Records"], callback=self._controlEditCallback) self._controlGroup.modeRadioGroup.set(0) top += 48 self._controlGroup.line1 = vanilla.HorizontalLine((10, top, -10, 1)) top += 11 # case self._controlGroup.caseTitle = vanilla.TextBox( (10, top, -10, 14), NSAttributedString.alloc().initWithString_attributes_( "CASE CONVERSION", titleControlAttributes), sizeStyle="small") top += 20 self._controlGroup.caseRadioGroup = vanilla.RadioGroup( (10, top, -10, 58), ["Unchanged", "Uppercase", "Lowercase"], callback=self._controlEditCallback) self._controlGroup.caseRadioGroup.set(0) top += 68 # language, script and direction self._controlGroup.scriptTitle = vanilla.TextBox( (10, top, -10, 14), NSAttributedString.alloc().initWithString_attributes_( "SCRIPT & LANGUAGE", titleControlAttributes), sizeStyle="small") top += 20 self._controlGroup.scriptPopUpButton = vanilla.PopUpButton( (10, top, -10, 20), [], callback=self._controlEditCallback) top += 25 self._controlGroup.languagePopUpButton = vanilla.PopUpButton( (10, top, -10, 20), [], callback=self._controlEditCallback) top += 35 self._controlGroup.directionTitle = vanilla.TextBox( (10, top, -10, 14), NSAttributedString.alloc().initWithString_attributes_( "WRITING DIRECTION", titleControlAttributes), sizeStyle="small") top += 20 self._controlGroup.directionRadioGroup = vanilla.RadioGroup( (10, top, -10, 38), ["Left to Right", "Right to Left"], callback=self._controlEditCallback) self._controlGroup.directionRadioGroup.set(0) top += 48 # GSUB and GPOS self._controlGroup.line2 = vanilla.HorizontalLine((10, top, -10, 1)) top += 11 # set document view height (x, y), (w, h) = self._nsObject.documentView().frame() self._nsObject.documentView().setFrame_(((x, y), (w, top))) x, y, w, h = self._controlGroup.getPosSize() self._controlGroup.setPosSize((x, y, w, top)) # storage self._dynamicTop = top self._gsubAttributes = {} self._gposAttributes = {}
def __init__(self, checkForUpdates=False, shouldLoad=False): self.w = vanilla.Window((800, 600), "Mechanic 2.1", minSize=(600, 400)) # toolbar self._toolbarSearch = vanilla.SearchBox((0, 0, 300, 0), callback=self.toolbarSearch) self._toolbarSearch.getNSSearchField().setFrame_(((0, 0), (300, 22))) toolbarItems = [ dict( itemIdentifier="search", label="Search", view=self._toolbarSearch.getNSSearchField(), ), dict(itemIdentifier=NSToolbarFlexibleSpaceItemIdentifier), dict( itemIdentifier="settings", label="Settings", imageNamed="prefToolbarMisc", callback=self.toolbarSettings, ), ] self.w.addToolbar(toolbarIdentifier="MechanicToolbar", toolbarItems=toolbarItems, addStandardItems=False, displayMode="icon") # extension list columnDescriptions = [ dict(title="", key="extensionController", width=25, cell=MCExtensionCirleCell.alloc().init(), editable=False), dict(title="Extension", key="extensionController", cell=MCImageTextFieldCell.alloc().init(), formatter=MCExtensionDescriptionFormatter.alloc().init(), editable=False), ] extensionsGroup = vanilla.Group((0, 0, -0, -0)) extensionsGroup.extensionList = vanilla.List( (0, 0, 0, -40), [], columnDescriptions=columnDescriptions, showColumnTitles=False, selectionCallback=self.extensionListSelectionCallback, doubleClickCallback=self.extensionListDoubleClickCallback, allowsMultipleSelection=True, rowHeight=39, drawFocusRing=False, ) extensionsGroup.extensionList.setSelection([]) # bottom bar extensionsGroup.checkForUpdates = vanilla.Button( (10, -30, 160, 22), "Check For Updates", callback=self.checkForUpdatesCallback, sizeStyle="small") extensionsGroup.purchaseButton = vanilla.Button( (10, -30, 100, 22), "Purchase", callback=self.purchaseCallback) extensionsGroup.installButton = vanilla.Button( (10, -30, 100, 22), "Install", callback=self.installCallback) extensionsGroup.uninstallButton = vanilla.Button( (10, -30, 120, 22), "Uninstall", callback=self.uninstallCallback) extensionsGroup.updateButton = vanilla.Button( (10, -30, 110, 22), "Update", callback=self.updateCallback) allButtons = [ extensionsGroup.purchaseButton, extensionsGroup.installButton, extensionsGroup.uninstallButton, extensionsGroup.updateButton ] for button in allButtons: button.show(False) # streams streamsGroup = vanilla.Group((0, 0, -0, -0)) streamsGroup.streamsLabel = vanilla.TextBox((0, 0, -0, -0), 'my streams', sizeStyle='small') streamsGroup.streamsList = vanilla.List( (0, 20, -0, -40), ["my precious", "testing", "pretty", "buggy"], allowsEmptySelection=True, drawFocusRing=False) # streamsGroup.streamsList.getNSTableView().setUsesAlternatingRowBackgroundColors_(False) streamsGroup.streamsList.getNSTableView().setSelectionHighlightStyle_( NSTableViewSelectionHighlightStyleSourceList) streamsGroup.addStream = vanilla.SquareButton((10, -30, 28, 20), "+") streamsGroup.removeStream = vanilla.SquareButton((37, -30, 28, 20), "-") # filters developersGroup = vanilla.Group((0, 0, -0, -0)) developersGroup.developersLabel = vanilla.TextBox((0, 0, -0, -0), 'developers', sizeStyle='small') developersGroup.developersList = vanilla.List( (0, 20, -0, -0), [], drawHorizontalLines=False, drawFocusRing=False, selectionCallback=self.filtersCallback) developersGroup.developersList.getNSTableView( ).setUsesAlternatingRowBackgroundColors_(False) # developersGroup.developersList.getNSTableView().setSelectionHighlightStyle_(NSTableViewSelectionHighlightStyleSourceList) tagsGroup = vanilla.Group((0, 0, -0, -0)) tagsGroup.tagsLabel = vanilla.TextBox((0, 0, -0, -0), 'tags', sizeStyle='small') tagsGroup.tagsList = vanilla.List( (0, 20, -0, -0), [], drawHorizontalLines=False, drawFocusRing=False, selectionCallback=self.filtersCallback) tagsGroup.tagsList.getNSTableView( ).setUsesAlternatingRowBackgroundColors_(False) # tagsGroup.tagsList.getNSTableView().setSelectionHighlightStyle_(NSTableViewSelectionHighlightStyleSourceList) sourcesGroup = vanilla.Group((0, 0, -0, -0)) sourcesGroup.sourcesLabel = vanilla.TextBox((0, 0, -0, -0), 'sources', sizeStyle='small') sourcesGroup.sourcesList = vanilla.List( (0, 20, -0, -0), [], drawHorizontalLines=False, drawFocusRing=False, selectionCallback=self.filtersCallback) sourcesGroup.sourcesList.getNSTableView( ).setUsesAlternatingRowBackgroundColors_(False) # sourcesGroup.sourcesList.getNSTableView().setSelectionHighlightStyle_(NSTableViewSelectionHighlightStyleSourceList) # split views filtersGroup = vanilla.SplitView((0, -0, -0, -0), paneDescriptions=[ dict(view=developersGroup, identifier="developers"), dict(view=tagsGroup, identifier="tags"), dict(view=sourcesGroup, identifier="sources"), ], dividerStyle='thin') mainPanes = vanilla.SplitView((0, 0, -0, -0), paneDescriptions=[ dict(view=filtersGroup, identifier="filters", size=160, minSize=160, maxSize=240), dict(view=extensionsGroup, identifier="extensions"), ], isVertical=False, dividerStyle='thin') self.w.splitView = vanilla.SplitView((0, 0, -0, -0), paneDescriptions=[ dict(view=streamsGroup, identifier="streams", size=140, minSize=120, maxSize=200), dict(view=mainPanes, identifier="main"), ], isVertical=True, dividerStyle='thin') self._extensionsGroup = extensionsGroup self._developersGroup = developersGroup self._tagsGroup = tagsGroup self._sourcesGroup = sourcesGroup self.w.open() self._didCheckedForUpdates = False if shouldLoad: self.loadExtensions(checkForUpdates)
def __init__(self, posSize, font=None, initialMode="cell", listColumnDescriptions=None, listShowColumnTitles=False, showPlacard=True, showModePlacard=True, placardActionItems=None, cellRepresentationName="defconAppKit.GlyphCell", glyphDetailWindowClass=GlyphInformationPopUpWindow, selectionCallback=None, doubleClickCallback=None, deleteCallback=None, editCallback=None, enableDelete=False, selfDropSettings=None, selfWindowDropSettings=None, selfDocumentDropSettings=None, selfApplicationDropSettings=None, otherApplicationDropSettings=None, allowDrag=False, dragAndDropType="DefconAppKitSelectedGlyphIndexesPboardType"): self._holdCallbacks = True super(GlyphCollectionView, self).__init__(posSize) if showModePlacard or placardActionItems is not None: showPlacard = True bottom = 0 if showPlacard: bottom = -19 self._selectionCallback = selectionCallback self._doubleClickCallback = doubleClickCallback self._deleteCallback = deleteCallback self._dragAndDropType = dragAndDropType self._enableDelete = enableDelete # set up the list self._listEditChangingAttribute = None self._listEditChangingGlyph = None enableDelete = deleteCallback is not None # prep for drag and drop if selfDropSettings is not None: selfDropSettings = dict(selfDropSettings) if selfWindowDropSettings is not None: selfWindowDropSettings = dict(selfWindowDropSettings) if selfDocumentDropSettings is not None: selfDocumentDropSettings = dict(selfDocumentDropSettings) if selfApplicationDropSettings is not None: selfApplicationDropSettings = dict(selfApplicationDropSettings) if otherApplicationDropSettings is not None: otherApplicationDropSettings = dict(otherApplicationDropSettings) dropSettings = [ (selfDropSettings, self._selfDropCallback), (selfWindowDropSettings, self._selfWindowDropCallback), (selfDocumentDropSettings, self._selfDocumentDropCallback), (selfApplicationDropSettings, self._selfApplicationDropCallback), (otherApplicationDropSettings, self._otherApplicationDropCallback) ] for d, internalCallback in dropSettings: if d is None: continue d["type"] = dragAndDropType d["finalCallback"] = d["callback"] d["callback"] = internalCallback dragSettings = None if allowDrag: dragSettings = dict(type=dragAndDropType, callback=self._packListRowsForDrag) if listColumnDescriptions is None: listColumnDescriptions = [dict(title="Name", attribute="name")] self._glyphCellView = self.glyphCellViewClass.alloc( ).initWithFont_cellRepresentationName_detailWindowClass_( font, cellRepresentationName, glyphDetailWindowClass) self._glyphCellView.vanillaWrapper = weakref.ref(self) self._glyphCellView.setAllowsDrag_(allowDrag) dropTypes = [] for d in (selfDropSettings, selfWindowDropSettings, selfDocumentDropSettings, selfApplicationDropSettings, otherApplicationDropSettings): if d is not None: dropTypes.append(d["type"]) self._glyphCellView.registerForDraggedTypes_(dropTypes) self._list = self.glyphListViewVanillaClass( (0, 0, 0, bottom), None, dataSource=self._arrayController, columnDescriptions=listColumnDescriptions, editCallback=editCallback, selectionCallback=self._listSelectionCallback, doubleClickCallback=doubleClickCallback, showColumnTitles=listShowColumnTitles, enableTypingSensitivity=True, enableDelete=enableDelete, autohidesScrollers=True, selfDropSettings=selfDropSettings, selfWindowDropSettings=selfWindowDropSettings, selfDocumentDropSettings=selfDocumentDropSettings, selfApplicationDropSettings=selfApplicationDropSettings, otherApplicationDropSettings=otherApplicationDropSettings, dragSettings=dragSettings) # set up the placard if showPlacard: self._placard = vanilla.Group((0, -21, 0, 21)) self._placard.base = GradientButtonBar((0, 0, 0, 0)) extensionLeft = 0 extensionWidth = 0 # mode if showModePlacard: extensionLeft += 42 modeButton = vanilla.SegmentedButton( (0, 0, 43, 0), [ dict(imageNamed="defconAppKitPlacardCellImage", width=20), dict(imageNamed="defconAppKitPlacardListImage", width=20) ], callback=self._placardSelection) modeButton.frameAdjustments = dict(regular=(0, 0, 0, 0)) modeButton.getNSSegmentedButton().setSegmentStyle_( NSSegmentStyleSmallSquare) modeButton.set(0) self._placard.button = modeButton # action button if placardActionItems is not None: extensionWidth -= 35 actionButton = vanilla.ActionButton((-35, 0, 45, 21), placardActionItems, sizeStyle="small", bordered=False) actionButton.frameAdjustments = dict(regular=(0, 0, 0, 0)) button = actionButton.getNSPopUpButton() button.setBezelStyle_(NSSmallSquareBezelStyle) self._placard.actionButton = actionButton # extension self._placard.extension = vanilla.Group( (extensionLeft, 0, extensionWidth, 0)) else: self._placard = None # tweak the scroll view self._list.getNSScrollView().setBackgroundColor_( DefconAppKitGlyphCellNSView.gridColor) # set the mode self._mode = None self.setMode(initialMode) self._holdCallbacks = False
def __init__(self): self.fontList = [] self.fontNames = [] self.fontStems = [] self.estimatedStems = None # Estimated stem measurements for the resulting font # Glyph groups self.groups = [] # Case info, normalized after editing self.normalizedInfo = {} self.dataNorms = { "scaleH": dict(default=100, dataType=float, scale=0.01), "scaleV": dict(default=100, dataType=float, scale=0.01), "interpH": dict(default=100, dataType=float, scale=0.01), "interpV": dict(default=100, dataType=float, scale=0.01), "tracking": dict(default=0, dataType=float, scale=1) } self.w = vanilla.Window((317, 700), "Scale And Interpolate %s" % VERSION, minSize=(317, 300), maxSize=(317, 969), autosaveName="ScaleAndInterp") # 882 height self.g = vanilla.Group((0, 0, 300, 900)) step = 10 self.g.font0title = vanilla.TextBox((10, step, -10, 25), colorText("Lightest Master (0%)", style="bold")) self.g.font0choice = vanilla.PopUpButton( (10, step + 20, -10, 25), self.fontNames, callback=self.fontChoiceChanged) step += 50 self.g.font0stemTextUC = vanilla.TextBox((20, step, -10, 20), "") self.g.font0stemTextLC = vanilla.TextBox((20, step + 20, -10, 20), "") step += 50 self.g.font1title = vanilla.TextBox((10, step, -10, 25), colorText("Heaviest Master (100%)", style="bold")) self.g.font1choice = vanilla.PopUpButton( (10, step + 20, -10, 25), self.fontNames, callback=self.fontChoiceChanged) step += 50 self.g.font1stemTextUC = vanilla.TextBox((20, step, -10, 20), "") self.g.font1stemTextLC = vanilla.TextBox((20, step + 20, -10, 20), "") step += 50 self.g.hr1 = vanilla.HorizontalLine((10, step, -10, 1)) step += 15 self.g.capsTitle = vanilla.TextBox((10, step, -10, 25), colorText("Caps", style="bold")) step += 25 self.g.ucGroups = vanilla.PopUpButton((10, step, -10, 25), []) step += 35 columnDescriptions = [ dict(title="Name"), dict(title="Value", editable=True, width=50) ] capInfo = [ dict(Name="Scale Horizontal %", attr="scaleH", Value=100), dict(Name="Scale Vertical %", attr="scaleV", Value=100), dict(Name="Interpolate Horizontal %", attr="interpH", Value=100), dict(Name="Interpolate Vertical %", attr="interpV", Value=100), dict(Name="Units of tracking", attr="tracking", Value=0) ] self.g.ucInfo = vanilla.List((10, step, -10, 100), capInfo, columnDescriptions=columnDescriptions, showColumnTitles=False, editCallback=self.dataChanged) step += 110 self.g.resultStemTextUC = vanilla.TextBox((20, step, -10, 20), "") step += 30 self.g.lcTitle = vanilla.TextBox((10, step, -10, 25), colorText("Lowercase", style="bold")) step += 25 self.g.lcGroups = vanilla.PopUpButton((10, step, -10, 25), []) step += 35 lcInfo = [ dict(Name="Scale Horizontal %", attr="scaleH", Value=100), dict(Name="Scale Vertical %", attr="scaleV", Value=100), dict(Name="Interpolate Horizontal %", attr="interpH", Value=100), dict(Name="Interpolate Vertical %", attr="interpV", Value=100), dict(Name="Units of tracking", attr="tracking", Value=0) ] self.g.lcInfo = vanilla.List((10, step, -10, 100), lcInfo, columnDescriptions=columnDescriptions, showColumnTitles=False, editCallback=self.dataChanged) step += 110 self.g.resultStemTextLC = vanilla.TextBox((20, step, -10, 20), "") step += 30 self.g.otherTitle = vanilla.TextBox((10, step, -10, 25), colorText("Other glyphs", style="bold")) step += 25 self.g.otherRadio = vanilla.RadioGroup((10, step, -10, 70), [ "Copy from the lightest master", "Process at 50% of UC and LC settings", "Skip any other glyphs" ], callback=self.dataChanged) self.g.otherRadio.set(2) step += 80 self.g.loadButton = vanilla.SquareButton((100, step, -10, 25), "Load settings from UFO", callback=self.loadSettings) step += 35 self.g.hr2 = vanilla.HorizontalLine((10, step, -10, 1)) step += 15 self.g.skewBox = vanilla.CheckBox( (10, step, -10, 25), "Skew Italic glyphs upright before scaling") self.g.skewBox.set(True) step += 25 self.g.infoBox = vanilla.CheckBox( (10, step, -10, 25), "Interpolate Font Info whenever possible") self.g.infoBox.set(True) step += 25 self.g.scaleComponentBox = vanilla.CheckBox( (10, step, -10, 25), "Don’t scale component positions") self.g.scaleComponentBox.set(True) step += 25 self.g.doKernBox = vanilla.CheckBox((10, step, -10, 25), "Process Kerning") self.g.doKernBox.set(True) step += 3 self.g.testKernButton = vanilla.SquareButton( (135, step, -10, 25), "Compatibility Test", callback=self.kernCompatibilityTestCallback) #step += 40 self.w.buildButton = vanilla.SquareButton( (10, -35, -10, 25), "Make Font", callback=self.makeFontCallback) # Add the group to a ScrollView view = self.g.getNSView() self.w.sv = vanilla.ScrollView( (0, 0, -0, -45), view, hasHorizontalScroller=False, hasVerticalScroller=True, autohidesScrollers=False, drawsBackground=False ) #backgroundColor=NSColor.windowBackgroundColor()) # Update the font info before opening self.fontsChanged() self.dataChanged() addObserver(self, "fontsChanged", "fontDidOpen") addObserver(self, "fontsChanged", "newFontDidOpen") addObserver(self, "fontsChanged", "fontDidClose") self.w.bind("close", self.windowClosed) self.w.open()
def __init__(self): self.soundTitles = ["no sound"] + RoboSoundsController.getSoundNames() self.w = vanilla.Window((800, 200), "RoboSounds", minSize=(200, 200)) columnDescriptions = [ dict(key="event", title="Event"), dict(key="frequency", title="Frequency", cell=vanilla.SliderListCell(minValue=0, maxValue=1.0, tickMarkCount=20, stopOnTickMarks=True)), dict(key="speak", title="Speak"), dict(key="sound", title="Sound", cell=vanilla.PopUpButtonListCell(self.soundTitles), binding="selectedValue") ] self.w.list = vanilla.List("auto", [], columnDescriptions=columnDescriptions, editCallback=self.listEditCallback) self.w.addButton = vanilla.GradientButton( "auto", imageNamed=NSImageNameAddTemplate, callback=self.addButtonCallback) self.w.removeButton = vanilla.GradientButton( "auto", imageNamed=NSImageNameRemoveTemplate, callback=self.removeButtonCallback) self.w.flex = vanilla.Group("auto") self.w.playButton = vanilla.Button("auto", title="▶︎", callback=self.playButtonCallback) self.w.playButton.getNSButton().setBordered_(False) options = [ dict(title="Select Sound Directory…", callback=self.selectSoundDirectoryCallback), dict(title="Reload Sounds", callback=self.reloadSoundsCallback), "----", dict(title="Prebuilt Settings", items=[ dict(title="Verbose", callback=self.importSettingsVerboseCallback), dict(title="Coach", callback=self.importSettingsCoachCallback), dict(title="Boring", callback=self.importSettingsBoringCallback) ]), dict(title="Import Settings…", callback=self.importSettingsCallback), dict(title="Export Settings…", callback=self.exportSettingsCallback) ] self.w.optionsButton = vanilla.ActionButton("auto", options, bordered=False) metrics = dict(border=15, space=10, button=20) rules = [ "H:|-border-[list]-border-|", "H:|-border-[addButton(==button)][removeButton(==button)][flex(>=50)][playButton]-space-[optionsButton]-border-|", "V:|-border-[list(>=200)]-space-[addButton(==button)]-border-|", "V:|-border-[list(>=200)]-space-[removeButton(==button)]-border-|", "V:|-border-[list(>=200)]-space-[flex]-border-|", "V:|-border-[list(>=200)]-space-[playButton(==button)]-border-|", "V:|-border-[list(>=200)]-space-[optionsButton(==button)]-border-|" ] self.w.addAutoPosSizeRules(rules, metrics) self.populateList() self.setUpBaseWindowBehavior() RoboSoundsController.startListening() self.w.open()
def __init__(self, fonts): self.fonts = fonts if len(self.fonts) in range(4): self.min_unit_width = 350 self.p_point_size = 160 elif len(self.fonts) in range(4, 7): self.min_unit_width = 200 self.p_point_size = 120 else: self.min_unit_width = 150 self.p_point_size = 100 # by default, all checkboxes are unchecked self.checked = [0 for i in range(len(self.fonts))] self.min_w_width = len(self.fonts) * self.min_unit_width # cmb_kern_dict is an ordered dict self.cmb_kern_dict = kerningHelper.get_combined_kern_dict(fonts) self.pair_list = list(self.cmb_kern_dict.keys()) self.filtered_pairlists = self.make_filtered_pairlists( self.cmb_kern_dict) # initial value for the first pair to show initial_pair = self.pair_list[0] self.pair = initial_pair initial_value = self.cmb_kern_dict[initial_pair] self.values = initial_value self.steps = len(self.values) self.update_display(self.values) self.drag_index = None self.w = vanilla.Window( (self.min_w_width, self.min_w_height), title='Kern-A-Lytics', minSize=(self.min_w_width / 2, self.min_w_height / 2), ) _, _, self.w_width, self.w_height = self.w.getPosSize() self.graph_height = self.w_height / 3 self.graph_width = (self.w_width - 2 * self.padding) self.step_dist = self.graph_width / self.steps graph_margin = self.step_dist / 2 self.canvas_delegate = CanvasDelegate(self) self.w.c = Canvas( (self.padding, self.padding, -self.padding, self.graph_height), delegate=self.canvas_delegate, canvasSize=(self.graph_width, self.graph_height), # backgroundColor=AppKit.NSColor.orangeColor(), backgroundColor=AppKit.NSColor.clearColor(), drawsBackground=False, ) # buttons buttons = [ # button label, callback name ('Delete Pairs', 'delete_button_callback'), ('Average Pairs', 'average_button_callback'), ('Equalize Pairs', 'transfer_button_callback'), ('Interpolate Pair', 'interpolate_button_callback'), # ('Transfer Pair', 'transfer_button_callback'), ('+10', 'plus_button_callback'), ('-10', 'minus_button_callback'), ('+10%', 'dummy_button_callback'), ('-10%', 'dummy_button_callback'), ] button_top = -210 # list starts at 210 and has 10 padding at bottom # total whitespace: 200 height - 8 * 20 = 40 # individual_whitespace = 40 / (len(buttons) - 1) button_height = 20 button_space = len(buttons) * button_height button_whitespace = (abs(button_top) - self.padding) - button_space button_step_space = button_whitespace / (len(buttons) - 1) for i, (b_label, b_callback_name) in enumerate(buttons): button = vanilla.Button( (self.w_width - self.padding - self.button_width, button_top + i * button_height, self.button_width, button_height), b_label, callback=getattr(self, b_callback_name)) setattr(self.w, 'button_{}'.format(i), button) # button_top += self.padding / 2 button_top += button_step_space # graph labels with monospaced digits nsfont = AppKit.NSFont.monospacedDigitSystemFontOfSize_weight_(14, 0.0) for i, number in enumerate(self.label_values): tb_x = self.padding + graph_margin + i * self.step_dist self.tb_y = self.padding * 2 + self.graph_height self.tb_height = 20 self.tb_width = 100 tb_control = vanilla.TextBox( (tb_x - self.tb_width / 2, self.tb_y, self.tb_width, self.tb_height), number, alignment='center', sizeStyle='small', selectable=True, ) tb_control.getNSTextField().setFont_(nsfont) setattr(self.w, 'textbox_{}'.format(i), tb_control) # pair preview pp_origin_x = self.padding pp_origin_y = self.padding * 4 + self.graph_height + self.tb_height self.w.pairPreview = vanilla.Group( (pp_origin_x, pp_origin_y, self.w_width, self.p_point_size)) for f_index, f in enumerate(self.fonts): x = self.step_dist * f_index pair_preview = DrawPair((x, 0, self.step_dist, -0)) initial_pair = self.pair_list[0] kern_value = self.cmb_kern_dict.get(initial_pair)[f_index] if kern_value is None: kern_value = 0 repr_pair = kerningHelper.get_repr_pair(f, initial_pair) # XXXX the following line is problematic # if UFOs with different group structures are opened repr_glyphs = [f[g_name] for g_name in repr_pair] pair_preview.setGlyphData_kerning(repr_glyphs, kern_value) setattr(self.w.pairPreview, 'pair_{}'.format(f_index), pair_preview) # checkboxes for i, f in enumerate(self.fonts): cb_x = self.padding + graph_margin + i * self.step_dist cb_control = vanilla.CheckBox( (cb_x - 6, pp_origin_y + self.p_point_size + self.padding * 2, 22, 22), '', value=False, sizeStyle='regular', callback=self.checkbox_callback) setattr(self.w, 'checkbox_{}'.format(i), cb_control) # pop-up button for list filtering list_width = self.w_width - self.button_width - self.padding * 3 self.w.list_filter = vanilla.PopUpButton((10, -240, list_width, 20), self.filter_options, callback=self.filter_callback) # list of kerning pairs (bottom) column_pairs = self.make_columns(self.pair_list) self.w.display_list = vanilla.List( (10, -210, list_width, -10), column_pairs, columnDescriptions=[{ 'title': 'L' }, { 'title': 'R' }], allowsMultipleSelection=False, selectionCallback=self.list_callback) self.w.bind('resize', self.resize_callback) self.w.open()
def __init__(self, font): self.font = font self.w = vanilla.Sheet((700, 300), parentWindow=CurrentFontWindow().w, minSize=(200, 200)) self.originalConstructions = ConstructionsLoader(font.defaultLayer).constructions columnDescriptions = [ dict( title="Name", key="name", editable=False, width=100 ), dict( title="Construction", key="construction", editable=True ), dict( title="Decompose", key="decompose", editable=True, cell=vanilla.CheckBoxListCell(), width=80 ) ] self.w.constructionList = vanilla.List( "auto", [], columnDescriptions=columnDescriptions ) self.w.showExistingGlyphsCheckBox = vanilla.CheckBox( "auto", "Show Existing Glyphs", callback=self.showExistingGlyphsCheckBoxCallback ) self.w.flex = vanilla.Group("auto") self.w.buildInAllFontsButton = vanilla.Button( "auto", "Build In All Fonts", callback=self.buildInAllFontsButtonCallback ) self.w.cancelButton = vanilla.Button( "auto", "Cancel", callback=self.cancelButtonCallback ) self.w.buildButton = vanilla.Button( "auto", "Build", callback=self.buildButtonCallback ) metrics = dict( margin=15, padding=10, buttonWidth=80 ) rules = [ "H:|[constructionList]|", "H:|-margin-[showExistingGlyphsCheckBox][flex(>=100)]-[buildInAllFontsButton]-padding-[cancelButton(==buttonWidth)]-padding-[buildButton(==buttonWidth)]-margin-|", "V:|" "[constructionList]" "-padding-" "[showExistingGlyphsCheckBox]" "-margin-" "|", "V:|" "[constructionList]" "-padding-" "[flex]" "-margin-" "|", "V:|" "[constructionList]" "-padding-" "[buildInAllFontsButton]" "-margin-" "|", "V:|" "[constructionList]" "-padding-" "[cancelButton]" "-margin-" "|", "V:|" "[constructionList]" "-padding-" "[buildButton]" "-margin-" "|" ] self.w.addAutoPosSizeRules(rules, metrics) self.populateConstructionList() self.w.setDefaultButton(self.w.buildButton) self.w.cancelButton.bind(".", ["command"]) self.w.open()
def __init__(self): self.debug = False # List of theme data dictionaries self.themes = [] # On launch: go ahead and start loading themes self.readThemePrefs() self.loadDefaultThemes() # On launch: hold aside current preferences for "undo" self.backupTheme = {} self.makeBackupTheme() # Build the list of theme names self.themeNames = [] # Placeholder for the name edit sheet self.nameSheet = None mid = 280 # The Vanilla window self.w = vanilla.Window((300, 560), "Theme Manager") # Theme list self.w.themeList = vanilla.List( (20, 20, mid - 20, 165), self.themeNames, selectionCallback=self.listSelectionCallback, doubleClickCallback=self.listDoubleClickCallback, allowsMultipleSelection=False) # Editing list extrasHeight = len(NONCOLORKEYS) * 25 + 5 try: colorCell = RFColorCell.alloc().initWithDoubleClickCallback_( self.colorDoubleClickCallback) except: colorCell = RFColorCell.alloc().initWithDoubleClickCallack_( self.colorDoubleClickCallback) columnDescriptions = [ dict(title="Color", key="color", cell=colorCell, width=90), dict(title="Attribute", key="name") ] self.w.editingList = vanilla.List( (mid + 20, 20, 480, -extrasHeight - 20), [], columnDescriptions=columnDescriptions, allowsEmptySelection=False, allowsMultipleSelection=False, enableTypingSensitivity=True, rowHeight=20, allowsSorting=False) # Extra values for editing self.w.editingExtras = vanilla.Group( (mid + 20, -extrasHeight - 10, -20, -20)) for i, extra in enumerate(NONCOLORKEYS): extraKey, extraName, extraType = extra extraEditor = vanilla.EditText((20, i * 25, 50, 20), sizeStyle="small", callback=self.setThemeExtra) extraTitle = vanilla.TextBox((95, i * 25, -20, 20), extraName) setattr(self.w.editingExtras, extraKey, extraEditor) setattr(self.w.editingExtras, extraKey + "-title", extraTitle) # Buttons y = 200 self.w.buttonNewTheme = vanilla.SquareButton( (20, y, 31, 25), "✚", callback=self.newThemeCallback) # ⌫✕✖︎✗✘★✚ self.w.buttonNewTheme.getNSButton().setToolTip_("New Theme") self.w.buttonRemoveTheme = vanilla.SquareButton( (50, y, 31, 25), "✘", callback=self.removeThemeCallback) #✘+ self.w.buttonRemoveTheme.getNSButton().setToolTip_("Remove Theme") self.w.buttonDuplicateTheme = vanilla.SquareButton( (80, y, 30, 25), "❏", callback=self.duplicateTheme) self.w.buttonDuplicateTheme.getNSButton().setToolTip_( "Duplicate Theme") self.w.buttonEditTheme = vanilla.SquareButton( (250, y, 30, 25), "✑", callback=self.editThemeCallback) self.w.buttonEditTheme.getNSButton().setToolTip_("Edit Theme") self.w.buttonImport = vanilla.SquareButton( (120, y, 61, 25), "Import", callback=self.importThemeCallback) self.w.buttonExport = vanilla.SquareButton( (180, y, 60, 25), "Export", callback=self.exportThemeCallback) self.w.buttonDuplicateTheme.enable(False) self.w.buttonRemoveTheme.enable(False) # Preview y += 40 self.w.previewGlyphView = GlyphView((20, y, mid - 20, 270)) self.w.previewGlyphView.setTheme(self.backupTheme) self.w.previewGlyphView.setShowOffCurvePoints(True) self.w.previewGlyphView.setShowBlues(True) # Apply theme y += 280 self.w.applyButton = vanilla.SquareButton( (20, y, mid - 60, 25), "Apply theme", callback=self.applyThemeCallback) self.w.applyButton.enable(False) self.w.buttonUndo = vanilla.SquareButton( (mid - 30, y, 30, 25), "↩︎", callback=self.undoThemeCallback) # ⤺⟲⎌ self.w.buttonUndo.getNSButton().setToolTip_("Revert Theme") self.w.buttonUndo.enable(False) # Give the window a callback to call when the window closes self.w.bind("close", self.windowClosedCallback) # Open the window self.w.open() self.rebuildThemeList(setList=True) # Load the preview font previewFontPath = os.path.join(EXTENSIONBUNDLE.resourcesPath(), "GlyphPreview.ufo") previewFont = OpenFont(previewFontPath, showInterface=False) previewGlyph = previewFont["a"] self.w.previewGlyphView.set(previewGlyph.naked())
def __init__(self, resources_path): self.pref_key = 'com.ryanbugden.sidebear.increment' initialDefaults = { self.pref_key: 2, } registerExtensionDefaults(initialDefaults) try: self.g = CurrentGlyph() except: self.g = None window_width = 255 window_margin = 20 gutter = 25 vert_gutter = 12 rule_gutter = vert_gutter - 2 text_box_height = 20 row_1_y = -14 row_2_y = row_1_y + vert_gutter + text_box_height - 5 row_3_y = row_2_y + vert_gutter + text_box_height row_4_y = row_3_y + text_box_height + rule_gutter row_5_y = row_4_y + rule_gutter third_width = (window_width - (window_margin * 2) - (gutter * 2)) / 3 self.window_height = window_margin * 2 + row_5_y + text_box_height + 8 # The group of elements self.w = vanilla.Group((0, 0, -0, -0)) # Current glyph self.w.curr_glyph_note = vanilla.TextBox( (window_margin + third_width / 2, window_margin + row_1_y, third_width * 2 + gutter * 2, text_box_height), "None", sizeStyle="regular", alignment="center") # Left width span rule self.w.left_w_span = vanilla.HorizontalLine( (window_margin + 2, window_margin + row_1_y + (text_box_height / 2), third_width, 1)) # Left width vert rule self.w.left_w_vert = vanilla.VerticalLine( (window_margin + 1, window_margin + row_1_y, 1, text_box_height)) # Right width span rule self.w.right_w_span = vanilla.HorizontalLine( (window_margin + third_width * 2 + gutter * 2, window_margin + row_1_y + (text_box_height / 2), third_width - 1, 1)) # Right width vert rule self.w.right_w_vert = vanilla.VerticalLine( (window_margin + third_width * 3 + gutter * 2 - 1, window_margin + row_1_y, 1, text_box_height)) # Left side-bearing self.w.LSB = vanilla.EditText((window_margin, window_margin + row_2_y, third_width, text_box_height), text="", sizeStyle="small", callback=self.editLSBCallback, continuous=False) self.w.LSB.getNSTextField().setFocusRingType_(1) self.w.LSB.getNSTextField().setAlignment_(2) # Left swap bridge rule self.w.left_sw_rule = vanilla.HorizontalLine( (window_margin + third_width, window_margin + row_2_y + text_box_height / 2, gutter, 1)) # Swap SB button self.w.swap_SB = vanilla.ImageButton( (window_margin + third_width + gutter, window_margin + row_2_y, third_width, text_box_height), imagePath=resources_path + '/_icon_Swap.pdf', callback=self.swapSBButtonCallback, sizeStyle='regular') # Right swap bridge rule self.w.right_sw_rule = vanilla.HorizontalLine( (window_margin + third_width * 2 + gutter, window_margin + row_2_y + text_box_height / 2, gutter, 1)) # Right side-bearing self.w.RSB = vanilla.EditText( (window_margin + third_width * 2 + gutter * 2, window_margin + row_2_y, third_width, text_box_height), text="", sizeStyle="small", callback=self.editRSBCallback, continuous=False) self.w.RSB.getNSTextField().setFocusRingType_(1) self.w.RSB.getNSTextField().setAlignment_(2) # Center Glyph button self.w.center_glyph = vanilla.ImageButton( (window_margin + third_width + gutter, window_margin + row_3_y, third_width, text_box_height), imagePath=resources_path + '/_icon_Center.pdf', callback=self.centerGlyphButtonCallback, sizeStyle='regular') # Left vert bridge rule self.w.left_vert_rule = vanilla.VerticalLine( (window_margin + third_width / 2, window_margin + row_2_y + text_box_height, 1, vert_gutter)) # Right vert bridge rule self.w.right_vert_rule = vanilla.VerticalLine( (window_margin + third_width * 2.5 + gutter * 2, window_margin + row_2_y + text_box_height, 1, vert_gutter)) # Equals RSB button self.w.equals_RSB = vanilla.ImageButton( (window_margin, window_margin + row_3_y, third_width, text_box_height), imagePath=resources_path + '/_icon_EqualRSB.pdf', callback=self.equalsRSBButtonCallback, sizeStyle='regular') # Equals LSB button self.w.equals_LSB = vanilla.ImageButton( (window_margin + third_width * 2 + gutter * 2, window_margin + row_3_y, third_width, text_box_height), imagePath=resources_path + '/_icon_EqualLSB.pdf', callback=self.equalsLSBButtonCallback, sizeStyle='regular') # Rule self.w.rule = vanilla.HorizontalLine( (window_margin, window_margin + row_4_y, third_width * 3 + gutter * 2, 1)) # Increment input self.increment = getExtensionDefault(self.pref_key, 2) self.w.inc_text_box = vanilla.EditText( (window_margin + gutter + third_width, window_margin + row_5_y, third_width, text_box_height), text="%s" % self.increment, sizeStyle="small", callback=self.incrementCallback) self.w.inc_text_box.getNSTextField().setFocusRingType_(1) self.w.inc_text_box.getNSTextField().setAlignment_(2) # Left expand/contract bridge rule self.w.left_ec_rule = vanilla.HorizontalLine( (window_margin + third_width, window_margin + row_5_y + text_box_height / 2, gutter, 1)) # Right expand/contract bridge rule self.w.right_ec_rule = vanilla.HorizontalLine( (window_margin + third_width * 2 + gutter, window_margin + row_5_y + text_box_height / 2, gutter, 1)) # Close SBs self.w.close_SB = vanilla.ImageButton( (window_margin, window_margin + row_5_y, third_width, text_box_height), imagePath=resources_path + '/_icon_Close.pdf', callback=self.closeSBButtonCallback, sizeStyle='regular') # Open SBs self.w.open_SB = vanilla.ImageButton( (window_margin + third_width * 2 + gutter * 2, window_margin + row_5_y, third_width, text_box_height), imagePath=resources_path + '/_icon_Open.pdf', callback=self.openSBButtonCallback, sizeStyle='regular') # Increment self.w.incr_caption = vanilla.TextBox( (window_margin + third_width, window_margin + row_5_y + 23, third_width + gutter * 2, text_box_height), "Increment", sizeStyle="mini", alignment="center") addObserver(self, "glyphChanged", "currentGlyphChanged") addObserver(self, "glyphChanged", "viewDidChangeGlyph") addObserver(self, "glyphChanged", "glyphWindowDidOpen") addObserver(self, "glyphDraw", "draw") self.updateUI_BothSB()
def __init__(self, posSize, initialMode="cell", listColumnDescriptions=None, listShowColumnTitles=False, showModePlacard=True, cellRepresentationName="defconAppKit.GlyphCell", glyphDetailWindowClass=GlyphInformationPopUpWindow, selectionCallback=None, doubleClickCallback=None, deleteCallback=None, editCallback=None, enableDelete=False, selfDropSettings=None, selfWindowDropSettings=None, selfDocumentDropSettings=None, selfApplicationDropSettings=None, otherApplicationDropSettings=None, allowDrag=False, dragAndDropType="DefconAppKitSelectedGlyphIndexesPboardType"): # placeholder attributes self._selectionCallback = None self._doubleClickTarget = None self._deleteCallback = deleteCallback self._dragAndDropType = dragAndDropType ## set up the list self._listEditChangingAttribute = None self._listEditChangingGlyph = None enableDelete = deleteCallback is not None if editCallback is not None: self._finalEditCallback = editCallback editCallback = self._listEditCallback # prep for drag and drop if selfDropSettings is not None: selfDropSettings = dict(selfDropSettings) if selfWindowDropSettings is not None: selfWindowDropSettings = dict(selfWindowDropSettings) if selfDocumentDropSettings is not None: selfDocumentDropSettings = dict(selfDocumentDropSettings) if selfApplicationDropSettings is not None: selfApplicationDropSettings = dict(selfApplicationDropSettings) if otherApplicationDropSettings is not None: otherApplicationDropSettings = dict(otherApplicationDropSettings) dropSettings = [ (selfDropSettings, self._selfDropCallback), (selfWindowDropSettings, self._selfWindowDropCallback), (selfDocumentDropSettings, self._selfDocumentDropCallback), (selfApplicationDropSettings, self._selfApplicationDropCallback), (otherApplicationDropSettings, self._otherApplicationDropCallback) ] for d, internalCallback in dropSettings: if d is None: continue d["type"] = dragAndDropType d["finalCallback"] = d["callback"] d["callback"] = internalCallback dragSettings = None if allowDrag: dragSettings = dict(type=dragAndDropType, callback=self._packListRowsForDrag) if listColumnDescriptions is None: listColumnDescriptions = [dict(title="Name", attribute="name")] super(GlyphCollectionView, self).__init__( posSize, [], columnDescriptions=listColumnDescriptions, editCallback=editCallback, selectionCallback=selectionCallback, doubleClickCallback=doubleClickCallback, showColumnTitles=listShowColumnTitles, enableTypingSensitivity=True, enableDelete=enableDelete, autohidesScrollers=False, selfDropSettings=selfDropSettings, selfWindowDropSettings=selfWindowDropSettings, selfDocumentDropSettings=selfDocumentDropSettings, selfApplicationDropSettings=selfApplicationDropSettings, otherApplicationDropSettings=otherApplicationDropSettings, dragSettings=dragSettings) self._keyToAttribute = {} self._orderedListKeys = [] self._wrappedListItems = {} for columnDescription in listColumnDescriptions: title = columnDescription["title"] key = columnDescription.get("key", title) attribute = columnDescription["attribute"] self._keyToAttribute[key] = attribute self._orderedListKeys.append(key) ## set up the cell view self._glyphCellView = self.glyphCellViewClass.alloc( ).initWithFrame_cellRepresentationName_detailWindowClass_( ((0, 0), (400, 400)), cellRepresentationName, glyphDetailWindowClass) self._glyphCellView.vanillaWrapper = weakref.ref(self) self._glyphCellView.setAllowsDrag_(allowDrag) dropTypes = [] for d in (selfDropSettings, selfWindowDropSettings, selfDocumentDropSettings, selfApplicationDropSettings, otherApplicationDropSettings): if d is not None: dropTypes.append(d["type"]) self._glyphCellView.registerForDraggedTypes_(dropTypes) ## set up the placard if showModePlacard: placardW = 34 placardH = 16 self._placard = vanilla.Group((0, 0, placardW, placardH)) self._placard.button = PlacardSegmentedButton( (0, 0, placardW, placardH), [ dict(imageNamed="defconAppKitPlacardCellImage", width=16), dict(imageNamed="defconAppKitPlacardListImage", width=18) ], callback=self._placardSelection, sizeStyle="mini") self._nsObject.setPlacard_(self._placard.getNSView()) else: self._placard = None ## tweak the scroll view self._nsObject.setBackgroundColor_(gridColor) ## table view tweak self._haveTweakedColumnWidths = initialMode == "list" ## set the mode self._mode = None self.setMode(initialMode)