简体   繁体   English

滚动条在最近的chaco版本中不起作用

[英]scrollbar does not work in recent chaco releases

This program was running fine in chaco 3.2, but with chaco 4, scrollbar does not show at all. 该程序在chaco 3.2中运行良好,但是在chaco 4中,滚动条根本不显示。

I would like either to find the problem or find a workaround. 我想找到问题或找到解决方法。

PanTool may be a workaround, but this will conflict with some linecursors used with mouse. PanTool可能是一种解决方法,但这将与鼠标使用的某些线形光标冲突。

#!/usr/bin/env python

# Major library imports
from numpy import linspace
from scipy.special import jn

# Enthought library imports
from enthought.enable.api import Component, ComponentEditor
from enthought.traits.api import HasTraits, Instance
from enthought.traits.ui.api import Item, Group, View

# Chaco imports
from enthought.chaco.api import ArrayPlotData, VPlotContainer, \
    Plot, OverlayPlotContainer, add_default_axes, add_default_grids
from enthought.chaco.plotscrollbar import PlotScrollBar
from enthought.chaco.tools.api import PanTool, ZoomTool

#===============================================================================
# # Create the Chaco plot.
#===============================================================================
def _create_plot_component():

    # Create some x-y data series to plot
    x = linspace(-2.0, 10.0, 100)
    pd = ArrayPlotData(index = x)
    for i in range(5):
        pd.set_data("y" + str(i), jn(i,x))

    # Create some line plots of some of the data
    plot1 = Plot(pd)
    plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")[0]
    p = plot1.plot(("index", "y3"), name="j_3", color="blue")[0]

    # Add the scrollbar
    plot1.padding_top = 0

    p.index_range.high_setting = 1
    # Create a container and add our plots
    container = OverlayPlotContainer(padding = 5,fill_padding = True,
                                     bgcolor = "lightgray", use_backbuffer=True)
    hscrollbar = PlotScrollBar(component=p, mapper=p.index_mapper,axis="index", resizable="",use_backbuffer = False,
                               height=15,position=(0,0))
    hscrollbar.force_data_update()

    plot1.overlays.append(hscrollbar)


    hgrid,vgrid = add_default_grids(plot1)
    add_default_axes(plot1)
    container.add(plot1)

    container.invalidate_and_redraw()
    return container

#===============================================================================
# Attributes to use for the plot view.
size=(900,500)
title="Scrollbar example"

#===============================================================================
# # Demo class that is used by the demo.py application.
#===============================================================================
class Demo(HasTraits):
    plot = Instance(Component)

    traits_view = View(
                    Group(
                        Item('plot', editor=ComponentEditor(size=size),
                             show_label=False),
                        orientation = "vertical"),
                    resizable=True, title=title
                    )

    def _plot_default(self):
         return _create_plot_component()

demo = Demo()

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

#--EOF---

We investigated and found some problems in the code of enable api ( https://github.com/enthought/enable ), that had disallowed the scrollbar to display in wx backend. 我们调查了enable api( https://github.com/enthought/enable )代码中的一些问题,这些问题不允许滚动条在wx后端显示。

The following patch solves the problem. 以下补丁解决了该问题。

There are other issues, like height setting that does not work, we will continue to investigate. 还有其他问题,例如高度设置无效,我们将继续进行调查。

diff --git a/enable/wx/scrollbar.py b/enable/wx/scrollbar.py
index 02d0da0..003cc90 100644
--- a/enable/wx/scrollbar.py
+++ b/enable/wx/scrollbar.py
@@ -136,7 +136,7 @@
     # We have to do this flip_y business because wx and enable use opposite
     # coordinate systems, and enable defines the component's position as its
     # lower left corner, while wx defines it as the upper left corner.
-        window = getattr(gc, "window", None)
+        window = getattr(self, "window", None)
     if window is None:
         return
     wx_ypos = window._flip_y(wx_ypos)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM