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

Commits:

3 changed files:

Changes:

  • gajim/gtk/groupchat_info.py
    ... ... @@ -104,8 +104,8 @@
    104 104
     class GroupChatInfoScrolled(Gtk.ScrolledWindow):
    
    105 105
         def __init__(self,
    
    106 106
                      account: Optional[str] = None,
    
    107
    -                 width: Optional[int] = 300,
    
    108
    -                 minimal: Optional[bool] = False
    
    107
    +                 width: int = 300,
    
    108
    +                 minimal: bool = False
    
    109 109
                      ) -> None:
    
    110 110
             Gtk.ScrolledWindow.__init__(self)
    
    111 111
             self.set_size_request(width, -1)
    
    ... ... @@ -131,7 +131,7 @@ def __init__(self,
    131 131
             self._ui.connect_signals(self)
    
    132 132
             self.show_all()
    
    133 133
     
    
    134
    -    def get_account(self) -> str:
    
    134
    +    def get_account(self) -> Optional[str]:
    
    135 135
             return self._account
    
    136 136
     
    
    137 137
         def set_account(self, account: str) -> None:
    
    ... ... @@ -166,20 +166,19 @@ def set_from_disco_info(self, info: DiscoInfo) -> None:
    166 166
             if self._account is None:
    
    167 167
                 name = info.muc_name
    
    168 168
             else:
    
    169
    -            con = app.connections[self._account]
    
    170
    -            name = get_groupchat_name(con, info.jid)
    
    169
    +            client = app.get_client(self._account)
    
    170
    +            name = get_groupchat_name(client, info.jid)
    
    171
    +        
    
    172
    +            contact = client.get_module('Contacts').get_contact(
    
    173
    +                info.jid, groupchat=True)
    
    174
    +            surface = contact.get_avatar(
    
    175
    +                AvatarSize.GROUP_INFO,
    
    176
    +                self.get_scale_factor())
    
    177
    +            self._ui.avatar_image.set_from_surface(surface)
    
    178
    +
    
    171 179
             self._ui.name.set_text(name)
    
    172 180
             self._ui.name.set_visible(True)
    
    173 181
     
    
    174
    -        # Set avatar
    
    175
    -        client = app.get_client(self._account)
    
    176
    -        contact = client.get_module('Contacts').get_contact(
    
    177
    -            info.jid, groupchat=True)
    
    178
    -        surface = contact.get_avatar(
    
    179
    -            AvatarSize.GROUP_INFO,
    
    180
    -            self.get_scale_factor())
    
    181
    -        self._ui.avatar_image.set_from_surface(surface)
    
    182
    -
    
    183 182
             # Set description
    
    184 183
             has_desc = bool(info.muc_description)
    
    185 184
             self._ui.description.set_text(info.muc_description or '')
    
    ... ... @@ -230,7 +229,7 @@ def set_from_disco_info(self, info: DiscoInfo) -> None:
    230 229
     
    
    231 230
             self._add_features(info.features)
    
    232 231
     
    
    233
    -    def _add_features(self, features: List[str]) -> None:
    
    232
    +    def _add_features(self, features: list[str]) -> None:
    
    234 233
             grid = self._ui.info_grid
    
    235 234
             for row in range(30, 9, -1):
    
    236 235
                 # Remove everything from row 30 to 10
    
    ... ... @@ -260,23 +259,23 @@ def _on_copy_address(self, _button: Gtk.Button) -> None:
    260 259
             clipboard.set_text(f'xmpp:{self._info.jid}?join', -1)
    
    261 260
     
    
    262 261
         @staticmethod
    
    263
    -    def _on_activate_log_link(button):
    
    262
    +    def _on_activate_log_link(button: Gtk.LinkButton) -> int:
    
    264 263
             open_uri(button.get_uri())
    
    265 264
             return Gdk.EVENT_STOP
    
    266 265
     
    
    267
    -    def _on_activate_contact_link(self, button):
    
    266
    +    def _on_activate_contact_link(self, button: Gtk.LinkButton) -> int:
    
    268 267
             open_uri(f'xmpp:{button.get_uri()}?message', account=self._account)
    
    269 268
             return Gdk.EVENT_STOP
    
    270 269
     
    
    271 270
         @staticmethod
    
    272
    -    def _on_activate_subject_link(_label, uri):
    
    271
    +    def _on_activate_subject_link(_label: Gtk.Label, uri: str) -> int:
    
    273 272
             # We have to use this, because the default GTK handler
    
    274 273
             # is not cross-platform compatible
    
    275 274
             open_uri(uri)
    
    276 275
             return Gdk.EVENT_STOP
    
    277 276
     
    
    278 277
         @staticmethod
    
    279
    -    def _get_feature_icon(icon, tooltip: str) -> Gtk.Image:
    
    278
    +    def _get_feature_icon(icon: str, tooltip: str) -> Gtk.Image:
    
    280 279
             image = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU)
    
    281 280
             image.set_valign(Gtk.Align.CENTER)
    
    282 281
             image.set_halign(Gtk.Align.END)
    
    ... ... @@ -291,7 +290,7 @@ def _get_feature_label(text: str) -> Gtk.Label:
    291 290
             return label
    
    292 291
     
    
    293 292
         def _get_contact_button(self, contact: str) -> Gtk.Button:
    
    294
    -        button = Gtk.LinkButton.new(contact)
    
    293
    +        button = Gtk.LinkButton(label=contact)
    
    295 294
             button.set_halign(Gtk.Align.START)
    
    296 295
             button.get_style_context().add_class('link-button')
    
    297 296
             button.connect('activate-link', self._on_activate_contact_link)
    

  • gajim/gtk/groupchat_invitation.py
    ... ... @@ -16,6 +16,7 @@
    16 16
     from gi.repository import Gtk
    
    17 17
     
    
    18 18
     from gajim.common import app
    
    19
    +from gajim.common.events import MucInvitation
    
    19 20
     from gajim.common.i18n import _
    
    20 21
     from gajim.common.helpers import get_group_chat_nick
    
    21 22
     
    
    ... ... @@ -25,7 +26,7 @@
    25 26
     
    
    26 27
     
    
    27 28
     class GroupChatInvitation(Gtk.ApplicationWindow):
    
    28
    -    def __init__(self, account, event):
    
    29
    +    def __init__(self, account: str, event: MucInvitation) -> None:
    
    29 30
             Gtk.ApplicationWindow.__init__(self)
    
    30 31
             self.set_name('GroupChatInvitation')
    
    31 32
             self.set_application(app.app)
    
    ... ... @@ -100,7 +101,7 @@ def __init__(self, account, event):
    100 101
     
    
    101 102
             main_box.add(button_box)
    
    102 103
     
    
    103
    -        self.connect('key-press-event', self._on_key_press_event)
    
    104
    +        self.connect('key-press-event', self._on_key_press)
    
    104 105
     
    
    105 106
             self.add(main_box)
    
    106 107
     
    
    ... ... @@ -109,16 +110,16 @@ def __init__(self, account, event):
    109 110
     
    
    110 111
             self.show_all()
    
    111 112
     
    
    112
    -    def _on_key_press_event(self, _widget, event):
    
    113
    +    def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None:
    
    113 114
             if event.keyval == Gdk.KEY_Escape:
    
    114 115
                 self.destroy()
    
    115 116
     
    
    116
    -    def _on_join(self, _widget):
    
    117
    +    def _on_join(self, _button: Gtk.Button) -> None:
    
    117 118
             nickname = self._nick_chooser.get_text()
    
    118 119
             app.interface.show_add_join_groupchat(
    
    119 120
                 self.account, self._room_jid, nickname=nickname)
    
    120 121
             self.destroy()
    
    121 122
     
    
    122
    -    def _on_decline(self, _widget):
    
    123
    +    def _on_decline(self, _button: Gtk.Button) -> None:
    
    123 124
             self._client.get_module('MUC').decline(self._room_jid, self._from)
    
    124 125
             self.destroy()

  • gajim/gtk/groupchat_join.py
    ... ... @@ -12,6 +12,9 @@
    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 cast
    
    16
    +from typing import Any
    
    17
    +
    
    15 18
     import logging
    
    16 19
     
    
    17 20
     from gi.repository import Gtk
    
    ... ... @@ -19,6 +22,7 @@
    19 22
     from gi.repository import Pango
    
    20 23
     
    
    21 24
     from nbxmpp.errors import StanzaError
    
    25
    +from nbxmpp.task import Task
    
    22 26
     
    
    23 27
     from gajim.common import app
    
    24 28
     from gajim.common.i18n import _
    
    ... ... @@ -35,7 +39,7 @@
    35 39
     
    
    36 40
     
    
    37 41
     class GroupchatJoin(Gtk.ApplicationWindow):
    
    38
    -    def __init__(self, account, jid):
    
    42
    +    def __init__(self, account: str, jid: str) -> None:
    
    39 43
             Gtk.ApplicationWindow.__init__(self)
    
    40 44
             self.set_name('GroupchatJoin')
    
    41 45
             self.set_application(app.app)
    
    ... ... @@ -61,7 +65,8 @@ def __init__(self, account, jid):
    61 65
             self._stack.add_named(ErrorPage(), 'error')
    
    62 66
     
    
    63 67
             self._stack.set_visible_child_name('progress')
    
    64
    -        self._stack.get_visible_child().start()
    
    68
    +        progress_page = cast(ProgressPage, self._stack.get_visible_child())
    
    69
    +        progress_page.start()
    
    65 70
     
    
    66 71
             self._stack.connect('notify::visible-child-name',
    
    67 72
                                 self._on_page_changed)
    
    ... ... @@ -84,7 +89,7 @@ def __init__(self, account, jid):
    84 89
     
    
    85 90
             self._main_box.add(join_box)
    
    86 91
     
    
    87
    -        self.connect('key-press-event', self._on_key_press_event)
    
    92
    +        self.connect('key-press-event', self._on_key_press)
    
    88 93
             self.connect('destroy', self._on_destroy)
    
    89 94
     
    
    90 95
             self.add(self._main_box)
    
    ... ... @@ -97,13 +102,13 @@ def __init__(self, account, jid):
    97 102
                 request_vcard=True,
    
    98 103
                 callback=self._disco_info_received)
    
    99 104
     
    
    100
    -    def _on_page_changed(self, stack, _param):
    
    105
    +    def _on_page_changed(self, stack: Gtk.Stack, _param: Any) -> None:
    
    101 106
             name = stack.get_visible_child_name()
    
    102 107
             self._join_button.set_sensitive(name == 'info')
    
    103 108
             self._nick_chooser.set_sensitive(name == 'info')
    
    104 109
     
    
    105 110
         @ensure_not_destroyed
    
    106
    -    def _disco_info_received(self, task):
    
    111
    +    def _disco_info_received(self, task: Task) -> None:
    
    107 112
             try:
    
    108 113
                 result = task.finish()
    
    109 114
             except StanzaError as error:
    
    ... ... @@ -124,11 +129,12 @@ def _disco_info_received(self, task):
    124 129
             else:
    
    125 130
                 self._set_error_from_code('not-muc-service')
    
    126 131
     
    
    127
    -    def _show_error_page(self, text):
    
    128
    -        self._stack.get_child_by_name('error').set_text(text)
    
    132
    +    def _show_error_page(self, text: str) -> None:
    
    133
    +        error_page = cast(ErrorPage, self._stack.get_child_by_name('error'))
    
    134
    +        error_page.set_text(text)
    
    129 135
             self._stack.set_visible_child_name('error')
    
    130 136
     
    
    131
    -    def _set_error(self, error):
    
    137
    +    def _set_error(self, error: StanzaError) -> None:
    
    132 138
             text = MUC_DISCO_ERRORS.get(error.condition, to_user_string(error))
    
    133 139
             if error.condition == 'gone':
    
    134 140
                 reason = error.get_text(get_rfc5646_lang())
    
    ... ... @@ -136,26 +142,26 @@ def _set_error(self, error):
    136 142
                     text = '%s:\n%s' % (text, reason)
    
    137 143
             self._show_error_page(text)
    
    138 144
     
    
    139
    -    def _set_error_from_code(self, error_code):
    
    145
    +    def _set_error_from_code(self, error_code: str) -> None:
    
    140 146
             self._show_error_page(MUC_DISCO_ERRORS[error_code])
    
    141 147
     
    
    142
    -    def _on_join(self, *args):
    
    148
    +    def _on_join(self, _button: Gtk.Button) -> None:
    
    143 149
             nickname = self._nick_chooser.get_text()
    
    144 150
     
    
    145 151
             app.interface.show_add_join_groupchat(
    
    146 152
                 self.account, self.jid, nickname=nickname)
    
    147 153
             self.destroy()
    
    148 154
     
    
    149
    -    def _on_destroy(self, *args):
    
    155
    +    def _on_destroy(self, _widget: Gtk.Widget) -> None:
    
    150 156
             self._destroyed = True
    
    151 157
     
    
    152
    -    def _on_key_press_event(self, _widget, event):
    
    158
    +    def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None:
    
    153 159
             if event.keyval == Gdk.KEY_Escape:
    
    154 160
                 self.destroy()
    
    155 161
     
    
    156 162
     
    
    157 163
     class ErrorPage(Gtk.Box):
    
    158
    -    def __init__(self):
    
    164
    +    def __init__(self) -> None:
    
    159 165
             Gtk.Box.__init__(self,
    
    160 166
                              orientation=Gtk.Orientation.VERTICAL,
    
    161 167
                              spacing=18)
    
    ... ... @@ -177,12 +183,12 @@ def __init__(self):
    177 183
             self.add(self._error_label)
    
    178 184
             self.show_all()
    
    179 185
     
    
    180
    -    def set_text(self, text):
    
    186
    +    def set_text(self, text: str) -> None:
    
    181 187
             self._error_label.set_text(text)
    
    182 188
     
    
    183 189
     
    
    184 190
     class ProgressPage(Gtk.Box):
    
    185
    -    def __init__(self):
    
    191
    +    def __init__(self) -> None:
    
    186 192
             Gtk.Box.__init__(self,
    
    187 193
                              orientation=Gtk.Orientation.VERTICAL,
    
    188 194
                              spacing=18)
    
    ... ... @@ -193,8 +199,8 @@ def __init__(self):
    193 199
             self.add(self._spinner)
    
    194 200
             self.show_all()
    
    195 201
     
    
    196
    -    def start(self):
    
    202
    +    def start(self) -> None:
    
    197 203
             self._spinner.start()
    
    198 204
     
    
    199
    -    def stop(self):
    
    205
    +    def stop(self) -> None:
    
    200 206
             self._spinner.stop()