gaupol/actions/format.py

Source code for module gaupol.actions.format from file gaupol/actions/format.py.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# -*- coding: utf-8 -*-

# Copyright (C) 2005 Osmo Salomaa
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (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 <http://www.gnu.org/licenses/>.

"""Text formatting actions for :class:`gaupol.Application`."""

import aeidon
import gaupol
_ = aeidon.i18n._


class ShowCaseMenuAction(gaupol.MenuAction):

    """Show the case format menu."""

    def __init__(self):
        """Initialize a :class:`ShowCaseMenuAction` instance."""
        gaupol.MenuAction.__init__(self, "show_case_menu")
        self.set_label(_("Ca_se"))
        self.action_group = "main-unsafe"

    def _affirm_doable(self, application, page, selected_rows):
        """Raise :exc:`aeidon.AffirmationError` if action cannot be done."""
        aeidon.util.affirm(page is not None)
        aeidon.util.affirm(selected_rows)
        col = page.view.get_focus()[1]
        aeidon.util.affirm(col is not None)
        aeidon.util.affirm(page.view.is_text_column(col))


class ToggleDialogDashesAction(gaupol.Action):

    """Add or remove dialogue dashes on the selected texts."""

    def __init__(self):
        """Initialize a :class:`ToggleDialogDashesAction` instance."""
        gaupol.Action.__init__(self, "toggle_dialogue_dashes")
        self.set_label(_("_Dialogue"))
        self.set_tooltip(_("Add or remove dialogue dashes on the selected texts"))
        self.action_group = "main-unsafe"

    def _affirm_doable(self, application, page, selected_rows):
        """Raise :exc:`aeidon.AffirmationError` if action cannot be done."""
        aeidon.util.affirm(page is not None)
        aeidon.util.affirm(selected_rows)
        col = page.view.get_focus()[1]
        aeidon.util.affirm(col is not None)
        aeidon.util.affirm(page.view.is_text_column(col))


class ToggleItalicizationAction(gaupol.Action):

    """Italicize or unitalicize the selected texts."""

    def __init__(self):
        """Initialize a :class:`ToggleItalicizationAction` instance."""
        gaupol.Action.__init__(self, "toggle_italicization")
        self.set_icon_name("format-text-italic")
        self.set_label(_("_Italic"))
        self.set_tooltip(_("Italicize or unitalicize the selected texts"))
        self.action_group = "main-unsafe"

    def _affirm_doable(self, application, page, selected_rows):
        """Raise :exc:`aeidon.AffirmationError` if action cannot be done."""
        aeidon.util.affirm(page is not None)
        aeidon.util.affirm(selected_rows)
        col = page.view.get_focus()[1]
        aeidon.util.affirm(col is not None)
        aeidon.util.affirm(page.view.is_text_column(col))
        doc = page.text_column_to_document(col)
        markup = page.project.get_markup(doc)
        aeidon.util.affirm(markup is not None)
        aeidon.util.affirm(markup.italic_tag is not None)


class UseLowerCaseAction(gaupol.Action):

    """Change the selected texts to lower case."""

    def __init__(self):
        """Initialize a :class:`UseLowerCaseAction` instance."""
        gaupol.Action.__init__(self, "use_lower_case")
        self.set_label(_("_Lower"))
        self.set_tooltip(_("Change the selected texts to lower case"))
        self.action_group = "main-unsafe"

    def _affirm_doable(self, application, page, selected_rows):
        """Raise :exc:`aeidon.AffirmationError` if action cannot be done."""
        aeidon.util.affirm(page is not None)
        aeidon.util.affirm(selected_rows)
        col = page.view.get_focus()[1]
        aeidon.util.affirm(col is not None)
        aeidon.util.affirm(page.view.is_text_column(col))


class UseSentenceCaseAction(gaupol.Action):

    """Change the selected texts to sentence case."""

    def __init__(self):
        """Initialize a :class:`UseSentenceCaseAction` instance."""
        gaupol.Action.__init__(self, "use_sentence_case")
        self.set_label(_("_Sentence"))
        self.set_tooltip(_("Change the selected texts to sentence case"))
        self.action_group = "main-unsafe"

    def _affirm_doable(self, application, page, selected_rows):
        """Raise :exc:`aeidon.AffirmationError` if action cannot be done."""
        aeidon.util.affirm(page is not None)
        aeidon.util.affirm(selected_rows)
        col = page.view.get_focus()[1]
        aeidon.util.affirm(col is not None)
        aeidon.util.affirm(page.view.is_text_column(col))


class UseTitleCaseAction(gaupol.Action):

    """Change the selected texts to title case."""

    def __init__(self):
        """Initialize a :class:`UseTitleCaseAction` instance."""
        gaupol.Action.__init__(self, "use_title_case")
        self.set_label(_("_Title"))
        self.set_tooltip(_("Change the selected texts to title case"))
        self.action_group = "main-unsafe"

    def _affirm_doable(self, application, page, selected_rows):
        """Raise :exc:`aeidon.AffirmationError` if action cannot be done."""
        aeidon.util.affirm(page is not None)
        aeidon.util.affirm(selected_rows)
        col = page.view.get_focus()[1]
        aeidon.util.affirm(col is not None)
        aeidon.util.affirm(page.view.is_text_column(col))


class UseUpperCaseAction(gaupol.Action):

    """Change the selected texts to upper case."""

    def __init__(self):
        """Initialize a :class:`UseUpperCaseAction` instance."""
        gaupol.Action.__init__(self, "use_upper_case")
        self.set_label(_("_Upper"))
        self.set_tooltip(_("Change the selected texts to upper case"))
        self.action_group = "main-unsafe"

    def _affirm_doable(self, application, page, selected_rows):
        """Raise :exc:`aeidon.AffirmationError` if action cannot be done."""
        aeidon.util.affirm(page is not None)
        aeidon.util.affirm(selected_rows)
        col = page.view.get_focus()[1]
        aeidon.util.affirm(col is not None)
        aeidon.util.affirm(page.view.is_text_column(col))


__all__ = tuple(x for x in dir() if x.endswith("Action"))