Пример #1
0
    def resizeNumberingCol(self, colWidthText, prevColWidth):
        """
        Resize the width of the column that contains example numbering.
        Size is an integer percentage of the page width.
        @param string colWidthText
        @param int    prevColWidth
        throws exceptions.ChoiceProblem

        It would be nice if there were such a thing as table styles.
        Then this function would presumably not be needed.
        """
        logger.debug(util.funcName('begin'))
        if colWidthText == "":
            raise exceptions.ChoiceProblem(
                "Please enter a value for column width.")
        try:
            newVal = int(colWidthText)
        except:
            raise exceptions.ChoiceProblem("Column width is not a number.")
        if newVal == prevColWidth:
            logger.debug("No need to change.")
            return
        if newVal > 50:     # more than 50% is unreasonable
            raise exceptions.ChoiceProblem(
                "Value %d for column width is too high.", newVal)
        elif newVal <= 0:
            raise exceptions.ChoiceProblem(
                "Value for column width must be more than zero.")

        PERCENT_TO_SEP = 100  # Separator width 10,000 is 100%.
                               # The user enters a number like 5 meaning 5%.
                               # So 5 * 100 would be 500 which is 5% of 10,000
        MARGIN_OF_ERROR = 2
        prevVal = prevColWidth * PERCENT_TO_SEP
        newVal = newVal * PERCENT_TO_SEP
        tables = self.unoObjs.document.getTextTables()
        logger.debug(
            "looping through %d tables.  prevVal = %d",
            tables.getCount(), prevVal)
        for table in iteruno.byIndex(tables):
            separators = table.getPropertyValue("TableColumnSeparators")
            if separators is None:
                logger.debug(
                    "No separators set for table %s", table.getName())
                continue
            sep0Pos = separators[0].Position
            logger.debug(
                "table %s separator is %d", table.getName(), sep0Pos)
            if (sep0Pos > prevVal - MARGIN_OF_ERROR and
                    sep0Pos < prevVal + MARGIN_OF_ERROR):
                separators[0].Position = newVal
                table.TableColumnSeparators = separators
                logger.debug("changed to %d", newVal)

        self.userVars.store("NumberingColWidth", str(newVal // PERCENT_TO_SEP))
        logger.debug(util.funcName('end'))
    def setAndVerifyConfig(self, newConfig):
        """Sets self.config from newConfig, which should be type
        ConversionSettings.
        Throws exceptions.ChoiceProblem if the choices are not acceptable.
        """
        logger.debug(util.funcName('begin'))
        if not self.styleFonts:
            raise exceptions.LogicError("Expected styleFonts to be set.")

        if not newConfig.whichScope:
            raise exceptions.ChoiceProblem("Please specify a scope.")
        if (newConfig.whichScope == 'ParaStyle'
                and not newConfig.searchConfig.style):
            raise exceptions.ChoiceProblem(
                "Please select a scope paragraph style.")
        if (newConfig.whichScope == 'CharStyle'
                and not newConfig.searchConfig.style):
            raise exceptions.ChoiceProblem(
                "Please select a scope character style.")
        if (newConfig.whichScope == 'Font'
                and not newConfig.searchConfig.fontName):
            raise exceptions.ChoiceProblem("Please select a scope font.")
        if (newConfig.whichScope == 'SFMs'
                and not newConfig.searchConfig.SFMs):
            raise exceptions.ChoiceProblem("Please specify SFMs.")

        if not newConfig.whichTarget:
            raise exceptions.ChoiceProblem("Please specify a target.")
        if (newConfig.whichTarget == 'ParaStyle'
                and not newConfig.targetStyle):
            raise exceptions.ChoiceProblem("Please select a target style.")
        if (newConfig.whichTarget == 'CharStyle'
                and not newConfig.targetStyle):
            raise exceptions.ChoiceProblem("Please select a target style.")
        if (newConfig.whichTarget == 'FontOnly'
                and not newConfig.targetFont.fontName):
            raise exceptions.ChoiceProblem("Please select a target font.")

        self.config = newConfig
        try:
            if newConfig.whichTarget == 'ParaStyle':
                self.styleFonts.setParaStyleWithFont(newConfig.targetFont,
                                                     newConfig.targetStyle)
            elif newConfig.whichTarget == 'CharStyle':
                self.styleFonts.setCharStyleWithFont(newConfig.targetFont,
                                                     newConfig.targetStyle)
        except RuntimeException as exc:
            logger.exception(exc)
            raise exceptions.StyleError("Could not create style '%s'.",
                                        newConfig.targetStyle)
        logger.debug(util.funcName('end'))
    def setAndVerifyConverter(self, newConv):
        """Parameter should be of type SEC_wrapper.ConverterSettings.
        Call this method before calling one of the doConversion() methods.
        """
        ## Get the converter if not yet done

        if newConv.convName == "":
            raise exceptions.ChoiceProblem("Please select a converter.")
        if newConv.convName == "<No converter>":
            return
        if self.secCall.config != newConv:
            try:
                self.secCall.setConverter(newConv)
                logger.debug("Did set converter.")
            except exceptions.FileAccessError as exc:
                self.msgbox.displayExc(exc)
                self.secCall.config.convName = ""
                raise exceptions.ChoiceProblem(
                    "Please select the converter again.")
Пример #4
0
 def insertByRefnum(self, refTextRough):
     try:
         self.operations.readData()
         if not refTextRough.strip():
             raise exceptions.ChoiceProblem(
                 *self.operations.messageAndSuggestions(
                     "Please enter a ref number."))
         logger.debug("do the insertion.")
         self.operations.insertEx(refTextRough, False, False)
     except exceptions.MessageError as exc:
         self.msgbox.displayExc(exc)
 def scopeLocale(self):
     """This is similar to searching for a character style."""
     logger.debug(util.funcName('begin'))
     lang = self.config.lang
     if not lang:
         raise exceptions.ChoiceProblem("No locale was specified.")
     for simpleTextSection in self.docEnum.documentSections():
         if (simpleTextSection.CharLocale.Language == lang or
                 simpleTextSection.CharLocaleComplex.Language == lang or
                 simpleTextSection.CharLocaleAsian.Language == lang):
             # TextPortions include the TextRange service.
             self.ranger.addRange(simpleTextSection)
Пример #6
0
 def verify(self):
     """Verify that settings are acceptable."""
     logger.debug(util.funcName('begin'))
     if (not self.filepath or not self.filepath.lower().endswith(
             (".ods", ".sxc", ".xls", ".xlsx"))):
         raise exceptions.ChoiceProblem(
             "Please specify a word list file.  To make a new empty "
             "list, go to Word List and Spelling and then save the "
             "spreadsheet file.")
     if not self.whichTask:
         raise exceptions.LogicError("No task was specified.")
     if not self.whichScope:
         raise exceptions.LogicError("No scope was specified.")
     if self.whichScope == 'Language' and not self.searchConfig.lang:
         raise exceptions.ChoiceProblem("Please select a language name.")
     if self.whichScope == 'ParaStyle' and not self.searchConfig.style:
         raise exceptions.ChoiceProblem(
             "Please select a scope paragraph style.")
     if self.whichScope == 'CharStyle' and not self.searchConfig.style:
         raise exceptions.ChoiceProblem(
             "Please select a scope character style.")
     if self.whichScope == 'Font' and not self.searchConfig.fontName:
         raise exceptions.ChoiceProblem("Please select a scope font.")
     if self.whichScope == 'SFMs' and not self.searchConfig.SFMs:
         raise exceptions.ChoiceProblem("Please specify SFMs.")
     logger.debug(util.funcName('end'))
Пример #7
0
def get_selected_index(listCtrl, itemDescription="an item"):
    """
    :param listCtrl: the UNO listbox control
    :param itemDescription: description of the item for error messages
    """
    itemPos = listCtrl.getSelectedItemPos()
    if itemPos is None or itemPos < 0:
        if listCtrl.getItemCount() == 1:
            itemPos = 0
        else:
            logger.debug("No item selected.")
            raise exceptions.ChoiceProblem("Please select %s in the list." %
                                           itemDescription)
    logger.debug("Item at index %d is selected.", itemPos)
    return itemPos
Пример #8
0
    def getFormResults(self, verify=True):
        """Reads form fields and gets settings.
        If verify is True, raises an exception if there is a problem.
        """
        logger.debug(util.funcName('begin'))
        exportType = ""
        if self.dlgCtrls.optReplacementCCT.getState() == 1:  # selected
            exportType = "ReplacementCCT"
        elif self.dlgCtrls.optSFM_CCT.getState() == 1:
            exportType = "SFM_CCT"
            sfMarkers = self.dlgCtrls.txtSFM.getText().strip()
            if verify and sfMarkers == "":
                ok = self.msgbox.displayOkCancel(
                    "No SF markers were specified.  Continue anyway?")
                if not ok:
                    raise exceptions.UserInterrupt()
            self.userVars.store("SFM_Markers", sfMarkers)
            self.app.setSFM(sfMarkers)
        elif self.dlgCtrls.optXSLT.getState() == 1:
            exportType = "XSLT"
            if verify and self.dlgCtrls.listXpaths.getItemCount() == 0:
                ok = self.msgbox.displayOkCancel(
                    "No Xpath expressions were specified.  Continue anyway?")
                if not ok:
                    raise exceptions.UserInterrupt()
            self.userVars.store("XSLT_MatchPartial",
                                str(self.dlgCtrls.chkMatchPartial.getState()))
            self.app.setMatchPartial(
                self.dlgCtrls.chkMatchPartial.getState() == 1)
            self.userVars.store("XpathCount",
                                str(self.dlgCtrls.listXpaths.getItemCount()))
            stringList = dutil.listbox_items(self.dlgCtrls.listXpaths)
            for exprNum, exprVal in enumerate(stringList):
                varname = "XpathExpr%02d" % exprNum
                self.userVars.store(varname, exprVal)
            self.app.setXpathExprs(stringList)
        self.userVars.store("ExportType", exportType)
        self.app.setExportType(exportType)

        filepath = self.dlgCtrls.txtFilePath.getText().strip()
        if verify and filepath == "":
            raise exceptions.ChoiceProblem("Please specify a file to export.")
        self.userVars.store("Filepath", filepath)
        self.app.setFilepath(filepath)
        logger.debug(util.funcName('end'))
Пример #9
0
 def alreadyInList(self):
     return exceptions.ChoiceProblem(
         "%s is already in the list." % self.ITEM_DESC_SPECIFIC)
Пример #10
0
 def noItemSelected(self):
     return exceptions.ChoiceProblem(
         "Please select %s in the list." % self.ITEM_DESC_GENERIC)
 def verify_results(self):
     if not self.outputTo.outdir:
         raise exceptions.ChoiceProblem("Please select an output folder.")
     if len(self.filesList.fileItems) == 0:
         raise exceptions.ChoiceProblem("Please add files to scan.")