How to use the aeidon.documents 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_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 / save.py View on Github external
def save_main(self, file=None, keep_changes=True):
        """
        Write subtitle data from main document to `file`.

        `file` can be ``None`` to use :attr:`main_file`.
        Raise :exc:`IOError` if writing fails.
        Raise :exc:`UnicodeError` if encoding fails.
        """
        file = file or self.main_file
        if file is not None and self.main_file is not None:
            file.copy_from(self.main_file)
        indices = self._save(aeidon.documents.MAIN, file, keep_changes)
        if keep_changes:
            if (self.main_file is not None and
                file.mode != self.main_file.mode):
                # Apply possibly changed mode (times vs. frames).
                for i, subtitle in enumerate(self.subtitles):
                    subtitle.mode = file.mode
                self.emit("positions-changed", self.get_all_indices())
            self.main_file = file
            self.main_changed = 0
            self.emit("main-texts-changed", indices)
        self.emit("main-file-saved", file)
github otsaloma / gaupol / gaupol / dialogs / open.py View on Github external
def _init_values(self, doc):
        """Initialize default values for widgets."""
        self.set_select_multiple(doc == aeidon.documents.MAIN)
        if os.path.isdir(gaupol.conf.file.directory):
            self.set_current_folder(gaupol.conf.file.directory)
        self.set_encoding(gaupol.conf.file.encoding)
        self._align_combo.set_active(gaupol.conf.file.align_method)
        self._align_combo.set_visible(doc == aeidon.documents.TRAN)
        self._align_label.set_visible(doc == aeidon.documents.TRAN)
github otsaloma / gaupol / aeidon / agents / open.py View on Github external
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.documents.MAIN:
            return self.open_main(path, encoding)
        if doc == aeidon.documents.TRAN:
            return self.open_translation(path, encoding, align_method)
        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)
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 / subtitle.py View on Github external
def set_text(self, doc, value):
        """Set text corresponding to `doc` to `value`."""
        if doc == aeidon.documents.MAIN:
            self.main_text = value
        if doc == aeidon.documents.TRAN:
            self.tran_text = value
github otsaloma / gaupol / gaupol / dialogs / open.py View on Github external
def _init_values(self, doc):
        """Initialize default values for widgets."""
        self.set_select_multiple(doc == aeidon.documents.MAIN)
        if os.path.isdir(gaupol.conf.file.directory):
            self.set_current_folder(gaupol.conf.file.directory)
        self.set_encoding(gaupol.conf.file.encoding)
        self._align_combo.set_active(gaupol.conf.file.align_method)
        self._align_combo.set_visible(doc == aeidon.documents.TRAN)
        self._align_label.set_visible(doc == aeidon.documents.TRAN)