Mercurial > libervia-desktop-kivy
comparison cagou/core/cagou_main.py @ 414:72a6b06728ab
core: file dropping:
on compatible OSes, one or more file(s) can now be dropped on the main window, it will
then be transmitted to the selected widget if it has a "on_drop_file" method.
This is used in chat widget to add an attachment
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 23 Feb 2020 15:39:06 +0100 |
parents | ab1e97b7e8a5 |
children | b047d14e4be5 |
comparison
equal
deleted
inserted
replaced
413:c466678c57b2 | 414:72a6b06728ab |
---|---|
18 | 18 |
19 | 19 |
20 import os.path | 20 import os.path |
21 import glob | 21 import glob |
22 import sys | 22 import sys |
23 from pathlib import Path | |
23 from functools import partial | 24 from functools import partial |
24 from sat.core.i18n import _ | 25 from sat.core.i18n import _ |
25 from . import kivy_hack | 26 from . import kivy_hack |
26 kivy_hack.do_hack() | 27 kivy_hack.do_hack() |
27 from cagou.backport import do_backport | 28 from cagou.backport import do_backport |
302 # a settings screen when pressing F1 or platform specific key | 303 # a settings screen when pressing F1 or platform specific key |
303 return | 304 return |
304 | 305 |
305 def build(self): | 306 def build(self): |
306 Window.bind(on_keyboard=self.key_input) | 307 Window.bind(on_keyboard=self.key_input) |
308 Window.bind(on_dropfile=self.on_dropfile) | |
307 wid = CagouRootWidget(Label(text=_("Loading please wait"))) | 309 wid = CagouRootWidget(Label(text=_("Loading please wait"))) |
308 local_platform.on_app_build(wid) | 310 local_platform.on_app_build(wid) |
309 return wid | 311 return wid |
310 | 312 |
311 def showProfileManager(self): | 313 def showProfileManager(self): |
368 else: | 370 else: |
369 Animation(height=head.HEIGHT, opacity=1, duration=0.3).start(head) | 371 Animation(height=head.HEIGHT, opacity=1, duration=0.3).start(head) |
370 return True | 372 return True |
371 else: | 373 else: |
372 return False | 374 return False |
375 | |
376 def on_dropfile(self, __, file_path): | |
377 if self.host.selected_widget is not None: | |
378 try: | |
379 on_drop_file = self.host.selected_widget.on_drop_file | |
380 except AttributeError: | |
381 log.info( | |
382 f"Select widget {self.host.selected_widget} doesn't handle file " | |
383 f"dropping") | |
384 else: | |
385 on_drop_file(Path(file_path.decode())) | |
373 | 386 |
374 | 387 |
375 class Cagou(QuickApp): | 388 class Cagou(QuickApp): |
376 MB_HANDLE = False | 389 MB_HANDLE = False |
377 AUTO_RESYNC = False | 390 AUTO_RESYNC = False |