-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Moosems/click-drag-bugs
Fix drag issues
- Loading branch information
Showing
6 changed files
with
230 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ dist/ | |
tklinenums.egg-info/ | ||
tklinenums/__pycache__/ | ||
.DS_Store | ||
.ruff_cache/ |
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
[tool.black] | ||
line-length = 110 | ||
line-length = 88 | ||
|
||
[tool.isort] | ||
line_length = 100 | ||
line_length = 88 | ||
profile = "black" | ||
multi_line_output = 3 | ||
|
||
[tool.ruff] | ||
line-length = 125 |
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 |
---|---|---|
@@ -1,34 +1,37 @@ | ||
from platform import system | ||
from tkinter import Text, Tk | ||
from tkinter.font import Font | ||
from tkinter.ttk import Style | ||
|
||
from tklinenums import TkLineNumbers | ||
|
||
if system() == "Darwin": | ||
contmand: str = "Command" | ||
else: | ||
contmand: str = "Control" | ||
# Create the root window | ||
root = Tk() | ||
|
||
root: Tk = Tk() | ||
# Set the ttk style (tkinter's way of styling) for the line numbers | ||
style = Style() | ||
style.configure("TkLineNumbers", foreground="#2197db", background="#ffffff") | ||
|
||
style: Style = Style() | ||
style.configure("TLineNumbers", background="#ffffff", foreground="#2197db") | ||
|
||
font: Font = Font(family="Courier New bold", size=15, name="TkLineNumsFont") | ||
# Create a style_provider function that returns the ttk style for the line numbers | ||
def ttk_style_provider(): | ||
fg: str = style.lookup("TkLineNumbers", "foreground", default="black") | ||
bg: str = style.lookup("TkLineNumbers", "background", default="white") | ||
return (fg, bg) | ||
|
||
text: Text = Text(root, wrap="char", font=font) | ||
|
||
# Create the Text widget and pack it to the right | ||
text = Text(root) | ||
text.pack(side="right") | ||
|
||
# Insert 50 lines of text into the Text widget | ||
for i in range(50): | ||
text.insert("end", f"Line {i+1}\n") | ||
|
||
linenums: TkLineNumbers = TkLineNumbers(root, text, font, justify="left") | ||
linenums.pack(fill="y", side="left", expand=True) | ||
linenums.reload(font) | ||
# Create the TkLineNumbers widget and pack it to the left | ||
linenums = TkLineNumbers(root, text, justify="center", colors=ttk_style_provider) | ||
linenums.pack(fill="y", side="left") | ||
|
||
text.bind("<Key>", lambda event: root.after_idle(linenums.redraw), add=True) | ||
text.bind(f"<BackSpace>", lambda event: root.after_idle(linenums.redraw), add=True) | ||
text.bind(f"<{contmand}-v>", lambda event: root.after_idle(linenums.redraw), add=True) | ||
# Redraw the line numbers when the text widget contents are modified | ||
text.bind("<<Modified>>", lambda _: root.after_idle(linenums.redraw), add=True) | ||
|
||
# Start the mainloop for the root window | ||
root.mainloop() |
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 |
---|---|---|
@@ -1 +1 @@ | ||
from .tklinenums import TkLineNumbers | ||
from .tklinenums import TkLineNumbers # noqa: F401 |
Oops, something went wrong.