def test1_single(self):
        """Test a single converter in the pool."""
        self.addConverter(CONV_NAME)
        inputStr = "abCde"
        convPool = ConvPool(self.userVars, self.msgbox)
        conv_settings = ConverterSettings(self.userVars)
        conv_settings.convName = CONV_NAME
        conv_settings.forward = True
        SelectSettingsCache.converter = conv_settings
        dummy_fontChange = convPool.selectConverter(conv_settings)
        sec_call = convPool[CONV_NAME]
        convertedVal = sec_call.convert(inputStr)
        self.assertEqual(convertedVal, "ABCDE")
        self.assertEqual(len(convPool._secCallObjs), 1)

        conv_settings = ConverterSettings(self.userVars)
        conv_settings.convName = CONV_NAME
        conv_settings.forward = False
        sec_call = convPool.loadConverter(conv_settings)
        convertedVal = sec_call.convert(inputStr)
        self.assertEqual(convertedVal, "abcde")
        self.assertEqual(len(convPool._secCallObjs), 1)

        with self.assertRaises(KeyError):
            sec_call = convPool["doesn't exist"]
    def test2_double(self):
        """Test two converters in the pool."""
        self.addConverter(CONV_NAME)
        inputStr = "abCde"
        convPool = ConvPool(self.userVars, self.msgbox)
        conv_settings1 = ConverterSettings(self.userVars)
        conv_settings1.convName = CONV_NAME
        conv_settings1.forward = False
        SelectSettingsCache.converter = conv_settings1
        # This calls our modified funcSelectConverter() above,
        # which tells the ConvPool what EncConverters actually
        # contains after test1_single().
        dummy_fontChange = convPool.selectConverter(conv_settings1)

        conv_settings1 = ConverterSettings(self.userVars)
        conv_settings1.convName = CONV_NAME
        conv_settings1.forward = True
        sec_call1 = convPool.loadConverter(conv_settings1)
        convertedVal = sec_call1.convert(inputStr)
        self.assertEqual(convertedVal, "ABCDE")

        CONV_NAME2 = "Any-Lower"
        self.addConverter(CONV_NAME2)
        conv_settings2 = ConverterSettings(self.userVars)
        conv_settings2.convName = CONV_NAME2
        with self.assertRaises(KeyError):
            sec_call2 = convPool[CONV_NAME2]
        convPool.loadConverter(conv_settings2)
        sec_call2 = convPool[CONV_NAME2]
        convertedVal = sec_call2.convert(inputStr)
        self.assertEqual(convertedVal, "abcde")
        self.assertEqual(len(convPool._secCallObjs), 2)
        self.assertEqual(sec_call1.convert("f"), "F")
        self.assertEqual(sec_call2.convert("G"), "g")
    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 #4
0
    def loadValues(self, userVars, paraStyleDispNames, charStyleDispNames):
        converter = ConverterSettings(userVars)
        converter.loadUserVars()
        self.txtConverterName.setText(converter.convName)
        self.chkDirectionReverse.setState(not converter.forward)
        self.chkVerify.setState(
            userVars.getInt('AskEachChange'))

        ## Option buttons

        dutil.selectRadio(self.radiosWhichScope, userVars.get('WhichScope'))
        dutil.selectRadio(self.radiosWhichTarget, userVars.get('WhichTarget'))
        dutil.selectRadio(self.radiosScopeFont, userVars.get('ScopeFontType'))
        dutil.selectRadio(
            self.radiosTargetFont, userVars.get('TargetFontType'))

        ## Combo box lists

        ComboTuple = collections.namedtuple(
            'ComboTuple', ['ctrl', 'varname', 'data'])
        self.combos = [
            ComboTuple(ctrl=self.comboScopeParaStyle,
                       varname='ScopeParaStyle',
                       data=paraStyleDispNames),
            ComboTuple(ctrl=self.comboScopeCharStyle,
                       varname='ScopeCharStyle',
                       data=charStyleDispNames),
            ComboTuple(ctrl=self.comboScopeFont,
                       varname='ScopeFont',
                       data=styles.getListOfFonts(self.unoObjs)),
            ComboTuple(ctrl=self.comboTargetParaStyle,
                       varname='TargetParaStyle',
                       data=paraStyleDispNames),
            ComboTuple(ctrl=self.comboTargetCharStyle,
                       varname='TargetCharStyle',
                       data=charStyleDispNames)]
        for combo in self.combos:
            dutil.fill_list_ctrl(
                combo.ctrl, combo.data, userVars.get(combo.varname))

        dutil.fill_list_ctrl(
            self.listTargetStyleFont,
            styles.getListOfFonts(self.unoObjs, addBlank=True))
        logger.debug("Finished populating font and styles lists.")

        ## Other fields

        varname = 'SFM_Markers'
        if userVars.isEmpty(varname):
            defaultCtrlText = "\\tx \\mb"
            userVars.store(varname, defaultCtrlText)
            userVarVal = defaultCtrlText
        else:
            userVarVal = userVars.get(varname)
        self.txtSFM.setText(userVarVal)
        self.addRemainingListeners()
 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
