Citação

Spec

spec-logo

Spec is a UI library for Pharo Smalltalk. Well, to be more precise, Spec is a library for describing UI elements, their properties and their behaviour. Under the hood the output of Spec is fed into a UI framework like Polymorph to draw the widgets on the screen.

In this series of tutorial episodes, you will understand its concepts and learn how to use it for your everyday UI programming requirements.

http://www.bahmanm.com/blogs/spec-part-1-basics


File out:


'From Pharo3.0 of 18 March 2013 [Latest update: #30848] on 18 May 2014 at 1:35:57.34744 pm'!
ComposableModel subclass: #MyFirstWindow
	instanceVariableNames: 'labelGreeting textName buttonGreet radioMr radioMrs radioMs labelName labelTitle'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'My-Spec-Tutorial'!
!MyFirstWindow commentStamp: 'chicoary 5/17/2014 22:50' prior: 0!
A MyFirstWindow is from a tutorial in http://www.bahmanm.com/blogs/spec-part-1-basics
!


!MyFirstWindow methodsFor: 'as yet unclassified' stamp: 'chicoary 5/18/2014 11:50'!
userTitle
        "Find out user's title by checking the radio buttons."
        
        radioMr state
                ifTrue: [ ^ radioMr label ]
                ifFalse: [ 
                        radioMrs state
                                ifTrue: [ ^ radioMrs label ] 
                                ifFalse: [ ^ radioMs label ] ].! !

!MyFirstWindow methodsFor: 'as yet unclassified' stamp: 'chicoary 5/18/2014 11:47'!
initializePresenter
        textName whenTextChanged: [ 
                buttonGreet enable ].
        buttonGreet action: [ 
                labelGreeting text: 'Hello, ', self userTitle, ' ', textName text, '!!'.
                buttonGreet disable ].! !

!MyFirstWindow methodsFor: 'as yet unclassified' stamp: 'chicoary 5/18/2014 13:33'!
initializeWidgets
	self title: 'Spec Hello World'.
	self
		instantiateModels:
			#(
				labelGreeting LabelModel
				textName TextInputFieldModel 
				buttonGreet ButtonModel 
				radioMr RadioButtonModel 
				radioMs RadioButtonModel 
				radioMrs RadioButtonModel
				labelName LabelModel 
				labelTitle LabelModel 
			).
	labelGreeting text: ''.
	textName autoAccept: true.
	buttonGreet
		label: 'Greet Me!!';
		disable.
	self setupTitleRadioButtons.
	labelName text: 'Your name, please?'.
	labelTitle text: 'Your title, please?'! !

!MyFirstWindow methodsFor: 'as yet unclassified' stamp: 'chicoary 5/18/2014 10:47'!
setupTitleRadioButtons
        radioMr label: 'Mr.'.
        radioMs label: 'Ms.'.
        radioMrs label: 'Mrs.'.
        
        RadioButtonGroup new
                addRadioButton: radioMr;
                addRadioButton: radioMs;
                addRadioButton: radioMrs;
                default: radioMr.! !


!MyFirstWindow methodsFor: 'accessing' stamp: 'chicoary 5/17/2014 22:58'!
buttonGreet
	^ buttonGreet! !

!MyFirstWindow methodsFor: 'accessing' stamp: 'chicoary 5/18/2014 10:36'!
radioMr
	^ radioMr! !

!MyFirstWindow methodsFor: 'accessing' stamp: 'chicoary 5/18/2014 10:36'!
radioMrs
	^ radioMrs! !

!MyFirstWindow methodsFor: 'accessing' stamp: 'chicoary 5/18/2014 10:36'!
radioMs
	^ radioMs! !

!MyFirstWindow methodsFor: 'accessing' stamp: 'chicoary 5/18/2014 13:11'!
labelTitle
	^ labelTitle! !

!MyFirstWindow methodsFor: 'accessing' stamp: 'chicoary 5/17/2014 19:38'!
labelGreeting
	^ labelGreeting! !

!MyFirstWindow methodsFor: 'accessing' stamp: 'chicoary 5/17/2014 22:58'!
textName
	^ textName! !


!MyFirstWindow methodsFor: 'accessing oop fields' stamp: 'chicoary 5/18/2014 13:10'!
labelName
	^ labelName! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

MyFirstWindow class
	instanceVariableNames: ''!
!MyFirstWindow class commentStamp: '' prior: 0!
!


!MyFirstWindow class methodsFor: 'as yet unclassified' stamp: 'chicoary 5/18/2014 13:15'!
defaultSpec
    ^ SpecLayout composed
        "Adding Main column"
        newColumn: [ :mainColumn |
             
            mainColumn
                "Adding Name row"
                newRow: [ :rowName | 
                    rowName
                        add: #labelName;
                        add: #textName ].
                            
            mainColumn
                "Adding Title row"
                newRow: [ :rowTitle | 
                    rowTitle
                        add: #labelTitle;
                        "Adding Title Radio row"
                        newRow: [ :rowTitleRadio | 
                            rowTitleRadio
                                add: #radioMr;
                                add: #radioMrs;
                                add: #radioMs ] ].
                                        
            mainColumn
                "Adding Button row" 
                newRow: [ :rowButton | 
                    rowButton 
                        add: #buttonGreet ].    
                            
            mainColumn 
                "Adding Greeting row"
                newRow: [ :rowGreeting |
                    rowGreeting 
                        add: #labelGreeting ] ];
        yourself   ! !

Anúncios

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s