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

RangeSelection2D not working as expected #542

Open
sogoogos opened this issue Nov 20, 2020 · 1 comment
Open

RangeSelection2D not working as expected #542

sogoogos opened this issue Nov 20, 2020 · 1 comment

Comments

@sogoogos
Copy link

Problem Description
I am trying to add the functionality to set ROI with a mouse using RangeSelection2D.
However, I am getting the following error after right-clicking the image displayed.

File "/Users/sshiozawa/.edm/envs/python-class/lib/python3.6/site-packages/chaco/linear_mapper.py", line 67, in map_data
    return (screen_val - self.low_pos) / self._scale + self.range.low
TypeError: unsupported operand type(s) for -: 'list' and 'float'

I see some old attempt here.

Reproduction Steps:
Run the following code with an image file and then right-click the image in the interface.

from skimage import io
import matplotlib.pyplot as plt
from traits.api import Array, Bool, Button, Enum, File, Float, HasTraits, Instance, Int, List, Str, on_trait_change
from traitsui.api import CheckListEditor, Group, Item, HGroup, spring, UItem, View
from chaco.api import Plot, ArrayPlotData
from chaco.tools.api import PanTool, RangeSelection2D, ZoomTool
from enable.api import BaseTool, ComponentEditor
class Image_GUI(HasTraits):
    # Define Parameters
    file_path = File(exists=True)
    img = Array()
    plot = Instance(Plot)
    # Define File Select Function
    def _file_path_changed(self):
        self.img = io.imread(self.file_path)
    # Define Plot Function
    def _plot_default(self):
        img = self.img
        # Show Plot if Image is loaded
        if len(img) > 0:
            # Show Plot
            data = ArrayPlotData(img=img)
            plot = Plot(data)
            plot.img_plot('img', origin='top left')
            # Set Aspect Ratio
            height, width, _ = img.shape
            plot.aspect_ratio = width / height
            plot.tools.append(RangeSelection2D(plot))
        else:
            plot = Plot()
        return plot
    # Run Plot Method if file is changed
    @on_trait_change('file_path')
    def create_new_plot(self):
        self.plot = self._plot_default()
    # Configure GUI Settings
    traits_view = View(Item('file_path'),
                       UItem('plot', editor=ComponentEditor()))
if __name__ == '__main__':
    img_gui = Image_GUI()
    img_gui.configure_traits()

Expected behavior:

[Describe expected behavior here]

OS, Python version:
macOS, Python 3.6.12

@rahulporuri
Copy link
Contributor

i'm able to reproduce this on windows and see below for the full traceback

Traceback (most recent call last):
  File "C:\Users\rporuri\.edm\envs\chaco-test-3.6-pyqt5\lib\site-packages\enable\qt4\base_window.py", line 267, in mousePressEvent
    self.handler.mousePressEvent(event)
  File "C:\Users\rporuri\.edm\envs\chaco-test-3.6-pyqt5\lib\site-packages\enable\qt4\base_window.py", line 150, in mousePressEvent
    self._enable_window._handle_mouse_event(name + "_down", event)
  File "C:\Users\rporuri\.edm\envs\chaco-test-3.6-pyqt5\lib\site-packages\enable\abstract_window.py", line 382, in _handle_mouse_event
    self.component.dispatch(mouse_event, event_name)
  File "C:\Users\rporuri\.edm\envs\chaco-test-3.6-pyqt5\lib\site-packages\enable\component.py", line 957, in dispatch
    self._new_dispatch(event, suffix)
  File "C:\Users\rporuri\.edm\envs\chaco-test-3.6-pyqt5\lib\site-packages\enable\component.py", line 1008, in _new_dispatch
    tool.dispatch(event, suffix)
  File "C:\Users\rporuri\.edm\envs\chaco-test-3.6-pyqt5\lib\site-packages\enable\interactor.py", line 104, in dispatch
    self._dispatch_stateful_event(event, suffix)
  File "C:\Users\rporuri\.edm\envs\chaco-test-3.6-pyqt5\lib\site-packages\enable\interactor.py", line 120, in _dispatch_stateful_event
    handler(event)
  File "C:\Users\rporuri\.edm\envs\chaco-test-3.6-pyqt5\lib\site-packages\chaco\tools\range_selection_2d.py", line 182, in normal_right_down
    mapped_pos = self._map_data([(x_pos,y_pos)])[0][self.axis_index]
  File "C:\Users\rporuri\.edm\envs\chaco-test-3.6-pyqt5\lib\site-packages\chaco\tools\range_selection_2d.py", line 282, in _map_data
    return self.mapper.map_data(screen_pts)
  File "C:\Users\rporuri\.edm\envs\chaco-test-3.6-pyqt5\lib\site-packages\chaco\linear_mapper.py", line 65, in map_data
    return (screen_val - self.low_pos) / self._scale + self.range.low
TypeError: unsupported operand type(s) for -: 'list' and 'float'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants