[Rock-dev] Subclassing a C++ widget from ruby, and registering the result as a Vizkit widget

Sylvain Joyeux sylvain.joyeux at dfki.de
Mon Apr 11 14:20:05 CEST 2011


On 04/11/2011 12:05 PM, Alexander Duda wrote:
> On Mon, 2011-04-11 at 11:09 +0200, Sylvain Joyeux wrote:
>> Hello
>>
>> I'd like to subclass the ImageView widget to create a RasterMapView
>> widget -- which is basically converting a Gdal raster band into an image.
>>
>> I'd like to do it in Ruby ... and register the result in vizkit.
>>
>> As far as I understood, it boils down to get vizkit to return me the
>> ImageView class (NOT an ImageView instance), i.e.
>>
>>
>> <code>
>> require 'vizkit'
>> image_view_klass = Vizkit.<I don't know what to put there>
>> class RasterMapView<  image_view_klass
>>     [implement the view]
>> end
>> Vizkit::UILoader.register_ruby_widget "RasterMapView",
>> RasterMapView.method(:new)
>> Vizkit::UILoader.register_widget_for "RasterMapView", Gdal::Band, :display
>> </code>
>>
>> Can I do that ? And if I can, how ?
>>
>> Sylvain
>
> This is not going to work because the ImageView class is not known to
> ruby. You can only instantiate an instance of the ImageView class which
> behaves like a QWidget class on the ruby side.
>
> Unfortunately all events from the ImageView class are not redirected to
> the ruby instance so you cannot extend the instance to implement a new
> behavior. To get this running you have to write qt bindings.
>
> But you could create your own view by creating a custom QImage which is
> displayed by a ImageView instance.
My problem was to make the raster-map-to-imageview functionality 
available to everyone. I came up with this solution:

 
https://rock.opendfki.de/wiki/WikiStart/Ruby/VizkitExtendingCXXWidgetsInRuby

Comments are welcome

Sylvain


More information about the Rock-dev mailing list