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 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 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)
Beispiel #4
0
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