-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverse_repository_app.py
73 lines (62 loc) · 1.81 KB
/
verse_repository_app.py
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
69
70
71
72
73
from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, DirectoryTree, TextArea, Button
from textual.containers import Horizontal, Vertical
import pyperclip
import os
class VerseRepositoryApp(App):
CSS = """
#file_tree {
width: 30%;
height: 100%;
}
#editor_container {
width: 70%;
height: 100%;
}
#editor {
height: 95%;
}
#copy_button {
dock: bottom;
width: 100%;
}
"""
BINDINGS = [
("q", "quit", "Quit"),
("c", "copy", "Copy"),
]
def __init__(self):
super().__init__()
self.current_file = None
def compose(self) -> ComposeResult:
yield Header()
yield Horizontal(
DirectoryTree("./verse", id="file_tree"),
Vertical(
TextArea(id="editor"),
Button("Copy to Clipboard", id="copy_button", variant="primary"),
id="editor_container"
)
)
yield Footer()
def on_mount(self):
self.query_one(DirectoryTree).focus()
self.query_one(TextArea).focus()
def on_directory_tree_file_selected(self, event: DirectoryTree.FileSelected):
self.current_file = event.path
with open(self.current_file, "r") as file:
content = file.read()
self.query_one(TextArea).load_text(content)
def on_button_pressed(self, event: Button.Pressed):
self.copy_to_clipboard()
def action_copy(self):
self.copy_to_clipboard()
def copy_to_clipboard(self):
content = self.query_one(TextArea).text
pyperclip.copy(content)
self.notify("Content copied to clipboard!")
def action_quit(self):
self.exit()
if __name__ == "__main__":
app = VerseRepositoryApp()
app.run()