def readConfig(mastername):
	GlyphsApp.Glyphs.clearLog()
	filepath = GlyphsApp.Glyphs.font.filepath
	if filepath is None:
		GlyphsApp.Message("Or I'm lost :(", "Please save the file first.", OKButton="OK")
		return None
	directory, glyphsfile = os.path.split(filepath)
	confpath = getConfigPath(directory, glyphsfile, mastername)
	array = []

	if os.path.isfile(confpath) == True:
		print("Config file exists\n")
	else :
		createFilePrompt = dialogs.askYesNo(\
			messageText='\nMissing config file for this font.',\
			informativeText='want to create one?')
		if createFilePrompt == 1:
			newFile = open(confpath,'w')
			newFile.write(DEFAULT_CONFIG_FILE)
			newFile.close()
		elif createFilePrompt == 0 or createFilePrompt == -1:
			GlyphsApp.Message("Error :(", "HT Letterspacer can't work without a config file", OKButton="OK")
			return None

	with open(confpath) as f:
		for line in f:
			if line[0] != '#' and len(line) > 5:
				newline = line.split(",")
				del newline[-1]
				newline[3] = float(newline[3])
				array.append(newline)
	return array
Example #2
0
	def addDelButtons(self, sender):
		try:
			# If it's an add button, ask for its name, and add an instance
			# if it's a delete button, give a warning, and delete the instance
			uiList = self.w.list
			values = [int((v[1]+v[2])/2) for v in av]

			if sender == self.w.add:
				newInstance = GSInstance()
				newInsName = AskString("Please name the new instance.", title="Creating New Instance")
				newInstance.active = True
				newInstance.name = newInsName
				newInstance.isItalic = False
				newInstance.isBold = False
				f.addInstance_(newInstance)
				newInstance.axes = values
				newInsParameters = { "Instance": "%s %s" % (f.familyName, newInsName), "WeightY": None }
				for i in range(len(self.usedAxisElements)):
					newInsParameters[self.usedAxisElements[i][0].get()] = int((av[i][1] + av[i][2])/2)
				insList.append(newInsParameters)
				uiList.append(newInsParameters)
			elif sender == self.w.delete:
				if askYesNo("Deleting Instance", 'Are you sure you want to delete the selected instance?', alertStyle=1, parentWindow=None, resultCallback=None):
					index = uiList.getSelection()[0]
					f.removeInstance_
					f.removeInstanceAtIndex_(index)
					del insList[index]
					del uiList[index]
				else:
					pass
		except Exception, e:
			Glyphs.showMacroWindow()
			print "Instance Slider Error (addDelButtons): %s" % e
