Skip to content

apply_dnd() doesn't work correctly with paths that contain Unicode characters #42

@Valer100

Description

@Valer100

When I try to drag and drop a file or a folder that has Unicode characters in their path, apply_dnd() will throw a UnicodeDecodeError. Here's the full exception message:

Exception ignored on calling ctypes callback function: <function apply_dnd.__init__.<locals>.py_drop_func at 0x0000026A686B23E0>
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\site-packages\pywinstyles\py_win_style.py", line 205, in py_drop_func
    drop_name = file_buffer.value.decode("utf-8")
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 25: invalid continuation byte

Minimal reproducible example:

import tkinter, pywinstyles
from tkinter import messagebox

window = tkinter.Tk()

def print_dnd_paths(file): print(file)
pywinstyles.apply_dnd(window, print_dnd_paths)

window.mainloop()

Here's a screen recording:

Screen.Recording.2024-10-27.153646.mp4

The folder's name that included Unicode characters: ăâîșț

Windows 11 23H2 (Build 22631.4391)
Python 3.11.9
pywinstyles 1.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions