-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use peer widget for minimap #32
Comments
@Moosems a really good suggestion! that also speeds up the editor a lot! also tried it out import tkinter as tk
class TextPeer(tk.Text):
"boakly's implementation: https://stackoverflow.com/a/58290100/14507110"
count = 0
def __init__(self, master, cnf={}, **kw):
TextPeer.count += 1
parent = master.master
peerName = "peer-{}".format(TextPeer.count)
if str(parent) == ".":
peerPath = ".{}".format(peerName)
else:
peerPath = "{}.{}".format(parent, peerName)
master.tk.call(master, 'peer', 'create', peerPath, *self._options(cnf, kw))
tk.BaseWidget._setup(self, parent, {'name': peerName})
root = tk.Tk()
text_widget1 = tk.Text(root, font="Consolas 13")
text_widget1.tag_config("red", foreground="red")
text_widget1.insert("1.0", "This is the first text widget.", "red")
text_widget1.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
text_widget2 = TextPeer(text_widget1, font="Ariel 5", width=30)
text_widget2.pack(side=tk.LEFT, fill=tk.Y)
root.mainloop() it works amazing, and the tags is ofc a plus, current minimap don't have tags added (it was already too much updation going on every change made in editor). |
@Moosems I had an attempt to optimize the minimap further by using lines instead of text (so to render the details less) self.text = self.tw.get_all_text()
y = 0
offset = 5
for line in self.text.split("\n"):
if ln := len(line):
self.cw.create_line(offset, y, ln, y, fill="grey", width=2, tag="redrawn")
y += 3 with splitting for spaces self.text = self.tw.get_all_text()
y = 0
offset = 5
for line in self.text.split("\n"):
if line.strip():
x = offset
for block in line.split():
if ln := len(block.strip()):
self.cw.create_line(x, y, x+ln, y, fill="grey", width=2, tag="redrawn")
x += ln
x += 1
y += 3 this implementation didn't support indentations at beginning, also no tags. still, this was too much for a single change made in editor too, needed a lot more optimizations. |
How fast is the peer widget with timed tests? |
Average execution time: 0.000263 seconds ...
text_widget2 = TextPeer(text_widget1, font="Ariel 5", width=30)
text_widget2.pack(side=tk.LEFT, fill=tk.Y)
import timeit
def measure_widget_performance():
text_widget1.insert("1.0", "This is the first text widget.", "red")
execution_time = timeit.timeit(measure_widget_performance, number=10)
print(f"Average execution time: {execution_time / 10:.6f} seconds")
...
root.mainloop() |
Make 1000 lines ;). |
I want to see how it handles a large text file. |
For each word you could check any colors associated from tags so at least the user can get the colors if not the actual words. I do like the idea of a peer widget a little better because it has all the tags and words but the scaling ratio could be difficult and though I get the want for optimization I do actually appreciate being able to see the words. At the very least having no wrap with side to side scrolling and indentations would be nice and colored words would similarly be nice. |
x = offset + (len(line) - len(line.strip())) |
if ln := len(block.strip()): -> if ln := len(block): |
Whichever way works better :). |
execution_time = timeit.timeit(measure_widget_performance, number=1000)
print(f"Average execution time: {execution_time / 10:.6f} seconds")
|
yess this will work! haha nice solution! ♥ |
Could you paste the current state of the code? |
I dont have much to show right now, pretty much what i posted above :)) (last week was busy because of uni oop sorry xd) |
Well I don't have the code for the optimized lines. |
- uses peer text widget now - slider removed
@Moosems check out this recent commit i just did, now uses a peer text widget instead. except, now the slider is not available for minimap. I couldn't render the slider image on top of peer text widget embedded inside the canvas |
Using a peer widget matches the tags and you can just reduce the font size :D.
The text was updated successfully, but these errors were encountered: