Welcome to mirror list, hosted at ThFree Co, Russian Federation.

msg_box_size.py « message_box_size - dev.gajim.org/gajim/gajim-plugins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a19f3c10f5a602655d6b08ff21a727fbf0f2dc9d (plain)
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
#
# This file is part of Gajim.
#
# Gajim 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.
#
# Gajim 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 Gajim. If not, see <http://www.gnu.org/licenses/>.

from __future__ import annotations

from typing import cast

from functools import partial

from gajim.gui.message_input import MessageInputTextView

from gajim.plugins import GajimPlugin
from gajim.plugins.plugins_i18n import _

from message_box_size.config_dialog import MessageBoxSizeConfigDialog


class MsgBoxSizePlugin(GajimPlugin):
    def init(self) -> None:
        # pylint: disable=attribute-defined-outside-init
        self.description = _('Allows you to adjust the height '
                             'of the message input.')
        self.config_dialog = partial(MessageBoxSizeConfigDialog, self)
        self.gui_extension_points = {
            'message_input': (self._on_message_input_created, None)
        }
        self.config_default_values = {
            'HEIGHT': (20, ''),
        }
        self._message_input = None

    def _on_message_input_created(self,
                                  message_input: MessageInputTextView
                                  ) -> None:

        self._message_input = message_input
        self.set_input_height(cast(int, self.config['HEIGHT']))

    def deactivate(self) -> None:
        self.set_input_height(-1)

    def set_input_height(self, height: int) -> None:
        assert self._message_input is not None
        self._message_input.set_size_request(-1, height)