How to use the aeidon.documents.MAIN function in aeidon

To help you get started, we’ve selected a few aeidon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github otsaloma / gaupol / gaupol / agents / save.py View on Github external
def save_main(self, page):
        """Save the main document of `page` to file."""
        if (page.project.main_file is None or
            page.project.main_file.path is None or
            page.project.main_file.encoding is None):
            return self.save_main_as(page)
        self._save_document(page, aeidon.documents.MAIN)
        self.emit("page-saved", self, page)
github otsaloma / gaupol / gaupol / agents / save.py View on Github external
def save_main_as(self, page, file=None):
        """Save the main document of `page` to a selected file."""
        if file is None:
            file = page.project.main_file
            file = self._select_file(_("Save As"), page, file)
        self._save_document(page, aeidon.documents.MAIN, file)
        self.emit("page-saved", self, page)
        path = page.project.main_file.path
        format = page.project.main_file.format
        self.add_to_recent_files(path, format, aeidon.documents.MAIN)
        self.flash_message(_('Saved main document as "{}"')
                           .format(os.path.basename(path)))
github otsaloma / gaupol / aeidon / agents / util.py View on Github external
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.documents.MAIN:
            if self.main_file is not None:
                return self.main_file.format
            return None
        if doc == aeidon.documents.TRAN:
            if self.tran_file is not None:
                return self.tran_file.format
            return self.get_format(aeidon.documents.MAIN)
        raise ValueError("Invalid document: {!r}"
                         .format(doc))
github otsaloma / gaupol / gaupol / agents / save.py View on Github external
def save(self, page, doc):
        """Save `doc` of `page` to file."""
        if doc == aeidon.documents.MAIN:
            return self.save_main(page)
        if doc == aeidon.documents.TRAN:
            return self.save_translation(page)
        raise ValueError("Invalid document: {!r}"
                         .format(doc))
github otsaloma / gaupol / gaupol / util.py View on Github external
def document_to_text_field(doc):
    """Return :attr:`gaupol.fields` item corresponding to `doc`."""
    if doc == aeidon.documents.MAIN:
        return gaupol.fields.MAIN_TEXT
    if doc == aeidon.documents.TRAN:
        return gaupol.fields.TRAN_TEXT
    raise ValueError("Invalid document: %s" % repr(doc))
github otsaloma / gaupol / aeidon / agents / set.py View on Github external
def set_main_text(self, index, value, register=-1):
        """Set the value of main document's text."""
        return self.set_text(index,
                             aeidon.documents.MAIN,
                             value,
                             register=register)
github otsaloma / gaupol / gaupol / agents / open.py View on Github external
def append_file(self, path, encoding=None):
        """Append subtitles from file at `path` to the current project."""
        encodings = self._get_encodings(encoding)
        doc = aeidon.documents.MAIN
        temp = self._open_file(path, encodings, doc, check_open=False)
        gaupol.util.set_cursor_busy(self.window)
        current = self.get_current_page()
        offset = current.project.subtitles[-1].end
        temp.project.shift_positions(None, offset)
        rows = self._append_subtitles(current, temp.project.subtitles)
        amount = len(rows)
        current.view.set_focus(rows[0], None)
        current.view.select_rows(rows)
        current.view.scroll_to_row(rows[0])
        basename = temp.get_main_basename()
        message = _('Appended {amount:d} subtitles from "{basename}"')
        self.flash_message(message.format(**locals()))
        gaupol.util.set_cursor_normal(self.window)
github otsaloma / gaupol / aeidon / agents / register.py View on Github external
def _shift_changed_value(self, action, shift):
        """Shift the values of changed attributes."""
        if aeidon.documents.MAIN in action.docs:
            self.main_changed += shift
        if tuple(action.docs) == (aeidon.documents.TRAN,):
            # Make translation document active.
            if self.tran_changed is None:
                self.tran_changed = 0
        if aeidon.documents.TRAN in action.docs:
            if self.tran_changed is not None:
                self.tran_changed += shift
github otsaloma / gaupol / aeidon / agents / util.py View on Github external
def get_file(self, doc):
        """Return the file corresponding to `doc`."""
        if doc == aeidon.documents.MAIN:
            return self.main_file
        if doc == aeidon.documents.TRAN:
            return self.tran_file
        raise ValueError("Invalid document: {!r}"
                         .format(doc))
github otsaloma / gaupol / aeidon / agents / preview.py View on Github external
def _get_subtitle_path(self, doc, encoding=None, temp=False):
        """
        Return path to a file to preview, either real or temporary.

        Raise :exc:`IOError` if writing to temporary file fails.
        Raise :exc:`UnicodeError` if encoding temporary file fails.
        """
        file = self.get_file(doc)
        if file is None or encoding != file.encoding:
            return self.new_temp_file(doc)
        if doc == aeidon.documents.MAIN:
            if not self.main_changed and not temp:
                return self.main_file.path
        if doc == aeidon.documents.TRAN:
            if not self.tran_changed and not temp:
                return self.tran_file.path
        return self.new_temp_file(doc)