def loadValues(self, userVars): scriptNames = sorted(list(unicode_data.SCRIPT_LETTERS.keys())) selectedValue = userVars.get("Script") if not selectedValue: selectedValue = "DEVANAGARI" dutil.fill_list_ctrl(self.comboScript, scriptNames, selectedValue) selectedValue = userVars.get("Font") if selectedValue: self.comboFont.setText(selectedValue) else: self.comboFont.setText("") self.chkKnownFonts.setState(userVars.getInt("OnlyKnownFonts")) self.setFontList() fontSize = FontSize(default=DEFAULT_FONT_SIZE) fontSize.loadUserVar(userVars, 'FontSize') fontSize.changeCtrlVal(self.txtFontSize) for chk in self.checkboxVarList: if userVars.isEmpty(chk.varname): chk.ctrl.setState(True) else: chk.ctrl.setState(userVars.getInt(chk.varname)) self.addRemainingListeners()
def selectTargetFont(self, control, styleType): """Selects the font based on the value specified in the control. If control is None (for initialization or testing), gets values from user variables instead. """ logger.debug(util.funcName('begin')) listCtrl = self.dlgCtrls.listTargetStyleFont # shorthand variable listValues = listCtrl.Items if control: fontType = 'Western' if self.dlgCtrls.optTargetFontComplex.getState() == 1: fontType = 'Complex' elif self.dlgCtrls.optTargetFontAsian.getState() == 1: fontType = 'Asian' displayName = control.getText() try: if styleType == 'Paragraph': styleName = self.paraStyleNames[displayName] elif styleType == 'Character': styleName = self.charStyleNames[displayName] except KeyError: # Perhaps a new style to be created logger.debug("%s is not a known style.", displayName) return fontName, fontSize = self.styleFonts.getFontOfStyle( styleType, fontType, styleName) else: fontName = self.userVars.get('TargetFontName') fontSize = FontSize() fontSize.loadUserVar(self.userVars, 'TargetFontSize') if fontName and fontName in listValues: listCtrl.selectItem(fontName, True) else: listCtrl.selectItemPos(0, True) fontSize.changeCtrlVal(self.dlgCtrls.txtFontSize)
def selectTargetFont(self): """Selects the font from user variables.""" logger.debug(util.funcName('begin')) listCtrl = self.dlgCtrls.listTargetFont # shorthand variable listValues = listCtrl.Items fontName = self.userVars.get('TargetFontName') fontSize = FontSize() fontSize.loadUserVar(self.userVars, 'TargetFontSize') if fontName and fontName in listValues: listCtrl.selectItem(fontName, True) else: listCtrl.selectItemPos(0, True) fontSize.changeCtrlVal(self.dlgCtrls.txtFontSize)
def loadValues(self, userVars, questions): logger.debug(util.funcName('begin')) if not userVars.isEmpty("CharSet"): self.script.setCharsetFromInput(userVars.get("CharSet")) self.charsetAlreadySet = True ## Option buttons whichSource = userVars.get("WhichSource") if whichSource == "Generate": self.optGenerate.setState(True) elif whichSource == "Wordlist": self.optWordlist.setState(True) whenToCheck = userVars.get("WhenToCheck") if whenToCheck == "Space": self.optCheckTypeSpace.setState(True) questions.waitForSpace = True elif whenToCheck == "LastChar": self.optCheckAtLastChar.setState(True) questions.waitForSpace = False ## Combo box lists logger.debug("Populating script and fonts lists") varname = "OnlyKnownFonts" if userVars.isEmpty(varname): self.chkKnownFonts.setState(True) else: self.chkKnownFonts.setState(userVars.getInt(varname)) scriptNames = sorted(list(unicode_data.SCRIPT_LETTERS.keys())) selectedValue = userVars.get("Script") if not selectedValue: selectedValue = "LATIN" dutil.fill_list_ctrl(self.comboScript, scriptNames, selectedValue) self.changeScript() selectedValue = userVars.get("Font") if selectedValue: self.comboFont.setText(selectedValue) self.changeFont() ## Other fields logger.debug("Loading other field values from user vars") syllableSize = userVars.getInt("SyllableSize") if syllableSize < 1 or syllableSize > 3: syllableSize = 2 self.listSyllableSize.selectItem(str(syllableSize), True) numSyllables = userVars.getInt("NumSyllables") if numSyllables < 1 or numSyllables > 9: numSyllables = 1 self.txtNumSyllables.setText(str(numSyllables)) numWords = userVars.getInt("NumWords") if numWords < 1 or numWords > 50: numWords = 1 self.txtNumWords.setText(str(numWords)) fontSize = FontSize(default=30.0) fontSize.loadUserVar(userVars, 'FontSize') fontSize.changeCtrlVal(self.txtFontSize) self.changeFontSize() self.enableDisable() self.addRemainingListeners() logger.debug(util.funcName('end'))
class StyleChange(StyleInfo, Syncable): """A structure to hold form data for changing one font.""" def __init__(self, style_from, userVars, varNum=0): """ :param style_from: StyleItem being converted from :param userVars: for persistent storage :param varNum: a user variable number unique to this change """ StyleInfo.__init__(self) Syncable.__init__(self, userVars) self.styleItem = style_from self.varNum = varNum # for storage in user variables self.converter = ConverterSettings(userVars) self.converted_data = dict() # key inputString, value convertedString self.remove_custom_formatting = True def setVarNum(self, varNum): self.varNum = varNum def varNumStr(self): """Many user variables for the class contain this substring, based on enumerating the font items. Specify varNum before calling this method. """ return "%03d" % self.varNum def numberedVar(self, suffix=""): """Get a user variable name that includes the file number. :param suffix: Add this to the end of the string. """ return "font%s_%s" % (self.varNumStr(), suffix) def loadUserVars(self): self.styleItem.fontName = self.userVars.get( self.numberedVar("fontNameFrom")) self.styleItem.styleDisplayName = self.userVars.get( self.numberedVar("styleNameFrom")) if not self.styleItem.fontName and not self.styleItem.styleDisplayName: raise self.noUserVarData(self.numberedVar("fontNameFrom")) self.fontName = self.userVars.get(self.numberedVar("fontNameTo")) self.styleDisplayName = self.userVars.get( self.numberedVar("styleNameTo")) self.fontType = self.userVars.get(self.numberedVar("fontType")) self.size = FontSize() if not self.userVars.isEmpty(self.numberedVar("size")): self.size.loadUserVar(self.userVars, self.numberedVar("size")) self.styleType = self.userVars.get(self.numberedVar("styleType")) self.styleDisplayName = self.userVars.get( self.numberedVar("styleName")) self.converter.convName = self.userVars.get( self.numberedVar("convName")) self.converter.normForm = self.userVars.getInt( self.numberedVar("normalize")) varname = self.numberedVar('forward') if (not self.userVars.isEmpty(varname) and self.userVars.getInt(varname) == 0): self.converter.forward = False varname = self.numberedVar('removeCustomFormatting') if (not self.userVars.isEmpty(varname) and self.userVars.getInt(varname) == 0): self.remove_custom_formatting = False def storeUserVars(self): """Sets the user vars for this item.""" fontNameFrom = self.styleItem.fontName if fontNameFrom == "(None)": fontNameFrom = None #TESTME self.userVars.store(self.numberedVar("fontNameFrom"), fontNameFrom) self.userVars.store(self.numberedVar("fontNameTo"), self.fontName) self.userVars.store( self.numberedVar("styleNameFrom"), self.styleItem.styleDisplayName) self.userVars.store( self.numberedVar("styleNameTo"), self.styleDisplayName) self.userVars.store(self.numberedVar("fontType"), self.fontType) self.userVars.store(self.numberedVar("styleType"), self.styleType) if self.size.isSpecified(): self.userVars.store( self.numberedVar('size'), self.size.getString()) self.userVars.store( self.numberedVar("convName"), self.converter.convName) self.userVars.store( self.numberedVar('forward'), str(int(self.converter.forward))) self.userVars.store( self.numberedVar("normalize"), str(self.converter.normForm)) self.userVars.store( self.numberedVar('removeCustomFormatting'), str(int(self.remove_custom_formatting))) def cleanupUserVars(self): """Returns True if something was cleaned up.""" foundSomething1 = self.userVars.delete( self.numberedVar("fontNameFrom")) foundSomething2 = self.userVars.delete( self.numberedVar("styleNameFrom")) self.userVars.delete(self.numberedVar("fontNameTo")) self.userVars.delete(self.numberedVar("styleNameTo")) self.userVars.delete(self.numberedVar("fontType")) self.userVars.delete(self.numberedVar('size')) self.userVars.delete(self.numberedVar("styleType")) self.userVars.delete(self.numberedVar("convName")) self.userVars.delete(self.numberedVar('forward')) self.userVars.delete(self.numberedVar("normalize")) self.userVars.delete(self.numberedVar('removeCustomFormatting')) return foundSomething1 or foundSomething2