Replace by character
This commit is contained in:
parent
fa4069030f
commit
31ddc1a199
35
easymacro.py
35
easymacro.py
|
@ -2892,7 +2892,7 @@ class LOWriterStyles(object):
|
||||||
return {s.DisplayName: s.Name for s in self._styles}
|
return {s.DisplayName: s.Name for s in self._styles}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '\n'.join(self.names)
|
return '\n'.join(tuple(self.names.values()))
|
||||||
|
|
||||||
|
|
||||||
class LOWriterStylesFamilies(object):
|
class LOWriterStylesFamilies(object):
|
||||||
|
@ -2967,18 +2967,23 @@ class LOWriterTextRange(object):
|
||||||
self._doc = doc
|
self._doc = doc
|
||||||
self._is_paragraph = self.obj.ImplementationName == 'SwXParagraph'
|
self._is_paragraph = self.obj.ImplementationName == 'SwXParagraph'
|
||||||
self._is_table = self.obj.ImplementationName == 'SwXTextTable'
|
self._is_table = self.obj.ImplementationName == 'SwXTextTable'
|
||||||
|
self._is_text = self.obj.ImplementationName == 'SwXTextPortion'
|
||||||
|
self._parts = []
|
||||||
|
if self._is_paragraph:
|
||||||
|
self._parts = [LOWriterTextRange(p, doc) for p in obj]
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
self._index = 0
|
self._index = 0
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
for i, p in enumerate(self.obj):
|
try:
|
||||||
if i == self._index:
|
obj = self._parts[self._index]
|
||||||
obj = LOWriterTextRange(p, self._doc)
|
except IndexError:
|
||||||
self._index += 1
|
raise StopIteration
|
||||||
return obj
|
|
||||||
raise StopIteration
|
self._index += 1
|
||||||
|
return obj
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def obj(self):
|
def obj(self):
|
||||||
|
@ -3003,10 +3008,18 @@ class LOWriterTextRange(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def style(self):
|
def style(self):
|
||||||
return self.obj.ParaStyleName
|
s = ''
|
||||||
|
if self.is_paragraph:
|
||||||
|
s = self.obj.ParaStyleName
|
||||||
|
elif self.is_text:
|
||||||
|
s = self.obj.CharStyleName
|
||||||
|
return s
|
||||||
@style.setter
|
@style.setter
|
||||||
def style(self, value):
|
def style(self, value):
|
||||||
self.obj.ParaStyleName = value
|
if self.is_paragraph:
|
||||||
|
self.obj.ParaStyleName = value
|
||||||
|
elif self.is_text:
|
||||||
|
self.obj.CharStyleName = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_paragraph(self):
|
def is_paragraph(self):
|
||||||
|
@ -3016,6 +3029,10 @@ class LOWriterTextRange(object):
|
||||||
def is_table(self):
|
def is_table(self):
|
||||||
return self._is_table
|
return self._is_table
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_text(self):
|
||||||
|
return self._is_text
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self):
|
||||||
return self.obj.Text
|
return self.obj.Text
|
||||||
|
|
Binary file not shown.
|
@ -2892,7 +2892,7 @@ class LOWriterStyles(object):
|
||||||
return {s.DisplayName: s.Name for s in self._styles}
|
return {s.DisplayName: s.Name for s in self._styles}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '\n'.join(self.names)
|
return '\n'.join(tuple(self.names.values()))
|
||||||
|
|
||||||
|
|
||||||
class LOWriterStylesFamilies(object):
|
class LOWriterStylesFamilies(object):
|
||||||
|
@ -2967,18 +2967,23 @@ class LOWriterTextRange(object):
|
||||||
self._doc = doc
|
self._doc = doc
|
||||||
self._is_paragraph = self.obj.ImplementationName == 'SwXParagraph'
|
self._is_paragraph = self.obj.ImplementationName == 'SwXParagraph'
|
||||||
self._is_table = self.obj.ImplementationName == 'SwXTextTable'
|
self._is_table = self.obj.ImplementationName == 'SwXTextTable'
|
||||||
|
self._is_text = self.obj.ImplementationName == 'SwXTextPortion'
|
||||||
|
self._parts = []
|
||||||
|
if self._is_paragraph:
|
||||||
|
self._parts = [LOWriterTextRange(p, doc) for p in obj]
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
self._index = 0
|
self._index = 0
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
for i, p in enumerate(self.obj):
|
try:
|
||||||
if i == self._index:
|
obj = self._parts[self._index]
|
||||||
obj = LOWriterTextRange(p, self._doc)
|
except IndexError:
|
||||||
self._index += 1
|
raise StopIteration
|
||||||
return obj
|
|
||||||
raise StopIteration
|
self._index += 1
|
||||||
|
return obj
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def obj(self):
|
def obj(self):
|
||||||
|
@ -3003,10 +3008,18 @@ class LOWriterTextRange(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def style(self):
|
def style(self):
|
||||||
return self.obj.ParaStyleName
|
s = ''
|
||||||
|
if self.is_paragraph:
|
||||||
|
s = self.obj.ParaStyleName
|
||||||
|
elif self.is_text:
|
||||||
|
s = self.obj.CharStyleName
|
||||||
|
return s
|
||||||
@style.setter
|
@style.setter
|
||||||
def style(self, value):
|
def style(self, value):
|
||||||
self.obj.ParaStyleName = value
|
if self.is_paragraph:
|
||||||
|
self.obj.ParaStyleName = value
|
||||||
|
elif self.is_text:
|
||||||
|
self.obj.CharStyleName = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_paragraph(self):
|
def is_paragraph(self):
|
||||||
|
@ -3016,6 +3029,10 @@ class LOWriterTextRange(object):
|
||||||
def is_table(self):
|
def is_table(self):
|
||||||
return self._is_table
|
return self._is_table
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_text(self):
|
||||||
|
return self._is_text
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self):
|
||||||
return self.obj.Text
|
return self.obj.Text
|
||||||
|
|
|
@ -7,18 +7,12 @@ ID_EXTENSION = ''
|
||||||
_ = None
|
_ = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _replace_styles():
|
|
||||||
dlg = _create_dialog_replace_styles()
|
|
||||||
dlg.open()
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
class Controllers(object):
|
class Controllers(object):
|
||||||
|
|
||||||
def __init__(self, dlg):
|
def __init__(self, dlg):
|
||||||
self.d = dlg
|
self.d = dlg
|
||||||
self.styles = {}
|
self.para_styles = {}
|
||||||
|
self.char_styles = {}
|
||||||
|
|
||||||
@app.catch_exception
|
@app.catch_exception
|
||||||
def cmd_replace_by_paragraph_action(self, event):
|
def cmd_replace_by_paragraph_action(self, event):
|
||||||
|
@ -42,8 +36,8 @@ class Controllers(object):
|
||||||
if not app.question(msg):
|
if not app.question(msg):
|
||||||
return
|
return
|
||||||
|
|
||||||
source = self.styles[source]
|
source = self.para_styles[source]
|
||||||
target = self.styles[target]
|
target = self.para_styles[target]
|
||||||
|
|
||||||
doc = app.active
|
doc = app.active
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -58,6 +52,45 @@ class Controllers(object):
|
||||||
app.debug(f'{i} replaces')
|
app.debug(f'{i} replaces')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@app.catch_exception
|
||||||
|
def cmd_replace_by_character_action(self, event):
|
||||||
|
source = self.d.lst_character_source.value
|
||||||
|
target = self.d.lst_character_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
|
||||||
|
|
||||||
|
source = self.char_styles[source]
|
||||||
|
target = self.char_styles[target]
|
||||||
|
|
||||||
|
doc = app.active
|
||||||
|
i = 0
|
||||||
|
for paragraph in doc.paragraphs:
|
||||||
|
if not paragraph.is_paragraph:
|
||||||
|
continue
|
||||||
|
for p in paragraph:
|
||||||
|
if p.style == source:
|
||||||
|
p.style = target
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
self.d.close()
|
||||||
|
app.debug(f'{i} replaces')
|
||||||
|
return
|
||||||
|
|
||||||
def cmd_close_action(self, event):
|
def cmd_close_action(self, event):
|
||||||
self.d.close()
|
self.d.close()
|
||||||
return
|
return
|
||||||
|
@ -68,7 +101,7 @@ def _create_dialog_replace_styles():
|
||||||
'Name': 'dialog',
|
'Name': 'dialog',
|
||||||
'Title': _('Replace Styles'),
|
'Title': _('Replace Styles'),
|
||||||
'Width': 220,
|
'Width': 220,
|
||||||
'Height': 100,
|
'Height': 125,
|
||||||
}
|
}
|
||||||
dlg = app.create_dialog(args)
|
dlg = app.create_dialog(args)
|
||||||
dlg.id = ID_EXTENSION
|
dlg.id = ID_EXTENSION
|
||||||
|
@ -77,9 +110,9 @@ def _create_dialog_replace_styles():
|
||||||
args = {
|
args = {
|
||||||
'Type': 'Label',
|
'Type': 'Label',
|
||||||
'Name': 'lbl_paragraphs',
|
'Name': 'lbl_paragraphs',
|
||||||
'Label': _('~Replace by paragraph'),
|
'Label': _('Replace by paragraph'),
|
||||||
'Width': 70,
|
'Width': 70,
|
||||||
'Height': 15,
|
'Height': 10,
|
||||||
'X': 10,
|
'X': 10,
|
||||||
'Y': 10,
|
'Y': 10,
|
||||||
}
|
}
|
||||||
|
@ -113,6 +146,43 @@ def _create_dialog_replace_styles():
|
||||||
}
|
}
|
||||||
dlg.add_control(args)
|
dlg.add_control(args)
|
||||||
|
|
||||||
|
args = {
|
||||||
|
'Type': 'Label',
|
||||||
|
'Name': 'lbl_character',
|
||||||
|
'Label': _('Replace by character'),
|
||||||
|
'Width': 70,
|
||||||
|
'Height': 10,
|
||||||
|
}
|
||||||
|
dlg.add_control(args)
|
||||||
|
|
||||||
|
args = {
|
||||||
|
'Type': 'ListBox',
|
||||||
|
'Name': 'lst_character_source',
|
||||||
|
'Width': 85,
|
||||||
|
'Height': 15,
|
||||||
|
'Dropdown': True,
|
||||||
|
}
|
||||||
|
dlg.add_control(args)
|
||||||
|
|
||||||
|
args = {
|
||||||
|
'Type': 'ListBox',
|
||||||
|
'Name': 'lst_character_target',
|
||||||
|
'Width': 85,
|
||||||
|
'Height': 15,
|
||||||
|
'Dropdown': True,
|
||||||
|
}
|
||||||
|
dlg.add_control(args)
|
||||||
|
|
||||||
|
args = {
|
||||||
|
'Type': 'Button',
|
||||||
|
'Name': 'cmd_replace_by_character',
|
||||||
|
'Width': 15,
|
||||||
|
'Height': 15,
|
||||||
|
'ImageURL': 'replace.svg',
|
||||||
|
'ImagePosition': 1,
|
||||||
|
}
|
||||||
|
dlg.add_control(args)
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
'Type': 'Button',
|
'Type': 'Button',
|
||||||
'Name': 'cmd_close',
|
'Name': 'cmd_close',
|
||||||
|
@ -124,22 +194,37 @@ def _create_dialog_replace_styles():
|
||||||
}
|
}
|
||||||
dlg.add_control(args)
|
dlg.add_control(args)
|
||||||
|
|
||||||
dlg.lst_paragraph_source.move(dlg.lbl_paragraphs)
|
dlg.lst_paragraph_source.move(dlg.lbl_paragraphs, 0, 5)
|
||||||
dlg.lst_paragraph_target.move(dlg.lst_paragraph_source, 5, 0)
|
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_replace_by_paragraph.move(dlg.lst_paragraph_target, 5, 0)
|
||||||
dlg.cmd_close.move(dlg.lst_paragraph_source, 0, 20)
|
|
||||||
dlg.cmd_close.center()
|
dlg.lbl_character.move(dlg.lst_paragraph_source, 0, 10)
|
||||||
|
dlg.lst_character_source.move(dlg.lbl_character, 0, 5)
|
||||||
|
dlg.lst_character_target.move(dlg.lst_character_source, 5, 0)
|
||||||
|
dlg.cmd_replace_by_character.move(dlg.lst_character_target, 5, 0)
|
||||||
|
|
||||||
|
dlg.cmd_close.move(dlg.lst_character_source, 0, 15, True)
|
||||||
|
|
||||||
doc = app.active
|
doc = app.active
|
||||||
styles = doc.styles['Paragraph'].names
|
styles = doc.styles['Paragraph'].names
|
||||||
dlg.lst_paragraph_source.data = tuple(styles.keys())
|
dlg.lst_paragraph_source.data = tuple(styles.keys())
|
||||||
dlg.lst_paragraph_target.data = tuple(styles.keys())
|
dlg.lst_paragraph_target.data = tuple(styles.keys())
|
||||||
dlg.events.styles = styles
|
dlg.events.para_styles = styles
|
||||||
|
|
||||||
|
styles = doc.styles['Character'].names
|
||||||
|
dlg.lst_character_source.data = tuple(styles.keys())
|
||||||
|
dlg.lst_character_target.data = tuple(styles.keys())
|
||||||
|
dlg.events.char_styles = styles
|
||||||
|
|
||||||
return dlg
|
return dlg
|
||||||
|
|
||||||
|
|
||||||
@app.catch_exception
|
def _replace_styles():
|
||||||
|
dlg = _create_dialog_replace_styles()
|
||||||
|
dlg.open()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def run(args, path_locales):
|
def run(args, path_locales):
|
||||||
global _
|
global _
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue