hoffstadt / hoffstadt/DearPyGui

Drag and drop priority bug

Open
#1,475 1 comment 2 reactions 0 assignees View on GitHub
state: pending type: bug
Dominant language
C++
Stars
15.6k
Forks
783
PR merge metrics
No merged PRs in 30d

Description

Version: 1.1.1
Operating System: Ubuntu 20.04

## My Issue/Question

I'm trying to make a TreeView, and i want to be able to move file and folder with drag and drop, I've been pretty successful for file (that i represent with a simple text (add_text), but not for folder that i represent with a tree_node.
So basically the bug is that if i put a tree_node as child of another and both have a drag_payload, the mouse will pick up the parent one. (where it should pick the one i have the mouse right on)

## To Reproduce
1. Launch the code pasted bellow, a file_dialog should be open, choose a folder with some subfolders inside of it.
2. try dragging a subfolder, a tooltip should show up the name of the folder

If the tooltip show the name of the top parent folder instead of the folder you tried to grab, then you successfully reproduced the bug.

## Minimal working example

```python
import dearpygui.dearpygui as dpg
from typing import List, Dict, Tuple
from pathlib import Path

def tree_callback(sender, app_data: Tuple[int, Path]):
widget, path = app_data

print("sender", type(sender), sender)
print("app_data", type(app_data), app_data)

if (dpg.get_item_parent(widget) != sender):
dpg.move_item(widget, parent=sender)

def create_tree(root: Path=Path("./")):
for path in root.iterdir():

## file
if path.is_file():
widget = dpg.add_text(default_value=path.name, color=(0, 255, 0, 255))

## directory
if path.is_dir():
with dpg.tree_node(label=path.name,
delay_search=True,
default_open=False,
payload_type="data",
drop_callback=tree_callback) as widget:

# print(widget, path.name)
# with dpg.tooltip(parent=widget):
# dpg.add_text(path.name)

with dpg.drag_payload(parent=widget,
drag_data=(widget, path),
payload_type="data"):
dpg.add_text(path.name)

create_tree(path)

def main():
dpg.create_context()

with dpg.window(label="MainWindow") as primary_window: #primary window
def callback(id, data):
path = Path(data['file_path_name'])
with dpg.window(label="Tree Folder", min_size=(400, 400), autosize=True):
create_tree(path)

dpg.add_file_dialog(
directory_selector=True,
callback=callback)

dpg.set_primary_window(primary_window, True)

dpg.create_viewport(title="dearPyGui Window", width=800, height=800)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

if __name__ == "__main__":
main()
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.