我正在尝试添加样式到SpTextPresenter (法老9,Spec 2,Windows10)。我有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但是结果是不好的-- text有标准的视图,有一个标准的字体,没有什么改变!窃听器在哪里?我想在text ( SpTextPresenter类型)中看到我的自定义字体。
编辑:顺便说一下,this也不起作用。
发布于 2021-01-07 20:32:48
是的,如果您声明了一个单例,并且保存了映像,它将在会话之间保持活动。就像法老里的任何东西一样,因为这是一个生活环境。
现在,这个问题让我觉得你缺乏法老的基本知识。正如我之前在这里所说的(在其他问题中),用堆栈溢出学习不是学习法老的最好方法。
看看这个网站:https://pharo.org/documentation,那里有很多学习的资源。
此外,有一个不和谐的服务器,您可以要求任何东西,而且会有很多人愿意帮助您(包括我)那里:https://discord.gg/QewZMZa
发布于 2021-01-07 17:04:37
其次,我从新手的角度来理解错误的原因。
我编写了一个单例(uniqueInstance)
uniqueInstance。我添加了uniqueInstance := nil,我发现造型开始起作用了。也许uniqueInstance被保存在图像(?)当我添加所需的代码部分时,应用程序继续使用图像中的旧uniqueInstance吗?我不确定..。但是将它分配给nil解决了问题。因此,我决定避免这种单例方法,并创建应用程序实例explicitly.https://stackoverflow.com/questions/65611485
复制相似问题