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

Commits:

2 changed files:

Changes:

  • gajim/gtk/chat_list.py
    ... ... @@ -861,9 +861,9 @@ def set_message_text(self,
    861 861
                 text = text.replace('/me', f'* {nickname}', 1)
    
    862 862
                 text = f'<i>{text}</i>'
    
    863 863
     
    
    864
    -        # Split by newline and display last line
    
    864
    +        # Split by newline and display last line (or first, if last is newline)
    
    865 865
             lines = text.split('\n')
    
    866
    -        text = lines[-1]
    
    866
    +        text = lines[-1] or lines[0]
    
    867 867
             self._ui.message_label.set_markup(text)
    
    868 868
     
    
    869 869
             if icon is None:
    

  • gajim/gtk/xml_console.py
    ... ... @@ -12,6 +12,11 @@
    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 List
    
    17
    +from typing import Optional
    
    18
    +from typing import Tuple
    
    19
    +
    
    15 20
     import time
    
    16 21
     
    
    17 22
     import nbxmpp
    
    ... ... @@ -22,6 +27,7 @@
    22 27
     
    
    23 28
     from gajim.common import app
    
    24 29
     from gajim.common import ged
    
    30
    +from gajim.common.const import Direction
    
    25 31
     from gajim.common.i18n import _
    
    26 32
     
    
    27 33
     from .builder import get_builder
    
    ... ... @@ -37,7 +43,7 @@
    37 43
     
    
    38 44
     
    
    39 45
     class XMLConsoleWindow(Gtk.ApplicationWindow, EventHelper):
    
    40
    -    def __init__(self):
    
    46
    +    def __init__(self) -> None:
    
    41 47
             Gtk.ApplicationWindow.__init__(self)
    
    42 48
             EventHelper.__init__(self)
    
    43 49
             self.set_application(app.app)
    
    ... ... @@ -47,8 +53,8 @@ def __init__(self):
    47 53
             self.set_show_menubar(False)
    
    48 54
             self.set_name('XMLConsoleWindow')
    
    49 55
     
    
    50
    -        self.selected_account = None
    
    51
    -        self._selected_send_account = None
    
    56
    +        self.selected_account: Optional[str] = None
    
    57
    +        self._selected_send_account: Optional[str] = None
    
    52 58
             self.presence = True
    
    53 59
             self.message = True
    
    54 60
             self.iq = True
    
    ... ... @@ -64,7 +70,8 @@ def __init__(self):
    64 70
             self._set_titlebar()
    
    65 71
             self.add(self._ui.box)
    
    66 72
     
    
    67
    -        self._ui.paned.set_position(self._ui.paned.get_property('max-position'))
    
    73
    +        self._ui.paned.set_position(
    
    74
    +            self._ui.paned.get_property('max-position'))
    
    68 75
     
    
    69 76
             self._combo = MaxWidthComboBoxText()
    
    70 77
             self._combo.set_max_size(200)
    
    ... ... @@ -90,7 +97,7 @@ def __init__(self):
    90 97
     
    
    91 98
             self.show_all()
    
    92 99
     
    
    93
    -        self.connect('key_press_event', self._on_key_press_event)
    
    100
    +        self.connect('key_press_event', self._on_key_press)
    
    94 101
             self._ui.connect_signals(self)
    
    95 102
     
    
    96 103
             self.register_events([
    
    ... ... @@ -99,7 +106,7 @@ def __init__(self):
    99 106
                 ('style-changed', ged.GUI1, self._on_style_changed)
    
    100 107
             ])
    
    101 108
     
    
    102
    -    def _get_style_scheme(self):
    
    109
    +    def _get_style_scheme(self) -> Optional[GtkSource.StyleScheme]:
    
    103 110
             if app.css_config.prefer_dark:
    
    104 111
                 style_scheme = self._style_scheme_manager.get_scheme(
    
    105 112
                     'solarized-dark')
    
    ... ... @@ -108,22 +115,22 @@ def _get_style_scheme(self):
    108 115
                     'solarized-light')
    
    109 116
             return style_scheme
    
    110 117
     
    
    111
    -    def _on_style_changed(self, *args):
    
    118
    +    def _on_style_changed(self, *args: Any) -> None:
    
    112 119
             style_scheme = self._get_style_scheme()
    
    113 120
             if style_scheme is not None:
    
    114 121
                 self._ui.sourceview.get_buffer().set_style_scheme(style_scheme)
    
    115 122
     
    
    116
    -    def _on_value_change(self, combo):
    
    123
    +    def _on_value_change(self, combo: Gtk.ComboBox) -> None:
    
    117 124
             self._selected_send_account = combo.get_active_id()
    
    118 125
     
    
    119
    -    def _set_titlebar(self):
    
    126
    +    def _set_titlebar(self) -> None:
    
    120 127
             if self.selected_account is None:
    
    121 128
                 title = _('All Accounts')
    
    122 129
             else:
    
    123 130
                 title = app.get_jid_from_account(self.selected_account)
    
    124 131
             self._ui.headerbar.set_subtitle(title)
    
    125 132
     
    
    126
    -    def _create_tags(self):
    
    133
    +    def _create_tags(self) -> None:
    
    127 134
             tags = [
    
    128 135
                 'incoming',
    
    129 136
                 'outgoing',
    
    ... ... @@ -135,7 +142,7 @@ def _create_tags(self):
    135 142
             for tag_name in tags:
    
    136 143
                 self._ui.sourceview.get_buffer().create_tag(tag_name)
    
    137 144
     
    
    138
    -    def _on_key_press_event(self, _widget, event):
    
    145
    +    def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None:
    
    139 146
             if event.keyval == Gdk.KEY_Escape:
    
    140 147
                 if self._ui.search_revealer.get_child_revealed():
    
    141 148
                     self._ui.search_revealer.set_reveal_child(False)
    
    ... ... @@ -153,10 +160,15 @@ def _on_key_press_event(self, _widget, event):
    153 160
                 self._ui.search_toggle.set_active(
    
    154 161
                     not self._ui.search_revealer.get_child_revealed())
    
    155 162
             if event.keyval == Gdk.KEY_F3:
    
    156
    -            self._find(True)
    
    163
    +            self._find(Direction.NEXT)
    
    157 164
     
    
    158
    -    def _on_row_activated(self, _listbox, row):
    
    165
    +    def _on_row_activated(self,
    
    166
    +                          _listbox: Gtk.ListBox,
    
    167
    +                          row: Gtk.ListBoxRow
    
    168
    +                          ) -> None:
    
    159 169
             text = row.get_child().get_text()
    
    170
    +
    
    171
    +        # pylint: disable=line-too-long
    
    160 172
             input_text = None
    
    161 173
             if text == 'Presence':
    
    162 174
                 input_text = (
    
    ... ... @@ -180,13 +192,14 @@ def _on_row_activated(self, _listbox, row):
    180 192
                     '<iq to="" type="get" xmlns="jabber:client">\n'
    
    181 193
                     '<query xmlns="http://jabber.org/protocol/disco#info"></query>\n'
    
    182 194
                     '</iq>')
    
    195
    +        # pylint: enable=line-too-long
    
    183 196
     
    
    184 197
             if input_text is not None:
    
    185 198
                 buffer_ = self._ui.input_entry.get_buffer()
    
    186 199
                 buffer_.set_text(input_text)
    
    187 200
                 self._ui.input_entry.grab_focus()
    
    188 201
     
    
    189
    -    def _on_send(self, *args):
    
    202
    +    def _on_send(self, *args: Any) -> None:
    
    190 203
             if not self._selected_send_account:
    
    191 204
                 return
    
    192 205
             if not app.account_is_available(self._selected_send_account):
    
    ... ... @@ -217,13 +230,13 @@ def _on_send(self, *args):
    217 230
                 self.last_stanza = stanza
    
    218 231
                 buffer_.set_text('')
    
    219 232
     
    
    220
    -    def _on_paste_last(self, *args):
    
    233
    +    def _on_paste_last(self, *args: Any) -> None:
    
    221 234
             buffer_ = self._ui.input_entry.get_buffer()
    
    222 235
             if buffer_ is not None and self.last_stanza is not None:
    
    223 236
                 buffer_.set_text(self.last_stanza)
    
    224 237
             self._ui.input_entry.grab_focus()
    
    225 238
     
    
    226
    -    def _on_input(self, button, *args):
    
    239
    +    def _on_input(self, button: Gtk.ToggleButton) -> None:
    
    227 240
             if button.get_active():
    
    228 241
                 self._ui.paned.get_child2().show()
    
    229 242
                 self._ui.send.show()
    
    ... ... @@ -238,18 +251,21 @@ def _on_input(self, button, *args):
    238 251
                 self._combo.hide()
    
    239 252
                 self._ui.menubutton.hide()
    
    240 253
     
    
    241
    -    def _on_search_toggled(self, button):
    
    254
    +    def _on_search_toggled(self, button: Gtk.ToggleButton) -> None:
    
    242 255
             self._ui.search_revealer.set_reveal_child(button.get_active())
    
    243 256
             self._ui.search_entry.grab_focus()
    
    244 257
     
    
    245
    -    def _on_search_activate(self, _widget):
    
    246
    -        self._find(True)
    
    258
    +    def _on_search_activate(self, _entry: Gtk.SearchEntry) -> None:
    
    259
    +        self._find(Direction.NEXT)
    
    247 260
     
    
    248
    -    def _on_search_clicked(self, button):
    
    249
    -        forward = bool(button is self._ui.search_forward)
    
    250
    -        self._find(forward)
    
    261
    +    def _on_search_clicked(self, button: Gtk.ToolButton) -> None:
    
    262
    +        if button is self._ui.search_forward:
    
    263
    +            direction = Direction.NEXT
    
    264
    +        else:
    
    265
    +            direction = Direction.PREV
    
    266
    +        self._find(direction)
    
    251 267
     
    
    252
    -    def _find(self, forward):
    
    268
    +    def _find(self, direction: Direction) -> None:
    
    253 269
             search_str = self._ui.search_entry.get_text()
    
    254 270
             textbuffer = self._ui.sourceview.get_buffer()
    
    255 271
             cursor_mark = textbuffer.get_insert()
    
    ... ... @@ -265,7 +281,7 @@ def _find(self, forward):
    265 281
             if search_str != self.last_search:
    
    266 282
                 current_pos = textbuffer.get_start_iter()
    
    267 283
     
    
    268
    -        if forward:
    
    284
    +        if direction == Direction.NEXT:
    
    269 285
                 match = current_pos.forward_search(
    
    270 286
                     search_str,
    
    271 287
                     Gtk.TextSearchFlags.VISIBLE_ONLY |
    
    ... ... @@ -287,7 +303,7 @@ def _find(self, forward):
    287 303
             self.last_search = search_str
    
    288 304
     
    
    289 305
         @staticmethod
    
    290
    -    def _get_accounts():
    
    306
    +    def _get_accounts() -> List[Tuple[str, str]]:
    
    291 307
             accounts = app.get_accounts_sorted()
    
    292 308
             combo_accounts = []
    
    293 309
             for account in accounts:
    
    ... ... @@ -296,8 +312,8 @@ def _get_accounts():
    296 312
             combo_accounts.append(('AccountWizard', 'Account Wizard'))
    
    297 313
             return combo_accounts
    
    298 314
     
    
    299
    -    def _on_filter_options(self, *args):
    
    300
    -        if self.filter_dialog:
    
    315
    +    def _on_filter_options(self, _button: Gtk.Button) -> None:
    
    316
    +        if self.filter_dialog is not None:
    
    301 317
                 self.filter_dialog.present()
    
    302 318
                 return
    
    303 319
     
    
    ... ... @@ -337,17 +353,17 @@ def _on_filter_options(self, *args):
    337 353
                                                 settings, self.selected_account)
    
    338 354
             self.filter_dialog.connect('destroy', self._on_filter_destroyed)
    
    339 355
     
    
    340
    -    def _on_filter_destroyed(self, _win):
    
    356
    +    def _on_filter_destroyed(self, _widget: Gtk.Widget) -> None:
    
    341 357
             self.filter_dialog = None
    
    342 358
     
    
    343
    -    def _on_clear(self, *args):
    
    359
    +    def _on_clear(self, _button: Gtk.Button) -> None:
    
    344 360
             self._ui.sourceview.get_buffer().set_text('')
    
    345 361
     
    
    346
    -    def _set_account(self, value, _data):
    
    362
    +    def _set_account(self, value: str, _data: Any) -> None:
    
    347 363
             self.selected_account = value
    
    348 364
             self._set_titlebar()
    
    349 365
     
    
    350
    -    def _on_setting(self, value, data):
    
    366
    +    def _on_setting(self, value: bool, data: str) -> None:
    
    351 367
             setattr(self, data, value)
    
    352 368
             value = not value
    
    353 369
             table = self._ui.sourceview.get_buffer().get_tag_table()