From 4e179c5f79da9db90e6fb2ee2e0ee2761a592db6 Mon Sep 17 00:00:00 2001 From: Billy Date: Thu, 4 Apr 2024 22:59:29 +0530 Subject: [PATCH 1/2] feat: Drag-n-drop for opening files --- biscuit/__init__.py | 2 +- biscuit/core/components/editors/editor.py | 11 ++++++++ biscuit/core/gui.py | 5 ++-- poetry.lock | 31 +++++++++++++++++++++-- pyproject.toml | 3 ++- requirements.txt | 1 + 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/biscuit/__init__.py b/biscuit/__init__.py index d0f0d184..c4aeb192 100644 --- a/biscuit/__init__.py +++ b/biscuit/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.66.4" +__version__ = "2.66.6" __version_info__ = tuple([int(num) for num in __version__.split(".")]) # For tests to run successfully diff --git a/biscuit/core/components/editors/editor.py b/biscuit/core/components/editors/editor.py index 1731d231..05d82b9f 100644 --- a/biscuit/core/components/editors/editor.py +++ b/biscuit/core/components/editors/editor.py @@ -1,3 +1,5 @@ +import tkinterDnD as dnd + from ..utils import Frame, IconButton @@ -19,6 +21,15 @@ def __init__(self, master, path=None, path2=None, editable=True, *args, **kwargs self.__buttons__ = [] + self.register_drop_target(dnd.FILE) + self.bind("<>", self.ondrop) + + def ondrop(self, event): + if not event.data: + return + + self.base.open_editor(event.data) + def add_button(self, *args): self.__buttons__.append(args) diff --git a/biscuit/core/gui.py b/biscuit/core/gui.py index 1f510489..29c7f553 100644 --- a/biscuit/core/gui.py +++ b/biscuit/core/gui.py @@ -1,12 +1,13 @@ import platform -import tkinter as tk + +from tkinterDnD import Tk from .components import * from .config import ConfigManager from .layout import * -class GUIManager(tk.Tk, ConfigManager): +class GUIManager(Tk, ConfigManager): """ GUI MANAGER ----------- diff --git a/poetry.lock b/poetry.lock index 22f63c53..7290ab88 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "appdirs" @@ -610,6 +610,20 @@ files = [ [package.extras] cli = ["click (>=5.0)"] +[[package]] +name = "python-tkdnd" +version = "0.2.1" +description = "Native drag & drop capabilities in tkinter. The tkinterDnD package is a nice and easy-to-use wrapper around the tkdnd tcl package." +optional = false +python-versions = ">=3.6" +files = [ + {file = "python-tkdnd-0.2.1.tar.gz", hash = "sha256:dbce480c1ab5923075aa6fa02e8ae85b984886dfaf20c82d20d78420ad19451b"}, + {file = "python_tkdnd-0.2.1-py3-none-any.whl", hash = "sha256:e476f02c5a9f36361f494cb9e6bc4515790e224a22b4d14b8fbd90d7c1fc0e81"}, +] + +[package.dependencies] +ttkwidgets = ">=0.12.0" + [[package]] name = "pywinpty" version = "2.0.13" @@ -785,6 +799,19 @@ files = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] +[[package]] +name = "ttkwidgets" +version = "0.13.0" +description = "A collection of widgets for Tkinter's ttk extensions by various authors" +optional = false +python-versions = ">=3.6" +files = [ + {file = "ttkwidgets-0.13.0.tar.gz", hash = "sha256:9b1d69dffebef1820ee46b244469913d1911a563a15bb9b0823c71c950daead7"}, +] + +[package.dependencies] +pillow = "*" + [[package]] name = "typing-extensions" version = "4.10.0" @@ -871,4 +898,4 @@ test = ["pytest (>=6.0.0)", "setuptools (>=65)"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "545d96c003e0abbc3d15eeb316517c9291ee85bcd313a0eaa3843a954ecf794c" +content-hash = "22361513e271aaa5563cb9aec0b52bf9e7861c6ff9fc09d58c37bdee596558da" diff --git a/pyproject.toml b/pyproject.toml index 7b0a82d9..bd0c846a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "biscuit" -version = "2.66.4" +version = "2.66.6" description = "The uncompromising code editor" authors = ["Billy "] license = "MIT" @@ -25,6 +25,7 @@ tarts = "^0.12.0" chardet = "^5.2.0" pywinpty = {version = "^2.0.13", platform = "win32"} ptyprocess = {version = "^0.7.0", platform = "linux"} +python-tkdnd = "^0.2.1" [tool.poetry.group.dev.dependencies] diff --git a/requirements.txt b/requirements.txt index 1c0a6a47..178db314 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ chardet python-lsp-server pywinpty; platform_system == "Windows" ptyprocess; platform_system != "Windows" +python-tkdnd \ No newline at end of file From 2f9ccee36c7ac63c34e877e02dbdb05e9bde8bda Mon Sep 17 00:00:00 2001 From: Billy Date: Thu, 4 Apr 2024 23:07:16 +0530 Subject: [PATCH 2/2] feat: Open directories by drag-n-drop --- biscuit/core/components/editors/editor.py | 2 +- biscuit/core/events.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/biscuit/core/components/editors/editor.py b/biscuit/core/components/editors/editor.py index 05d82b9f..7a5aee0f 100644 --- a/biscuit/core/components/editors/editor.py +++ b/biscuit/core/components/editors/editor.py @@ -28,7 +28,7 @@ def ondrop(self, event): if not event.data: return - self.base.open_editor(event.data) + self.base.open(event.data, warn_for_directory=True) def add_button(self, *args): self.__buttons__.append(args) diff --git a/biscuit/core/events.py b/biscuit/core/events.py index 33653a09..0a69188f 100644 --- a/biscuit/core/events.py +++ b/biscuit/core/events.py @@ -47,7 +47,11 @@ def set_title(self, title: str = None) -> None: self.menubar.set_title(title) self.menubar.reposition_title() - def open(self, path: str) -> None: + def open(self, path: str, warn_for_directory=False) -> None: + """Opens file/directory based on path. + + TODO: Open directory in new window if warn_for_directory is True. + """ if not path: return