Replace style by paragraphs

This commit is contained in:
Mauricio Baeza 2021-04-12 17:44:49 -05:00
parent 530b26dd82
commit 37ecf06ed7
11 changed files with 575 additions and 4 deletions

View File

@ -316,7 +316,10 @@ def get_app_config(node_name: str, key: str=''):
LANGUAGE = get_app_config('org.openoffice.Setup/L10N/', 'ooLocale')
LANG = LANGUAGE.split('-')[0]
COUNTRY = LANGUAGE.split('-')[1]
try:
COUNTRY = LANGUAGE.split('-')[1]
except:
COUNTRY = ''
LOCALE = Locale(LANG, COUNTRY, '')
NAME = TITLE = get_app_config('org.openoffice.Setup/Product', 'ooName')
VERSION = get_app_config('org.openoffice.Setup/Product','ooSetupVersion')
@ -2879,6 +2882,55 @@ class LOCalcRange(object):
return
class LOWriterStyles(object):
def __init__(self, styles):
self._styles = styles
@property
def names(self):
return self._styles.ElementNames
def __str__(self):
return '\n'.join(self.names)
class LOWriterStylesFamilies(object):
def __init__(self, styles):
self._styles = styles
def __getitem__(self, index):
styles = {
'Character': 'CharacterStyles',
'Paragraph': 'ParagraphStyles',
'Page': 'PageStyles',
'Frame': 'FrameStyles',
'Numbering': 'NumberingStyles',
'Table': 'TableStyles',
'Cell': 'CellStyles',
}
name = styles.get(index, index)
return LOWriterStyles(self._styles[name])
def __iter__(self):
self._index = 0
return self
def __next__(self):
obj = LOWriterStyles(self._styles[self._index])
self._index += 1
return obj
# ~ raise StopIteration
@property
def names(self):
return self._styles.ElementNames
def __str__(self):
return '\n'.join(self.names)
class LOWriterPageStyle(LOBaseObject):
def __init__(self, obj):
@ -2949,6 +3001,17 @@ class LOWriterTextRange(object):
def value(self, value):
self.string = value
@property
def style(self):
return self.obj.ParaStyleName
@style.setter
def style(self, value):
self.obj.ParaStyleName = value
@property
def is_paragraph(self):
return self._is_paragraph
@property
def is_table(self):
return self._is_table
@ -3144,6 +3207,10 @@ class LOWriter(LODocument):
ps = self.obj.StyleFamilies['PageStyles']
return LOWriterPageStyles(ps)
@property
def styles(self):
return LOWriterStylesFamilies(self.obj.StyleFamilies)
@property
def search_descriptor(self):
return self.obj.createSearchDescriptor()

Binary file not shown.

View File

@ -1,6 +1,7 @@
import uno
import unohelper
from com.sun.star.task import XJobExecutor
import main
ID_EXTENSION = 'net.elmau.zaz.doc'
@ -12,8 +13,9 @@ class ZazDoc(unohelper.Base, XJobExecutor):
def __init__(self, ctx):
self.ctx = ctx
def trigger(self, args='pyUNO'):
print('Hello World', args)
def trigger(self, args):
main.ID_EXTENSION = ID_EXTENSION
main.run(args, __file__)
return

