def showThisGlyphInSC_CB(self, sender): if CurrentSpaceCenter() is None: spaceCenter = OpenSpaceCenter(self.glyph.font) spaceCenter.set([self.glyphBelowName]) else: scGlyphs = CurrentSpaceCenter().get() spaceCenter = OpenSpaceCenter(self.glyph.font) spaceCenter.set(scGlyphs + [self.glyphBelowName])
def setSpaceCenter(self, font, text): currentSC = CurrentSpaceCenter() if currentSC is None: print('opening space center, click back into MM window') OpenSpaceCenter(font, newWindow=False) currentSC = CurrentSpaceCenter() currentSC.setRaw(text)
def showAllPairs(self, sender=None): # open all resulting pairs in Space Center rawString = "" for g1, g2 in self.touchingPairs: rawString += "/%s/%s/space" % (g1, g2) s = OpenSpaceCenter(self.f) s.setRaw(rawString)
def openTab(self, aString): aString = aString[1:] if CurrentSpaceCenter(): CurrentSpaceCenter().set(aString) else: OpenSpaceCenter(CurrentFont(), newWindow=True) CurrentSpaceCenter().set(aString)
def tofuButtonCallback(self, sender): self.outputText = self.inputText noBueno = self.tofuText self.updateFont() if self.ucCheck == 1: self.outputText = self.inputText.upper() noBueno = noBueno.upper() if self.lcCheck == 1: self.outputText = self.inputText.lower() noBueno = noBueno.lower() if self.digitCheck == 1: noBueno += s.digits if self.punctCheck == 1: noBueno += s.punctuation + "‘’“”«»".decode("utf-8") self.outputText = removeExtraSpaces("".join( letter for letter in self.outputText if letter not in noBueno)) # outputText = outputText.translate(None, noBueno) self.w.outputText.set(self.outputText) if self.copyToSCCheck == 1 and self.outputText != "": try: OpenSpaceCenter(self.font, newWindow=False) sc = CurrentSpaceCenter() sc.setRaw(self.outputText) except AttributeError: Message("You need a font to copy to Space Center")
def makeWords(self, sender=None): """Parse user input, save new values to prefs, compile and display the resulting words. I think this function is too long and bloated, it should be taken apart. ######## """ global warned self.f = CurrentFont() if self.f is not None: self.fontChars, self.glyphNames = self.fontCharacters(self.f) self.glyphNamesForValues = { self.fontChars[i]: self.glyphNames[i] for i in range(len(self.fontChars)) } else: self.fontChars = [] self.glyphNames = [] self.wordCount = self.getIntegerValue(self.g1.wordCount) self.minLength = self.getIntegerValue(self.g1.minLength) self.maxLength = self.getIntegerValue(self.g1.maxLength) self.case = self.g1.case.get() self.customCharset = [] charset = self.g1.base.get() self.limitToCharset = True if charset == 0: self.limitToCharset = False elif charset == 2: # use selection if len(self.f.selection) == 0: # nothing selected Message( "word-o-mat: No glyphs were selected in the font window. Will use any characters available in the current font." ) self.g1.base.set(1) # use font chars else: try: self.customCharset = [] for gname in self.f.selection: if self.f[gname].unicode is not None: try: self.customCharset.append( unichr(int(self.f[gname].unicode))) except ValueError: pass except AttributeError: pass elif charset == 3: # use mark color c = self.g1.colorWell.get() if c is None: pass elif c.className( ) == "NSCachedWhiteColor": # not set, corresponds to mark color set to None c = None self.customCharset = [] self.reqMarkColor = (c.redComponent(), c.greenComponent(), c.blueComponent(), c.alphaComponent()) if c is not None else None for g in self.f: if g.mark == self.reqMarkColor: try: self.customCharset.append(unichr(int(g.unicode))) except: pass if len(self.customCharset) == 0: Message( "word-o-mat: Found no glyphs that match the specified mark color. Will use any characters available in the current font." ) self.g1.base.set(1) # use font chars self.toggleColorSwatch(0) self.matchMode = "text" if self.g2.matchMode.get( ) == 0 else "grep" # braucht es diese zeile noch? self.requiredLetters = self.getInputString( self.g2.textMode.mustLettersBox, False) self.requiredGroups[0] = self.getInputString( self.g2.textMode.group1box, True) self.requiredGroups[1] = self.getInputString( self.g2.textMode.group2box, True) self.requiredGroups[2] = self.getInputString( self.g2.textMode.group3box, True) self.matchPattern = self.g2.grepMode.grepBox.get() self.banRepetitions = self.g3.checkbox0.get() self.outputWords = [] # initialize/empty self.source = self.g1.source.get() languageCount = len(self.textfiles) if self.source == languageCount: # User Dictionary self.allWords = self.dictWords["user"] elif self.source == languageCount + 1: # Use all languages for i in range(languageCount): # if any language: concatenate all the wordlists self.allWords.extend(self.dictWords[self.textfiles[i]]) elif self.source == languageCount + 2: # Custom word list try: if self.customWords != []: self.allWords = self.customWords else: self.allWords = self.dictWords["ukacd"] self.g1.source.set(0) except AttributeError: self.allWords = self.dictWords["ukacd"] self.g1.source.set(0) else: # language lists for i in range(languageCount): if self.source == i: self.allWords = self.dictWords[self.textfiles[i]] # store new values as defaults markColorPref = self.reqMarkColor if self.reqMarkColor is not None else "None" extDefaults = { "wordCount": self.wordCount, "minLength": self.minLength, "maxLength": self.maxLength, "case": self.case, "limitToCharset": self.writeExtDefaultBoolean(self.limitToCharset), "source": self.source, "matchMode": self.matchMode, "matchPattern": self.matchPattern, # non compiled string "markColor": markColorPref, } for key, value in extDefaults.iteritems(): setExtensionDefault("com.ninastoessinger.word-o-mat." + key, value) # go make words if self.checkInput(self.limitToCharset, self.fontChars, self.customCharset, self.requiredLetters, self.minLength, self.maxLength, self.case) == True: checker = wordcheck.wordChecker(self.limitToCharset, self.fontChars, self.customCharset, self.requiredLetters, self.requiredGroups, self.matchPatternRE, self.banRepetitions, self.minLength, self.maxLength, matchMode=self.matchMode) for i in self.allWords: if len(self.outputWords) >= self.wordCount: break else: w = choice(self.allWords) if self.case == 1: w = w.lower() elif self.case == 2: # special capitalization rules for Dutch IJ # this only works when Dutch is selected as language, not "any". try: ijs = ["ij", "IJ", "Ij"] if self.languageNames[ self.source] == "Dutch" and w[:2] in ijs: wNew = "IJ" + w[2:] w = wNew else: w = w.title() except IndexError: w = w.title() elif self.case == 3: # special capitalization rules for German double s if u"ß" in w: w2 = w.replace(u"ß", "ss") w = w2 w = w.upper() if checker.checkWord(w, self.outputWords): self.outputWords.append(w) # output if len(self.outputWords) < 1: Message("word-o-mat: no matching words found <sad trombone>") else: joinString = " " if self.g3.listOutput.get() == True: joinString = "\\n" self.outputWords = self.sortWordsByWidth(self.outputWords) outputString = joinString.join(self.outputWords) try: sp = OpenSpaceCenter(CurrentFont()) sp.setRaw(outputString) except: if warned == False: Message( "word-o-mat: No open fonts found; words will be displayed in the Output Window." ) warned = True print "word-o-mat:", outputString
# # 2015 Benedikt Bramböck # @arialcrime # ######################################################### from mojo.UI import OpenSpaceCenter import collections, random, string, os cities = open('cities.txt', 'r') letters = string.uppercase azcities = '' alphabetdict = collections.defaultdict(list) for city in cities: city = city[:-1] alphabetdict[city[0].upper()].append(city) #print alphabet for l in letters: add = random.choice(alphabetdict[l]) + ' ' azcities += add # Copy list of cities to clipboard # os.system("echo '%s' | pbcopy" % azcities) print azcities sp = OpenSpaceCenter(CurrentFont()) sp.setRaw(azcities)
def openSpaceCenter(self, sender): self._canUpdateChangeCount = False OpenSpaceCenter(self._font) self._canUpdateChangeCount = True
def openClusterInSpaceCenterCallback(self, sender): spaceCenter = OpenSpaceCenter(self.glyph.font) spaceCenter.set([glyph.glyph.name for glyph in self.glyphList])
def getText(self): if CurrentFont() is None: NSBeep() self.showMessage("Open a font first.", "") return if not self.isConnected(): NSBeep() self.showMessage("Required internet connection not found.", "") return values = { 'chars': self.w.chars.get().encode('utf-8'), 'script': scriptsTagDict[scriptsNameList[self.w.scriptsPopup.get()]], 'tb': langsTagDict[langsNameDict[scriptsNameList[ self.w.scriptsPopup.get()]][self.w.langsPopup.get()]] } if self.w.punctCheck.get(): values['punct'] = True if self.w.figsCheck.get(): values['figs'] = True if self.w.figsPopup.isVisible(): figsOptTagsList = ["dflt", "locl"] values['figsOpt'] = figsOptTagsList[self.w.figsPopup.get()] if self.w.trimCheck.get() and self.w.trimCheck.isEnable(): values['trim'] = True if self.w.caseCheck.get() and self.w.caseCheck.isEnable(): values['case'] = True if self.w.casingCheck.get() and self.w.casingCheck.isEnable(): values['casing'] = casingNameList[self.w.casingPopup.get()].lower() data = urlencode(values) data = data.encode('utf-8') print(data) request = Request(url, data) response = urlopen(request) text = response.read() textU = unicode(text, 'utf-8') if (msgStr in textU): textU = textU.replace(msgStr, "") NSBeep() self.showMessage(textU, "") return elif (wrnStr in textU): resultIndex = textU.find(rsltStr) secmsgIndex = textU.find(sndStr) frstmsgU = textU[:secmsgIndex].replace(wrnStr, "") scndmsgU = textU[secmsgIndex:resultIndex].replace(sndStr, "") textU = textU[resultIndex:].replace(rsltStr, "") NSBeep() self.showMessage(frstmsgU, scndmsgU) textList = textU.split() trimmedText = ' '.join(textList[:int(self.w.slider.get())]) if CurrentSpaceCenter() is None: OpenSpaceCenter(CurrentFont(), newWindow=False) sp = CurrentSpaceCenter() print(trimmedText) sp.setRaw(trimmedText) # Toggle RTL-LTR try: sp.setLeftToRight(not self.scriptIsRTL) sp.setInputWritingDirection( 'Right to Left' if self.scriptIsRTL else 'Left to Right') except AttributeError: pass return