Exemple #6
0
    def loadValues(self, userVars):
        converter = ConverterSettings(userVars)
        converter.loadUserVars()
        self.txtConverterName.setText(converter.convName)
        self.chkDirectionReverse.setState(not converter.forward)

        ## Other fields

        self.txtSourceCol.setText(userVars.get("ConvSourceColumn"))
        self.txtTargetCol.setText(userVars.get("ConvTargetColumn"))

        varname = "SkipFirstRow"
        if not userVars.isEmpty(varname):
            self.chkSkipRow.setState(userVars.getInt(varname))
Exemple #7
0
 def getFormResults(self):
     """
     Reads form fields and stores user vars.
     returns: converter settings
     """
     logger.debug(util.funcName('begin'))
     converter = ConverterSettings(self.userVars)
     converter.loadUserVars()  # for normForm
     converter.convName = self.dlgCtrls.txtConverterName.getText()
     converter.forward = (self.dlgCtrls.chkDirectionReverse.getState() == 0)
     converter.storeUserVars()
     self.sourceCol = self.dlgCtrls.txtSourceCol.getText()
     self.targetCol = self.dlgCtrls.txtTargetCol.getText()
     self.skipFirstRow = bool(self.dlgCtrls.chkSkipRow.getState())
     self.userVars.store("ConvSourceColumn", self.sourceCol)
     self.userVars.store("ConvTargetColumn", self.targetCol)
     self.userVars.store("SkipFirstRow",
                         str(self.dlgCtrls.chkSkipRow.getState()))
     logger.debug(util.funcName('end'))
     return converter
 def test1_toUpper(self):
     """Keep it simple here -- a first test to see if basic conversion
     is working.
     Also tests the reverse checkbox.
     """
     convName = "capsTest.tec"
     self.addConverter(convName)
     textContent = "abCde\rFghI jkl"
     for reverse in False, True:
         self.setTextContent(textContent)
         func = self._test1_make_useDialog(reverse, convName)
         self.runDlg(func)
         expectedContent = textContent.replace("\r", "\r\n")
         if reverse:
             expectedContent = expectedContent.lower()
         else:
             expectedContent = expectedContent.upper()
         self.verifyTextContent(expectedContent)
     # Set converter settings to default.
     conv = ConverterSettings(self.dlg.userVars)
     conv.storeUserVars()
    def loadValues(self, userVars):
        converter = ConverterSettings(userVars)
        converter.loadUserVars()
        self.txtConverterName.setText(converter.convName)
        self.chkDirectionReverse.setState(not converter.forward)
        self.chkVerify.setState(
            userVars.getInt('AskEachChange'))

        ## Option buttons

        dutil.selectRadio(self.radiosWhichScope, userVars.get('WhichScope'))
        dutil.selectRadio(self.radiosWhichTarget, userVars.get('WhichTarget'))
        dutil.selectRadio(self.radiosScopeFont, userVars.get('ScopeFontType'))
        dutil.selectRadio(
            self.radiosTargetFont, userVars.get('TargetFontType'))

        ## Combo box lists

        ComboTuple = collections.namedtuple(
            'ComboTuple', ['ctrl', 'varname', 'data'])
        self.combos = [
            ComboTuple(ctrl=self.comboScopeFont,
                       varname='ScopeFont',
                       data=styles.getListOfFonts(self.unoObjs))]
        for combo in self.combos:
            logger.debug("Filling Scope Font list.")
            #XXX: Sometimes hangs here.
            dutil.fill_list_ctrl(
                combo.ctrl, combo.data, userVars.get(combo.varname))

        logger.debug("Filling Target Font list.")
        dutil.fill_list_ctrl(
            self.listTargetFont,
            styles.getListOfFonts(self.unoObjs, addBlank=True))
        logger.debug("Finished populating font and styles lists.")

        ## Other fields

        self.addRemainingListeners()