Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
agmmnn committed Dec 20, 2022
1 parent 138bd38 commit fc35bd7
Show file tree
Hide file tree
Showing 14 changed files with 963 additions and 69 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![screenshot](https://user-images.githubusercontent.com/16024979/208250956-6a3c37ad-25b3-4698-8863-7c116e76b652.gif)
![textual-filedrop](https://user-images.githubusercontent.com/16024979/208708722-e550d8ca-22a7-47f0-adf9-16cad570cdfd.png)

# textual-filedrop

Expand Down Expand Up @@ -42,3 +42,28 @@ def on_file_drop_selected(self, message: FileDrop.Selected) -> None:

# output: path, [filepaths], [filenames], [filesobj]
```

## Examples

### [subdomain_lister](./examples/subdomain_lister.py)

Drag and drop the subdomain list files and see the results as a tree list.

![subdomain_lister](https://user-images.githubusercontent.com/16024979/208706132-0a33bb21-51b8-441a-aeb9-668dbfcb382c.gif)

### [fullscreen](./examples/fullscreen.py)

Fullscreen example, will show the results in the textual console.

### [hidden](./examples/hidden.py)

As long as focus is on, the FileDrop widget will be active even if it is not visible on the screen.

## Dev

```
poetry install
textual console
poetry run textual run --dev examples/subdomain_lister.py
```
10 changes: 5 additions & 5 deletions examples/fullscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def compose(self) -> ComposeResult:
def on_mount(self):
self.query_one("#filedrop").focus()

def on_file_drop_selected(self, message: FileDrop.Selected) -> None:
path = message.path
filepaths = message.filepaths
filenames = message.filenames
filesobj = message.filesobj
def on_file_drop_dropped(self, event: FileDrop.Dropped) -> None:
path = event.path
filepaths = event.filepaths
filenames = event.filenames
filesobj = event.filesobj
print(path, filepaths, filenames, filesobj)


Expand Down
46 changes: 46 additions & 0 deletions examples/hidden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from textual.app import App, ComposeResult, RenderableType
from textual.widgets import Static
from textual_filedrop import FileDrop
from textual.reactive import reactive


class FileDropApp(App):
DEFAULT_CSS = """
#title {
margin: 1 3;
height: auto;
color: $accent;
}
#content {
border: vkey gray;
height: 18;
padding: 1 1;
margin: 0 3;
background: $panel;
}
"""

def compose(self) -> ComposeResult:
yield FileDrop(id="filedrop", display=False)
yield Static("filename", id="title")
yield Static(id="content")

def on_mount(self):
self.query_one("#filedrop").focus()

def on_file_drop_dropped(self, event: FileDrop.Dropped) -> None:
path = event.path
filepaths = event.filepaths
filenames = event.filenames
filesobj = event.filesobj

with open(filepaths[0], "r") as f:
self.query_one("#title").update(filenames[0])
self.query_one("#content").update(f.read())

print(path, filepaths, filenames, filesobj)


if __name__ == "__main__":
app = FileDropApp()
app.run()
27 changes: 16 additions & 11 deletions examples/subdomain_lister.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class CombinerApp(App):
CSS = """
DEFAULT_CSS = """
Screen {
align: center middle;
}
Expand All @@ -19,22 +19,26 @@ class CombinerApp(App):
"""

def compose(self) -> ComposeResult:
yield Vertical(FileDrop(id="drag"), Horizontal(classes="root"))
yield FileDrop(id="drop")
yield Horizontal(classes="root")

def on_mount(self):
self.root = self.query_one(".root")
self.drag = self.query_one("#drag")
self.drag.focus()
self.root.styles.display = "none"
self.drop = self.query_one("#drop")
self.drop.focus()

def on_file_drop_selected(self, message: FileDrop.Selected) -> None:
def on_file_drop_dropped(self, event: FileDrop.Dropped) -> None:
self.root.styles.display = "block"
try:
self.query_one(".tree").remove()
self.query_one(".url").remove()
except:
pass
self.drag.styles.height = 7
self.drag.styles.dock = "top"
self.drop.styles.height = 7
self.drop.styles.dock = "top"

filepaths = message.filepaths
filepaths = event.filepaths
subs = []
for i in filepaths:
try:
Expand Down Expand Up @@ -71,9 +75,10 @@ def on_file_drop_selected(self, message: FileDrop.Selected) -> None:
tree.show_root = False
tree.show_guides = True
self.root.mount(tree)
self.drop.mount(Static("", classes="url"))

def on_tree_node_selected(self, message: Tree.NodeSelected) -> None:
print(message.name)
def on_tree_node_selected(self, event: Tree.NodeSelected) -> None:
pass

@classmethod
def add_json(cls, node: TreeNode, json_data: object, root_name: str) -> None:
Expand Down Expand Up @@ -102,7 +107,7 @@ def add_node(name: str, node: TreeNode, data: object) -> None:
new_node = node.add("", expand=True)
add_node(key, new_node, value)
elif isinstance(data, list):
node._label = Text(f"{name}")
node._label = Text(f"{name}")
for index, value in enumerate(data):
new_node = node.add("", expand=True)
add_node(str(index), new_node, value)
Expand Down
9 changes: 9 additions & 0 deletions examples/subdomains1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
https://www.example.com
https://mail.example.com
https://blog.example.com
https://store.example.com
https://api.example.com
https://dev.api.example.com
https://test.api.example.com
https://staging.store.example.com
https://support.blog.example.com
13 changes: 13 additions & 0 deletions examples/subdomains2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
https://www.abc.com
https://mail.abc.com
https://blog.abc.com
https://store.abc.com
https://api.abc.com
https://dev.api.abc.com
https://test.api.abc.com
https://staging.store.abc.com
https://support.blog.abc.com
https://alpha.dev.api.abc.com
https://beta.test.api.abc.com
https://prerelease.staging.store.abc.com
https://help.support.blog.abc.com
Loading

0 comments on commit fc35bd7

Please sign in to comment.