How to use the aeidon.modes 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 / aeidon / files / mpsub.py View on Github external
def set_header(self, header):
        """
        Parse and set header, mode and framerate.

        Raise :exc:`ValueError` if ``FORMAT`` line is invalid.
        """
        mode = aeidon.modes.NONE
        framerates = dict((x.mpsub, x) for x in aeidon.framerates)
        for line in header.split("\n"):
            if line.startswith("FORMAT="):
                mode = line[7:].strip()
        if mode == "TIME":
            self.mode = aeidon.modes.TIME
            self.framerate = aeidon.framerates.NONE
            return setattr(self, "header", header)
        if mode in list(framerates.keys()):
            self.mode = aeidon.modes.FRAME
            self.framerate = framerates[mode]
            return setattr(self, "header", header)
        raise ValueError("Invalid FORMAT line: {}"
                         .format(repr(header)))
github otsaloma / gaupol / gaupol / view.py View on Github external
def _init_props(self, edit_mode):
        """Initialize properties."""
        if edit_mode == aeidon.modes.TIME:
            columns = (int, str, str, float, str, str)
        if edit_mode == aeidon.modes.FRAME:
            columns = (int, int, int, int, str, str)
        store = Gtk.ListStore(*columns)
        self.set_model(store)
        self._init_columns(edit_mode)
        self._init_cell_data_functions()
        self.set_name("gaupol-view")
        self.set_headers_visible(True)
        self.set_rubber_banding(True)
        selection = self.get_selection()
        selection.set_mode(Gtk.SelectionMode.MULTIPLE)
        self._init_search()
github otsaloma / gaupol / aeidon / subtitle.py View on Github external
def _convert_position(self, value):
        """Return `value` of position in correct mode."""
        if aeidon.is_time(value):
            if self._mode == aeidon.modes.TIME:
                return value
            if self._mode == aeidon.modes.FRAME:
                return self.calc.time_to_frame(value)
        if aeidon.is_frame(value):
            if self._mode == aeidon.modes.TIME:
                return self.calc.frame_to_time(value)
            if self._mode == aeidon.modes.FRAME:
                return value
        if aeidon.is_seconds(value):
            if self._mode == aeidon.modes.TIME:
                return self.calc.seconds_to_time(value)
            if self._mode == aeidon.modes.FRAME:
                return self.calc.seconds_to_frame(value)
        raise ValueError("Invalid type for value: {!r}"
                         .format(type(value)))
github otsaloma / gaupol / gaupol / view.py View on Github external
def _init_props(self, edit_mode):
        """Initialize properties."""
        if edit_mode == aeidon.modes.TIME:
            columns = (int, str, str, float, str, str)
        if edit_mode == aeidon.modes.FRAME:
            columns = (int, int, int, int, str, str)
        store = Gtk.ListStore(*columns)
        self.set_model(store)
        self._init_columns(edit_mode)
        self._init_cell_data_functions()
        self.set_name("gaupol-view")
        self.set_headers_visible(True)
        self.set_rubber_banding(True)
        selection = self.get_selection()
        selection.set_mode(Gtk.SelectionMode.MULTIPLE)
        self._init_search()
github otsaloma / gaupol / aeidon / files / subrip.py View on Github external
# along with this program. If not, see .

"""SubRip file."""

import aeidon
import re

__all__ = ("SubRip",)


class SubRip(aeidon.SubtitleFile):

    """SubRip file."""

    format = aeidon.formats.SUBRIP
    mode = aeidon.modes.TIME

    _re_time_line = re.compile((
        # Techically all these fields should have fixed widths, but in the
        # name of being liberal in accepting input, accept lesser widths
        # assuming that they are just lacking zero-padding from the side
        # that is farther from the decimal point.
        r"^(-?\d{1,2}:\d{1,2}:\d{1,2},\d{1,3}) -->"
        r" (-?\d{1,2}:\d{1,2}:\d{1,2},\d{1,3})"
        r"(  X1:(\d+) X2:(\d+) Y1:(\d+) Y2:(\d+))?\s*$"))

    def read(self):
        """
        Read file and return subtitles.

        Raise :exc:`IOError` if reading fails.
        Raise :exc:`UnicodeError` if decoding fails.
github otsaloma / gaupol / gaupol / agents / tools.py View on Github external
def _on_transform_positions_activate(self, *args):
        """Change positions by linear two-point correction."""
        page = self.get_current_page()
        if page.edit_mode == aeidon.modes.TIME:
            dialog = gaupol.TimeTransformDialog(self.window, self)
        if page.edit_mode == aeidon.modes.FRAME:
            dialog = gaupol.FrameTransformDialog(self.window, self)
        gaupol.util.flash_dialog(dialog)
github otsaloma / gaupol / gaupol / page.py View on Github external
def reload_view_all(self):
        """Clear and repopulate the entire view."""
        store = self.view.get_model()
        self.view.set_model(None)
        store.clear()
        mode = self.edit_mode
        for i, subtitle in enumerate(self.project.subtitles):
            store.insert(i)
            store[i][0] = i + 1
            store[i][1] = subtitle.get_start(mode)
            store[i][2] = subtitle.get_end(mode)
            if mode == aeidon.modes.TIME:
                store[i][3] = subtitle.duration_seconds
            if mode == aeidon.modes.FRAME:
                store[i][3] = subtitle.duration_frame
            store[i][4] = subtitle.main_text
            store[i][5] = subtitle.tran_text
        self.view.set_model(store)
github otsaloma / gaupol / aeidon / files / subviewer2.py View on Github external
# along with this program. If not, see .

"""SubViewer 2.0 file."""

import aeidon
import re

__all__ = ("SubViewer2",)


class SubViewer2(aeidon.SubtitleFile):

    """SubViewer 2.0 file."""

    format = aeidon.formats.SUBVIEWER2
    mode = aeidon.modes.TIME
    _re_time_line = re.compile((r"^(-?\d\d:\d\d:\d\d.\d\d)"
                                r",(-?\d\d:\d\d:\d\d.\d\d)\s*$"))

    def read(self):
        """
        Read file and return subtitles.

        Raise :exc:`IOError` if reading fails.
        Raise :exc:`UnicodeError` if decoding fails.
        """
        self.header = ""
        subtitles = []
        lines = self._read_lines()
        while lines[0].startswith("["):
            self.header += "\n"
            self.header += lines.pop(0)
github otsaloma / gaupol / aeidon / agents / util.py View on Github external
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
github otsaloma / gaupol / aeidon / file.py View on Github external
:cvar format: :attr:`aeidon.formats` item corresponding to file format
    :cvar mode: :attr:`aeidon.modes` item corresponding to native positions
    :ivar encoding: Character encoding used to read and write file
    :ivar has_utf_16_bom: True if BOM found for UTF-16-BE or UTF-16-LE
    :ivar header: String of metadata at the top of the file
    :ivar newline: :attr:`aeidon.newlines` item, detected upon read
    :ivar path: Full, absolute path to the file on disk

    If the file format contains a header, it will default to a fairly blank
    template header read upon instantiation of the class, from either
    ``aeidon.DATA_DIR/headers`` or ``aeidon.DATA_HOME_DIR/headers``. If the
    read file contains a header, it will replace the template.
    """
    format = aeidon.formats.NONE
    mode = aeidon.modes.NONE

    def __init__(self, path, encoding, newline=None):
        """Initialize a :class:`SubtitleFile` instance."""
        self.encoding = encoding
        self.has_utf_16_bom = False
        self.header = (aeidon.util.get_template_header(self.format)
                       if self.format.has_header else "")

        self.newline = newline or aeidon.util.get_default_newline()
        self.path = os.path.abspath(path)

    def copy_from(self, other):
        """Copy generic properties from `other`."""
        self.has_utf_16_bom = other.has_utf_16_bom
        if self.format != other.format: return
        self.header = other.header