52
source/images/close.svg Normal file
View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 32 32"
version="1.1"
x="0px"
y="0px"
id="svg18"
width="32"
height="32">
<metadata
id="metadata24">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>9.4</dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs22" />
<title
id="title2">9.4</title>
<desc
id="desc4">Created with Sketch.</desc>
<g
stroke="none"
stroke-width="1"
fill="none"
fill-rule="evenodd"
id="g12"
transform="scale(0.66666667)">
<g
fill-rule="nonzero"
fill="#000000"
id="g10">
<g
id="g8">
<path
d="m 26.828427,24 6.366079,6.366079 c 0.779879,0.779879 0.784376,2.039815 -0.0021,2.826309 -0.781048,0.781049 -2.047059,0.781368 -2.826309,0.0021 L 24,26.828427 17.633921,33.194506 c -0.779879,0.779879 -2.039815,0.784376 -2.826309,-0.0021 -0.781049,-0.781048 -0.781368,-2.047059 -0.0021,-2.826309 L 21.171573,24 14.805494,17.633921 c -0.779879,-0.779879 -0.784376,-2.039815 0.0021,-2.826309 0.781048,-0.781049 2.047059,-0.781368 2.826309,-0.0021 L 24,21.171573 30.366079,14.805494 c 0.779879,-0.779879 2.039815,-0.784376 2.826309,0.0021 0.781049,0.781048 0.781368,2.047059 0.0021,2.826309 z M 24,48 C 10.745166,48 0,37.254834 0,24 0,10.745166 10.745166,0 24,0 37.254834,0 48,10.745166 48,24 48,37.254834 37.254834,48 24,48 Z m 0,-4 C 35.045695,44 44,35.045695 44,24 44,12.954305 35.045695,4 24,4 12.954305,4 4,12.954305 4,24 4,35.045695 12.954305,44 24,44 Z"
id="path6" />
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

50
source/images/replace.svg Normal file
View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.0"
x="0px"
y="0px"
viewBox="0 0 24 24"
enable-background="new 0 0 100 100"
xml:space="preserve"
id="svg10"
width="24"
height="24"
sodipodi:docname="ok.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2560"
inkscape:window-height="1006"
id="namedview8"
showgrid="false"
inkscape:zoom="25.71875"
inkscape:cx="9.0330528"
inkscape:cy="13.975581"
inkscape:window-x="0"
inkscape:window-y="37"
inkscape:window-maximized="1"
inkscape:current-layer="svg10"
inkscape:document-rotation="0" /><metadata
id="metadata16"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
id="defs14" /><g
id="g20"
transform="matrix(0.26666667,0,0,0.26666667,-1.3333334,-1.3333334)"><path
d="M 50,5 C 25.2,5 5,25.2 5,50 5,74.8 25.2,95 50,95 74.8,95 95,74.8 95,50 95,25.2 74.8,5 50,5 Z m 0,80 C 30.7,85 15,69.3 15,50 15,30.7 30.7,15 50,15 69.3,15 85,30.7 85,50 85,69.3 69.3,85 50,85 Z"
id="path2" /><polygon
points="45,67.1 72.1,40 65,32.9 45,52.9 35,42.9 27.9,50 "
id="polygon4" /></g></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,46 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2021-04-12 17:25-0500\n"
"PO-Revision-Date: 2021-04-12 17:27-0500\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"X-Generator: Poedit 2.4.1\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: en\n"
#: source/pythonpath/main.py:28
msgid "Select style source"
msgstr ""
#: source/pythonpath/main.py:32
msgid "Select style target"
msgstr ""
#: source/pythonpath/main.py:36
msgid "Select different styles"
msgstr ""
#: source/pythonpath/main.py:40
msgid "Replace selected styles?"
msgstr ""
#: source/pythonpath/main.py:62
msgid "Replace Styles"
msgstr ""
#: source/pythonpath/main.py:73
msgid "~Replace by paragraph"
msgstr ""
#: source/pythonpath/main.py:112
msgid "~Close"
msgstr ""

View File

@ -0,0 +1,46 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2021-04-12 17:11-0500\n"
"PO-Revision-Date: 2021-04-12 17:15-0500\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"X-Generator: Poedit 2.4.1\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: en\n"
#: source/pythonpath/main.py:28
msgid "Select style source"
msgstr ""
#: source/pythonpath/main.py:32
msgid "Select style target"
msgstr ""
#: source/pythonpath/main.py:36
msgid "Select different styles"
msgstr ""
#: source/pythonpath/main.py:40
msgid "Replace style \"%s\" with style \"s%\" ?"
msgstr ""
#: source/pythonpath/main.py:62
msgid "Replace Styles"
msgstr ""
#: source/pythonpath/main.py:73
msgid "~Replace by paragraph"
msgstr ""
#: source/pythonpath/main.py:112
msgid "~Close"
msgstr ""

View File

@ -0,0 +1,49 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2021-04-12 17:25-0500\n"
"PO-Revision-Date: 2021-04-12 17:26-0500\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"X-Generator: Poedit 2.4.1\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: source/pythonpath/main.py:28
msgid "Select style source"
msgstr "Seleccionar estilo origen"
#: source/pythonpath/main.py:32
msgid "Select style target"
msgstr "Seleccionar estilo destino"
#: source/pythonpath/main.py:36
msgid "Select different styles"
msgstr "Seleccionar estilos diferentes"
#: source/pythonpath/main.py:40
msgid "Replace selected styles?"
msgstr "¿Reemplazar estilos seleccionados?"
#: source/pythonpath/main.py:62
msgid "Replace Styles"
msgstr "Reemplazar Estilos"
#: source/pythonpath/main.py:73
msgid "~Replace by paragraph"
msgstr "~Reemplazar por párrafo"
#: source/pythonpath/main.py:112
msgid "~Close"
msgstr "~Cerrar"
#~ msgid "Replace style \"%s\" with style \"s%\" ?"
#~ msgstr "¿Reemplazar el estilo \"%s\" con el estilo \"s%\" ?"

View File

@ -0,0 +1,46 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2021-04-12 17:11-0500\n"
"PO-Revision-Date: 2021-04-12 17:14-0500\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"X-Generator: Poedit 2.4.1\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: es\n"
#: source/pythonpath/main.py:28
msgid "Select style source"
msgstr "Seleccionar estilo origen"
#: source/pythonpath/main.py:32
msgid "Select style target"
msgstr "Seleccionar estilo destino"
#: source/pythonpath/main.py:36
msgid "Select different styles"
msgstr "Seleccionar estilos diferentes"
#: source/pythonpath/main.py:40
msgid "Replace style \"%s\" with style \"s%\" ?"
msgstr "¿Reemplazar el estilo \"%s\" con el estilo \"s%\" ?"
#: source/pythonpath/main.py:62
msgid "Replace Styles"
msgstr "Reemplazar Estilos"
#: source/pythonpath/main.py:73
msgid "~Replace by paragraph"
msgstr "~Reemplazar por párrafo"
#: source/pythonpath/main.py:112
msgid "~Close"
msgstr "~Cerrar"

View File

@ -316,7 +316,10 @@ def get_app_config(node_name: str, key: str=''):
LANGUAGE = get_app_config('org.openoffice.Setup/L10N/', 'ooLocale')
LANG = LANGUAGE.split('-')[0]
COUNTRY = LANGUAGE.split('-')[1]
try:
COUNTRY = LANGUAGE.split('-')[1]
except:
COUNTRY = ''
LOCALE = Locale(LANG, COUNTRY, '')
NAME = TITLE = get_app_config('org.openoffice.Setup/Product', 'ooName')
VERSION = get_app_config('org.openoffice.Setup/Product','ooSetupVersion')
@ -2879,6 +2882,55 @@ class LOCalcRange(object):
return
class LOWriterStyles(object):
def __init__(self, styles):
self._styles = styles
@property
def names(self):
return self._styles.ElementNames
def __str__(self):
return '\n'.join(self.names)
class LOWriterStylesFamilies(object):
def __init__(self, styles):
self._styles = styles
def __getitem__(self, index):
styles = {
'Character': 'CharacterStyles',
'Paragraph': 'ParagraphStyles',
'Page': 'PageStyles',
'Frame': 'FrameStyles',
'Numbering': 'NumberingStyles',
'Table': 'TableStyles',
'Cell': 'CellStyles',
}
name = styles.get(index, index)
return LOWriterStyles(self._styles[name])
def __iter__(self):
self._index = 0
return self
def __next__(self):
obj = LOWriterStyles(self._styles[self._index])
self._index += 1
return obj
# ~ raise StopIteration
@property
def names(self):
return self._styles.ElementNames
def __str__(self):
return '\n'.join(self.names)
class LOWriterPageStyle(LOBaseObject):
def __init__(self, obj):
@ -2949,6 +3001,17 @@ class LOWriterTextRange(object):
def value(self, value):
self.string = value
@property
def style(self):
return self.obj.ParaStyleName
@style.setter
def style(self, value):
self.obj.ParaStyleName = value
@property
def is_paragraph(self):
return self._is_paragraph
@property
def is_table(self):
return self._is_table
@ -3144,6 +3207,10 @@ class LOWriter(LODocument):
ps = self.obj.StyleFamilies['PageStyles']
return LOWriterPageStyles(ps)
@property
def styles(self):
return LOWriterStylesFamilies(self.obj.StyleFamilies)
@property
def search_descriptor(self):
return self.obj.createSearchDescriptor()