def readConfig():
    directory, glyphsfile = os.path.split(Glyphs.font.filepath)
    conffile = glyphsfile.split('.')[0] + "_autospace.py"
    confpath = os.path.join(directory, conffile)
    array = []

    if os.path.isfile(confpath) == True:
        print 'Config file exists'
    else:
        createFilePrompt = dialogs.askYesNo(\
         messageText='\nMissing config file for this font.',\
         informativeText='want to create one?')
        if createFilePrompt == 1:
            newFile = open(confpath, 'w')
            newFile.write(defaultConfigFile)
            newFile.close()
        elif createFilePrompt == 0 or createFilePrompt == -1:
            Message("Error :(",
                    "HT Letterspacer can't work without a config file",
                    OKButton="OK")
            return None

    with open(confpath) as f:
        for line in f:
            if line[0] != '#' and len(line) > 5:
                newline = line.split(",")
                del newline[-1]
                newline[3] = float(newline[3])
                array.append(newline)
    return array
	def addDelButtons(self, sender):
		try:
			# If it's an add button, ask for its name, and add an instance
			# if it's a delete button, give a warning
			uiList = self.w.list
			if sender == self.w.add:
				newInstance = GSInstance()
				newInsName = AskString("Please name the new instance.", title="Creating New Instance")
				newInstance.active = True
				newInstance.name = newInsName
				newInstance.weightValue = weMin
				newInstance.widthValue = wiMin
				newInstance.customValue = csMin
				newInstance.isItalic = False
				newInstance.isBold = False
				font.addInstance_(newInstance)
				insList.append({"Instance": "%s %s" % (font.familyName, newInsName), "Weight": weMin, "Width": wiMin, "Custom": csMin, "WeightY": None})
				uiList.append({"Instance": "%s %s" % (font.familyName, newInsName), "Weight": weMin, "Width": wiMin, "Custom": csMin, "WeightY": None})
			elif sender == self.w.delete:
				if askYesNo("Deleting Instance", 'Are you sure you want to delete the selected instance?', alertStyle=1, parentWindow=None, resultCallback=None):
					index = uiList.getSelection()[0]
					font.removeInstanceAtIndex_(index)
					del insList[index]
					del uiList[index]
				else:
					pass
		except Exception, e:
			# brings macro window to front and reports error:
			Glyphs.showMacroWindow()
			print "Instance Slider Error (addDelButtons): %s" % e
 def addDelButtons(self, sender):
     try:
         # If it's an add button, ask for its name, and add an instance
         # if it's a delete button, give a warning, and delete the instance
         uiList = self.w.list
         if sender == self.w.add:
             newInstance = GSInstance()
             newInsName = AskString("Please name the new instance.",
                                    title="Creating New Instance")
             newInstance.active = True
             newInstance.name = newInsName
             newInstance.weightValue = weMin
             newInstance.widthValue = wiMin
             newInstance.customValue = csMin
             newInstance.isItalic = False
             newInstance.isBold = False
             font.addInstance_(newInstance)
             insList.append({
                 "Instance":
                 "%s %s" % (font.familyName, newInsName),
                 "Weight":
                 weMin,
                 "Width":
                 wiMin,
                 "Custom":
                 csMin,
                 "WeightY":
                 None
             })
             uiList.append({
                 "Instance":
                 "%s %s" % (font.familyName, newInsName),
                 "Weight":
                 weMin,
                 "Width":
                 wiMin,
                 "Custom":
                 csMin,
                 "WeightY":
                 None
             })
         elif sender == self.w.delete:
             if askYesNo(
                     "Deleting Instance",
                     'Are you sure you want to delete the selected instance?',
                     alertStyle=1,
                     parentWindow=None,
                     resultCallback=None):
                 index = uiList.getSelection()[0]
                 font.removeInstanceAtIndex_(index)
                 del insList[index]
                 del uiList[index]
             else:
                 pass
     except Exception, e:
         Glyphs.showMacroWindow()
         print "Instance Slider Error (addDelButtons): %s" % e
Example #6
0
	def optionTasks( self, sender ): # variety of stuff tabs[0].option has to do
		try:
			favNameList = self.favNameList()
			index = sender.get()
			global lastIndex
			emptyList = [{" ":"1", "Left":"", "Right":"", "Add Flipped":False, "Pair Count":0}]
			if not "lastIndex" in globals(): # only the case with first access
				lastIndex = 8
			if index == 1: # New Set
				lastIndex = 1
				self.w.tabs[0].permList.set(emptyList)
				self.refreshSectionPreview(0)
				self.w.tabs[0].options.set(0)
			elif index == 2: # Save Set in Favourites
				if lastIndex == 1:
					setName = AskString("Save As:", title="Save Pair List")
				else:
					setName = favNameList[lastIndex-8]
				self.SavePreferences(setName, False) # deleteBool = False
				self.refreshOptions()
				favNameList = self.favNameList()
				self.w.tabs[0].options.set(favNameList.index(setName)+8)
				lastIndex = favNameList.index(setName)+8
			elif index == 3: # Save Set in Favourites As...
				newName = AskString("Save As:", title="Save Pair List")
				if newName == "": #exists already or empty, or None:
					self.w.tabs[0].options.set(lastIndex)
				elif newName in favDic:
					Glyphs.displayDialog_("A set with the same name already exists.")
					self.w.tabs[0].options.set(lastIndex)
				else:
					self.SavePreferences(newName, False) # deleteBool = False
					self.refreshOptions()
					favNameList = self.favNameList()
					self.w.tabs[0].options.set(favNameList.index(newName)+8)
			elif index == 4: # Delete Set from Favourites...
				lastName = favNameList[lastIndex-8]
				if len(favNameList)==1:
					Glyphs.displayDialog_("Actually, you can't empty the Favourites list.\nSorry for my incompetent coding.")
				else:
					if askYesNo(messageText='Are you sure you want to delete "%s"?' % lastName, alertStyle=1,) == 1:
						self.SavePreferences(lastName, True) # deleteBool = True
						self.refreshOptions()
						self.w.tabs[0].permList.set(emptyList)
						self.w.tabs[0].options.set(0)
					else:
						self.w.tabs[0].options.set(lastIndex)
			elif index == 5: # Copy Set As Flat Text
				self.BubbleKernMain(sender)
				self.w.tabs[0].options.set(lastIndex)
			elif index >= 8: # if one of Favourites
				lastIndex = index
				self.favDicToList(favNameList[index-8])
		except Exception, e:
			Glyphs.showMacroWindow()
			print "BubbleKern Error (optionTasks): %s" % e
Example #7
0
 def fontPopUpCallback(self, sender):
     if self._compareLibsToList() is False:
         result = askYesNo(
             'Some changes were not pushed into font, would you like to do it now? Otherwise the changes will be lost'
         )
         if bool(result) is True:
             self.pushIntoFontButtonCallback(sender=None)
     self.selectedFont = self.allFonts[sender.get()]
     links = loadLinksFromFont(self.selectedFont)
     self.w.linksList.set(links)
Example #8
0
	def optionTasks( self, sender ): # variety of stuff tabs[0].option has to do
		try:
			favNameList = self.favNameList()
			index = sender.get()
			global lastIndex
			emptyList = [{" ":"1", "Left":"", "Right":"", "Add Flipped":False, "Pair Count":0}]
			if not "lastIndex" in globals(): # only the case with first access
				lastIndex = 8
			if index == 1: # New Set
				self.w.tabs[0].permList.set(emptyList)
				self.refreshSectionPreview(0)
				self.w.tabs[0].options.set(0)
			elif index == 2: # Save Set in Favourites
				lastName = favNameList[lastIndex-8]
				self.SavePreferences(lastName, False) # deleteBool = False
				self.w.tabs[0].options.set(lastIndex)
			elif index == 3: # Save Set in Favourites As...
				newName = AskString("Save As:", title="Save Pair List")
				if newName == "": #exists already or empty, or None:
					self.w.tabs[0].options.set(lastIndex)
				elif newName in favDic:
					Glyphs.displayDialog_("A set with the same name already exists.")
					self.w.tabs[0].options.set(lastIndex)
				else:
					self.SavePreferences(newName, False) # deleteBool = False
					self.refreshOptions()
					favNameList = self.favNameList()
					self.w.tabs[0].options.set(favNameList.index(newName)+8)
			elif index == 4: # Delete Set from Favourites...
				lastName = favNameList[lastIndex-8]
				if len(favNameList)==1:
					Glyphs.displayDialog_("Actually, you can't empty the Favourites list.\nSorry for my incompetent coding.")
				else:
					if askYesNo(messageText='Are you sure you want to delete "%s"?' % lastName, alertStyle=1,) == 1:
						self.SavePreferences(lastName, True) # deleteBool = True
						self.refreshOptions()
						self.w.tabs[0].permList.set(emptyList)
						self.w.tabs[0].options.set(0)
					else:
						self.w.tabs[0].options.set(lastIndex)
			elif index == 5: # Copy Set As Flat Text
				self.BubbleKernMain(sender)
				self.w.tabs[0].options.set(lastIndex)
			elif index >= 8: # if one of Favourites
				lastIndex = index
				self.favDicToList(favNameList[index-8])
		except Exception, e:
			Glyphs.showMacroWindow()
			print "BubbleKern Error (optionTasks): %s" % e
Example #9
0
    def servantGlyphChanged(self, notification):
        glyph = notification.object
        warningMessage = 'The glyph <{servantName}> is linked to <{masterName}>, do you want to broke the link?'

        if PLUGIN_LIB_NAME in glyph.lib:
            thisLib = glyph.lib[PLUGIN_LIB_NAME]

            if thisLib['lftActive'] is True:
                lftMaster = self.selectedFont[thisLib['lft']]
                if glyph.leftMargin != lftMaster.leftMargin:
                    result = askYesNo(
                        'Warning',
                        warningMessage.format(servantName=glyph.name,
                                              masterName=lftMaster.name))
                    if bool(result) is False:
                        glyph.leftMargin = lftMaster.leftMargin
                        thisLib['lftActive'] = True
                    else:
                        thisLib['lftActive'] = False

            if thisLib['rgtActive'] is True:
                rgtMaster = self.selectedFont[thisLib['rgt']]
                if glyph.rightMargin != rgtMaster.rightMargin:
                    result = askYesNo(
                        'Warning',
                        warningMessage.format(servantName=glyph.name,
                                              masterName=rgtMaster.name))
                    if bool(result) is False:
                        glyph.rightMargin = rgtMaster.rightMargin
                        thisLib['rgtActive'] = True
                    else:
                        thisLib['rgtActive'] = False

            links = loadLinksFromFont(self.selectedFont)
            self.w.linksList.set(links)
        self.w.canvas.update()
Example #10
0
 def delRecipe(self, sender):
     self.currentRecipe = self.font.lib['morf']['recipes'].keys()[
         self.w.recipe.get()]
     answer = askYesNo(messageText="Really want to DELETE recipe: %s" %
                       self.currentRecipe,
                       informativeText="No undo here!")
     if answer:
         #pass
         del self.font.lib['morf']['recipes'][self.currentRecipe]
         self.font.update()
         for g in self.font:
             if 'morf' in g.lib.keys():
                 for k in g.lib['morf'].keys():
                     if k == self.currentRecipe:
                         del g.lib['morf'][k]
                         g.update()
     self.w.recipe.setItems(self.font.lib['morf']['recipes'].keys())
     self.mainFunction({"glyph": CurrentGlyph()})
Example #11
0
    def addDelButtons(self, sender):
        try:
            # If it's an add button, ask for its name, and add an instance
            # if it's a delete button, give a warning, and delete the instance
            uiList = self.w.list
            values = [int((v[1] + v[2]) / 2) for v in av]

            if sender == self.w.add:
                newInstance = GSInstance()
                newInsName = AskString("Please name the new instance.",
                                       title="Creating New Instance")
                newInstance.active = True
                newInstance.name = newInsName
                newInstance.isItalic = False
                newInstance.isBold = False
                f.addInstance_(newInstance)
                newInstance.axes = values
                newInsParameters = {
                    "Instance": "%s %s" % (f.familyName, newInsName),
                    "WeightY": None
                }
                for i in range(len(self.usedAxisElements)):
                    newInsParameters[self.usedAxisElements[i][0].get()] = int(
                        (av[i][1] + av[i][2]) / 2)
                insList.append(newInsParameters)
                uiList.append(newInsParameters)
            elif sender == self.w.delete:
                if askYesNo(
                        "Deleting Instance",
                        'Are you sure you want to delete the selected instance?',
                        alertStyle=1,
                        parentWindow=None,
                        resultCallback=None):
                    index = uiList.getSelection()[0]
                    f.removeInstance_
                    f.removeInstanceAtIndex_(index)
                    del insList[index]
                    del uiList[index]
                else:
                    pass
        except Exception as e:
            Glyphs.showMacroWindow()
            print("Instance Slider Error (addDelButtons): %s" % e)
Example #12
0
def createArchiveYesNo():
    return askYesNo("No archive folder exists", "A new folder named _archive will be created for the saved file. Continue?")
