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
Add Canvas
and OpenGLCanvas
widgets
#121
base: master
Are you sure you want to change the base?
Conversation
@@ -151,7 +151,6 @@ def config( | |||
if size: | |||
if isinstance(size, float): | |||
size = round(size) | |||
size = -size # Negative value means points in Tk, but pixels in Tukaan. Invert it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe revert this, and use a global tkfont instance to convert points to pixels in get_font_options_for_text_item
|
||
self._gradient_superclass = Gradient(self) | ||
self.linear_gradient = LinearGradient(self) | ||
self.radial_gradient = RadialGradient(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super unintuitive, and makes no sense.
Unfortunately we can't make it totally independent from the camvas wodget, because that's not how TkPath works, but it shouldn't be a "method".
Plus another thing came into my mind, that's actually a serious problem. There are random helper objects that are mutable and there are others that are immutable. This is because the objects that are mutable are actual Tk stuff, and others are just simple Python objects, e.g dataclasses, which can't notify the widget is an attribute is changed. This is NOT good. Something must be done.
Mutable:
Font
- gradients
- Control variables
Immutable
Color
Brush
andPen
ArrowHead
What do mutable and unmutable objects mean? |
Mutable and immutable are just what they sound like. A mutable object can be mutated, i.e. modified, while an immutable cannot. # Mutable
foo = [1, 2, 3]
foo[2] = 4 # Works, because lists are mutable
# Immutable
bar = (1, 2, 3)
bar[2] = 4 # Throws an error obviously In this case for example the font object is mutable. So if you change its font family or size after you assigned it to a widget, the widget will pick up the changes. While when you modify parameters of a color object that you've previously assigned to a widget, nothing will happen. |
Interesting. |
Honestly I'm quite dissatisfied with this. |
For example, this might seem a sane thing: line = Line(canvas, pen=my_fancy_pen)
line.draw(0, 0, 20, 20) especially considering that widgets are created and placed in the same way basically. But on the other hand it's quite inconvenient and unintuitive to do. line = canvas.create_line_between(Point(0, 0), Point(20, 20), pen=my_fancy_pen) |
TODO:
Features of the traditional canvas widget:
https://www.tcl.tk/man/tcl8.6/TkCmd/canvas.html
Features of the TkPath canvas widget
https://github.com/avarga/tkpath/blob/master/doc/readme.adoc
OpenGL rendering
moderngl
orpyopengl
?Moderngl is faster and more pythonic, but then we have to implement every platform specific stuff manually (context creation, makecurrent and swapbuffer)
Implement new dynamic theming engine using
tkp::surface
TODO in TkPath:
libtukaan
. Currently I have only a local.so
Done (at least partially):
These things need to be tested and possibly bugfixed
See comment about these two in
items.py