File: 443.py

package info (click to toggle)
python-trame 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 101,620 kB
  • sloc: python: 13,515; sh: 183; javascript: 93; makefile: 7
file content (68 lines) | stat: -rw-r--r-- 1,827 bytes parent folder | download
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 os

from trame.app import get_server
from trame.ui.vuetify3 import SinglePageLayout
from trame.widgets import trame, vuetify3

server = get_server()
server.client_type = os.environ.get("VUE_VERSION", "vue3")

FILE_LISTING = [
    {
        "text": "Hello.txt",
        "value": "hello.txt",
        "type": "File",
        "prependIcon": "mdi-file-document-outline",
    }
]

PATH_HIERARCHY = []

server.state["menu_items"] = ["one", "two", "three"]


def on_click(e):
    print(e)


def load_data(entry, item):
    print(entry, item)


with SinglePageLayout(server) as layout:
    layout.title.set_text("List Browser")
    with layout.content:
        trame.ListBrowser(
            style="position: relative",
            classes="pa-8",
            location=("[100, 100]",),
            handle_position="bottom",
            filter=True,
            list=("listing", FILE_LISTING),
            path=("path", PATH_HIERARCHY),
            click=(on_click, "[$event]"),
            contextmenu="""
                    $event.preventDefault();
                    menuX = $event.clientX;
                    menuY = $event.clientY;
                    menuShow = $event.srcElement.textContent;
                 """,
        )
        with vuetify3.VMenu(
            v_model=("menuShow", False),
            style=("{ position: 'absolute', left: `${menuX}px`, top: `${menuY}px`}",),
        ) as menu:
            with vuetify3.VList():
                with vuetify3.VListItem(
                    v_for="(item, i) in menu_items",
                    key="i",
                    value=["item"],
                ):
                    vuetify3.VBtn(
                        "{{ item }}",
                        click=(load_data, "[menuShow, item]"),
                    )


if __name__ == "__main__":
    server.start()