enthought / traitsui

TraitsUI: Traits-capable windowing framework
http://docs.enthought.com/traitsui
Other
297 stars 96 forks source link

TraitsUI halves odd numbers: TraitError: The 'top' trait of an ImageSlice instance must be an integer (wxPython 4 experiment) #580

Open mprogram opened 5 years ago

mprogram commented 5 years ago

For experimenting with the wxPython4.0 backend under Python 3 I've rebased locally enthought/pyface/pull/287 and adopted a similar approach to porting traitsui to wxPython4.0

It works for me now, and the popping deprecation warnings of various nature were more or less successfully traced down and so far resolved (or I think so). One I couldn't deal with, however, requires a deeper analysis:

Exception occurred in traits notification handler.
Please check the log file for details.
Exception occurred in traits notification handler for object: <traitsui.wx.image_slice.ImageSlice object at 0x7f8cfd959258>, trait: image, old value: None, new value: <pyface.ui.wx.image_resource.ImageResource object at 0x7f8cfec72620>
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/traits/trait_notifiers.py", line 394, in __call__
    self.handler(*args)
  File "/usr/lib/python3/dist-packages/traitsui/wx/image_slice.py", line 244, in _image_changed
    self._analyze_bitmap()
  File "/usr/lib/python3/dist-packages/traitsui/wx/image_slice.py", line 258, in _analyze_bitmap
    data = reshape(fromstring(image.GetData(), uint8), (dy, dx, 3))
TypeError: fromstring() argument 1 must be read-only bytes-like object, not bytearray

I would appreciate somebody looking at the relevant code base and, possibly, analyse it Python3-compatibility. I was testing the backend it with: https://docs.enthought.com/mayavi/mayavi/mlab.html

mprogram commented 5 years ago

_BTW, traitsui/wx/set_editor.py, line 220, in _create_button, has extraneous: space_before_

corranwebster commented 5 years ago

Try replacing it with frombuffer (https://docs.scipy.org/doc/numpy/reference/generated/numpy.frombuffer.html#numpy.frombuffer)

mprogram commented 5 years ago

Thank you for your suggestion! There is no error after fromstring -> frombuffer change, and yeah, I've got an Anaglyph stereo working (it doesn't work under Qt)! Now, if I go to Configure the scene:

Exception occurred in traits notification handler for object: <traitsui.wx.image_slice.ImageSlice object at 0x7f6daaa98c50>, trait: image, old value: None, new value: <pyface.ui.wx.image_resource.ImageResource object at 0x7f6daab77e08>
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/traits/trait_notifiers.py", line 394, in __call__
    self.handler(*args)
  File "/usr/lib/python3/dist-packages/traitsui/wx/image_slice.py", line 244, in _image_changed
    self._analyze_bitmap()
  File "/usr/lib/python3/dist-packages/traitsui/wx/image_slice.py", line 325, in _analyze_bitmap
    self._find_best_borders(data)
  File "/usr/lib/python3/dist-packages/traitsui/wx/image_slice.py", line 400, in _find_best_borders
    self._is_equal(data, left - 1, top, left, top, 1, height))
  File "/usr/lib/python3/dist-packages/traitsui/wx/image_slice.py", line 462, in _is_equal
    return (abs(data[y0: y0 + dy, x0: x0 + dx] -
TypeError: slice indices must be integers or None or have an __index__ method

and if to View the Mayavi pipeline:

Exception occurred in traits notification handler for object: <traitsui.wx.image_slice.ImageSlice object at 0x7f6da89c0f68>, trait: image, old value: None, new value: <pyface.ui.wx.image_resource.ImageResource object at 0x7f6daab3fba0>
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/traits/trait_notifiers.py", line 394, in __call__
    self.handler(*args)
  File "/usr/lib/python3/dist-packages/traitsui/wx/image_slice.py", line 244, in _image_changed
    self._analyze_bitmap()
  File "/usr/lib/python3/dist-packages/traitsui/wx/image_slice.py", line 319, in _analyze_bitmap
    self.top = min(dy / 2, self.dys[0])
  File "/usr/lib/python3/dist-packages/traits/trait_handlers.py", line 236, in error
    object, name, self.full_info(object, name, value), value
traits.trait_errors.TraitError: The 'top' trait of an ImageSlice instance must be an integer (int or long), but a value of 5.5 <class 'float'> was specified.

which seems to be still traitsui error due to self.top = min(dy / 2, self.dys[0]), and, perhaps, #576

mdickinson commented 5 years ago

@mprogram Your first traceback above seems to be only part-complete. What's the exception for that traceback?

mprogram commented 5 years ago

Apologies for getting late. Indeed, I've missed the last row in the first traceback, so, edited my previous post.