Index: gc_core/py/lang_core/gc_engine.py ================================================================== --- gc_core/py/lang_core/gc_engine.py +++ gc_core/py/lang_core/gc_engine.py @@ -27,11 +27,11 @@ __all__ = [ "lang", "locales", "pkg", "name", "version", "author", \ "load", "parse", "getSpellChecker", \ "setOption", "setOptions", "getOptions", "getDefaultOptions", "getOptionsLabels", "resetOptions", "displayOptions", \ - "ignoreRule", "resetIgnoreRules", "reactivateRule", "listRules", "displayRules" ] + "ignoreRule", "resetIgnoreRules", "reactivateRule", "listRules", "displayRules", "setWriterUnderliningStyle" ] __version__ = "${version}" lang = "${lang}" @@ -51,10 +51,13 @@ _dOptionsColors = None _oSpellChecker = None _oTokenizer = None _aIgnoredRules = set() +# Writer underlining style +_bMulticolor = True +_nUnderliningStyle = 0 #### Initialization def load (sContext="Python", sColorType="aRGB"): @@ -189,10 +192,29 @@ def resetOptions (): "set options to default values" global _dOptions _dOptions = getDefaultOptions() + +def setWriterUnderliningStyle (sStyle="BOLDWAVE", bMulticolor=True): + "set underlining style for Writer (WAVE, BOLDWAVE, BOLD)" + global _nUnderliningStyle + global _bMulticolor + # https://api.libreoffice.org/docs/idl/ref/FontUnderline_8idl.html + # WAVE: 10, BOLD: 12, BOLDWAVE: 18 DASH: 5 + if sStyle == "WAVE": + _nUnderliningStyle = 0 # 0 for default Writer setting + elif sStyle == "BOLDWAVE": + _nUnderliningStyle = 18 + elif sStyle == "BOLD": + _nUnderliningStyle = 12 + elif sStyle == "DASH": + _nUnderliningStyle = 5 + else: + _nUnderliningStyle = 0 + _bMulticolor = bMulticolor + #### Parsing def parse (sText, sCountry="${country_default}", bDebug=False, dOptions=None, bContext=False, bFullInfo=False): "init point to analyse and returns an iterable of errors or (with option ) paragraphs errors and sentences with tokens and errors" @@ -661,14 +683,15 @@ xErr.aRuleIdentifier = sRuleId xErr.aShortComment = sMessage # sMessage.split("|")[0] # in context menu xErr.aFullComment = sMessage # sMessage.split("|")[-1] # in dialog xErr.aSuggestions = tuple(lSugg) # Properties - lProperties = [ - PropertyValue(Name="LineType", Value=18), # WAVE: 10, DASH: 5, BOLD: 12, BOLDWAVE: 18 https://api.libreoffice.org/docs/idl/ref/FontUnderline_8idl.html - PropertyValue(Name="LineColor", Value=_dOptionsColors.get(sOption, 33023)) - ] + lProperties = [] + if _nUnderliningStyle: + lProperties.append(PropertyValue(Name="LineType", Value=_nUnderliningStyle)) + if _bMulticolor: + lProperties.append(PropertyValue(Name="LineColor", Value=_dOptionsColors.get(sOption, 33023))) if sURL: lProperties.append(PropertyValue(Name="FullCommentURL", Value=sURL)) xErr.aProperties = lProperties return xErr Index: gc_core/py/oxt/Grammalecte.py ================================================================== --- gc_core/py/oxt/Grammalecte.py +++ gc_core/py/oxt/Grammalecte.py @@ -39,10 +39,12 @@ # opt_handler.load(xCurCtx) dOpt = Options.load(xCurCtx) gce.setOptions(dOpt) # dictionaries options self.loadUserDictionaries() + # underlining options + self.setWriterUnderliningStyle() # store for results of big paragraphs self.dResult = {} self.nMaxRes = 1500 self.lLastRes = deque(maxlen=self.nMaxRes) self.nRes = 0 @@ -148,12 +150,22 @@ if sJSON: oSpellChecker = gce.getSpellChecker(); oSpellChecker.setPersonalDictionary(json.loads(sJSON)) except: traceback.print_exc() + + def setWriterUnderliningStyle (self): + try: + xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", False) + xChild = xSettingNode.getByName("o_${lang}") + sLineType = xChild.getPropertyValue("line_type") + bMulticolor = bool(xChild.getPropertyValue("line_multicolor")) + gce.setWriterUnderliningStyle(sLineType, bMulticolor) + except: + traceback.print_exc() g_ImplementationHelper = unohelper.ImplementationHelper() g_ImplementationHelper.addImplementation(Grammalecte, "org.openoffice.comp.pyuno.Lightproof."+gce.pkg, ("com.sun.star.linguistic2.Proofreader",),) # g_ImplementationHelper.addImplementation( opt_handler.LightproofOptionsEventHandler, \ # "org.openoffice.comp.pyuno.LightproofOptionsEventHandler." + gce.pkg, ("com.sun.star.awt.XContainerWindowEventHandler",),) Index: gc_core/py/oxt/OptionsDialog.xcs ================================================================== --- gc_core/py/oxt/OptionsDialog.xcs +++ gc_core/py/oxt/OptionsDialog.xcs @@ -19,19 +19,21 @@ The data for one leaf. + 1 1 - 0 0 1 classic - + + 1 + BOLDWAVE Index: gc_lang/fr/config.ini ================================================================== --- gc_lang/fr/config.ini +++ gc_lang/fr/config.ini @@ -104,10 +104,13 @@ oxt/DictOptions/lxe_strings.py = pythonpath/lxe_strings.py oxt/DictOptions/SearchWords.py = pythonpath/SearchWords.py oxt/DictOptions/sw_strings.py = pythonpath/sw_strings.py oxt/DictOptions/TagsInfo.py = pythonpath/TagsInfo.py oxt/DictOptions/ti_strings.py = pythonpath/ti_strings.py +# Graphic options +oxt/GraphicOptions/GraphicOptions.py = pythonpath/GraphicOptions.py +oxt/GraphicOptions/go_strings.py = pythonpath/go_strings.py # ContextMenu oxt/ContextMenu/ContextMenu.py = ContextMenu.py oxt/ContextMenu/jobs.xcu = config/jobs.xcu # TextFormatter oxt/TextFormatter/TextFormatter.py = pythonpath/TextFormatter.py Index: gc_lang/fr/oxt/AppLauncher.py ================================================================== --- gc_lang/fr/oxt/AppLauncher.py +++ gc_lang/fr/oxt/AppLauncher.py @@ -64,10 +64,14 @@ xDialog.run(self.sLang) elif sCmd == "EN": import Enumerator xDialog = Enumerator.Enumerator(self.ctx) xDialog.run(self.sLang) + elif sCmd == "GO": + import GraphicOptions + xDialog = GraphicOptions.GraphicOptions(self.ctx) + xDialog.run(self.sLang) elif sCmd.startswith("FA/"): findAll(sCmd[6:], (sCmd[3:4] == "y"), (sCmd[4:5] == "y")) # elif sCmd.startswith("URL/"): # # Call from context menu to launch URL? # # http://opengrok.libreoffice.org/xref/core/sw/source/ui/lingu/olmenu.cxx#785 ADDED gc_lang/fr/oxt/GraphicOptions/GraphicOptions.py Index: gc_lang/fr/oxt/GraphicOptions/GraphicOptions.py ================================================================== --- gc_lang/fr/oxt/GraphicOptions/GraphicOptions.py +++ gc_lang/fr/oxt/GraphicOptions/GraphicOptions.py @@ -0,0 +1,159 @@ +# Graphic Options +# by Olivier R. +# License: MPL 2 + +import unohelper +import uno +import re +import traceback + +import helpers +import go_strings + +from com.sun.star.task import XJobExecutor +from com.sun.star.awt import XActionListener +from com.sun.star.beans import PropertyValue + + +class GraphicOptions (unohelper.Base, XActionListener, XJobExecutor): + + def __init__ (self, ctx): + self.ctx = ctx + self.xSvMgr = self.ctx.ServiceManager + self.xContainer = None + self.xDialog = None + + def _addWidget (self, name, wtype, x, y, w, h, **kwargs): + xWidget = self.xDialog.createInstance('com.sun.star.awt.UnoControl%sModel' % wtype) + xWidget.Name = name + xWidget.PositionX = x + xWidget.PositionY = y + xWidget.Width = w + xWidget.Height = h + for k, w in kwargs.items(): + setattr(xWidget, k, w) + self.xDialog.insertByName(name, xWidget) + return xWidget + + def run (self, sLang): + self.dUI = go_strings.getUI(sLang) + + self.xDesktop = self.xSvMgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.ctx) + self.xDocument = self.xDesktop.getCurrentComponent() + self.xGLOptionNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", True) + + # dialog + self.xDialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx) + self.xDialog.Width = 200 + self.xDialog.Height = 220 + self.xDialog.Title = self.dUI.get('title', "#title#") + xWindowSize = helpers.getWindowSize() + self.xDialog.PositionX = int((xWindowSize.Width / 2) - (self.xDialog.Width / 2)) + self.xDialog.PositionY = int((xWindowSize.Height / 2) - (self.xDialog.Height / 2)) + + # fonts + xFDTitle = uno.createUnoStruct("com.sun.star.awt.FontDescriptor") + xFDTitle.Height = 9 + xFDTitle.Weight = uno.getConstantByName("com.sun.star.awt.FontWeight.BOLD") + xFDTitle.Name = "Verdana" + + xFDSubTitle = uno.createUnoStruct("com.sun.star.awt.FontDescriptor") + xFDSubTitle.Height = 10 + xFDSubTitle.Weight = uno.getConstantByName("com.sun.star.awt.FontWeight.BOLD") + xFDSubTitle.Name = "Verdana" + + # widget + nX = 10 + nY1 = 10 + nY2 = nY1 + 45 + nY3 = nY2 + 55 + nY4 = nY3 + 65 + + nWidth = self.xDialog.Width - 20 + nHeight = 10 + + # Info + self._addWidget("graphic_info", 'FixedText', nX, nY1, nWidth, nHeight*2, Label = self.dUI.get("graphic_info", "#err"), MultiLine = True, FontDescriptor = xFDSubTitle) + self._addWidget("spell_info", 'FixedText', nX, nY1+20, nWidth, nHeight*2, Label = self.dUI.get("spell_info", "#err"), MultiLine = True) + + # Line type + self._addWidget('linetype_section', 'FixedLine', nX, nY2, nWidth, nHeight, Label = self.dUI.get('linetype_section', "#err"), FontDescriptor = xFDTitle) + self.xWaveLine = self._addWidget('wave_line', 'RadioButton', nX, nY2+15, nWidth, nHeight, Label = self.dUI.get('wave_line', "#err")) + self.xBoldWaveLine = self._addWidget('boldwave_line', 'RadioButton', nX, nY2+25, nWidth, nHeight, Label = self.dUI.get('boldwave_line', "#err")) + self.xBoldLine = self._addWidget('bold_line', 'RadioButton', nX, nY2+35, nWidth, nHeight, Label = self.dUI.get('bold_line', "#err")) + + # Color + self._addWidget("color_section", 'FixedLine', nX, nY3, nWidth, nHeight, Label = self.dUI.get("color_section", "#err"), FontDescriptor = xFDTitle) + self.xMulticolor = self._addWidget('multicolor_line', 'CheckBox', nX, nY3+15, nWidth, nHeight, Label = self.dUI.get('multicolor_line', "#err")) + self._addWidget('multicolor_descr', 'FixedText', nX, nY3+25, nWidth, nHeight*4, Label = self.dUI.get('multicolor_descr', "#err"), MultiLine = True) + + # Restart message + self._addWidget('restart', 'FixedText', nX, nY4, nWidth, nHeight*2, Label = self.dUI.get('restart', "#err"), FontDescriptor = xFDTitle, MultiLine = True, TextColor = 0x880000) + + # Button + self._addWidget('apply_button', 'Button', self.xDialog.Width-115, self.xDialog.Height-20, 50, 14, Label = self.dUI.get('apply_button', "#err"), FontDescriptor = xFDTitle, TextColor = 0x005500) + self._addWidget('cancel_button', 'Button', self.xDialog.Width-60, self.xDialog.Height-20, 50, 14, Label = self.dUI.get('cancel_button', "#err"), FontDescriptor = xFDTitle, TextColor = 0x550000) + + self._loadOptions() + + # container + self.xContainer = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx) + self.xContainer.setModel(self.xDialog) + self.xContainer.getControl('apply_button').addActionListener(self) + self.xContainer.getControl('apply_button').setActionCommand('Apply') + self.xContainer.getControl('cancel_button').addActionListener(self) + self.xContainer.getControl('cancel_button').setActionCommand('Cancel') + self.xContainer.setVisible(False) + toolkit = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.ExtToolkit', self.ctx) + self.xContainer.createPeer(toolkit, None) + self.xContainer.execute() + + # XActionListener + def actionPerformed (self, xActionEvent): + if xActionEvent.ActionCommand == 'Apply': + try: + # Grammalecte options + xChild = self.xGLOptionNode.getByName("o_fr") + xChild.setPropertyValue("line_multicolor", self.xMulticolor.State) + if self.xWaveLine.State: + sLineType = "WAVE" + elif self.xBoldWaveLine.State: + sLineType = "BOLDWAVE" + elif self.xBoldLine.State: + sLineType = "BOLD" + else: + sLineType = "BOLDWAVE" + xChild.setPropertyValue("line_type", sLineType) + self.xGLOptionNode.commitChanges() + except: + traceback.print_exc() + # Close window + self.xContainer.endExecute() + + # XJobExecutor + def trigger (self, args): + try: + dialog = GraphicOptions(self.ctx) + dialog.run() + except: + traceback.print_exc() + + def _loadOptions (self): + try: + xChild = self.xGLOptionNode.getByName("o_fr") + self.xMulticolor.State = xChild.getPropertyValue("line_multicolor") + sLineType = xChild.getPropertyValue("line_type") + if sLineType == "WAVE": + self.xWaveLine.State = 1 + elif sLineType == "BOLDWAVE": + self.xBoldWaveLine.State = 1 + elif sLineType == "BOLD": + self.xBoldLine.State = 1 + else: + print("Error. Unknown line type: " + sLineType) + except: + traceback.print_exc() + + +#g_ImplementationHelper = unohelper.ImplementationHelper() +#g_ImplementationHelper.addImplementation(GraphicOptions, 'net.grammalecte.GraphicOptions', ('com.sun.star.task.Job',)) ADDED gc_lang/fr/oxt/GraphicOptions/go_strings.py Index: gc_lang/fr/oxt/GraphicOptions/go_strings.py ================================================================== --- gc_lang/fr/oxt/GraphicOptions/go_strings.py +++ gc_lang/fr/oxt/GraphicOptions/go_strings.py @@ -0,0 +1,49 @@ +def getUI (sLang): + if sLang in dStrings: + return dStrings[sLang] + return dStrings["fr"] + +dStrings = { + "fr": { + "title": "Grammalecte · Options graphiques", + + "graphic_info": "Apparence du soulignement des erreurs grammaticales et typographiques", + + "linetype_section": "Type de ligne", + "wave_line": "Vaguelette fine (réglage par défaut de Writer)", + "boldwave_line": "Vaguelette épaisse (réglage par défaut de Grammalecte)", + "bold_line": "Trait droit et épais", + + "color_section": "Couleurs", + "multicolor_line": "Utiliser plusieurs couleurs", + "multicolor_descr": "Par défaut, Writer signale les erreurs grammaticales et typographiques avec une vaguelette de couleur bleue. Si cette option est cochée, Grammalecte attribuera des couleurs différentes aux erreurs selon leur type.", + + "spell_info": "L’apparence du soulignement des erreurs orthographiques (vaguelette rouge) n’est pas modifiable", + + "restart": "Le changement ne prendra effet qu’après le redémarrage du logiciel.", + + "apply_button": "Appliquer", + "cancel_button": "Annuler", + }, + "en": { + "title": "Grammalecte · Graphic options", + + "graphic_info": "Appearance of uderlines for grammar and typographical mistakes", + + "linetype_section": "Line types", + "wave_line": "Thin wave (default setting of Writer)", + "boldwave_line": "Thick wave (default setting of Grammalecte)", + "bold_line": "Thick and straight line", + + "color_section": "Colors", + "multicolor_line": "Use several colors", + "multicolor_descr": "By default, Writer underlines grammar and typographical mistakes with a blue wave. If this option is activated, Grammalecte uses different colors for mistakes according to the type they belong to.", + + "spell_info": "Appearance of underlines for spelling mistakes (red and thin wave) can’t be modified", + + "restart": "The modification will be effective only after restarting the software.", + + "apply_button": "Apply", + "cancel_button": "Cancel", + }, +} Index: gc_lang/fr/oxt/addons.xcu ================================================================== --- gc_lang/fr/oxt/addons.xcu +++ gc_lang/fr/oxt/addons.xcu @@ -134,10 +134,32 @@ org.dicollecte.images:Grammalecte + + service:net.grammalecte.AppLauncher?GO + + + + + Options grap~hiques… + Grap~hic options… + + + _self + + + com.sun.star.text.TextDocument,com.sun.star.text.GlobalDocument,com.sun.star.text.WebDocument + + + org.dicollecte.images:Grammalecte + + + service:net.grammalecte.AppLauncher?DI