Here are the examples of the python api aeidon.deco.export taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
199 Examples
3
Example 1
@aeidon.deco.export
def get_file(self, doc):
"""Return the file corresponding to `doc`."""
if doc == aeidon.docuements.MAIN:
return self.main_file
if doc == aeidon.docuements.TRAN:
return self.tran_file
raise ValueError("Invalid docuement: {}"
.format(repr(doc)))
3
Example 2
Project: gaupol Source File: util.py
@aeidon.deco.export
def get_text_length(self, index, doc):
"""Return the amount of characters in text excluding markup."""
text = self.subtitles[index].get_text(doc)
re_tag = self.get_markup_tag_regex(doc)
if re_tag is not None:
text = re_tag.sub("", text)
return len(text)
3
Example 3
@aeidon.deco.export
def group_actions(self, register, count, description):
"""Group the registered actions as one item in the stack."""
if register is None: return
action_group = aeidon.RevertableActionGroup()
action_group.actions = []
action_group.description = description
stack = self._get_destination_stack(register)
for i in range(count):
action = stack.pop(0)
if isinstance(action, aeidon.RevertableActionGroup):
action_group.actions.extend(action.actions)
else: # Single action
action_group.actions.append(action)
stack.insert(0, action_group)
3
Example 4
Project: gaupol Source File: set.py
@aeidon.deco.export
@aeidon.deco.revertable
def set_main_text(self, index, value, register=-1):
"""Set the value of main docuement's text."""
return self.set_text(index,
aeidon.docuements.MAIN,
value,
register=register)
3
Example 5
@aeidon.deco.export
def undo(self, count=1):
"""Undo `count` amount of actions from the undoable stack."""
group = aeidon.RevertableActionGroup
if count > 1 or isinstance(self.undoables[0], group):
return self._revert_multiple(count, aeidon.registers.UNDO)
self._do_description = self.undoables[0].description
self.undoables.pop(0).revert()
3
Example 6
@aeidon.deco.export
@aeidon.deco.revertable
def shift_positions(self, indices, value, register=-1):
"""
Make subtitles appear earlier or later.
`indices` can be ``None`` to process all subtitles.
`value` can be any valid position type, negative to make subtitles
appear ealier, positive to make subtitles appear later.
"""
new_subtitles = []
indices = indices or self.get_all_indices()
for index in indices:
subtitle = self.subtitles[index].copy()
subtitle.shift_positions(value)
new_subtitles.append(subtitle)
self.replace_positions(indices, new_subtitles, register=register)
self.set_action_description(register, _("Shifting positions"))
3
Example 7
Project: gaupol Source File: util.py
@aeidon.deco.export
def get_markup_clean_func(self, doc):
"""Return the function to clean markup or ``None``."""
format = self.get_format(doc)
if format is None: return None
return aeidon.markups.new(format).clean
3
Example 8
@aeidon.deco.export
@aeidon.deco.revertable
def change_case(self, indices, doc, method, register=-1):
"""
Change the case of texts with `method`.
`method` should be a string: either "title", "capitalize", "upper" or
"lower", which correspond to the built-in Python string methods.
"""
new_texts = []
parser = self.get_parser(doc)
for index in indices:
subtitle = self.subtitles[index]
parser.set_text(subtitle.get_text(doc))
self._change_case_first(parser, method)
new_texts.append(parser.get_text())
self.replace_texts(indices, doc, new_texts, register=register)
self.set_action_description(register, _("Changing case"))
3
Example 9
@aeidon.deco.export
def close_all(self, confirm=True):
"""Close all pages after asking to save their docuements."""
if confirm and sum(len(self._need_confirmation(
x)) for x in self.pages) > 1:
return self._confirm_close_multiple(tuple(self.pages))
while self.pages:
self.close(self.pages[-1], confirm=confirm)
3
Example 10
Project: gaupol Source File: format.py
@aeidon.deco.export
@aeidon.deco.revertable
def remove_dialogue_dashes(self, indices, doc, register=-1):
"""Remove dialogue dashes from all lines of texts."""
new_texts = []
parser = self.get_parser(doc)
for index in indices:
subtitle = self.subtitles[index]
parser.set_text(subtitle.get_text(doc))
parser.set_regex(r"^[\-\–\—]\s*")
parser.replacement = ""
parser.replace_all()
new_texts.append(parser.get_text())
self.replace_texts(indices, doc, new_texts, register=register)
self.set_action_description(register, _("Removing dialogue dashes"))
3
Example 11
Project: gaupol Source File: search.py
@aeidon.deco.export
def set_search_regex(self, pattern, flags=re.DOTALL|re.MULTILINE):
"""
Set the regular expression pattern to find.
Raise :exc:`re.error` if bad pattern.
"""
# Ignore case only if in flags.
self._finder.ignore_case = False
self._finder.set_regex(pattern, flags)
3
Example 12
@aeidon.deco.export
def save_translation(self, file=None, keep_changes=True):
"""
Write subtitle data from translation docuement to `file`.
`file` can be ``None`` to use :attr:`tran_file`.
Raise :exc:`IOError` if writing fails.
Raise :exc:`UnicodeError` if encoding fails.
"""
file = file or self.tran_file
if file is not None and self.tran_file is not None:
file.copy_from(self.tran_file)
indices = self._save(aeidon.docuements.TRAN, file, keep_changes)
if keep_changes:
self.tran_file = file
self.tran_changed = 0
self.emit("translation-texts-changed", indices)
self.emit("translation-file-saved", file)
3
Example 13
@aeidon.deco.export
def open(self, doc, path, encoding=None, align_method=None):
"""
Read and parse subtitle data for `doc` from `path`.
`encoding` can be ``None`` to use the system default encoding.
Return the amount of subtitles that needed to be moved in order
to arrange them in ascending chronological order.
Raise :exc:`IOError` if reading fails.
Raise :exc:`UnicodeError` if decoding fails.
Raise :exc:`aeidon.FormatError` if unable to detect format.
Raise :exc:`aeidon.ParseError` if parsing fails.
"""
if doc == aeidon.docuements.MAIN:
return self.open_main(path, encoding)
if doc == aeidon.docuements.TRAN:
return self.open_translation(path, encoding, align_method)
raise ValueError("Invalid docuement: {}".format(repr(doc)))
3
Example 14
Project: gaupol Source File: set.py
@aeidon.deco.export
@aeidon.deco.revertable
def set_translation_text(self, index, value, register=-1):
"""Set the value of translation docuement's text."""
return self.set_text(index,
aeidon.docuements.TRAN,
value,
register=register)
3
Example 15
Project: gaupol Source File: edit.py
@aeidon.deco.export
@aeidon.deco.revertable
def split_subtitle(self, index, register=-1):
"""Split subtitle in two equal duration ones."""
subtitle = self.subtitles[index]
middle = self.calc.get_middle(subtitle.start, subtitle.end)
subtitle_1 = self.new_subtitle()
subtitle_1.start = subtitle.start
subtitle_1.end = middle
subtitle_1.main_text = subtitle.main_text
subtitle_1.tran_text = subtitle.tran_text
subtitle_2 = self.new_subtitle()
subtitle_2.start = middle
subtitle_2.end = subtitle.end
self.remove_subtitles((index,), register=register)
indices = (index, index+1)
subtitles = (subtitle_1, subtitle_2)
self.insert_subtitles(indices, subtitles, register=register)
self.group_actions(register, 2, _("Splitting subtitle"))
3
Example 16
Project: gaupol Source File: util.py
@aeidon.deco.export
def get_liner(self, doc):
"""Return a new :class:`aeidon.Liner` instance."""
re_tag = self.get_markup_tag_regex(doc)
clean_func = self.get_markup_clean_func(doc)
return aeidon.Liner(re_tag, clean_func)
3
Example 17
Project: gaupol Source File: register.py
@aeidon.deco.export
def cut_reversion_stacks(self):
"""Cut undo and redo stacks to their maximum lengths."""
if self.undo_limit is not None:
del self.redoables[self.undo_limit:]
del self.undoables[self.undo_limit:]
3
Example 18
@aeidon.deco.export
def get_mode(self):
"""Return mode of the main file or default."""
if self.main_file is not None:
return self.main_file.mode
return aeidon.modes.TIME
3
Example 19
@aeidon.deco.export
@aeidon.deco.revertable
def merge_subtitles(self, indices, register=-1):
"""Merge subtitles at `indices` to form one subtitle."""
indices = sorted(indices)
subtitle = self.new_subtitle()
subtitle.start = self.subtitles[indices[0]].start
subtitle.end = self.subtitles[indices[-1]].end
main_texts = [self.subtitles[i].main_text for i in indices]
tran_texts = [self.subtitles[x].tran_text for x in indices]
subtitle.main_text = "\n".join(filter(None, main_texts))
subtitle.tran_text = "\n".join(filter(None, tran_texts))
self.remove_subtitles(indices, register=register)
self.insert_subtitles([indices[0]], [subtitle], register=register)
self.group_actions(register, 2, _("Merging subtitles"))
3
Example 20
@aeidon.deco.export
def close(self, page, confirm=True):
"""Close `page` after asking to save its docuements."""
if confirm:
self._confirm_close(page)
if not page in self.pages: return
index = self.pages.index(page)
if self.notebook.get_current_page() == index:
self.notebook.next_page()
self.notebook.remove_page(index)
self.pages.remove(page)
self.update_gui()
self.emit("page-closed", page)
3
Example 21
@aeidon.deco.export
def register_action(self, action):
"""Register `action` as done, undone or redone."""
if action.register == aeidon.registers.DO:
self.undoables.insert(0, action)
self.redoables = []
self._shift_changed_value(action, action.register.shift)
if action.register == aeidon.registers.UNDO:
self.redoables.insert(0, action)
action.description = self._do_description
self._shift_changed_value(action, action.register.shift)
if action.register == aeidon.registers.REDO:
self.undoables.insert(0, action)
action.description = self._do_description
self._shift_changed_value(action, action.register.shift)
3
Example 22
Project: gaupol Source File: register.py
@aeidon.deco.export
def set_action_description(self, register, description):
"""Set the description of the most recent registered action."""
if register is None: return
stack = self._get_destination_stack(register)
stack[0].description = description
3
Example 23
Project: gaupol Source File: edit.py
@aeidon.deco.export
@aeidon.deco.revertable
@aeidon.deco.notify_frozen
def remove_subtitles(self, indices, register=-1):
"""Remove subtitles at `indices`."""
indices = sorted(indices)
subtitles = [self.subtitles.pop(i) for i in reversed(indices)][::-1]
action = aeidon.RevertableAction(register=register)
action.docs = tuple(aeidon.docuements)
action.description = _("Removing subtitles")
action.revert_function = self.insert_subtitles
action.revert_args = (indices, subtitles)
self.register_action(action)
self.emit("subtitles-removed", indices)
3
Example 24
@aeidon.deco.export
def save(self, doc, file=None, keep_changes=True):
"""
Write subtitle data from `doc` to `file`.
`file` can be ``None`` to use existing file.
Raise :exc:`IOError` if writing fails.
Raise :exc:`UnicodeError` if encoding fails.
"""
if doc == aeidon.docuements.MAIN:
return self.save_main(file, keep_changes)
if doc == aeidon.docuements.TRAN:
return self.save_translation(file, keep_changes)
raise ValueError("Invalid docuement: {}".format(repr(doc)))
3
Example 25
Project: gaupol Source File: format.py
@aeidon.deco.export
@aeidon.deco.revertable
def toggle_dialogue_dashes(self, indices, doc, register=-1):
"""Show or hide dialogue dashes on texts."""
if self._should_add_dialogue_dashes(indices, doc):
return self.add_dialogue_dashes(indices, doc, register=register)
return self.remove_dialogue_dashes(indices, doc, register=register)
3
Example 26
@aeidon.deco.export
@aeidon.deco.revertable
def replace(self, register=-1):
"""
Replace the current match of pattern.
Raise :exc:`re.error` if bad replacement.
"""
orig_text = self._finder.text
self._finder.replace()
if self._finder.text == orig_text: return
self.set_text(self._match_index,
self._match_doc,
self._finder.text,
register=register)
self.set_action_description(register, _("Replacing"))
3
Example 27
@aeidon.deco.export
def find_next(self, index=None, doc=None, pos=None):
"""
Find the next match starting from given position.
`index`, `doc` and `pos` can be ``None`` to start from beginning.
Raise :exc:`StopIteration` if no (more) matches exist.
Return tuple of index, docuement, match span.
"""
index = (0 if index is None else index)
doc = (self._docs[0] if doc is None else doc)
return self._find(index, doc, pos, next=True)
3
Example 28
Project: gaupol Source File: format.py
@aeidon.deco.export
@aeidon.deco.revertable
def unitalicize(self, indices, doc, register=-1):
"""Remove any italic markup surrounding texts."""
new_texts = []
markup = self.get_markup(doc)
re_italic_tag = markup.italic_tag
for index in indices:
text = self.subtitles[index].get_text(doc)
text = re_italic_tag.sub("", text)
new_texts.append(text)
self.replace_texts(indices, doc, new_texts, register=register)
self.set_action_description(register, _("Unitalicizing"))
3
Example 29
Project: gaupol Source File: search.py
@aeidon.deco.export
def set_search_target(self, indices=None, docs=None, wrap=True):
"""
Set the targets to search in.
`indices` can be ``None`` to target all subtitles.
`docs` can be ``None`` to target all docuements.
"""
self._indices = (tuple(indices) if indices else None)
self._docs = tuple(docs or aeidon.docuements)
self._wrap = wrap
3
Example 30
Project: gaupol Source File: edit.py
@aeidon.deco.export
@aeidon.deco.revertable
@aeidon.deco.notify_frozen
def replace_texts(self, indices, doc, texts, register=-1):
"""Replace texts in `doc`'s `indices` with `texts`."""
orig_texts = [self.subtitles[i].get_text(doc) for i in indices]
for i, index in enumerate(indices):
self.subtitles[index].set_text(doc, texts[i])
action = aeidon.RevertableAction(register=register)
action.docs = (doc,)
action.description = _("Replacing texts")
action.revert_function = self.replace_texts
action.revert_args = (indices, doc, orig_texts)
self.register_action(action)
self.emit(self.get_text_signal(doc), indices)
3
Example 31
@aeidon.deco.export
@aeidon.deco.revertable
def set_text(self, index, doc, value, register=-1):
"""Set the value of `doc`'s text."""
subtitle = self.subtitles[index]
orig_value = subtitle.get_text(doc)
if value == orig_value: return
subtitle.set_text(doc, value)
action = aeidon.RevertableAction(register=register)
action.docs = (doc,)
action.description = _("Editing text")
action.revert_function = self.set_text
action.revert_args = (index, doc, orig_value)
self.register_action(action)
signal = self.get_text_signal(doc)
self.emit(signal, (index,))
3
Example 32
@aeidon.deco.export
@aeidon.deco.revertable
def set_framerate(self, framerate, register=-1):
"""Set the value of framerate."""
orig_framerate = self.framerate
self.framerate = framerate
self.calc = aeidon.Calculator(framerate)
for subtitle in self.subtitles:
subtitle.framerate = framerate
action = aeidon.RevertableAction(register=register)
action.docs = tuple(aeidon.docuements)
action.description = _("Setting framerate")
action.revert_function = self.set_framerate
action.revert_args = (orig_framerate,)
self.register_action(action)
3
Example 33
@aeidon.deco.export
def get_changed(self, doc):
"""Return the changed value corresponding to `doc`."""
if doc == aeidon.docuements.MAIN:
return self.main_changed
if doc == aeidon.docuements.TRAN:
return self.tran_changed
raise ValueError("Invalid docuement: {}"
.format(repr(doc)))
3
Example 34
Project: gaupol Source File: edit.py
@aeidon.deco.export
@aeidon.deco.revertable
def clear_texts(self, indices, doc, register=-1):
"""Set texts to blank strings."""
new_texts = [""] * len(indices)
self.replace_texts(indices, doc, new_texts, register=register)
self.set_action_description(register, _("Clearing texts"))
3
Example 35
@aeidon.deco.export
def get_format(self, doc):
"""
Return format of the file corresponding to `doc`.
For a translation file that is ``None``, return format of main file.
If main file is ``None``, return ``None``.
"""
if doc == aeidon.docuements.MAIN:
if self.main_file is not None:
return self.main_file.format
return None
if doc == aeidon.docuements.TRAN:
if self.tran_file is not None:
return self.tran_file.format
return self.get_format(aeidon.docuements.MAIN)
raise ValueError("Invalid docuement: {}"
.format(repr(doc)))
3
Example 36
Project: gaupol Source File: position.py
@aeidon.deco.export
@aeidon.deco.revertable
def transform_positions(self, indices, p1, p2, register=-1):
"""
Change positions by a linear two-point correction.
`indices` can be ``None`` to process all subtitles.
`p1` and `p2` should be tuples of index, position.
"""
new_subtitles = []
indices = indices or self.get_all_indices()
coefficient, constant = self._get_transform(p1, p2)
for index in indices:
subtitle = self.subtitles[index].copy()
subtitle.scale_positions(coefficient)
subtitle.shift_positions(constant)
new_subtitles.append(subtitle)
self.replace_positions(indices, new_subtitles, register=register)
self.set_action_description(register, _("Transforming positions"))
3
Example 37
@aeidon.deco.export
def get_markup(self, doc):
"""Return `doc`'s markup instance or ``None``."""
format = self.get_format(doc)
if format is None: return None
return aeidon.markups.new(format)
3
Example 38
Project: gaupol Source File: format.py
@aeidon.deco.export
@aeidon.deco.revertable
def add_dialogue_dashes(self, indices, doc, register=-1):
"""Add dialogue dashes to all lines of texts."""
new_texts = []
parser = self.get_parser(doc)
for index in indices:
subtitle = self.subtitles[index]
parser.set_text(subtitle.get_text(doc))
parser.set_regex(r"^[\-\–\—]\s*")
parser.replacement = ""
parser.replace_all()
parser.set_regex(r"^")
parser.replacement = r"- "
parser.replace_all()
new_texts.append(parser.get_text())
self.replace_texts(indices, doc, new_texts, register=register)
self.set_action_description(register, _("Adding dialogue dashes"))
3
Example 39
Project: gaupol Source File: util.py
@aeidon.deco.export
def get_markup_tag_regex(self, doc):
"""Return the regular expression for a markup tag or ``None``."""
format = self.get_format(doc)
if format is None: return None
return aeidon.markups.new(format).tag
3
Example 40
Project: gaupol Source File: register.py
@aeidon.deco.export
def emit_action_signal(self, register):
"""Emit an action signal for the most recent registered action."""
if register is not None:
self.emit(register.signal,
self._get_destination_stack(register)[0])
3
Example 41
@aeidon.deco.export
def get_parser(self, doc):
"""Return a new :class:`aeidon.Parser` instance."""
re_tag = self.get_markup_tag_regex(doc)
clean_func = self.get_markup_clean_func(doc)
return aeidon.Parser(re_tag, clean_func)
3
Example 42
Project: gaupol Source File: clipboard.py
@aeidon.deco.export
@aeidon.deco.revertable
def cut_texts(self, indices, doc, register=-1):
"""Cut texts to the clipboard."""
self.copy_texts(indices, doc)
self.clear_texts(indices, doc, register=register)
self.set_action_description(register, _("Cutting texts"))
3
Example 43
Project: gaupol Source File: util.py
@aeidon.deco.export
def get_text_signal(self, doc):
"""Return the ``texts-changed`` signal corresponding to `doc`."""
if doc == aeidon.docuements.MAIN:
return "main-texts-changed"
if doc == aeidon.docuements.TRAN:
return "translation-texts-changed"
raise ValueError("Invalid docuement: {}"
.format(repr(doc)))
3
Example 44
@aeidon.deco.export
def redo(self, count=1):
"""Redo `count` amount of actions from the redoable stack."""
group = aeidon.RevertableActionGroup
if count > 1 or isinstance(self.redoables[0], group):
return self._revert_multiple(count, aeidon.registers.REDO)
self._do_description = self.redoables[0].description
self.redoables.pop(0).revert()
3
Example 45
@aeidon.deco.export
@aeidon.deco.revertable
def italicize(self, indices, doc, register=-1):
"""Surround texts with italic markup."""
new_texts = []
markup = self.get_markup(doc)
re_italic_tag = markup.italic_tag
for index in indices:
text = self.subtitles[index].get_text(doc)
text = re_italic_tag.sub("", text)
text = markup.italicize(text)
new_texts.append(text)
self.replace_texts(indices, doc, new_texts, register=register)
self.set_action_description(register, _("Italicizing"))
3
Example 46
Project: gaupol Source File: clipboard.py
@aeidon.deco.export
def copy_texts(self, indices, doc):
"""Copy texts to the clipboard."""
self.clipboard.clear()
for index in range(min(indices), max(indices) + 1):
subtitle = self.subtitles[index]
text = (subtitle.get_text(doc) if index in indices else None)
self.clipboard.append(text)
3
Example 47
Project: gaupol Source File: clipboard.py
@aeidon.deco.export
@aeidon.deco.revertable
def paste_texts(self, index, doc, register=-1):
"""Paste texts from the clipboard and return pasted indices."""
texts = self.clipboard.get_texts()
length = len(self.subtitles)
new_count = len(texts) - (length - index)
if new_count > 0:
indices = list(range(length, length + new_count))
self.insert_subtitles(indices, register=register)
indices = [index+i for i in range(len(texts)) if texts[i] is not None]
new_texts = [x for x in texts if x is not None]
self.replace_texts(indices, doc, new_texts, register=register)
if new_count > 0:
self.group_actions(register, 2, "")
self.set_action_description(register, _("Pasting texts"))
return tuple(indices)
3
Example 48
Project: gaupol Source File: edit.py
@aeidon.deco.export
@aeidon.deco.revertable
@aeidon.deco.notify_frozen
def replace_positions(self, indices, subtitles, register=-1):
"""Replace positions at `indices` with those from `subtitles`."""
orig_subtitles = [self.subtitles[i].copy() for i in indices]
for i, index in enumerate(indices):
self.subtitles[index].start = subtitles[i].start
self.subtitles[index].end = subtitles[i].end
action = aeidon.RevertableAction(register=register)
action.docs = tuple(aeidon.docuements)
action.description = _("Replacing positions")
action.revert_function = self.replace_positions
action.revert_args = (indices, orig_subtitles)
self.register_action(action)
self.emit("positions-changed", indices)
3
Example 49
Project: gaupol Source File: format.py
@aeidon.deco.export
@aeidon.deco.revertable
def toggle_italicization(self, indices, doc, register=-1):
"""Add or remove italic markup surrounding texts."""
if self._should_italicize(indices, doc):
return self.italicize(indices, doc, register=register)
return self.unitalicize(indices, doc, register=register)
3
Example 50
@aeidon.deco.export
def find_previous(self, index=None, doc=None, pos=None):
"""
Find the previous match starting from given position.
`index`, `doc` and `pos` can be ``None`` to start from end.
Raise :exc:`StopIteration` if no (more) matches exist.
Return tuple of index, docuement, match span.
"""
index = (len(self.subtitles)-1 if index is None else index)
doc = (self._docs[-1] if doc is None else doc)
return self._find(index, doc, pos, next=False)