Skip to content
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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Add Canvas and OpenGLCanvas widgets #121

wants to merge 1 commit into from

Conversation

rdbende
Copy link
Member

@rdbende rdbende commented Dec 27, 2022

TODO:

TODO in TkPath:

  • Add to libtukaan. Currently I have only a local .so
  • Some commands cause segfaults randomly. I've put some TODO comments to them
  • Finish partially or not implemented features

Done (at least partially):

These things need to be tested and possibly bugfixed

  • Canvas items
    • Line (connects two points)
    • Vector (has a length and a angle)
      See comment about these two in items.py
    • Polygonal line
    • Rectangle
    • Square (rectangle subclass)
    • Ellipse
    • Circle (ellipse subclass)
    • Polygon
    • Text
    • Image
    • Path
    • Item group
  • Utility classes
    • Arrowheads
    • Stroke patterns
    • Transformations
    • Pen (to draw object stroke)
    • Brush (to draw object fill)
  • TkPath works on Linux

@@ -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
Copy link
Member Author

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)
Copy link
Member Author

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 and Pen
  • ArrowHead

@sumeshir26
Copy link

What do mutable and unmutable objects mean?
As far as I know, a object is a instance of a class right?

@rdbende
Copy link
Member Author

rdbende commented Dec 29, 2022

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.

@sumeshir26
Copy link

Interesting.

@rdbende rdbende marked this pull request as draft December 30, 2022 17:00
@rdbende
Copy link
Member Author

rdbende commented Jan 4, 2023

Honestly I'm quite dissatisfied with this.

@rdbende
Copy link
Member Author

rdbende commented Jan 4, 2023

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.
Imo it's much cleaner to do it like this:

line = canvas.create_line_between(Point(0, 0), Point(20, 20), pen=my_fancy_pen)

@rdbende rdbende mentioned this pull request Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants