def makeWords(self, sender=None): global warned self.f = CurrentFont() self.fontChars = self.fontCharacters(self.f) self.wordCount = self.getIntegerValue(self.w.basicsBox.wordCount) self.minLength = self.getIntegerValue(self.w.basicsBox.minLength) self.maxLength = self.getIntegerValue(self.w.basicsBox.maxLength) self.case = self.w.basicsBox.case.get() self.requiredLetters = self.getInputString(self.w.reqBox.mustLettersBox, False) self.requiredGroups[0] = self.getInputString(self.w.reqBox.group1box, True) self.requiredGroups[1] = self.getInputString(self.w.reqBox.group2box, True) self.requiredGroups[2] = self.getInputString(self.w.reqBox.group3box, True) self.bannedLetters = self.getInputString(self.w.reqBox.notLettersBox, False) self.bannedLetters.append(" ") self.limitToCharset = self.w.optionsBox.checkbox0.get() self.banRepetitions = self.w.optionsBox.checkbox1.get() self.randomize = self.w.optionsBox.checkbox2.get() self.outputWords = [] #initialize/empty checker = wordChecker(self.limitToCharset, self.fontChars, self.requiredLetters, self.requiredGroups, self.bannedLetters, self.banRepetitions, self.minLength, self.maxLength) for i in self.allWords: if len(self.outputWords) >= self.wordCount: break else: if self.randomize: w = choice(self.allWords) else: w = i if self.case == 1: w = w.lower() elif self.case == 2: w = w.title() elif self.case == 3: w = w.upper() if checker.checkWord(w, self.outputWords): self.outputWords.append(w) # output if len(self.outputWords) < 1: print "word-o-mat: No matching words found <sad trombone>" else: outputString = " ".join(self.outputWords) try: sp = OpenSpaceCenter(CurrentFont()) sp.setRaw(outputString) except: print "word-o-mat:", outputString pass
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
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 = [] self.limitToCharset = self.g1.base.get() if self.limitToCharset == 2: # use selection if len(self.f.selection) == 0: # nothing selected Message(title="word-o-mat", message="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 g in self.f.selection: if g.unicode is not None: try: self.customCharset.append(unichr(int(g.unicode, 16))) except ValueError: pass except AttributeError: pass elif self.limitToCharset == 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(title="word-o-mat", message="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.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(title="word-o-mat", message="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(title="word-o-mat", message="No open fonts found; words will be displayed in the Output Window.") warned = True print("word-o-mat:", outputString) else: print("word-o-mat: Aborted because of errors")
def makeWords(self, sender=None): global warned self.f = CurrentFont() self.fontChars, self.glyphNames = self.fontCharacters(self.f) self.glyphNamesForValues = {self.fontChars[i]: self.glyphNames[i] for i in range(len(self.fontChars))} self.wordCount = self.getIntegerValue(self.basicsBox.wordCount) self.minLength = self.getIntegerValue(self.basicsBox.minLength) self.maxLength = self.getIntegerValue(self.basicsBox.maxLength) self.case = self.basicsBox.case.get() self.customCharset = [] charset = self.basicsBox.radioGroup.get() self.limitToCharset = True if charset == 0: self.limitToCharset = False else: if charset == 2: # use selection if len(self.f.selection) == 0: #nothing selected Message("No glyphs were selected in the font window. Word-o-mat will use any characters available in the font.") self.basicsBox.radioGroup.set(1) # use font chars else: try: #self.customCharset = self.f.selection # this just gives me the glyph names self.customCharset = [] for gname in self.f.selection: if self.f[gname].unicode is not None: # make sure this does what it should try: self.customCharset.append(unichr(int(self.f[gname].unicode))) except ValueError: pass #for entry in self.customCharset: # print entry except AttributeError: pass self.requiredLetters = self.getInputString(self.reqBox.mustLettersBox, False) self.requiredGroups[0] = self.getInputString(self.reqBox.group1box, True) self.requiredGroups[1] = self.getInputString(self.reqBox.group2box, True) self.requiredGroups[2] = self.getInputString(self.reqBox.group3box, True) self.banRepetitions = self.reqBox.checkbox0.get() self.outputWords = [] #initialize/empty self.source = self.basicsBox.source.get() languageCount = len(self.textfiles) if self.source == languageCount: # User Dictionary self.allWords = self.dictWords["user"] elif self.source == languageCount+1: # Custom word list try: if self.customWords != []: self.allWords = self.customWords else: self.allWords = self.dictWords["ukacd"] self.basicsBox.source.set(0) except AttributeError: self.allWords = self.dictWords["ukacd"] self.basicsBox.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 extDefaults = { "wordCount": self.wordCount, "minLength": self.minLength, "maxLength": self.maxLength, "case": self.case, "limitToCharset": self.writeExtDefaultBoolean(self.limitToCharset), "source": self.source, } 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 = wordChecker(self.limitToCharset, self.fontChars, self.customCharset, self.requiredLetters, self.requiredGroups, self.banRepetitions, self.minLength, self.maxLength) 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: w = w.title() elif self.case == 3: 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.reqBox.delimiterRadio.get() == 1: if self.reqBox.listOutput.get() == True: joinString = "\\n" self.outputWords = self.sortWordsByWidth(self.outputWords) ##### NEW / EXPERIMENTAL FEATURE outputString = joinString.join(self.outputWords) try: sp = OpenSpaceCenter(CurrentFont()) sp.setRaw(outputString) except: if warned == False: Message("No open fonts found; word-o-mat will output to the Output Window.") warned = True print "word-o-mat:", outputString else: print "word-o-mat: Aborted because of errors"