def createUI(self): self.window = CurrentFontWindow() if self.window is None: return toolbarItems = self.window.getToolbarItems() self.newToolbarItems = list() newItem1 = dict(itemIdentifier="Search", label="Search", imageNamed=NSImageNameRevealFreestandingTemplate, callback=self.popSearchWindow); self.newToolbarItems.append(newItem1); newItem2_1 = dict(itemIdentifier="Rewind", label="Rewind", imageNamed=NSImageNameRefreshFreestandingTemplate, callback=self.restoreAttribute); self.newToolbarItems.append(newItem2_1); newItem2_2 = dict(itemIdentifier="Undo", label="Undo", imageNamed=NSImageNameInvalidDataFreestandingTemplate, callback=self.rollbackAttribute); self.newToolbarItems.append(newItem2_2); newItem3 = dict(itemIdentifier="Save", label="Save", imageNamed=NSImageNameComputer, callback=None); self.newToolbarItems.append(newItem3); newItem4 = dict(itemIdentifier="Exit", label="Exit", imageNamed=NSImageNameStopProgressFreestandingTemplate, callback=self.windowCloseCallback); self.newToolbarItems.append(newItem4); newItem5 = dict(itemIdentifier="Settings", label="Settings", imageNamed=NSImageNameAdvanced, callback=self.popSettingWindow); self.newToolbarItems.append(newItem5); newItem6 = dict(itemIdentifier="Attribute", label="Attribute", imageNamed=NSImageNameFontPanel, callback=self.popAttributeWindow); self.newToolbarItems.append(newItem6); newItem7 = dict(itemIdentifier="Help", label="Help", imageNamed=NSImageNameInfo, callback=self.popManualWindow); self.newToolbarItems.append(newItem7); newItem8 = dict(itemIdentifier="Except", label="Except", imageNamed=NSImageNameTrashFull, callback=self.handleRemoveGlyph); self.newToolbarItems.append(newItem8); #기존 툴바에 새로운 툴바 아이템 추가 for i in range(len(self.newToolbarItems)): toolbarItems.append(self.newToolbarItems[i]) # 현재 폰트 창에 toolbarItems를 추가 vanillaWindow = self.window.window() self.window.toolbar = vanillaWindow.addToolbar(toolbarIdentifier="myCustomToolbar", toolbarItems=toolbarItems, addStandardItems=False) addObserver(self, "drawBroadNibBackground", "drawBackground")
def resize(self, sender): SWM = getDefault("singleWindowMode") fw = CurrentFontWindow() fo = fw.fontOverview gc = fo.getGlyphCollection() v = gc.getGlyphCellView() # make cells small first starter = 10 v.setCellSize_([starter, starter]) # get the width of the whole window x, y, w, h = fw.window().getPosSize() # get the width of overall font overview fo_w = fo.getNSView().frameSize().width # get the width of the cell view vw, vh = v.frameSize().width, v.frameSize().height # get the width of the sets menu to the left of the font overview sets_w = fo_w - vw # get number of glyphs num_g = len(gc.getGlyphNames()) cells_across = 1 cw = int(vw / cells_across) while ((num_g) / cells_across) * cw > vh: cells_across += 1 cw = ch = int(vw / cells_across) vw = cw * cells_across fo_total_w = vw + sets_w # set frame size in single window mode if SWM == 1: fw.editor.splitView.setDimension('fontOverview', fo_total_w) fw.editor.splitView.setDimension('glyphView', w - fo_total_w) fw.centerGlyphInView() # set frame size in multi-window mode else: windows = NSApp().orderedWindows() (x, y), (w, h) = windows[0].frame() x_diff = w - fo_total_w windows[0].setFrame_display_animate_( ((x + x_diff, y), (fo_total_w, h)), True, False) # change the cell size once and for all, update the slider to reflect the change v.setCellSize_([cw, ch]) fo.views.sizeSlider.set(cw) # set this as the new default cell size (this happens when you use the native slide too) setDefault("fontCollectionViewGlyphSize", int(cw))
def callbackCatNameSelect(self, sender): f = CurrentFont() items = [] fontUniValues = [] if f is not None: fontUniValues = list(set([g.unicode for g in f])) glyphSelection = [] self.currentSelection = [] for i in sender.getSelection(): thisCat = self.catNames[i] for glyph in self.dataByCategory[thisCat]: if glyph not in glyphSelection: glyphSelection.append(glyph) items = [g.asDict(self._unicodes, self._names, self.joiningTypes) for g in sorted(glyphSelection, key=lambda x:str(x))] sortedItems = sorted(items, key=lambda x: x['uni'], reverse=False) items = sorted(items, key=lambda x: x['uni'], reverse=False) self.w.selectedNames.set(sortedItems) selectedUniNumbers = ["%d"%it['uni'] for it in items if it['uni'] in fontUniValues] if selectedUniNumbers: query = "Unicode in {%s}"%",".join(selectedUniNumbers) queryObj = NSPredicate.predicateWithFormat_(query) CurrentFontWindow().getGlyphCollection().setQuery(queryObj)
def callback(self, sender): w = CurrentFontWindow() if w: f = CurrentFont() fileName = None if f.path: fileName, ext = os.path.splitext(os.path.basename(f.path)) stamp = datetime.datetime.now().strftime("(%Y%m%d_%H%M%S)") fileName = "%s-%s%s" % (fileName, stamp, ext) dialogs.putFile(title="Save a Copy as..", fileName=fileName, fileTypes=["ufo"], parentWindow=w.window(), resultCallback=self.saveCopy)
def didOpen(self, notification): window = CurrentFontWindow() if window is None: return toolbarItems = window.getToolbarItems() toolbarIcon = NSImage.alloc().initByReferencingFile_(os.path.join(self.base_path, "icon.pdf")) newItem = dict( itemIdentifier='radialguides', label='Radial Guides', imageObject=toolbarIcon, view=toolbarIcon, callback=self.openSheet ) index=-2 toolbarItems.insert(index, newItem) vanillaWindow = window.window() vanillaWindow.addToolbar( toolbarIdentifier='radialguides', toolbarItems=toolbarItems, addStandardItems=False )
def windowClosing(self, sender): # Reset the font window glyph collection query CurrentFontWindow().getGlyphCollection().setQuery(None)
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()
class EditGroupMenu(object): def __init__(self,groupDict,jsonFileName1,jsonFileName2): self.font = getExtensionDefault(DefaultKey + ".font") self.groupDict = groupDict self.defaultKey = "com.asaumierdemers.BroadNibBackground" self.markColor = 0.3, 0.4, 0.7, 0.7 self.layerName = self.font.layerOrder[0] self.currentPen = None self.window = None # 현재 띄워져 있는 ufo 윈도우 self.w = list() for i in range(7): self.w.append(None) self.mode = None # 연산 방법(matrix, topology) self.jsonFileName1 = jsonFileName1 self.jsonFileName2 = jsonFileName2 self.createUI() self.testPath = getExtensionDefault(DefaultKey+".testPath") self.color = None self.step = None self.width = None self.height = None self.shape = None self.angle = None self.keyDict = None """ UI 컴포넌트 부착 """ def createUI(self): self.window = CurrentFontWindow() if self.window is None: return toolbarItems = self.window.getToolbarItems() self.newToolbarItems = list() newItem1 = dict(itemIdentifier="Search", label="Search", imageNamed=NSImageNameRevealFreestandingTemplate, callback=self.popSearchWindow); self.newToolbarItems.append(newItem1); newItem2_1 = dict(itemIdentifier="Rewind", label="Rewind", imageNamed=NSImageNameRefreshFreestandingTemplate, callback=self.restoreAttribute); self.newToolbarItems.append(newItem2_1); newItem2_2 = dict(itemIdentifier="Undo", label="Undo", imageNamed=NSImageNameInvalidDataFreestandingTemplate, callback=self.rollbackAttribute); self.newToolbarItems.append(newItem2_2); newItem3 = dict(itemIdentifier="Save", label="Save", imageNamed=NSImageNameComputer, callback=None); self.newToolbarItems.append(newItem3); newItem4 = dict(itemIdentifier="Exit", label="Exit", imageNamed=NSImageNameStopProgressFreestandingTemplate, callback=self.windowCloseCallback); self.newToolbarItems.append(newItem4); newItem5 = dict(itemIdentifier="Settings", label="Settings", imageNamed=NSImageNameAdvanced, callback=self.popSettingWindow); self.newToolbarItems.append(newItem5); newItem6 = dict(itemIdentifier="Attribute", label="Attribute", imageNamed=NSImageNameFontPanel, callback=self.popAttributeWindow); self.newToolbarItems.append(newItem6); newItem7 = dict(itemIdentifier="Help", label="Help", imageNamed=NSImageNameInfo, callback=self.popManualWindow); self.newToolbarItems.append(newItem7); newItem8 = dict(itemIdentifier="Except", label="Except", imageNamed=NSImageNameTrashFull, callback=self.handleRemoveGlyph); self.newToolbarItems.append(newItem8); #기존 툴바에 새로운 툴바 아이템 추가 for i in range(len(self.newToolbarItems)): toolbarItems.append(self.newToolbarItems[i]) # 현재 폰트 창에 toolbarItems를 추가 vanillaWindow = self.window.window() self.window.toolbar = vanillaWindow.addToolbar(toolbarIdentifier="myCustomToolbar", toolbarItems=toolbarItems, addStandardItems=False) addObserver(self, "drawBroadNibBackground", "drawBackground") def popManualWindow(self,sender): manual = extPath.resourcePath + "manual.html" HelpWindow(htmlPath=manual) def popSettingWindow(self, sender): if self.w[5] is not None and self.w[5].w is not None: self.w[5].w.close() self.w[5] = settingWindow(self) def popAttributeWindow(self, sender): # Window for Assign & Remove Attribute mode = getExtensionDefault(DefaultKey + ".mode") contourNumber = getExtensionDefault(DefaultKey + ".contourNumber") if mode is None or contourNumber is None: Message("먼저 속성을 부여할 그룹을 찾아야 합니다.") return if self.w[3] is not None and self.w[3].w is not None: self.w[3].w.close() print("self.w[3].w = ", self.w[3].w) self.w[3] = attributeWindow() def popSearchWindow(self, sender): # Window for Matrix & Topology Process if self.w[4] is not None and self.w[4].w is not None: self.w[4].w.close() self.w[4] = toolsWindow() print("created") def handleRemoveGlyph(self, sender): """ 스마트 셋 없이 처리하는 경우 """ smartSetRefresh() groupDict = getExtensionDefault(DefaultKey+".groupDict") keyList = list(groupDict.keys()) for glyph in keyList: if glyph.selected is True: del groupDict[glyph] setExtensionDefault(DefaultKey+".groupDict", groupDict) def windowCloseCallback(self, sender): try: removeObserver(self, "drawBackground") super(BroadNibBackground, self).windowCloseCallback(sender) except Exception as e: print(e) currentToolbarItems = self.window.getToolbarItems() for i in range(len(self.newToolbarItems)): currentToolbarItems.pop() self.window.setToolbar() for i in range(len(self.w)): if self.w[i] is not None: self.w[i].w.close() del self def restoreAttribute(self, sender): restoreStack = getExtensionDefault(DefaultKey + ".restoreStack") if restoreStack is None or restoreStack.isEmpty() is True: restoreStack.print() Message("더 이상 되돌릴 수 없습니다.") return top = restoreStack.pop() if top is None: restoreStack.print() Message("더 이상 되돌릴 수 없습니다.") return for element in top: element[0].name = element[1] restoreStack.print() CurrentFont().update() CurrentFont().save(self.testPath) def rollbackAttribute(self, sender): restoreStack = getExtensionDefault(DefaultKey + ".restoreStack") if restoreStack is None or restoreStack.front == restoreStack.rear: restoreStack.print() Message("복원할 수 없습니다.") return target = restoreStack.rollback() if target is None: Message("복원할 수 없습니다.") return for element in target: element[0].name = element[1] restoreStack.print() CurrentFont().update() CurrentFont().save(self.testPath) def drawBroadNibBackground(self, info): # 칠할 필요가 없다면 종료 state = getExtensionDefault(DefaultKey+".state") if bool(state) is not True: return # paint current group's contour targetGlyph = info["glyph"].getLayer(self.layerName) # picks current contours which should be painted from current group contourList = [] try : targetIdxList = getExtensionDefault(DefaultKey+".groupDict")[targetGlyph] setExtensionDefault(DefaultKey + ".contourNumber", targetIdxList[0]) color = getExtensionDefault(DefaultKey+".color") r,g,b,a = color fill(r,g,b,a) step = getExtensionDefault(DefaultKey+".step"); width = getExtensionDefault(DefaultKey+".width"); height = getExtensionDefault(DefaultKey+".height"); if info["glyph"].layerName == self.layerName or not self.currentPen: self.currentPen = BroadNibPen(None, step, width, height, 0, oval) for idx in targetIdxList: targetGlyph.contours[idx].draw(self.currentPen) except Exception as e: setExtensionDefault(DefaultKey + ".contourNumber", None) return