146
source/pythonpath/main.py Normal file
View File

@ -0,0 +1,146 @@
#!/usr/bin/env python3
import easymacro as app
ID_EXTENSION = ''
_ = None
def _replace_styles():
dlg = _create_dialog_replace_styles()
dlg.open()
return
class Controllers(object):
def __init__(self, dlg):
self.d = dlg
@app.catch_exception
def cmd_replace_by_paragraph_action(self, event):
source = self.d.lst_paragraph_source.value
target = self.d.lst_paragraph_target.value
if not source:
msg = _('Select style source')
app.errorbox(msg)
return
if not target:
msg = _('Select style target')
app.errorbox(msg)
return
if source == target:
msg = _('Select different styles')
app.errorbox(msg)
return
msg = _('Replace selected styles?')
if not app.question(msg):
return
doc = app.active
i = 0
for p in doc.paragraphs:
if not p.is_paragraph:
continue
if p.style == source:
p.style = target
i += 1
self.d.close()
app.debug(f'{i} replaces')
return
def cmd_close_action(self, event):
self.d.close()
return
def _create_dialog_replace_styles():
args = {
'Name': 'dialog',
'Title': _('Replace Styles'),
'Width': 220,
'Height': 100,
}
dlg = app.create_dialog(args)
dlg.id = ID_EXTENSION
dlg.events = Controllers
args = {
'Type': 'Label',
'Name': 'lbl_paragraphs',
'Label': _('~Replace by paragraph'),
'Width': 70,
'Height': 15,
'X': 10,
'Y': 10,
}
dlg.add_control(args)
args = {
'Type': 'ListBox',
'Name': 'lst_paragraph_source',
'Width': 85,
'Height': 15,
'Dropdown': True,
}
dlg.add_control(args)
args = {
'Type': 'ListBox',
'Name': 'lst_paragraph_target',
'Width': 85,
'Height': 15,
'Dropdown': True,
}
dlg.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_replace_by_paragraph',
'Width': 15,
'Height': 15,
'ImageURL': 'replace.svg',
'ImagePosition': 1,
}
dlg.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_close',
'Label': _('~Close'),
'Width': 70,
'Height': 20,
'ImageURL': 'close.svg',
'ImagePosition': 1,
}
dlg.add_control(args)
dlg.lst_paragraph_source.move(dlg.lbl_paragraphs)
dlg.lst_paragraph_target.move(dlg.lst_paragraph_source, 5, 0)
dlg.cmd_replace_by_paragraph.move(dlg.lst_paragraph_target, 5, 0)
dlg.cmd_close.move(dlg.lst_paragraph_source, 0, 20)
dlg.cmd_close.center()
doc = app.active
styles = doc.styles['Paragraph'].names
dlg.lst_paragraph_source.data = styles
dlg.lst_paragraph_target.data = styles
return dlg
@app.catch_exception
def run(args, path_locales):
global _
_ = app.install_locales(path_locales)
if args == 'replacestyles':
_replace_styles()
return