Example #13
0
    def __init__(self, willOpen=True):
        super(SidebearingsLinker, self).__init__()

        # collecting fonts
        self.allFonts = AllFonts()
        if self.allFonts != []:
            self.selectedFont = self.allFonts[0]

        # interface
        self.w = FloatingWindow((PLUGIN_WIDTH, PLUGIN_HEIGHT), PLUGIN_TITLE)

        jumpingY = MARGIN_VER
        self.w.fontPopUp = PopUpButton(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['PopUpButtonRegularHeight']),
            getNamesFrom(self.allFonts),
            callback=self.fontPopUpCallback)

        jumpingY += vanillaControlsSize['PopUpButtonRegularHeight'] + MARGIN_ROW
        self.w.canvas = CanvasGroup(
            (MARGIN_HOR, jumpingY, NET_WIDTH, CANVAS_HEIGHT), delegate=self)

        jumpingY += CANVAS_HEIGHT + MARGIN_ROW
        linksColumnDescriptions = [{
            "title": "left",
            'key': 'lft',
            'width': LIST_WIDE_COL
        }, {
            "title": "active",
            "cell": CheckBoxListCell(),
            'key': 'lftActive',
            'width': LIST_NARROW_COL
        }, {
            "title": "glyph",
            'key': 'servant',
            'width': LIST_WIDE_COL,
            "editable": False
        }, {
            "title": "active",
            "cell": CheckBoxListCell(),
            'key': 'rgtActive',
            'width': LIST_NARROW_COL
        }, {
            "title": "right",
            'key': 'rgt',
            'width': LIST_WIDE_COL
        }]

        if self.selectedFont is not None:
            links = loadLinksFromFont(self.selectedFont)
        else:
            links = []

        self.w.linksList = List(
            (MARGIN_HOR, jumpingY, NET_WIDTH, 200),
            links,
            showColumnTitles=False,
            allowsMultipleSelection=False,
            drawVerticalLines=True,
            columnDescriptions=linksColumnDescriptions,
            selectionCallback=self.selectionLinksListCallback,
            editCallback=self.editLinksListCallback)

        if self.selectedFont is not None:
            self.w.linksList.setSelection([0])
            self.currentRow = self.w.linksList[0]
            self.matchDisplayedSubscriptions()

        jumpingY += self.w.linksList.getPosSize()[3] + MARGIN_ROW
        buttonWidth = (NET_WIDTH - MARGIN_HOR) / 2
        self.w.linkAllButton = SquareButton(
            (MARGIN_HOR, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Link All',
            callback=self.linkAllButtonCallback)

        self.w.unlockAllButton = SquareButton(
            (MARGIN_HOR * 2 + buttonWidth, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Unlink All',
            callback=self.unlockAllButtonCallback)

        jumpingY += vanillaControlsSize[
            'ButtonRegularHeight'] * 1.5 + MARGIN_ROW
        self.w.separationLineOne = HorizontalLine(
            (MARGIN_HOR, jumpingY, NET_WIDTH,
             vanillaControlsSize['HorizontalLineThickness']))

        jumpingY += MARGIN_ROW
        self.w.pushIntoFontButton = SquareButton(
            (MARGIN_HOR, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Push into font',
            callback=self.pushIntoFontButtonCallback)
        self.w.pushIntoFontButton.enable(False)

        self.w.clearLibsButton = SquareButton(
            (MARGIN_HOR * 2 + buttonWidth, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Clear Libs',
            callback=self.clearLibsButtonCallback)

        jumpingY += vanillaControlsSize[
            'ButtonRegularHeight'] * 1.5 + MARGIN_ROW
        self.w.loadFromTable = SquareButton(
            (MARGIN_HOR, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Load from table',
            callback=self.loadFromTableCallback)
        self.w.loadFromTable.enable(True)

        self.w.exportTable = SquareButton(
            (MARGIN_HOR * 2 + buttonWidth, jumpingY, buttonWidth,
             vanillaControlsSize['ButtonRegularHeight'] * 1.5),
            'Export table',
            callback=self.exportTableCallback)
        self.w.exportTable.enable(True)

        jumpingY += vanillaControlsSize[
            'ButtonRegularHeight'] * 1.5 + MARGIN_VER * 2
        self.w.resize(PLUGIN_WIDTH, jumpingY)

        self.setUpBaseWindowBehavior()

        if self.selectedFont is not None:
            self.matchSubscriptions()
            result = askYesNo('Warning',
                              'Do you want to align servants to masters?')
            if bool(result) is True:
                self._alignServantsToMasters()

        addObserver(self, "drawOnGlyphCanvas", "draw")
        addObserver(self, "drawOnGlyphCanvas", "drawInactive")
        addObserver(self, 'fontDidOpenCallback', 'fontDidOpen')
        addObserver(self, 'fontDidCloseCallback', 'fontDidClose')
        if willOpen is True:
            self.w.open()
Example #14
0
 def askYesNoSheet(self, sender):
     dialogs.askYesNo("Hello world",
                      "foo bar",
                      parentWindow=self.w,
                      resultCallback=self.dummyCallback)
Example #15
0
 def askYesNoCallback(self, sender):
     dialogs.askYesNo("Hello world",
                      "foo bar",
                      resultCallback=self.dummyCallback)
Example #16
0
 def askYesNo(self, sender):
     print("result", dialogs.askYesNo("Hello world", "foo bar"))