gaphor / gaphas

Gaphas is the diagramming widget library for Python.
https://gaphas.readthedocs.io
166 stars 21 forks source link

Generic item hierarchy #113

Closed amolenaar closed 3 years ago

amolenaar commented 4 years ago

Is your feature request related to a problem? Please describe.

Currently all canvas items should inherit from Item. The hierarchy is exclusively maintained in the Canvas class. This is not ideal, since this requires double bookkeeping in case the application has its own data model and it makes Canvas a central component, used by all items.

Describe the solution you'd like

Allow Gaphas to visualize any tree hierarchy. E.g. for Gaphor, we have an owner field that defines the relation between an element and its owner. This should also be usable to display items.

Additional context

It looks like the interface between GtkView and Canvas is actually quite thin: get_all_items() and sort(). Painters and Tools also use get_matrix_i2c() and get_connection().

get_matrix_i2c() could be replaced by a Projection.

How to deal with constaint solving, once the canvas hierarchy has been extracted? Do we still need a Canvas class?

amolenaar commented 3 years ago

I have to do some extra checks to ensure the Item protocol is the only methods used throughout Gaphas (and gaphor). Maybe some features should be moved to generic functions (?). Generic functions can provide an extra layer of decoupling.

There's one exception: segment.py. It relies on Lines and the ability to split/merge line segments. For this the Line class provides extra methods. Loading and using segment.py is optional, though.

amolenaar commented 3 years ago

Item is a protocol now. It contains a few methods and properties.