def __init__(self, scopeType, named): StyleItem.__init__(self, scopeType) self.styleInternalName = "" # with _20_ instead of spaces self.fontStandard = "(Default)" # could be non-Unicode Devanagari self.fontComplex = "(Default)" # CTL fonts such as Unicode Devanagari self.fontAsian = "(Default)" # Chinese, Japanese, Korean (CJK) fonts self.sizeStandard = FontSize() self.sizeComplex = FontSize() self.sizeAsian = FontSize() self.named = named # True = named style, False = automatic style
def getFormResults(self): """Reads form fields and gets settings.""" logger.debug(util.funcName('begin')) charcompString = self.dlgCtrls.txtCharComp.getText() self.app.setCharCompFromInput(charcompString) self.userVars.store("CharComparison", charcompString) ## Font name and size fontName = self.dlgCtrls.comboFont.getText() if fontName == "(None)": fontName = None fontSize = FontSize(default=DEFAULT_FONT_SIZE) fontSize.loadCtrl(self.dlgCtrls.txtFontSize) self.userVars.store('Font', fontName) self.userVars.store('FontSize', fontSize.getString()) self.userVars.store("OnlyKnownFonts", str(self.dlgCtrls.chkKnownFonts.getState())) self.userVars.store("Script", self.dlgCtrls.comboScript.getText()) ## Checkbox var list for chk in self.dlgCtrls.checkboxVarList: self.userVars.store(chk.varname, str(chk.ctrl.getState())) logger.debug(util.funcName('end'))
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 __init__(self): self.fontName = "" self.fontType = 'Western' # 'Western' (Standard), 'Complex' or 'Asian' self.size = FontSize() self.styleType = StyleType.NO_CHANGE self.styleDisplayName = "" # for example "Default Style" self.styleName = "" # underlying name of styleDisplayName, "Standard"
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 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 getFontOfStyle(self, styleFamilyName='', fontType='', styleName=None, styleKey=None): """ :param styleFamilyName: 'Paragraph' or 'Character' :param fontType: 'Western', 'Asian', or 'Complex' :param styleName: for example "Default" or "Heading 1" :param styleKey: for example 'word1' but see _setStyleKey() :returns: font name and size of the specified type """ logger.debug(util.funcName( 'begin', args=(styleFamilyName, fontType, styleName, styleKey))) styleKey = self._setStyleKey(styleName, styleKey) styleFamily = self.parastyles if styleFamilyName == 'Character': styleFamily = self.charstyles propSuffix = fontType if propSuffix == 'Western': propSuffix = '' fontSize = FontSize(propSuffix=propSuffix) if styleKey in styleFamily: styleObj = styleFamily.styleObjs.getByName(styleName) fontName = styleObj.getPropertyValue('CharFontName%s' % propSuffix) fontSize.loadElemProp(styleObj) return fontName, fontSize return "", fontSize
def getFormResults(self): """Reads form fields and sets self.config and self.converter. In setAndVerifyConfig() in app layer, the settings will be checked for inconsistencies. """ logger.debug(util.funcName('begin')) ## Converter self.converter = ConverterSettings(self.userVars) self.converter.loadUserVars() # for normForm self.converter.convName = self.dlgCtrls.txtConverterName.getText() self.converter.forward = ( self.dlgCtrls.chkDirectionReverse.getState() == 0) self.converter.storeUserVars() ## Radio buttons and the corresponding combo box selection self.config = ConversionSettings() searchConfig = self.config.searchConfig # shorthand name self.config.whichScope = dutil.whichSelected( self.dlgCtrls.radiosWhichScope) self.userVars.store('WhichScope', self.config.whichScope) if self.config.whichScope == 'Font': searchConfig.fontName = self.dlgCtrls.comboScopeFont.getText() searchConfig.fontType = dutil.whichSelected( self.dlgCtrls.radiosScopeFont) self.userVars.store('ScopeFontType', searchConfig.fontType) searchConfig.load_userVars(self.userVars) self.config.whichTarget = dutil.whichSelected( self.dlgCtrls.radiosWhichTarget) self.userVars.store('WhichTarget', self.config.whichTarget) ## Target font targetFontName = self.dlgCtrls.listTargetFont.getSelectedItem() if targetFontName == "(None)": targetFontName = None targetFontSize = FontSize() targetFontSize.loadCtrl(self.dlgCtrls.txtFontSize) if self.config.whichTarget == 'Font': self.userVars.store('TargetFontName', targetFontName) self.userVars.store('TargetFontSize', targetFontSize.getString()) targetFontType = dutil.whichSelected( self.dlgCtrls.radiosTargetFont) self.userVars.store('TargetFontType', targetFontType) self.config.targetFont = styles.FontDefStruct( targetFontName, targetFontType, targetFontSize) self.config.askEach = (self.dlgCtrls.chkVerify.getState() == 1) ## Save selections for next time for combo in self.dlgCtrls.combos: self.userVars.store(combo.varname, combo.ctrl.getText()) self.userVars.store('AskEachChange', str(self.dlgCtrls.chkVerify.getState())) logger.debug(util.funcName('end'))
def __init__(self, fontName="", fontType='Western', fontSize=None): """ :param fontName: for example "Times New Roman" :param fontType: Western, Complex or Asian :param fontSize: type utils.fontsize.FontSize """ self.fontName = fontName self.fontType = fontType if not fontSize: fontSize = FontSize() self.fontSize = fontSize
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 _read_font_size(self, styleItem, textprop): """Modifies styleItem and self.stylesDict.""" has_props = False for xmlAttr, styleItemAttr, fontType in [ ("style:font-size-asian", 'sizeAsian', 'Asian'), ("style:font-size-complex", 'sizeComplex', 'Complex'), ("fo:font-size", 'sizeStandard', 'Western') ]: fontSize = textprop.getAttribute(xmlAttr) if fontSize and fontSize.endswith("pt"): fontSize = fontSize[:-len("pt")] propSuffix = fontType if propSuffix == 'Western': propSuffix = "" fontSizeObj = FontSize(fontSize, propSuffix, True) styleItem.size = fontSizeObj styleItem.fontType = fontType setattr(styleItem, styleItemAttr, fontSizeObj) has_props = True return has_props
class FontDefStruct: def __init__(self, fontName="", fontType='Western', fontSize=None): """ :param fontName: for example "Times New Roman" :param fontType: Western, Complex or Asian :param fontSize: type utils.fontsize.FontSize """ self.fontName = fontName self.fontType = fontType if not fontSize: fontSize = FontSize() self.fontSize = fontSize FONT_ORTH = FontDefStruct("Mangal", "Complex", FontSize(14.0, spec=True)) FONT_VERN = FontDefStruct("Doulos SIL", "Western", FontSize(14.0, spec=True)) FONT_GLOSS = FontDefStruct("Times New Roman", "Western", FontSize(12.0, spec=True)) FONT_FIXED = FontDefStruct("Courier New", "Western", FontSize(12.0, spec=True)) class DocumentStyles: """Abstract base class for managing the styles in a document.""" styleVars = [] defaultNames = {} def __init__(self, unoObjs, userVars): if self.__class__ is DocumentStyles: # The base class should not be instantiated. raise NotImplementedError()
class FontDefStruct: def __init__(self, fontName="", fontType='Western', fontSize=None): """ :param fontName: for example "Times New Roman" :param fontType: Western, Complex or Asian :param fontSize: type utils.fontsize.FontSize """ self.fontName = fontName self.fontType = fontType if not fontSize: fontSize = FontSize() self.fontSize = fontSize FONT_ORTH = FontDefStruct( "Mangal", "Complex", FontSize(14.0, spec=True)) FONT_VERN = FontDefStruct( "Doulos SIL", "Western", FontSize(14.0, spec=True)) FONT_GLOSS = FontDefStruct( "Times New Roman", "Western", FontSize(12.0, spec=True)) FONT_FIXED = FontDefStruct( "Courier New", "Western", FontSize(12.0, spec=True)) class DocumentStyles: """Abstract base class for managing the styles in a document.""" styleVars = [] defaultNames = {} def __init__(self, unoObjs, userVars): if self.__class__ is DocumentStyles:
def changeFontSize(self): fontSize = FontSize(default=30.0) fontSize.loadCtrl(self.txtFontSize) for txctrl in (self.txtCharset, self.txtQuestion, self.txtAnswer): fontSize.changeCtrlProp(txctrl)
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'))
def getFormResults(self): """Reads form fields and sets app configuration.""" logger.debug(util.funcName('begin')) config = scriptpractice.PracticeSettings() charsetString = self.dlgCtrls.txtCharset.getText() self.script.setCharsetFromInput(charsetString) self.userVars.store("CharSet", charsetString) self.questions.setConfig(config, self.wordList) ## Radio buttons and the corresponding combo box selection self.whichSource = "" if self.dlgCtrls.optGenerate.getState(): self.whichSource = "Generate" elif self.dlgCtrls.optWordlist.getState(): self.whichSource = "Wordlist" self.userVars.store("WhichSource", config.whichSource) config.whichSource = self.whichSource ## Font name and size fontName = self.dlgCtrls.comboFont.getText() if fontName == "(None)": fontName = None fontSize = FontSize(default=30.0) fontSize.loadCtrl(self.dlgCtrls.txtFontSize) self.userVars.store('Font', fontName) self.userVars.store('FontSize', fontSize.getString()) self.userVars.store("Script", self.dlgCtrls.comboScript.getText()) self.userVars.store("OnlyKnownFonts", str(self.dlgCtrls.chkKnownFonts.getState())) ## Syllable and Word size strval = self.dlgCtrls.listSyllableSize.getSelectedItem() try: val = int(strval) except ValueError: val = 2 if val < 1 or val > 3: val = 2 config.syllableSize = val self.userVars.store("SyllableSize", str(val)) strval = self.dlgCtrls.txtNumSyllables.getText() try: val = int(strval) except ValueError: val = 1 self.dlgCtrls.txtNumSyllables.setText(str(val)) if val < 1 or val > 9: val = 1 self.dlgCtrls.txtNumSyllables.setText(str(val)) config.numSyllables = val self.userVars.store("NumSyllables", str(val)) strval = self.dlgCtrls.txtNumWords.getText() try: val = int(strval) except ValueError: val = 1 self.dlgCtrls.txtNumWords.setText(str(val)) if val < 1 or val > 50: val = 1 self.dlgCtrls.txtNumWords.setText(str(val)) config.numWords = val self.userVars.store("NumWords", str(val)) logger.debug(util.funcName('end'))
def update_change(self, styleChange): styleChange.size = FontSize(propSuffix=styleChange.getPropSuffix()) styleChange.size.loadCtrl(self.txtFontSize)
def changeFontSize(self): fontSize = FontSize(default=DEFAULT_FONT_SIZE) fontSize.loadCtrl(self.txtFontSize) fontSize.changeCtrlProp(self.txtCharComp)