예제 #1
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()
class DlgDataConversion:
    """Main class for this dialog."""

    def __init__(self, drawingUnoObjs):
        self.unoObjs = drawingUnoObjs
        finder = uservars.SettingsDocFinder(
            uservars.Prefix.DATA_CONV_DRAW, self.unoObjs)
        writerUnoObjs = finder.getWriterDoc()
        self.userVars = uservars.UserVars(
            uservars.Prefix.DATA_CONV_DRAW, writerUnoObjs.document, logger)
        self.msgbox = MessageBox(self.unoObjs)
        self.styleFonts = styles.StyleFonts(self.unoObjs)
        self.app = DataConversion(self.unoObjs, self.userVars, self.styleFonts)
        self.dlgCtrls = None
        self.evtHandler = None
        self.config = None
        self.converter = None
        self.convertOnClose = False
        self.dlgClose = None

    def showDlg(self):
        logger.debug(util.funcName(obj=self))
        dlg = dutil.createDialog(self.unoObjs, _dlgdef)
        if not dlg:
            return
        ctrl_getter = dutil.ControlGetter(dlg)
        self.evtHandler = DlgEventHandler(self)
        self.dlgCtrls = None
        self.dlgCtrls = DlgControls(
            self.unoObjs, ctrl_getter, self.evtHandler)
        self.evtHandler.setCtrls(self.dlgCtrls)

        logger.debug("Getting styles...")
        self.dlgCtrls.loadValues(self.userVars)
        self.dlgCtrls.enableDisable(self)

        ## Display the dialog

        self.dlgClose = dlg.endExecute
        dlg.execute()

        if self.convertOnClose:
            self.app.doConversions_draw()
        dlg.dispose()

    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 selectConverter(self):
        logger.debug(util.funcName('begin'))
        logger.debug("Selecting a converter...")
        converter = self.app.selectConverter()
        self.dlgCtrls.txtConverterName.setText(converter.convName)
        self.dlgCtrls.chkDirectionReverse.setState(not converter.forward)

    def noConverter(self):
        logger.debug(util.funcName('begin'))
        logger.debug("Clearing converter...")
        self.dlgCtrls.txtConverterName.setText("<No converter>")

    def closeAndConvert(self):
        logger.debug(util.funcName('begin'))
        logger.debug("Closing and Converting...")
        self.getFormResults()
        try:
            self.app.setAndVerifyConverter(self.converter)
            self.app.setAndVerifyConfig(self.config)
            self.convertOnClose = True
            self.dlgClose()
        except (exceptions.ChoiceProblem, exceptions.StyleError) as exc:
            self.msgbox.displayExc(exc)

    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'))
예제 #4
0
class DlgDataConversion:
    """Main class for this dialog."""

    def __init__(self, unoObjs):
        self.unoObjs = unoObjs
        self.userVars = uservars.UserVars(
            uservars.Prefix.DATA_CONVERSION, unoObjs.document, logger)
        self.msgbox = MessageBox(unoObjs)
        self.styleFonts = styles.StyleFonts(unoObjs)
        self.app = DataConversion(unoObjs, self.userVars, self.styleFonts)
        self.dlgCtrls = None
        self.evtHandler = None
        self.charStyleNames = []
        self.paraStyleNames = []
        self.config = None
        self.converter = None
        self.convertOnClose = False
        self.dlgClose = None

    def showDlg(self):
        logger.debug(util.funcName(obj=self))
        dlg = dutil.createDialog(self.unoObjs, _dlgdef)
        if not dlg:
            return
        ctrl_getter = dutil.ControlGetter(dlg)
        self.evtHandler = DlgEventHandler(self)
        self.dlgCtrls = None
        self.dlgCtrls = DlgControls(
            self.unoObjs, ctrl_getter, self.evtHandler)
        self.evtHandler.setCtrls(self.dlgCtrls)

        logger.debug("Getting styles...")
        styleNames = styles.getListOfStyles('ParagraphStyles', self.unoObjs)
        self.paraStyleNames = dict(styleNames)
        paraStyleDispNames = tuple([dispName for dispName, name in styleNames])
        styleNames = styles.getListOfStyles('CharacterStyles', self.unoObjs)
        self.charStyleNames = dict(styleNames)
        charStyleDispNames = tuple([dispName for dispName, name in styleNames])
        self.dlgCtrls.loadValues(
            self.userVars, paraStyleDispNames, charStyleDispNames)
        self.dlgCtrls.enableDisable(self)

        ## Display the dialog

        self.dlgClose = dlg.endExecute
        dlg.execute()

        if self.convertOnClose:
            self.app.doConversions_writer()
        dlg.dispose()

    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 selectConverter(self):
        logger.debug(util.funcName('begin'))
        logger.debug("Selecting a converter...")
        converter = self.app.selectConverter()
        self.dlgCtrls.txtConverterName.setText(converter.convName)
        self.dlgCtrls.chkDirectionReverse.setState(not converter.forward)

    def noConverter(self):
        logger.debug(util.funcName('begin'))
        logger.debug("Clearing converter...")
        self.dlgCtrls.txtConverterName.setText("<No converter>")

    def closeAndConvert(self):
        logger.debug(util.funcName('begin'))
        logger.debug("Closing and Converting...")
        self.getFormResults()
        try:
            self.app.setAndVerifyConverter(self.converter)
            self.app.setAndVerifyConfig(self.config)
            self.convertOnClose = True
            self.dlgClose()
        except (exceptions.ChoiceProblem, exceptions.StyleError) as exc:
            self.msgbox.displayExc(exc)

    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)
        elif self.config.whichScope == 'ParaStyle':
            displayName = self.dlgCtrls.comboScopeParaStyle.getText()
            # use display name when searching
            searchConfig.style = displayName
        elif self.config.whichScope == 'CharStyle':
            displayName = self.dlgCtrls.comboScopeCharStyle.getText()
            if displayName in self.charStyleNames:
                searchConfig.style = self.charStyleNames[displayName]
            else:
                searchConfig.style = displayName
        elif self.config.whichScope == 'SFMs':
            searchConfig.SFMs = self.dlgCtrls.txtSFM.getText()
        searchConfig.load_userVars(self.userVars)

        self.config.whichTarget = dutil.whichSelected(
            self.dlgCtrls.radiosWhichTarget)
        self.userVars.store('WhichTarget', self.config.whichTarget)
        self.config.targetStyle = ''
        if self.config.whichTarget == 'ParaStyle':
            displayName = self.dlgCtrls.comboTargetParaStyle.getText()
            if displayName in self.paraStyleNames:
                self.config.targetStyle = self.paraStyleNames[displayName]
            else:
                # Perhaps a new style to be created
                self.config.targetStyle = displayName
        elif self.config.whichTarget == 'CharStyle':
            displayName = self.dlgCtrls.comboTargetCharStyle.getText()
            if displayName in self.charStyleNames:
                self.config.targetStyle = self.charStyleNames[displayName]
            else:
                # Perhaps a new style to be created
                self.config.targetStyle = displayName

        ## Target font

        targetFontName = self.dlgCtrls.listTargetStyleFont.getSelectedItem()
        if targetFontName == "(None)":
            targetFontName = None
        targetFontSize = FontSize()
        targetFontSize.loadCtrl(self.dlgCtrls.txtFontSize)
        if self.config.whichTarget == 'FontOnly':
            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('SFM_Markers', self.dlgCtrls.txtSFM.getText())
        self.userVars.store('AskEachChange',
                            str(self.dlgCtrls.chkVerify.getState()))
        logger.debug(util.funcName('end'))