How to create a standalone app with Glamorous Toolkit

Creating a standalone app based on Glamorous Toolkit is as simple as opening an application specific window and closing the existing GT window. This can be achieved in just a few steps.

Open a space with a scene

BlSpace Object subclass: #BlSpace uses: TBlEventTarget + TBlSpaceProperties + TBlDebug instanceVariableNames: 'id host hostSpace extent position root resizable borderless dirtyAreas eventDispatcher eventListener eventRecorder mouseProcessor focusProcessor keyboardProcessor focusChain dragboard nextPulseRequested currentCursor session focused title fullscreen fullsize layoutError tasks time touchProcessor frame gestureProcessor elementsNeedingPaint elementsNeedingLayout telemetry reference elementsNeedingStyle elementsNeedingPropertiesComputation iconStencil' classVariableNames: 'UniqueIdGenerator' package: 'Bloc-Space' is responsible for displaying a scene in a separate window. Users can customise window's title or extent. To spawn a window send BlSpace>>#show show "Open me in a window and show it to the user" "delegate showing work to the Universe" (BlParallelUniverse forHost: self host class) openSpace: self to an instance of the space.

        
| aContainer aSpace | 
aContainer := BrVerticalPane new
		matchParent;
		alignCenter.
aContainer addChild: (BrLabel new
		look: (BrGlamorousLabelLook new fontSize: 100; bold);
		text: 'Hello world!').
		
aSpace := BlSpace new
		addChild: aContainer;
		extent: 800@600;
		title: 'Hello World'.

aSpace show.
]
        
      

A basic window

Clean up existing windows

Glamorous Toolkit comes with a GtWorld BlSpace subclass: #GtWorld instanceVariableNames: 'worldElement' classVariableNames: '' package: 'GToolkit-World-UI' opened by default. When creating a standalone app based on GT we should close that window, which can be done in two steps.

Disable shutdown-on-close listener

To shutdown the process when a window is closed, we add a BlSpaceShutdownOnCloseListener BlBasicEventHandler subclass: #BlSpaceShutdownOnCloseListener instanceVariableNames: 'shouldSave' classVariableNames: '' package: 'Bloc-Space - Events' as an event handler to a BlSpace Object subclass: #BlSpace uses: TBlEventTarget + TBlSpaceProperties + TBlDebug instanceVariableNames: 'id host hostSpace extent position root resizable borderless dirtyAreas eventDispatcher eventListener eventRecorder mouseProcessor focusProcessor keyboardProcessor focusChain dragboard nextPulseRequested currentCursor session focused title fullscreen fullsize layoutError tasks time touchProcessor frame gestureProcessor elementsNeedingPaint elementsNeedingLayout telemetry reference elementsNeedingStyle elementsNeedingPropertiesComputation iconStencil' classVariableNames: 'UniqueIdGenerator' package: 'Bloc-Space' . It should be removed before we close such spaces.

        
GtWorld allInstances do: [ :eachWorld | eachWorld removeShutdownListener ]
]
        
      

Closing an existing GtWorld

To close an opened window, it is enough to just send BlSpace>>#close close "Delegate closing work to the Universe" (BlParallelUniverse forHost: self host class) closeSpace: self to the associated space.

        
GtWorld allInstances do: [ :eachWorld | eachWorld close ]
]
        
      

Save the image

Once the intended application window is opened and there are no more GT windows we can save the image (without quitting):

        
Smalltalk snapshot: true andQuit: false
]