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

Feature/viewer-widget #8

Merged
merged 16 commits into from
Dec 19, 2023
Merged

Feature/viewer-widget #8

merged 16 commits into from
Dec 19, 2023

Conversation

ZacZhangzhuo
Copy link
Collaborator

@ZacZhangzhuo ZacZhangzhuo commented Dec 17, 2023

What type of change is this?

  • Basic Viewer buildup with the widgets:
    • viewer lunchable. The main widget and the other associated widgets can be shown on the screen.
    • test files added for checking.
    • doc file cleanup for sphinx-compas2-theme compatibility.
    • tutorial docs added.
    • some other small patches.
2023-12-12-17-16-59-27 2023-12-12-17-16-59-22
2023-12-12-17-16-59-20 2023-12-12-17-16-59-17

image

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I added a line to the CHANGELOG.md file in the Unreleased section under the most fitting heading (e.g. Added, Changed, Removed).
  • I ran all tests on my computer and it's all green (i.e. invoke test).
  • I ran lint on my computer and there are no errors (i.e. invoke lint).
  • I added new functions/classes and made them available on a second-level import, e.g. compas.datastructures.Mesh.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if appropriate)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

static icons and css clean up. the config.py is also updated based on Tom's template.

# ==========================================================================
# Messages
# ==========================================================================
def _about(self) -> None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

naming this _about because the name about is occupied by the about: str from the config file.

I was careful about the _ for private functions and attributes. most of them I produced are private, so they are all with the _ prefix

temp.py Outdated
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this random file was accidentally uploaded last time. remove now

src/compas_viewer/configurations/controller_config.py Outdated Show resolved Hide resolved
src/compas_viewer/configurations/controller_config.py Outdated Show resolved Hide resolved
src/compas_viewer/viewer.py Outdated Show resolved Hide resolved
src/compas_viewer/viewer.py Show resolved Hide resolved
config: Optional[ViewerConfigData] = None,
) -> None:
# custom or default config
config = config or Viewer.from_default().data
Copy link
Member

Choose a reason for hiding this comment

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

the use from_default like this doesn't make sense to me.
"from" functions are supposed to be alternative constructors.
they can be used as an alternative to the normal constructor, not inside of it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes. let me write as config = config or ViewerConfig.from_default().data which makes more sense.

ICONS = Path(Path(__file__).parent, "_static", "icons")


class Viewer(ViewerConfig):
Copy link
Member

Choose a reason for hiding this comment

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

why does the viewer extend the viewer configuration?
should the configuration not be an attribute of the viewer?

Copy link
Collaborator Author

@ZacZhangzhuo ZacZhangzhuo Dec 17, 2023

Choose a reason for hiding this comment

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

maybe we should find a better name for ViewerConfig since I understand making the viewer inherited from its config doesn't make sense.. but the idea is:

inheritance tree: compas.Data -> compas_viewer.Config -> compas_viewer.ViewerConfig -> compas_viewer.View so the needed config is safely checked before initialising the Viewer, and we don't have to assign every config attribute into the Viewer. The Viewer naturally has the attributes like width at the beginning.

In the past we the View was inherited from the Qt like class View(QtWidgets.QOpenGLWidget): , which is a bit indirect for other operations.

Copy link
Member

Choose a reason for hiding this comment

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

things like an OpenGL view should not be based on the data framework

