File size: 2,859 Bytes
6af7472
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import gradio as gr
import modelscope_studio.components.antd as antd
import modelscope_studio.components.antdx as antdx
import modelscope_studio.components.base as ms


def on_right_click(e: gr.EventData):
    print("right clicked:", e._data["payload"])


with gr.Blocks() as demo:
    with ms.Application():
        with antdx.XProvider():
            antd.Divider("Shared Context Menu")
            # `context_menu` applies to all nodes, a node can override it
            # with its own `context_menu` (pass False to disable).
            with antdx.Folder(default_expand_all=True,
                              context_menu=[{
                                  "key": "rename",
                                  "label": "Rename"
                              }, {
                                  "key": "delete",
                                  "label": "Delete",
                                  "danger": True
                              }]) as folder:
                with antdx.Folder.TreeNode(title="src", path="/src"):
                    antdx.Folder.TreeNode(title="index.ts",
                                          path="/src/index.ts",
                                          content="export * from './app';")
                    # disable the context menu for this node only
                    antdx.Folder.TreeNode(title="app.ts",
                                          path="/src/app.ts",
                                          content="console.log('Hello');",
                                          context_menu=False)
                antdx.Folder.TreeNode(
                    title="package.json",
                    path="/package.json",
                    content='{\n  "name": "my-project"\n}',
                    # override the shared menu for this node
                    context_menu=[{
                        "key": "copy_path",
                        "label": "Copy Path"
                    }])

            antd.Divider("Dynamic Context Menu")
            # `context_menu` also accepts a Javascript function string,
            # which receives the node data and its full path key.
            antdx.Folder(
                default_expand_all=True,
                context_menu=
                "(node, key) => node.children ? [{ key: 'new_file', label: 'New File' }] : [{ key: 'open', label: 'Open ' + key }]",
                tree_data=[{
                    "title":
                    "project",
                    "path":
                    "/project",
                    "children": [{
                        "title": "main.py",
                        "path": "/project/main.py",
                        "content": "print('Hello, World!')"
                    }]
                }])

            folder.right_click(fn=on_right_click)

if __name__ == "__main__":
    demo.queue().launch()