How to use the aeidon.Delegate 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 / help.py View on Github external
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .

"""Help and information."""

import aeidon
import gaupol


class HelpAgent(aeidon.Delegate):

    """Help and information."""

    @aeidon.deco.export
    def _on_browse_documentation_activate(self, *args):
        """Open web browser to view documentation."""
        gaupol.util.show_uri(gaupol.DOCUMENTATION_URL)

    @aeidon.deco.export
    def _on_report_a_bug_activate(self, *args):
        """Open web browser to submit a bug report."""
        gaupol.util.show_uri(gaupol.BUG_REPORT_URL)

    @aeidon.deco.export
    def _on_view_about_dialog_activate(self, *args):
        """Show information about Gaupol."""
github otsaloma / gaupol / aeidon / agents / format.py View on Github external
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .

"""Changing the appearance of texts."""

import aeidon
import re

from aeidon.i18n import _


class FormatAgent(aeidon.Delegate):

    """Changing the appearance of texts."""

    _re_alphanum = re.compile(r"\w")

    @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 = ""
github otsaloma / gaupol / gaupol / agents / text.py View on Github external
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .

"""Processing texts."""

import aeidon
import gaupol


class TextAgent(aeidon.Delegate):

    """Processing texts."""

    @aeidon.deco.export
    def _on_check_spelling_activate(self, *args):
        """Check for incorrect spelling."""
        gaupol.util.set_cursor_busy(self.window)
        try:
            # Fails if no dictionary for conf.spell_check.language.
            dialog = gaupol.SpellCheckDialog(self.window, self)
        except ValueError:
            return gaupol.util.set_cursor_normal(self.window)
        gaupol.util.set_cursor_normal(self.window)
        gaupol.util.flash_dialog(dialog)

    @aeidon.deco.export
github otsaloma / gaupol / gaupol / dialogs / preferences.py View on Github external
def __init__(self, master, application):
        """Initialize an :class:`EditorPage` instance."""
        aeidon.Delegate.__init__(self, master)
        self._set_attributes(self._widgets, "editor_")
        self.application = application
        self._init_length_combo()
        self._init_values()
github otsaloma / gaupol / aeidon / agents / register.py View on Github external
the method has been run, cuts the undo and redo stacks if needed and
    defaults the `register` keyword argument to :attr:`aeidon.registers.DO`.

Each method marked as revertable should match exactly one action in the undo
and redo stacks. Hence, if a method calls other revertable methods, the
resulting action needs to be grouped as one using :meth:`group_actions`.

If a revertable method needs to be performed without the possibility of
reverting, the `register` keyword argument should be given a value of ``None``.
This way it will not be in any way processed by the undo/redo system.
"""

import aeidon


class RegisterAgent(aeidon.Delegate):

    """
    Managing revertable actions.

    :ivar _do_description: Original description of the action
    """

    def __init__(self, master):
        """Initialize a :class:`RegisterAgent` instance."""
        aeidon.Delegate.__init__(self, master)
        self._do_description = None
        aeidon.util.connect(self, self, "notify::undo_limit")

    def _break_action_group(self, stack, index=0):
        """Break the action group in `stack` and return amount broken into."""
        action_group = stack.pop(index)
github otsaloma / gaupol / aeidon / agents / util.py View on Github external
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .

"""Miscellaneous helper methods."""

import aeidon


class UtilityAgent(aeidon.Delegate):

    """Miscellaneous helper methods."""

    @aeidon.deco.export
    def get_all_indices(self):
        """Return a list of all indices of subtitles."""
        return list(range(len(self.subtitles)))

    @aeidon.deco.export
    def get_changed(self, doc):
        """Return the changed value corresponding to `doc`."""
        if doc == aeidon.documents.MAIN:
            return self.main_changed
        if doc == aeidon.documents.TRAN:
            return self.tran_changed
        raise ValueError("Invalid document: {!r}"
github otsaloma / gaupol / aeidon / agents / text.py View on Github external
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .

"""Automatic correcting of texts."""

import aeidon
import re

from aeidon.i18n import _


class TextAgent(aeidon.Delegate):

    """Automatic correcting of texts."""

    _re_capitalizable = re.compile(r"^\W*(?
github otsaloma / gaupol / gaupol / agents / format.py View on Github external
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .

"""Formatting text."""

import aeidon


class FormatAgent(aeidon.Delegate):

    """Formatting text."""

    @aeidon.deco.export
    def _on_toggle_dialogue_dashes_activate(self, *args):
        """Add or remove dialogue dashes on the selected texts."""
        page = self.get_current_page()
        rows = page.view.get_selected_rows()
        col = page.view.get_focus()[1]
        doc = page.text_column_to_document(col)
        page.project.toggle_dialogue_dashes(rows, doc)

    @aeidon.deco.export
    def _on_toggle_italicization_activate(self, *args):
        """Italicize or unitalicize the selected texts."""
        page = self.get_current_page()
github otsaloma / gaupol / gaupol / agents / search.py View on Github external
def __init__(self, master):
        """Initialize a :class:`SearchAgent` instance."""
        aeidon.Delegate.__init__(self, master)
        self._search_dialog = None