显示一系列对象作为表

发布于 2025-02-11 14:03:12 字数 862 浏览 1 评论 0原文

我有一个candle对象的数组,如下所示:

“在此处输入图像描述”

Pharo中有没有办法以表格格式显示数组?

|       date | open | high | low | close |
|------------+------+------+-----+-------|
| 2018-12-28 |   10 |   20 |  30 |    40 |
| 2019-12-28 |   50 |   60 |  70 |    80 |

gtoolkit

gtoolkit Tour的幻灯片似乎提到了这一点:

”在此处输入图像描述”

但是,似乎我必须定义一个特殊集合来持有candle对象,然后定义一个gtviewcandleson方法>自定义蜡烛的渲染方式。

只是想知道是否有一种方法可以与正常数组一起使用,或者GToolKit方法是否是必需的。

I have an array of Candle objects as shown below:

enter image description here

Is there a way in Pharo to display the array in a tabular format?

|       date | open | high | low | close |
|------------+------+------+-----+-------|
| 2018-12-28 |   10 |   20 |  30 |    40 |
| 2019-12-28 |   50 |   60 |  70 |    80 |

gtoolkit

The gtoolkit tour has a slide that seems to mention this:

enter image description here

However, it seems that I'd have to define a special collection for holding Candle objects and then define a gtViewCandlesOn method on it to customize how the candles will be rendered.

Just wondering if there's an approach that will work with normal arrays or if the gtoolkit approach is the way to go.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

万人眼中万个我 2025-02-18 14:03:13

这取决于使用上下文。如果您也将其在其他活动上使用,则可以使用 gtoolkit gtoolkit 是整个框架,将其仅用于此表格视图可能是非常过分的。

无论如何,我为Pharo Launcher命令行界面进行了类似的操作 - 称其为ConsoleListformatter。它非常简单地使用,您需要在蜡烛类上定义2种方法(#listprintattributeblocks: #listprintattributelabels:),将蜡烛集合设置为formatter实例。调用PrintList将完成这项工作。

您可以在此处使用 consoleListformatter类

此外,如果要在检查员中打印为集合,则需要覆盖#printon的原始实现:() >在使用 gtoolkit Inspector 的情况下)在收集类中。相反,我将定义模型类,例如烛台将使用实例var和candles的集合,然后您可以定义自己的#printon: on candlelist >不干扰原始集合实现。

让我知道,如果您需要更多详细信息!

干杯,
大卫

It depends on context of use. You can use GToolkit, if you use it on other activities as well. GToolkit is whole framework and probably it is quite overkill to use it just for this tabular view.

Anyway, I did something similar for Pharo launcher command line interface - calling it ConsoleListFormatter. It is pretty straightforward to use, you need to define 2 methods on your candle class (#listPrintAttributeBlocks: #listPrintAttributeLabels:) and set collection of Candles to formatter instance. Calling printList will do the job.

You can use it here ConsoleListFormatter class

Furthermore, if you want to print as collection in the inspector, you would need to override original implementation of #printOn: (or gtViewCandlesOn: in case of use GToolkit inspector) method on Collection class. Rather I would define model class, e.g. CandleList that would use instance var with collection of candles, then you can define your own #printOn: on CandleList without interfering original collection implementation.

Let me know, if you need more details!

Cheers,
David

苦妄 2025-02-18 14:03:13

要扩展检查员,请检查

inspectorPresentationOrder:title:

:例如:

AbstractFileReference >> #inspectionContents
    <inspectorPresentationOrder: 0 title: 'Contents'> 
    | maxBytes buffer atEnd stringContents displayStream displayString |
    
    maxBytes := 10000.
    
    self binaryReadStreamDo: [ :stream | 
        buffer := stream next: maxBytes.
        atEnd := stream atEnd ].
    ...
    ^ SpCodePresenter new
        withoutSyntaxHighlight;
        text: displayString;
        whenSubmitDo: [ :text | 
            self writeStreamDo: [ :s | s nextPutAll: text string ] ];
        yourself

但是要激活此检查员选项卡,我们有此方法:

AbstractFileReference >> #inspectionContentsContext: aContext 
    
    aContext active: self isFile

我为此做出此方法,您可以在您的项目中添加一些扩展方法,以便在数组类中为检查员添加一些扩展方法,并在拥有一个时打印您想要的任何内容阵列中的特殊对象。

To extend the inspector please check

inspectorPresentationOrder:title:

For example:

AbstractFileReference >> #inspectionContents
    <inspectorPresentationOrder: 0 title: 'Contents'> 
    | maxBytes buffer atEnd stringContents displayStream displayString |
    
    maxBytes := 10000.
    
    self binaryReadStreamDo: [ :stream | 
        buffer := stream next: maxBytes.
        atEnd := stream atEnd ].
    ...
    ^ SpCodePresenter new
        withoutSyntaxHighlight;
        text: displayString;
        whenSubmitDo: [ :text | 
            self writeStreamDo: [ :s | s nextPutAll: text string ] ];
        yourself

But to activate this inspector tab we have this method:

AbstractFileReference >> #inspectionContentsContext: aContext 
    
    aContext active: self isFile

I order to do that in your project you can add some extension methods for the inspector in Array class and print what ever you want when you have an special object in your array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文