community icon indicating copy to clipboard operation
community copied to clipboard

on_drop_file event trigger deprecrated on_dropfile

Open epitavy opened this issue 3 years ago • 7 comments

Software Versions

  • Python: 3.8.10
  • OS: Ubuntu 20.04
  • Kivy: 2.1.0
  • Kivy installation method: Using pip (20.0.2) in a venv

Describe the bug As the title says, the Window event on_drop_file trigger the deprecated on_dropfile event. First, it triggers a Deprected warning while the on_dropfile event is not used in user code. Second, the arguments passed to the function do not match the documentation, either on_dropfile nor on_drop_file.

Expected behavior I expected only the on_drop_file event to be trigger and that the callback will be called with exactly 3 arguments: filename, x and y. Instead, the on_drop_file event is called, then appear the Deprecation warning. Moreover, the callback should takes 4 arguments: window, filename, x and y.

To Reproduce

  1. Run the following code
  2. Drop a file on the Kivy window
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window

def on_drop_file(window, filename, x, y):
    print(window, filename, x, y)

class DropFile(App):
    def build(self):
        Window.bind(on_drop_file=on_drop_file)
        return BoxLayout()

DropFile().run()

Output:

[INFO   ] [Logger      ] Record log in /home/me/.kivy/logs/kivy_22-03-29_25.txt
[INFO   ] [Kivy        ] v2.1.0
[INFO   ] [Kivy        ] Installed at "/home/me/.venv/lib/python3.8/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0]
[INFO   ] [Python      ] Interpreter at "/home/me/.venv/bin/python3"
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 189 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'4.6 (Compatibility Profile) Mesa 21.2.6'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Mesa Intel(R) UHD Graphics 630 (CML GT2)'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Base        ] Start application main loop
<kivy.core.window.window_sdl2.WindowSDL object at 0x7fd2dbfbd0b0>  b'/mytestfile.txt' 230 57
[WARNING] [Deprecated  ] Deprecated in 2.1.0, use on_drop_file event instead. Event on_dropfile will be removed in the next two releases.: Call to deprecated function on_dropfile in /home/me/.venv/lib/python3.8/site-packages/kivy/core/window/__init__.py line 2106.Called from /home/me/.venv/lib/python3.8/site-packages/kivy/core/window/__init__.py line 1045 by <lambda>().
[INFO   ] [Base        ] Leaving application in progress...

epitavy avatar Mar 29 '22 10:03 epitavy

It's happening by design https://github.com/kivy/kivy/pull/7786#pullrequestreview-873878786.

Documentation for 2.0.0 states that on_dropfile only has filename as argument and documentation for 2.1.0 states that on_drop_file has (filename, x, y, *args) as arguments.

pythonic64 avatar Mar 30 '22 14:03 pythonic64

Currently, the on_drop_file event use four positional arguments, instead of three as stated in the documentation: (window, filename, x, y). Why is there a deprecation warning ? The above code don't make use of the deprecated on_dropfile event.

epitavy avatar Apr 01 '22 13:04 epitavy

Instance of WindowBase is omitted but assumed for events in the documentation and the same goes for all documentation of all classes which inherit from EventDispatcher.

@matham made the decision not to check for observers of on_dropfile event and that's why you will get the deprecation warning. It's in the comments at https://github.com/kivy/kivy/pull/7786#pullrequestreview-873878786 (expand the resolved conversation).

pythonic64 avatar Apr 01 '22 21:04 pythonic64

Ok, thank you then. I guess nothing can be done from my side to prevent this deprecation warning.

epitavy avatar Apr 02 '22 18:04 epitavy

You would have to change Kivy source code to comment-out https://github.com/kivy/kivy/blob/4fbf9059ce5917ac27685d2b5795e4c447a3f571/kivy/core/window/init.py#L1043-L1046 or https://github.com/kivy/kivy/blob/4fbf9059ce5917ac27685d2b5795e4c447a3f571/kivy/core/window/init.py#L2105-L2107 lines and re-compile the framework.

pythonic64 avatar Apr 02 '22 20:04 pythonic64

Ahh I didn't connect that not checking for observers would result in always dispatching the deprecated message.

A better solution would be to add a method has_observers here: https://github.com/kivy/kivy/blob/4fbf9059ce5917ac27685d2b5795e4c447a3f571/kivy/_event.pyx#L658 that more efficiently checks whether there are observers at all rather than getting the list.

matham avatar Apr 04 '22 20:04 matham

😆 😆 😆

pythonic64 avatar Apr 04 '22 20:04 pythonic64

any fix for this yet?

orionnelson avatar Jul 25 '23 20:07 orionnelson