-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
364ccfb
commit f746b4d
Showing
4 changed files
with
87 additions
and
17 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# For licensing and distribution details, please read carefully xgrid/__init__.py | ||
|
||
""" | ||
Get rectangular selection from image with SVG shape | ||
""" | ||
|
||
# guitest: show | ||
|
||
import os.path as osp | ||
|
||
from guidata.env import execenv | ||
from guidata.qthelpers import qt_app_context | ||
|
||
from plotpy.builder import make | ||
from plotpy.tests.data import gen_image4 | ||
from plotpy.tests.gui.test_get_segment import SEG_AXES_COORDS, PatchedSelectDialog | ||
from plotpy.tools import RectangularShapeTool | ||
from plotpy.widgets.selectdialog import select_with_shape_tool | ||
|
||
|
||
class SVGToolExample(RectangularShapeTool): | ||
"""Tool to select a rectangular area and create a pattern from it""" | ||
|
||
TITLE = "Pattern selection tool" | ||
ICON = "pattern.svg" | ||
AVOID_NULL_SHAPE = True | ||
SVG_FNAME = osp.join(osp.dirname(__file__), "svg_tool.svg") | ||
|
||
def create_shape(self): | ||
"""Create shape to be drawn""" | ||
svg_data = open(self.SVG_FNAME, "rb").read() | ||
shape = make.svg("rectangle", svg_data, 0, 0, 1, 1, "SVG") | ||
self.set_shape_style(shape) | ||
return shape, 0, 2 | ||
|
||
|
||
def test_get_rectangle_with_svg(): | ||
"""Test get_rectangle_with_svg""" | ||
with qt_app_context(): | ||
image = make.image(data=gen_image4(200, 200), colormap="gray") | ||
shape = select_with_shape_tool( | ||
None, SVGToolExample, image, "Test", tooldialogclass=PatchedSelectDialog | ||
) | ||
rect = shape.get_rect() | ||
if execenv.unattended: | ||
assert [round(i) for i in list(rect)] == SEG_AXES_COORDS | ||
elif rect is not None: | ||
print("Area:", rect) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_get_rectangle_with_svg() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters