Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

smalltalk - Why this styling of Spec 2 app does not work?

I am trying to add style to SpTextPresenter (Pharo 9, Spec 2, Windows 10). I have MyApp class:

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

with class method uniqueInstance (and class instance - "singleton" idea was copy-pasted from LibC):

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

and an instance method initialize:

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

and MyAppConfiguration class:

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

with the method configure:

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

Somewhere in the code I do:

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

I have several presenters, but one of them really contains text variable which is created in a initializePresenters method:

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

But the result is bad - the text has standard view, with a standard font, nothing changed! Where is the bug? I want to see in the text (of SpTextPresenter type) my custom font.

EDIT: btw, this does not work too.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, if you declare a singleton and you save the image, it will stay alive between sessions. As anything in Pharo, because is a live environment.
Now, that question makes me think you are lacking the basics of Pharo. And as I said here before (in other question), learning by stackoverflow is not the best way to learn Pharo.
Take a look at this site: https://pharo.org/documentation, there are a lot of resources for learning there.
Also, there a discord server where you can ask anything and there will be a lot of people willing to help you (me included) there: https://discord.gg/QewZMZa


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...