Daniel Brötzmann pushed to branch master at gajim / gajim

Commits:

1 changed file:

Changes:

  • gajim/gtk/single_message.py
    ... ... @@ -12,9 +12,14 @@
    12 12
     # You should have received a copy of the GNU General Public License
    
    13 13
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    14 14
     
    
    15
    +from typing import Any
    
    16
    +from typing import Optional
    
    17
    +
    
    15 18
     from gi.repository import Gdk
    
    16 19
     from gi.repository import Gtk
    
    17 20
     
    
    21
    +from nbxmpp.protocol import JID
    
    22
    +
    
    18 23
     from gajim.common import app
    
    19 24
     from gajim.common.helpers import get_contact_dict_for_account
    
    20 25
     from gajim.common.helpers import validate_jid
    
    ... ... @@ -31,7 +36,10 @@
    31 36
     
    
    32 37
     
    
    33 38
     class SingleMessageWindow(Gtk.ApplicationWindow):
    
    34
    -    def __init__(self, account, recipients=None):
    
    39
    +    def __init__(self,
    
    40
    +                 account: str,
    
    41
    +                 recipients: Optional[str] = None
    
    42
    +                 ) -> None:
    
    35 43
             Gtk.ApplicationWindow.__init__(self)
    
    36 44
             self.set_application(app.app)
    
    37 45
             self.set_position(Gtk.WindowPosition.CENTER)
    
    ... ... @@ -54,10 +62,7 @@ def __init__(self, account, recipients=None):
    54 62
             self._message_buffer = self._ui.message_textview.get_buffer()
    
    55 63
             self._message_buffer.connect('changed', self._update_char_counter)
    
    56 64
     
    
    57
    -        if isinstance(recipients, list):
    
    58
    -            jids = ', '.join([contact.jid for contact in recipients])
    
    59
    -            self._ui.recipients_entry.set_text(jids)
    
    60
    -        elif recipients is not None:
    
    65
    +        if recipients is not None:
    
    61 66
                 self._ui.recipients_entry.set_text(recipients)
    
    62 67
     
    
    63 68
             if (app.settings.get('use_speller') and
    
    ... ... @@ -85,28 +90,28 @@ def __init__(self, account, recipients=None):
    85 90
             if self._recipients is not None:
    
    86 91
                 self._ui.message_textview.grab_focus()
    
    87 92
     
    
    88
    -        self.connect('key-press-event', self._on_key_press_event)
    
    93
    +        self.connect('key-press-event', self._on_key_press)
    
    89 94
             self._ui.connect_signals(self)
    
    90 95
     
    
    91 96
             self.show_all()
    
    92 97
     
    
    93
    -    def _on_key_press_event(self, _widget, event):
    
    98
    +    def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None:
    
    94 99
             if event.keyval == Gdk.KEY_Escape:
    
    95 100
                 self.destroy()
    
    96 101
     
    
    97
    -    def _on_changed(self, *args):
    
    102
    +    def _on_changed(self, *args: Any) -> None:
    
    98 103
             recipients = self._ui.recipients_entry.get_text()
    
    99 104
             begin, end = self._message_buffer.get_bounds()
    
    100 105
             message = self._message_buffer.get_text(begin, end, True)
    
    101
    -        self._ui.send_button.set_sensitive(recipients and message)
    
    106
    +        self._ui.send_button.set_sensitive(bool(recipients and message))
    
    102 107
     
    
    103
    -    def _update_char_counter(self, _widget):
    
    108
    +    def _update_char_counter(self, _widget: Gtk.TextView) -> None:
    
    104 109
             characters_no = self._message_buffer.get_char_count()
    
    105 110
             self._ui.count_chars_label.set_text(
    
    106 111
                 _('Characters typed: %s') % str(characters_no))
    
    107 112
             self._on_changed()
    
    108 113
     
    
    109
    -    def _on_send_clicked(self, _widget):
    
    114
    +    def _on_send_clicked(self, _widget: Gtk.Button) -> None:
    
    110 115
             if not app.account_is_available(self.account):
    
    111 116
                 ErrorDialog(_('Not Connected'),
    
    112 117
                             _('Please make sure you are connected with "%s".') %
    
    ... ... @@ -118,7 +123,7 @@ def _on_send_clicked(self, _widget):
    118 123
             begin, end = self._message_buffer.get_bounds()
    
    119 124
             message = self._message_buffer.get_text(begin, end, True)
    
    120 125
     
    
    121
    -        recipient_list = []
    
    126
    +        recipient_list: list[JID] = []
    
    122 127
             for jid in jids.split(','):
    
    123 128
                 try:
    
    124 129
                     jid = validate_jid(jid.strip())