Mercurial > libervia-desktop-kivy
annotate libervia/desktop_kivy/plugins/plugin_transfer_file.py @ 517:f316c7f19909
install: update Kivy version to fix build issue.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 13 Jul 2024 13:08:13 +0200 |
parents | d78728d7fd6a |
children |
rev | line source |
---|---|
379 | 1 #!/usr/bin/env python3 |
2 | |
86 | 3 |
514
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
4 # Libervia Desktop-Kivy |
461 | 5 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org) |
86 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
514
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
20 from functools import partial |
279
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
21 import sys |
514
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
22 |
493
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
23 from libervia.backend.core import log as logging |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
24 from libervia.backend.core.i18n import _ |
514
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
25 |
86 | 26 from kivy import properties |
514
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
27 from kivy.uix.boxlayout import BoxLayout |
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
28 from libervia.desktop_kivy.core import file_chooser |
279
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
29 |
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
30 log = logging.getLogger(__name__) |
86 | 31 |
32 | |
33 PLUGIN_INFO = { | |
312 | 34 "name": _("file"), |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
35 "main": "FileTransmitter", |
312 | 36 "description": _("transmit a local file"), |
37 "icon_medium": "{media}/icons/muchoslava/png/fichier_50.png", | |
86 | 38 } |
39 | |
40 | |
279
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
41 class FileChooserBox(BoxLayout): |
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
42 callback = properties.ObjectProperty() |
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
43 cancel_cb = properties.ObjectProperty() |
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
44 default_path = properties.StringProperty() |
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
45 |
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
46 |
514
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
47 class FileTransmitter(BoxLayout, file_chooser.FileChooser): |
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
48 """Widget to transmit files""" |
86 | 49 |
279
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
50 def __init__(self, *args, **kwargs): |
514
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
51 if sys.platform == "android": |
279
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
52 self.native_filechooser = False |
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
53 self.default_path = storagepath.get_downloads_dir() |
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
54 |
514
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
55 super().__init__(*args, **kwargs) |
279
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
56 |
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
57 if self.native_filechooser: |
514
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
58 self.open() |
279
aea973de55d9
transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
59 else: |
514
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
60 self.add_widget( |
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
61 FileChooserBox( |
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
62 default_path=self.default_path, |
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
63 callback=self.on_files, |
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
64 cancel_cb=partial(self.cancel_cb, self), |
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
65 ) |
d78728d7fd6a
plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
66 ) |