为什么这个造型规格2应用程序无法正常工作?

时间:2021-01-07 11:26:10

标签: smalltalk pharo

我试图添加样式SpTextPresenter(的菲罗9,规格2,视窗10 )。我有MyApp类别:

SpApplication subclass: #MyApp
    instanceVariableNames: ''
    classVariableNames: ''
    package: 'MyAdm'

与类方法uniqueInstance(和类实例 - “单” 想法是从复制的LibC粘贴):

uniqueInstance
    ^ uniqueInstance ifNil: [ uniqueInstance := self new ]

和实例方法initialize

initialize
    super initialize.
    self useBackend: #Morphic with: MyAppConfiguration new.

MyAppConfiguration类别:

SpMorphicConfiguration subclass: #MyAppConfiguration
    instanceVariableNames: ''
    classVariableNames: ''
    package: 'MyAdm'

与方法configure

configure: anApplication
    super configure: anApplication.
    self styleSheet addClass: 'text' with: [ :style |
        style addPropertyFontWith: [ :font |
            font bold: true;
                  size: 20;
                  name: 'Courier'
        ].
    ].

某处在我的代码:

.....
    "presenterClass is an argument which is a class of my presenter"
    presenter := MyApp uniqueInstance newPresenter: presenterClass.
    presenter openWithSpec.
    presenter updatePresenter.
....

我有几个演示者,但其中一个确实包含在 text 方法中创建的 initializePresenters 变量:

initializePresenters
    text := self newText addStyle: 'text'.
    super initializePresenters

但结果是坏 - {的{1}}的标准视图,其中一标准字体,没有什么改变!错误在哪里?我想在text({的{1}}型)我的自定义字体看到的。

修改:顺便说一句,https://pypi.org/project/django-simple-history/不工作太

2 个答案:

答案 0 :(得分:3)

是的,如果您声明单例并保存图像,它将在会话之间保持活动状态。 与 Pharo 中的任何事物一样,因为它是一个实时环境
现在,这个问题让我觉得你缺乏 Pharo 的基础知识。正如我之前在这里所说的(在其他问题中),通过 stackoverflow 学习并不是学习 Pharo 的最佳方式。
看看这个网站:https://pharo.org/documentation,那里有很多学习资源。
此外,还有一个不和谐服务器,您可以在那里提出任何问题,那里会有很多人愿意帮助您(包括我在内):https://discord.gg/QewZMZa

答案 1 :(得分:0)

接下来是我从新手角度对故障原因的理解。

  1. 我写了一个单例 (uniqueInstance)
  2. 然后我添加了实现样式功能的代码的其他部分
  3. 它没有用
  4. 我的理解是,每次运行应用程序时都不会重新创建 uniqueInstance。我添加了 uniqueInstance := nil 并且我发现样式开始起作用了。也许 uniqueInstance 已保存在图像中 (?),当我添加所需的代码部分时,应用程序继续使用图像中的旧 uniqueInstance?我不确定...但将其分配给 nil 解决了问题。
  5. 因此,我决定避免这种单例方法并明确创建应用程序实例。
  6. 老实说,问题中的代码没有帮助 - 但 THIS VERSION 工作正常。