[chaco] visibility title issue...

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[chaco] visibility title issue...

fred-2
Hi all,

With the attached CME, set title, then set it visible then press Draw!
button is OK.

But set title, then press Draw! button and then set title visible is not
OK: title is located at bottom left.

Any hint?

TIA

Cheers

--
Fred


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

cme.py (3K) Download Attachment
snapshot.png (121K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [chaco] visibility title issue...

Warren Weckesser
fred wrote:

> Hi all,
>
> With the attached CME, set title, then set it visible then press Draw!
> button is OK.
>
> But set title, then press Draw! button and then set title visible is
> not OK: title is located at bottom left.
>
> Any hint?
>

I was able to reproduce the problem, but I don't know why it happens.

For what it's worth, the attached cme2.py avoids the problem by taking a
different approach to the visibility of the title.

Warren


> TIA
>
> Cheers
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev

#!/usr/bin/env python

from numpy import *

from enthought.traits.api import *
from enthought.traits.ui.api import *

from enthought.enable.api import *
from enthought.chaco.api import *
from enthought.chaco.tools.api import *


class ImagePlot(HasTraits):
   
    xmin, xmax = -8.0, 8.0
    ymin, ymax = -10.0, 10.0
    nx = 100
    ny = 100
   
    plot = Instance(Plot)
    container = Instance(HPlotContainer)
   
    title = String(label='title',
                   auto_set=False, enter_set=True)
    visibility = Bool
    draw_button = Button('Draw!')
   
    colorbar_labels_format = String
   
    view = View(HGroup(Item('title'),
                       UItem('visibility'),
                       UItem('draw_button')),
                Item('container',
                     editor=ComponentEditor(),
                     show_label=False),
                width=800, height=700,
                resizable=True,
                title='Chaco Plot')
   
    def _draw_button_fired(self):
        x = linspace(self.xmin, self.xmax, self.nx)
        y = linspace(self.ymin, self.ymax, self.ny)
        xgrid, ygrid = meshgrid(x, y)
        array_plot_data = ArrayPlotData(imagedata=sin(xgrid*ygrid))
        self.plot = Plot(array_plot_data)
        self.plot.img_plot('imagedata',
                           name='imagedata')
        if self.visibility:
            self.plot.title = self.title
        self.plot.tools.append(PanTool(self.plot))
        self.plot.tools.append(ZoomTool(self.plot))
        self.plot.tools.append(DragZoom(self.plot,
                                        drag_button='right'))
       
        colormap = self.plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            orientation='v',
                            resizable='v',
                            width=30,
                            padding=50)
        colorbar._axis.orientation = 'right'
        colorbar.plot = self.plot
        colorbar.padding_top = self.plot.padding_top
        colorbar.padding_bottom = self.plot.padding_bottom
       
        container = HPlotContainer()
        container.add(self.plot)
        container.add(colorbar)
        self.container = container
   
    def _title_changed(self):
        if self.plot is not None and self.visibility:
            self.plot.title = self.title
            self.plot.request_redraw()
   
    def _visibility_changed(self, new_value):
        if self.plot is not None:
            if new_value:
                self.plot.title = self.title
            else:
                self.plot.title = ''
            self.plot.request_redraw()

if __name__ == "__main__":
   
    ImagePlot().configure_traits()

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [chaco] visibility title issue...

fred-2
Le 08/04/2010 13:57, Warren Weckesser a écrit :

> I was able to reproduce the problem, but I don't know why it happens.
Ok.
Me too :-)
>
> For what it's worth, the attached cme2.py avoids the problem by taking a
> different approach to the visibility of the title.
Thanks, Warren.

I get another one : set the color of the title to transparent when not
visible ;-)



Cheers,

--
Fred
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [chaco] visibility title issue...

Peter Wang
In reply to this post by fred-2
On Thu, Apr 8, 2010 at 4:24 AM, fred <[hidden email]> wrote:
> Hi all,
> With the attached CME, set title, then set it visible then press Draw!
> button is OK.
> But set title, then press Draw! button and then set title visible is not OK:
> title is located at bottom left.
> Any hint?

Yes.  If the PlotLabel object is visible when the plot is initially
drawn, then it participates in layout, and its size and position are
set appropriate.  Thus, when you check the checkbox before pressing
Draw for the first time, the label shows up correctly.

If the checkbox is not set when you first press Draw, then when the
plot performs layout for the first time, the PlotLabel is skipped
because it is not visible.  If you subsequently click the checkbox to
toggle the label's visibility, the label renders itself at its default
position (the origin).  Calling request_redraw() on the plot is not
sufficient, because the issue is that layout is not occurring, and the
plot will not perform layout again unless its size changes.  (You can
demonstrate this by resizing the window just a little bit, and seeing
that the label "jumps" to the correct location.)

Fortunately, there is a very simple fix: whenever the visibility
checkbox is changed, you can directly call do_layout() on the plot
title object, like so:

    def _visibility_changed(self):
        if (self.plot is not None):
            self.plot._title.visible = self.visibility
            self.plot._title.do_layout()
            self.plot.request_redraw()

I have attached an the amended CME.  Also note that I replaced your
loop that searches the plot.overlays with a direct access to the
_title attribute of Plot, which is the reference to the PlotLabel.

HTH,
Peter

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

title_vis.py (4K) Download Attachment