# HG changeset patch # User Goffi # Date 1582468746 -3600 # Node ID 72a6b06728abf8d9a75ef1705f097bd92fa88e34 # Parent c466678c57b2f36d821815fd3e5f9317adbf7aa2 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 diff -r c466678c57b2 -r 72a6b06728ab cagou/core/cagou_main.py --- a/cagou/core/cagou_main.py Sun Feb 23 15:39:06 2020 +0100 +++ b/cagou/core/cagou_main.py Sun Feb 23 15:39:06 2020 +0100 @@ -20,6 +20,7 @@ import os.path import glob import sys +from pathlib import Path from functools import partial from sat.core.i18n import _ from . import kivy_hack @@ -304,6 +305,7 @@ def build(self): Window.bind(on_keyboard=self.key_input) + Window.bind(on_dropfile=self.on_dropfile) wid = CagouRootWidget(Label(text=_("Loading please wait"))) local_platform.on_app_build(wid) return wid @@ -371,6 +373,17 @@ else: return False + def on_dropfile(self, __, file_path): + if self.host.selected_widget is not None: + try: + on_drop_file = self.host.selected_widget.on_drop_file + except AttributeError: + log.info( + f"Select widget {self.host.selected_widget} doesn't handle file " + f"dropping") + else: + on_drop_file(Path(file_path.decode())) + class Cagou(QuickApp): MB_HANDLE = False diff -r c466678c57b2 -r 72a6b06728ab cagou/plugins/plugin_wid_chat.py --- a/cagou/plugins/plugin_wid_chat.py Sun Feb 23 15:39:06 2020 +0100 +++ b/cagou/plugins/plugin_wid_chat.py Sun Feb 23 15:39:06 2020 +0100 @@ -530,6 +530,10 @@ screen_manager.current = 'chat_selector' return True + ## drop ## + + def on_drop_file(self, path): + self.addAttachment(path) ## header ##