# ==========================================================================
# Messages
# ==========================================================================
def _about(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

add blank line and remove the underscore (since this seems to be a public method: it is used in one of the examples)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes you are right. but

naming this _about because the name about is occupied by the about: str from the config file.

any suggestion on solving this?

Copy link
Member

@tomvanmele tomvanmele Dec 17, 2023

Choose a reason for hiding this comment

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

it cannot be that the config file is in this namespace since the viewer should not inherit from config

Copy link
Member

Choose a reason for hiding this comment

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

i think this can now just be "about"

@ZacZhangzhuo
Copy link
Collaborator Author

ZacZhangzhuo commented Dec 17, 2023

pytest locally sucssful but in the github action:

tests/test_placeholder.py .                                              [ 50%]
Fatal Python error: Aborted

Current thread 0x00007f48d8437b80 (most recent call first):
  File "/home/runner/work/compas_viewer/compas_viewer/src/compas_viewer/viewer.py", line 105 in _init
  File "/home/runner/work/compas_viewer/compas_viewer/src/compas_viewer/viewer.py", line 89 in __init__
  File "/home/runner/work/compas_viewer/compas_viewer/tests/test_viewer.py", line 12 in test_default_config
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/python.py", line 194 in pytest_pyfunc_call
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_callers.py", line 77 in _multicall
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_manager.py", line 115 in _hookexec
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_hooks.py", line 493 in __call__
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/python.py", line 1[792](https://github.com/compas-dev/compas_viewer/actions/runs/7239911557/job/19722325003?pr=8#step:2:807) in runtest
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/runner.py", line 169 in pytest_runtest_call
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_callers.py", line 77 in _multicall
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_manager.py", line 115 in _hookexec
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_hooks.py", line 493 in __call__
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/runner.py", line 262 in <lambda>
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/runner.py", line 341 in from_call
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/runner.py", line 261 in call_runtest_hook
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/runner.py", line 222 in call_and_report
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/runner.py", line 133 in runtestprotocol
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/runner.py", line 114 in pytest_runtest_protocol
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_callers.py", line 77 in _multicall
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_manager.py", line 115 in _hookexec
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_hooks.py", line 493 in __call__
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/main.py", line 350 in pytest_runtestloop
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_callers.py", line 77 in _multicall
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_manager.py", line 115 in _hookexec
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_hooks.py", line 493 in __call__
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/main.py", line 325 in _main
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/main.py", line 271 in wrap_session
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/main.py", line 318 in pytest_cmdline_main
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_callers.py", line 77 in _multicall
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_manager.py", line 115 in _hookexec
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pluggy/_hooks.py", line 493 in __call__
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/config/__init__.py", line 169 in main
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/_pytest/config/__init__.py", line 192 in console_main
  File "/opt/hostedtoolcache/Python/3.8.18/x64/bin/pytest", line 8 in <module>
tests/test_viewer.py 
Error: Process completed with exit code 250.

any suggestion?

should I write less test files but doc examples to exam... ?

@tomvanmele
Copy link
Member

for me the test works locally, but the user has to close the viewer window to stop the test so i don't know how this would work in a workflow. i don't think this is needed right now...

@tomvanmele
Copy link
Member

tomvanmele commented Dec 17, 2023

also, i would still use an environment with a conda-based setup for this repo, especially to make it cross-platform. for me the following environment works well and doesn't take much time to resolve... (you may need to tweak it for windows)

name: viewer-dev
channels:
  - conda-forge
dependencies:
  - python=3.9
  - pip
  - freetype-py
  - textdistance
  - pyside2
  - pyopengl
  - qtpy
  - pip:
    - -r requirements-dev.txt

and compas 2 is needed as well of course...

@ZacZhangzhuo
Copy link
Collaborator Author

for me the test works locally, but the user has to close the viewer window to stop the test so i don't know how this would work in a workflow. i don't think this is needed right now...

that is because pytest intelligently test examples:

057     Examples
058     -------
059     >>> from compas_viewer import Viewer
060     >>> viewer = Viewer()
061     >>> viewer.show()

I remove the example for now

@tomvanmele
Copy link
Member

you can add # doctest: +SKIP for stuff like this

@tomvanmele
Copy link
Member

also, i would still use an environment with a conda-based setup for this repo, especially to make it cross-platform. for me the following environment works well and doesn't take much time to resolve... (you may need to tweak it for windows)

name: viewer-dev
channels:
  - conda-forge
dependencies:
  - python=3.9
  - pip
  - freetype-py
  - textdistance
  - pyside2
  - pyopengl
  - qtpy
  - pip:
    - -r requirements-dev.txt

and compas 2 is needed as well of course...

but if it worked with the pip install until now, just leave it, we can have a look at this later...

Examples
-------
>>> from compas_viewer import Viewer
>>> viewer = Viewer()
Copy link
Member

Choose a reason for hiding this comment

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

you need to skip this as well, because it sets a lot of stuff in motion that is otherwise never properly stopped...

@ZacZhangzhuo
Copy link
Collaborator Author

ZacZhangzhuo commented Dec 17, 2023

comment summary:

This PR is ready to be merged if we are happy with these three questions:
#8 (comment) (changed from Viewer.from_default().data into ViewerConfig.from_default().data
#8 (comment) (changed, Viewer no longer inherent from ViewerConfig)
#8 (comment) (unchanged, need naming or other suggestions)

@Licini

# ==========================================================================
# Messages
# ==========================================================================
def _about(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

i think this can now just be "about"

src/compas_viewer/viewer.py Show resolved Hide resolved
@ZacZhangzhuo ZacZhangzhuo merged commit e8c0ffb into main Dec 19, 2023
@ZacZhangzhuo ZacZhangzhuo deleted the feature/render branch December 19, 2023 15:00
@ZacZhangzhuo ZacZhangzhuo mentioned this pull request Dec 19, 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.

2 participants