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 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'))
Exemple #3
0
    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'))
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