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

Css pseudo states #358

Merged
merged 37 commits into from Jul 12, 2020
Merged

Css pseudo states #358

merged 37 commits into from Jul 12, 2020

Conversation

amolenaar
Copy link
Member

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Documentation content changes

What is the current behavior?

Style can be defined, but style can not be changed on the view state of an item (focused, selected, etc.).

Issue Number: #284

What is the new behavior?

Style will be updated based on the view state of an item.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This PR does some serious rearrangement of code:

  • All styling related code is now in gaphor.core.styling (also the code previously in gaphor.diagram.style).
  • A custom Gaphas Painter is used to add style information to the drawing context

@amolenaar amolenaar changed the base branch from faster-text-layout to master July 5, 2020 15:19
@amolenaar amolenaar force-pushed the css-pseudo-states branch 2 times, most recently from 8668e6e to 9776ee3 Compare July 5, 2020 15:55
Copy link
Member

@danyeaw danyeaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good, I think the refactoring made this more clear which is awesome!

pyproject.toml Outdated
@@ -35,7 +35,9 @@ classifiers = [
python = "^3.7"
pycairo = "^1.18"
PyGObject = "^3.30"
gaphas = "^2.1"
#gaphas = "^2.1"
gaphas = { git = "https://github.com/gaphor/gaphas.git", branch = "master" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure you're on top of it, but just a reminder to not forget to change this back now that you released a new version

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make sure I do not need to make more changes to Gaphas before creating a new Gaphas release.

gaphor/core/modeling/elementfactory.py Show resolved Hide resolved
@amolenaar amolenaar marked this pull request as draft July 7, 2020 06:30
@amolenaar
Copy link
Member Author

amolenaar commented Jul 7, 2020

I'm not finished yet. There's still some tough nuts to crack. I moved the style lookup out of the Presentation class, since I also need to add state info (focused, selected). This information lives in the View.

Styling information is used in 2 places:

  1. Item.draw(). Injected via the View (Painter)
  2. Item.[pre|post]_update(). Updating the object internal state (padding, text size)

The ItemWrapper (bad name) objects should have a reference to the view, since they need to look up state information for the rendered item, but possible also for its parent and children.

From a conceptual point of view it makes sense to let Diagram own (or reference) a style sheet. There is currenly a bit of a mismatch, since in Gaphor we talk about diagrams, and in Gaphas we talk about _Canvas_es and _View_s. I think I need a DiagramView that references a diagram, not a canvas. The DiagramView can take care of setting the right types of painters and it can deal with diagram properties such as line-style (sloppy/straight) and background-color. This should even allow us to change the diagram style (a bit) per diagram. E.g. diagrams starting with "draft" could be rendered in the sloppy style.

* Require Gaphas 2.1.1 (master) code
* Everything styling related to gaphor.core.styling.
* Provide style data through update/draw contexts
* Style is requested via the diagram object
* Use Style type all around
Makes more sense than going via the canvas
Also defined a protocol for the style node.
Each item type should bring its own style node implementation (wrapper).
Since that's how it's defined for HTML as well.
@amolenaar
Copy link
Member Author

View states now translate to pseudo-classes in CSS.

image

@amolenaar amolenaar marked this pull request as ready for review July 9, 2020 17:58
@amolenaar
Copy link
Member Author

I also added support for styling of the diagram background and line style.

Sloppy-line setting is gone from the preferences window

Screenshot from 2020-07-09 22-54-37

@amolenaar amolenaar requested a review from danyeaw July 9, 2020 21:02
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 11, 2020

Sourcery Code Quality Report (beta)

✅ Merging this PR will increase code quality in the affected files by 0.03 out of 10.

Before After Change
Quality 8.91 8.94 0.03
Complexity 1.14 1.08 -0.06
Method Length 43.5 42.23 -1.27
Lines 10307 10307 0
Changed files Quality Before Quality After Quality Change
docs/conf.py 8.0 7.98 -0.01 ⬇️
examples/list_classes.py 6.79 6.79 0.0
gaphor/abc.py 9.7 9.7 0.0
gaphor/entrypoint.py 8.31 8.31 0.0
gaphor/SysML/modelinglanguage.py 9.72 9.73 0.01 ⬆️
gaphor/SysML/toolbox.py 8.91 8.91 0.0
gaphor/SysML/blocks/property.py 8.79 8.79 0.0
gaphor/SysML/blocks/proxyport.py 9.17 9.19 0.02 ⬆️
gaphor/UML/init.py 9.73 9.73 0.0
gaphor/UML/iconname.py 9.52 9.52 0.0
gaphor/UML/modelinglanguage.py 9.72 9.73 0.01 ⬆️
gaphor/UML/toolbox.py 8.86 8.86 0.0
gaphor/UML/umloverrides.py 9.2 9.2 0.0
gaphor/UML/actions/init.py 9.04 9.04 0.0
gaphor/UML/actions/activitynodes.py 8.74 8.75 0.01 ⬆️
gaphor/UML/actions/partition.py 7.48 7.49 0.01 ⬆️
gaphor/UML/actions/tests/test_activitynodes.py 8.99 8.99 0.0
gaphor/UML/actions/tests/test_flow.py 9.31 9.3 -0.01 ⬇️
gaphor/UML/actions/tests/test_objectnode.py 9.46 9.46 0.0
gaphor/UML/classes/init.py 9.21 9.21 0.0
gaphor/UML/classes/association.py 8.71 8.71 -0.0
gaphor/UML/classes/classconnect.py 8.47 8.47 0.0
gaphor/UML/classes/dependency.py 9.14 9.13 -0.01 ⬇️
gaphor/UML/classes/implementation.py 8.97 8.93 -0.04 ⬇️
gaphor/UML/classes/interface.py 8.0 8.0 0.0
gaphor/UML/classes/klass.py 8.55 8.55 0.0
gaphor/UML/classes/stereotype.py 9.21 9.21 0.0
gaphor/UML/classes/tests/test_class.py 8.47 8.48 0.01 ⬆️
gaphor/UML/components/init.py 9.48 9.48 0.0
gaphor/UML/components/artifact.py 8.26 8.26 0.0
gaphor/UML/components/component.py 7.99 7.99 0.0
gaphor/UML/interactions/init.py 9.48 9.48 0.0
gaphor/UML/interactions/executionspecification.py 8.96 8.98 0.01 ⬆️
gaphor/UML/interactions/interaction.py 8.58 8.58 0.0
gaphor/UML/interactions/tests/test_executionspecification.py 8.85 8.84 -0.0
gaphor/UML/profiles/init.py 9.63 9.63 0.0
gaphor/UML/states/init.py 9.48 9.48 0.0
gaphor/UML/states/state.py 7.86 7.86 0.0
gaphor/UML/tests/test_uml2.py 9.1 9.1 0.0
gaphor/UML/tests/test_umlfmt.py 9.04 9.04 0.0
gaphor/UML/usecases/init.py 9.55 9.55 0.0
gaphor/core/modeling/init.py 9.63 9.55 -0.08 ⬇️
gaphor/core/modeling/diagram.py 9.32 9.3 -0.01 ⬇️
gaphor/core/modeling/element.py 9.53 9.54 0.01 ⬆️
gaphor/core/modeling/elementfactory.py 9.32 9.38 0.05 ⬆️
gaphor/core/modeling/presentation.py 9.54 9.53 -0.01 ⬇️
gaphor/core/modeling/stylesheet.py N/A 9.57 N/A
gaphor/core/modeling/tests/test_diagram.py 9.51 9.52 0.01 ⬆️
gaphor/core/modeling/tests/test_diagram_style.py N/A 9.63 N/A
gaphor/core/modeling/tests/test_presentation.py 9.6 9.64 0.04 ⬆️
gaphor/core/styling/init.py 8.6 9.24 0.64 ⬆️
gaphor/core/styling/declarations.py 8.7 8.91 0.21 ⬆️
gaphor/core/styling/properties.py N/A 7.1 N/A
gaphor/core/styling/selectors.py 8.83 8.83 -0.0
gaphor/core/styling/tests/test_css.py 9.47 9.39 -0.08 ⬇️
gaphor/core/styling/tests/test_selector.py 9.07 9.07 -0.0
gaphor/diagram/painter.py N/A 8.95 N/A
gaphor/diagram/presentation.py 8.92 8.91 -0.0
gaphor/diagram/shapes.py 8.74 8.77 0.03 ⬆️
gaphor/diagram/text.py 8.13 8.25 0.12 ⬆️
gaphor/diagram/general/init.py 9.48 9.48 0.0
gaphor/diagram/general/comment.py 8.45 8.45 0.0
gaphor/diagram/general/simpleitem.py 9.12 9.15 0.02 ⬆️
gaphor/diagram/tests/test_shapes.py 9.16 9.16 -0.0
gaphor/diagram/tests/test_text.py 8.44 8.44 0.0
gaphor/plugins/diagramexport/init.py 8.89 8.85 -0.03 ⬇️
gaphor/plugins/diagramexport/tests/test_diagramexport.py 9.43 9.54 0.11 ⬆️
gaphor/services/tests/test_undomanager.py 8.06 8.06 0.0
gaphor/storage/tests/test_storage_message_item_upgrade.py 8.74 8.74 0.0
gaphor/storage/tests/test_storage_upgrades.py 9.21 9.21 0.0
gaphor/ui/diagrampage.py 8.79 8.73 -0.06 ⬇️
gaphor/ui/elementeditor.py 9.04 9.04 0.0
gaphor/ui/mainwindow.py 8.83 8.84 0.0
gaphor/ui/namespace.py 8.2 8.2 0.0
gaphor/ui/preferences.py 9.36 9.42 0.06 ⬆️
gaphor/ui/tests/test_namespace.py 9.23 9.23 0.0
gaphor/ui/tests/test_preferences.py 9.48 9.58 0.1 ⬆️
tests/test_gaphorconvert.py 9.25 9.25 0.0

Here are some functions in these files that still need a tune-up:

File Function Quality Recommendation
gaphor/UML/classes/association.py AssociationEnd.post_update 3.65 Split out functionality
gaphor/ui/namespace.py Namespace.construct 4.3 Split out functionality
gaphor/UML/classes/association.py AssociationItem.post_update 4.73 Split out functionality
gaphor/diagram/text.py _text_point_at_line_end 4.74 Split out functionality
gaphor/ui/namespace.py NamespaceView.on_drag_data_received 4.75 Split out functionality

Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it via email or our Gitter!

@amolenaar amolenaar merged commit 6c91b15 into master Jul 12, 2020
@amolenaar amolenaar deleted the css-pseudo-states branch July 12, 2020 19:13
@danyeaw danyeaw added the feature A new feature label Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants