Skip to content

Commit

Permalink
URL possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacZhangzhuo committed Jan 11, 2024
1 parent a7b6cc9 commit eb92ec4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 38 deletions.
2 changes: 1 addition & 1 deletion data/default_config/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

"COMPAS Core": {
"action": "url",
"kwargs": { "url": "https://compas.dev/compas_viewer/latest/" }
"kwargs": { "url": "https://compas.dev/compas/latest/" }
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/compas_viewer/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_action_cls(name: str) -> Any:
from .select_all import SelectAll # noqa: E402
from .viewmode import ViewRight, ViewFront, ViewTop, ViewPerspective # noqa: E402
from .delete_selected import DeleteSelected # noqa: E402
from .file import ImportFile, ExportFile, OpenURL # noqa: E402
from .io import ImportFile, ExportFile, OpenURL # noqa: E402

register_actions()

Expand Down
4 changes: 2 additions & 2 deletions src/compas_viewer/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def __init__(self, name: str, viewer: "Viewer", config: ActionConfig):
self.released.connect(self.released_action)

@abstractmethod
def pressed_action(self):
def pressed_action(self, **kwargs):
"""
The behavior of the action when the key is pressed.
"""
self.viewer.renderer.update()

@abstractmethod
def released_action(self):
def released_action(self, **kwargs):
"""
The behavior of the action when the key is released.
"""
Expand Down
33 changes: 0 additions & 33 deletions src/compas_viewer/actions/file.py

This file was deleted.

35 changes: 35 additions & 0 deletions src/compas_viewer/actions/io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from PySide6.QtGui import QDesktopServices
from .action import Action


class ImportFile(Action):
"""Import a file into the viewer."""

def pressed_action(self):
raise NotImplementedError("Importing files is not yet implemented.")


class ExportFile(Action):
"""Export a file from the viewer."""

def pressed_action(self):
raise NotImplementedError("Exporting files is not yet implemented.")


class OpenURL(Action):
"""Open external url."""

def pressed_action(self, url: str):
""" "
Open external url.
Parameters
----------
url : str
The url to open.
See Also
--------
:PySide6:`PySide6/QtGui/QDesktopServices`
"""
QDesktopServices.openUrl(url)
7 changes: 6 additions & 1 deletion src/compas_viewer/layout/menubar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from functools import partial
from typing import TYPE_CHECKING

from compas_viewer.actions import Action
Expand Down Expand Up @@ -36,5 +37,9 @@ def init(self):
for _k, _i in i.items():
action_config = ActionConfig({"key": "no"}) # type: ignore
parent.addAction(
_k, "", Action(_i["action"], self.viewer, action_config, **_i.get("kwargs", {})).pressed_action
_k,
partial(
Action(_i["action"], self.viewer, action_config).pressed_action,
**_i.get("kwargs", {}),
),
)

0 comments on commit eb92ec4

Please sign in to comment.