Adding tilde character parameter
With my contribution, user can add a tilde character parameter to the TkLineNums widget. If user doesn't send this parameter, TkLineNums will work normally, without a tilde character.
example: self.line_counter = TkLineNumbers(master, self, justify="right", colors=("#e3ba68", "#1D1E1E"),tilde="~", bd=0)
Example of tilde character in Vim text editor:
In this case, "~" is the tilde character, and it represents a non-existent line.
In my code, there is a visual bug that I could not find a fix. If user have a wrapped line (a big line that don't fit in the text widget resolution, so It "breaks" into 2+ visible lines), the tilde algorithm will try to add a tilde character in that counter position, causing a visual bug.
example:
this tilde character overlapping with the "7" in the line counter was created because of the wrapped line space.
This bug only happen if:
If we fix this visual problem, tilde characters will work flawlessly! =)
I am getting issues like this:
I am getting issues like this:
this error happens because the font size was not correctly treated in the tilde algorithm. If you use font="monospace 11" or font=tk.Font(family="Consolas", size=25), this error persists?
No but I made a PR with changes that worked for me. Something about this PR also makes the <<Modified>> event not work, something to look into eventually.
No but I made a PR with changes that worked for me. Something about this PR also makes the
<<Modified>>event not work, something to look into eventually.
Exactly bro! I don't know why, but the line counter only updates when i click on it in this example, so I need to use <KeyRelease> event. Also, I was trying to fix font problems and I got some weird results. I will write them for you soon.
I think maybe there is a easier way to make this works. Also, I don't understand why the code works really well in Pytext but doesn't in his __name__ == "__main__" example!
In Pytext, when we run type(self.textwidget.cget("font")), it returns <class 'customtkinter.windows.widgets.font.ctk_font.CTkFont'>, and not str (I'm not using tkinter, but customtkinter).
Is there any CTK interop going on?
Is there any CTK interop going on?
No, I just used a CTkFont instead of tk.Font. I tryied to import CTK and use CTkFont instead of tk.Font in your example, but same error. Tomorrow I will analyze more deeper
Hello, @Moosems ! How are you? I hope you're doing great! I think I found a fix for these font problems and, here in my computer, both tkinter and customtkinter are working flawlessly! I added a example for each library. Check the "better perfomance" commit that I created and test it. :)
Lets not add ctk to the main file, please. The plan and hope is to use no external libraries.
Lets not add ctk to the main file, please. The plan and hope is to use no external libraries.
no problem. I will adapt code for only using tkinter Font class
@Moosems Also, how the line_elided works? It always show False to me, even if there is wrapped lines.
line_elided isn't for wrapped lines. You can hide lines in tkinter so it handles that. Wrapped lines are handled differently :).
@Moosems I removed customtkinter from TkLineNums, but, consequently, using customtkinter with a tuple type font, as:
font = ("Consolas", 20), will result in font linespaces inconsistencies, so I decided to use a raise TypeError in this case, telling the user to use a CTkFont instance instead, like this: font = ctk.CTkFont("Consolas", 20). In this case, won't have font linespace inconsistencies.
This TypeError only happens if user is using customtkinter to create his GUI and necessarily using a tuple type font, so it will be very rare and in a specific situation that can be easily avoided.
So if I understand it right, this or would require me to use a Font object and wouldn't allow a tuple?
So if I understand it right, this or would require me to use a Font object and wouldn't allow a tuple?
If you're using customtkinter, yes, you will need a CTkFont instance. Otherwise, like using only tkinter, It will work normally with tuples, tk.Font() and str, as "Consolas 20".
But not font=("Courier New Bold", 15)?
But not
font=("Courier New Bold", 15)?
In customtkinter no, it should be font=CTkFont("Courier New Bold", 15). In tkinter it will work.
and, of course, this limitation only happens if user is using a tilde char, otherwise it won't make any difference.
Sounds good to me! Personally ctk support is a secondary priority so I'm fine with letting things like that go :).
@lorenzolpandolfo Take a look at this ;)
Sounds good to me! Personally ctk support is a secondary priority so I'm fine with letting things like that go :).
All right! Of course, with more time I can analyze more about this fonts inconsistencies, but, at time, in a situation that can be easily avoided (just using a font instance of ctk), i think its the best thing to do at time.
For some context, using tk.Font(family=tuple[0], size=tuple[1]) (if user is using CTK) will result in linespace inconsistencies. I think that tkinter and customtkinter deal with different forms the linespaces and sizes.
@lorenzolpandolfo Take a look at this ;)
Thank you! Before I found your library, I was creating my own line counter for my text editor. But it was not dealing correctly with wrapped lines. Even researching in a lot of places, I could not to make it work. 😅 I will read It with time later!
Also, @Moosems I was thinking here, this PR is to your main branch. I think we should change that to a unstable branch or something, to make things more safer
A dev branch?
A dev branch?
yes, or a tilde-unstable, or something like this. So people can test it and it won't possibly break projects that use this repository on main branch.
Hello, @Moosems !
I fixed the tilde char being added to wrapped lines and now everything is working correctly.
example:
Sadly, CTK support is no longer available, because we need the count() method to check wrapped lines, which is a tk.Text method only, and it is not existent in the CTkTextbox class.
I opened a issue in customtkinter to see if there is a way to use the .count method in a CTkTextbox instance, since customtkinter was made on top of tkinter.
A way to go through this problem is to, in a customtkinter project, the textwidget must be a tkinter Text widget. Unless I find a way to use .count in CTkTextbox, of course!
Sounds great! If you could run ruff, black, and isort I'll make sure to take a look at it later today and make any final changes :).
Sounds great! If you could run ruff, black, and isort I'll make sure to take a look at it later today and make any final changes :).
I used ruff and fixed all observations, then black and isort. With my changes, the "line_elided" variable was not being used, so I commented it.
Try the Arial to TkFixedFont commit and tell me what do you think! :)
Also, if user does not provide a font to the textwidget, it will be "TkFixedFont". But, I don't think there is a way to access this font size, since self.textwidget.cget("font") returns a str TkFixedFont, without any size. So, if user would like to use the tilde char but is using TkFixedFont, the tilde char size will be 10. Here, in my computer, it looks ok, but maybe it can cause font sizes inconsistencies if the TkFixedFont size is not 10.
But this is a very specific problem, I think that most people won't use TkFixedFont, since it is just a placeholder font.
@Moosems really good news: CTkTextbox support added! =)
hello, @Moosems ! When you have time, check my new commit =)