-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Custom list widget for open editors
- Loading branch information
Showing
4 changed files
with
122 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import tkinter as tk | ||
|
||
from biscuit.core.components.utils.iconbutton import IconButton | ||
|
||
from .codicon import get_codicon | ||
from .frame import Frame | ||
from .icon import Icon | ||
|
||
|
||
class CloseListItem(Frame): | ||
""" | ||
A varient of IconLabelButton that has a close icon on the right side of the button. | ||
""" | ||
def __init__(self, master, text=None, icon=None, function=lambda *_: None, closefn=lambda *_:None, iconside=tk.LEFT, padx=5, pady=1, *args, **kwargs) -> None: | ||
super().__init__(master, padx=padx, pady=pady, *args, **kwargs) | ||
self.function = function | ||
self.closefn = closefn | ||
|
||
self.bg, self.fg, self.hbg, self.hfg = self.base.theme.utils.iconlabelbutton.values() | ||
self.config(bg=self.bg) | ||
self.text = text | ||
self.icon = icon | ||
|
||
if icon: | ||
self.icon_label = tk.Label(self, text=get_codicon(self.icon), anchor=tk.CENTER, | ||
bg=self.bg, fg=self.fg, font=("codicon", 14)) | ||
self.icon_label.pack(side=iconside, fill=tk.BOTH, expand=True) | ||
|
||
if text: | ||
self.text_label = tk.Label(self, text=self.text, anchor=tk.CENTER, pady=2, | ||
bg=self.bg, fg=self.fg, font=("Segoe UI", 10)) | ||
self.text_label.pack(side=iconside, fill=tk.BOTH, expand=True) | ||
|
||
self.close_btn = IconButton(self, 'close', self.closefn) | ||
self.close_btn.config(bg=self.bg, fg=self.fg) | ||
self.close_btn.pack(side=tk.RIGHT, fill=tk.BOTH) | ||
|
||
self.config_bindings() | ||
self.visible = False | ||
|
||
def config_bindings(self) -> None: | ||
self.bind("<Enter>", self.on_enter) | ||
self.bind("<Leave>", self.on_leave) | ||
|
||
self.bind("<Button-1>", self.on_click) | ||
if self.text: | ||
self.text_label.bind("<Button-1>", self.on_click) | ||
if self.icon: | ||
self.icon_label.bind("<Button-1>", self.on_click) | ||
|
||
def on_enter(self, *_) -> None: | ||
self.config(bg=self.hbg) | ||
if self.text: | ||
self.text_label.config(bg=self.hbg, fg=self.hfg) | ||
if self.icon: | ||
self.icon_label.config(bg=self.hbg, fg=self.hfg) | ||
self.close_btn.config(bg=self.hbg, fg=self.hfg) | ||
|
||
def on_leave(self, *_) -> None: | ||
self.config(bg=self.bg) | ||
if self.text: | ||
self.text_label.config(bg=self.bg, fg=self.fg) | ||
if self.icon: | ||
self.icon_label.config(bg=self.bg, fg=self.fg) | ||
self.close_btn.config(bg=self.bg, fg=self.fg) | ||
|
||
def on_click(self, *_) -> None: | ||
self.function() | ||
|
||
def change_text(self, text) -> None: | ||
self.text_label.config(text=text) | ||
|
||
def change_icon(self, icon) -> None: | ||
self.icon_label.config(text=icon) | ||
|
||
def set_pack_data(self, **kwargs) -> None: | ||
self.pack_data = kwargs | ||
|
||
def get_pack_data(self): | ||
return self.pack_data | ||
|
||
def show(self) -> None: | ||
if not self.visible: | ||
self.visible = True | ||
self.pack(**self.get_pack_data()) | ||
|
||
def hide(self) -> None: | ||
if self.visible: | ||
self.visible = False | ||
self.pack_forget() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters