Philipp Hörist pushed to branch master at gajim / gajim

Commits:

8 changed files:

Changes:

  • gajim/gtk/avatar_selector.py
    ... ... @@ -128,11 +128,11 @@ def prepare_crop_area(self, path: str) -> None:
    128 128
             self._crop_area.show()
    
    129 129
     
    
    130 130
         def _on_load_clicked(self, _button: Gtk.Button) -> None:
    
    131
    -        def _on_file_selected(path: str) -> None:
    
    132
    -            self.prepare_crop_area(path)
    
    131
    +        def _on_file_selected(paths: list[str]) -> None:
    
    132
    +            self.prepare_crop_area(paths[0])
    
    133 133
     
    
    134 134
             AvatarChooserDialog(_on_file_selected,
    
    135
    -                            transient_for=self.get_toplevel(),
    
    135
    +                            transient_for=cast(Gtk.Window, self.get_toplevel()),
    
    136 136
                                 modal=True)
    
    137 137
     
    
    138 138
         def _on_drag_data_received(self,
    

  • gajim/gtk/file_transfer_selector.py
    ... ... @@ -223,7 +223,9 @@ def _on_resource_selection(self,
    223 223
             self.emit('changed', state)
    
    224 224
     
    
    225 225
         def _on_choose_files_clicked(self, _button: Gtk.Button) -> None:
    
    226
    -        FileChooserDialog(self.add_files,
    
    226
    +        def _on_chosen(paths: list[str]) -> None:
    
    227
    +            self.add_files([Path(p).as_uri() for p in paths])
    
    228
    +        FileChooserDialog(_on_chosen,
    
    227 229
                               select_multiple=True,
    
    228 230
                               transient_for=app.window,
    
    229 231
                               path=app.settings.get('last_send_dir') or None)
    

  • gajim/gtk/filechoosers.py
    ... ... @@ -36,6 +36,8 @@
    36 36
     
    
    37 37
     from .const import Filter
    
    38 38
     
    
    39
    +AcceptCallbackT = Callable[[list[str]], None]
    
    40
    +
    
    39 41
     
    
    40 42
     def _require_native() -> bool:
    
    41 43
         if app.is_flatpak():
    
    ... ... @@ -60,11 +62,11 @@ def set_filter(self, filter: Gtk.FileFilter) -> None: # noqa
    60 62
         def _on_response(self,
    
    61 63
                          dialog: Union[Gtk.FileChooser, Gtk.FileChooserNative],
    
    62 64
                          response: Gtk.ResponseType,
    
    63
    -                     accept_cb: Callable[[list[str]], None],
    
    65
    +                     accept_cb: AcceptCallbackT,
    
    64 66
                          cancel_cb: Optional[Callable[..., Any]]
    
    65 67
                          ) -> None:
    
    66 68
             if response == Gtk.ResponseType.ACCEPT:
    
    67
    -            accept_cb(dialog.get_uris())
    
    69
    +            accept_cb(dialog.get_filenames())
    
    68 70
     
    
    69 71
             if response in (Gtk.ResponseType.CANCEL,
    
    70 72
                             Gtk.ResponseType.DELETE_EVENT):
    
    ... ... @@ -120,7 +122,7 @@ class NativeFileChooserDialog(Gtk.FileChooserNative, BaseFileChooser):
    120 122
         _action = Gtk.FileChooserAction.OPEN
    
    121 123
     
    
    122 124
         def __init__(self,
    
    123
    -                 accept_cb: Callable[..., Any],
    
    125
    +                 accept_cb: AcceptCallbackT,
    
    124 126
                      cancel_cb: Optional[Callable[..., Any]] = None,
    
    125 127
                      transient_for: Optional[Gtk.Window] = None,
    
    126 128
                      path: Optional[str] = None,
    
    ... ... @@ -180,7 +182,7 @@ class GtkFileChooserDialog(Gtk.FileChooserDialog, BaseFileChooser):
    180 182
         _preview_size = (200, 200)
    
    181 183
     
    
    182 184
         def __init__(self,
    
    183
    -                 accept_cb: Callable[[list[str]], None],
    
    185
    +                 accept_cb: AcceptCallbackT,
    
    184 186
                      cancel_cb: Optional[Callable[..., Any]] = None,
    
    185 187
                      transient_for: Optional[Gtk.Window] = None,
    
    186 188
                      path: Optional[str] = None,
    
    ... ... @@ -232,18 +234,9 @@ class GtkAvatarChooserDialog(BaseAvatarChooserDialog, GtkFileChooserDialog):
    232 234
         pass
    
    233 235
     
    
    234 236
     
    
    235
    -def FileChooserDialog(*args: Any,
    
    236
    -                      **kwargs: Any
    
    237
    -                      ) -> Union[NativeFileOpenDialog, GtkFileOpenDialog]:
    
    238
    -    if _require_native():
    
    239
    -        return NativeFileOpenDialog(*args, **kwargs)
    
    240
    -    return GtkFileOpenDialog(*args, **kwargs)
    
    241
    -
    
    242
    -
    
    243
    -def AvatarChooserDialog(*args: Any,
    
    244
    -                        **kwargs: Any
    
    245
    -                        ) -> Union[NativeAvatarChooserDialog,
    
    246
    -                                   GtkAvatarChooserDialog]:
    
    247
    -    if _require_native():
    
    248
    -        return NativeAvatarChooserDialog(*args, **kwargs)
    
    249
    -    return GtkAvatarChooserDialog(*args, **kwargs)
    237
    +if _require_native():
    
    238
    +    FileChooserDialog = NativeFileOpenDialog
    
    239
    +    AvatarChooserDialog = NativeAvatarChooserDialog
    
    240
    +else:
    
    241
    +    FileChooserDialog = GtkFileOpenDialog
    
    242
    +    AvatarChooserDialog = GtkAvatarChooserDialog

  • gajim/gtk/filetransfer.py
    ... ... @@ -467,7 +467,8 @@ def on_file_request_accepted(self,
    467 467
                                      contact: BareContact,
    
    468 468
                                      file_props: FileProp
    
    469 469
                                      ) -> None:
    
    470
    -        def _on_accepted(account, contact, file_props, file_path):
    
    470
    +        def _on_accepted(account, contact, file_props, file_paths):
    
    471
    +            file_path = file_paths[0]
    
    471 472
                 if os.path.exists(file_path):
    
    472 473
                     app.settings.set('last_save_dir', os.path.dirname(file_path))
    
    473 474
     
    

  • gajim/gtk/groupchat_manage.py
    ... ... @@ -11,6 +11,7 @@
    11 11
     # You should have received a copy of the GNU General Public License
    
    12 12
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    13 13
     
    
    14
    +from typing import cast
    
    14 15
     from typing import Any
    
    15 16
     
    
    16 17
     import logging
    
    ... ... @@ -193,25 +194,25 @@ def _on_avatar_cancel_clicked(self, _button: Gtk.Button) -> None:
    193 194
             self._ui.stack.set_visible_child_name('manage')
    
    194 195
     
    
    195 196
         def _on_change_avatar_clicked(self, _button: Gtk.Button) -> None:
    
    196
    -        def _on_accept(path: str) -> None:
    
    197
    -            self._avatar_selector.prepare_crop_area(path)
    
    197
    +        def _on_accept(paths: list[str]) -> None:
    
    198
    +            self._avatar_selector.prepare_crop_area(paths[0])
    
    198 199
                 self._ui.avatar_update_button.set_sensitive(
    
    199 200
                     self._avatar_selector.get_prepared())
    
    200 201
                 self._ui.stack.set_visible_child_name('avatar')
    
    201 202
                 self._ui.avatar_update_button.grab_default()
    
    202 203
     
    
    203 204
             AvatarChooserDialog(_on_accept,
    
    204
    -                            transient_for=self.get_toplevel(),
    
    205
    +                            transient_for=cast(Gtk.Window, self.get_toplevel()),
    
    205 206
                                 modal=True)
    
    206 207
     
    
    207 208
         def _on_avatar_select_file_clicked(self, _button: Gtk.Button) -> None:
    
    208
    -        def _on_accept(path: str) -> None:
    
    209
    -            self._avatar_selector.prepare_crop_area(path)
    
    209
    +        def _on_accept(paths: list[str]) -> None:
    
    210
    +            self._avatar_selector.prepare_crop_area(paths[0])
    
    210 211
                 self._ui.avatar_update_button.set_sensitive(
    
    211 212
                     self._avatar_selector.get_prepared())
    
    212 213
     
    
    213 214
             AvatarChooserDialog(_on_accept,
    
    214
    -                            transient_for=self.get_toplevel(),
    
    215
    +                            transient_for=cast(Gtk.Window, self.get_toplevel()),
    
    215 216
                                 modal=True)
    
    216 217
     
    
    217 218
         def _on_upload_avatar_result(self, task: Task) -> None:
    

  • gajim/gtk/main.py
    ... ... @@ -525,7 +525,8 @@ def _on_preview_action(self,
    525 525
                 open_file(preview.orig_path)
    
    526 526
     
    
    527 527
             elif action_name == 'preview-save-as':
    
    528
    -            def _on_ok(target: str) -> None:
    
    528
    +            def _on_ok(paths: list[str]) -> None:
    
    529
    +                target = paths[0]
    
    529 530
                     assert preview is not None
    
    530 531
                     assert preview.orig_path is not None
    
    531 532
     
    

  • gajim/gtk/plugins.py
    ... ... @@ -420,7 +420,8 @@ def _on_yes():
    420 420
                                        callback=_on_yes)],
    
    421 421
                     transient_for=self).show()
    
    422 422
     
    
    423
    -        def _try_install(zip_filename: str) -> None:
    
    423
    +        def _try_install(paths: list[str]) -> None:
    
    424
    +            zip_filename = paths[0]
    
    424 425
                 try:
    
    425 426
                     plugin = app.plugin_manager.install_from_zip(zip_filename)
    
    426 427
                 except PluginsystemError as er_type:
    

  • gajim/gtk/profile.py
    ... ... @@ -319,18 +319,19 @@ def _on_remove_avatar(self, _button: Gtk.Button) -> None:
    319 319
             self._new_avatar = None
    
    320 320
     
    
    321 321
         def _on_edit_avatar(self, button: Gtk.Button) -> None:
    
    322
    -        def _on_file_selected(path: str) -> None:
    
    322
    +        def _on_file_selected(paths: list[str]) -> None:
    
    323 323
                 if self._avatar_selector is None:
    
    324 324
                     self._avatar_selector = AvatarSelector()
    
    325 325
                     self._ui.avatar_selector_box.add(self._avatar_selector)
    
    326 326
     
    
    327
    -            self._avatar_selector.prepare_crop_area(path)
    
    327
    +            self._avatar_selector.prepare_crop_area(paths[0])
    
    328 328
                 self._ui.avatar_update_button.set_sensitive(
    
    329 329
                     self._avatar_selector.get_prepared())
    
    330 330
                 self._ui.profile_stack.set_visible_child_name('avatar_selector')
    
    331 331
     
    
    332 332
             AvatarChooserDialog(_on_file_selected,
    
    333
    -                            transient_for=button.get_toplevel())
    
    333
    +                            transient_for=cast(Gtk.Window,
    
    334
    +                                               button.get_toplevel()))
    
    334 335
     
    
    335 336
         def _on_cancel_update_avatar(self, _button: Gtk.Button) -> None:
    
    336 337
             self._ui.profile_stack.set_visible_child_name('profile')