Skip to content

Instantly share code, notes, and snippets.

@EiichiroIto
Last active August 27, 2022 11:10
Show Gist options
  • Save EiichiroIto/bf299bb84e1132b4ea8507bae630c73f to your computer and use it in GitHub Desktop.
Save EiichiroIto/bf299bb84e1132b4ea8507bae630c73f to your computer and use it in GitHub Desktop.
Tips for creating applications with Pharo Smalltalk

Tips for creating applications with Pharo Smalltalk

The information here is intended for Pharo 10, and is not likely to work for previous or subsequent versions.

Display full screen

To display the Pharo Desktop by filling the OS host screen, do the following.

Display fullscreenOn.

Note that the Pharo system may crash under Ubuntu Linux 22.04.

To restore the full-screen display, do the following.

Display fullscreenOff.

Use "Display isFullscreen" to check if it is in full screen.

Prevent the window from being closed

To disable the close button on a window created with SpPresenter, do the following in the SpPresenter (actually subclass of SpPresenter) object.

self window window makeUnclosable.

This setting is the same as "Make unclosable" in the SystemWindow's window menu (see below).

In Pharo 10, this setting causes the title bar to be displayed incorrectly. Therefore, it is better to set it together with "withoutDecorations" setting.

As explained later, eliminating the window decoration will make the close button inoperable, but Ctrl-W will close the window, so this setting is important.

To restore the window to its original state, do the following.

self window window makeClosable.

Make the window undruggable

To prevent a window created with SpPresenter from being dragged, do the following.

self window window beSticky.

This setting is the same as "Make undraggable" in the SystemWindow window menu.

To restore the window to its original state, do the following.

self window window beUnsticky.

Maximize the window

To maximize the window created by SpPresenter to fit the Pharo window, do the following.

self window window fullscreen.

Note: even with this setting, if the host OS window size is changed, the application window will not follow the change. Some additional work is required to make the application respond to the change.

Disable resizing the window

To prevent a window created with SpPresenter from being resized (i.e., not resized by mouse operation), do the following.

self window beNotResizable.

This can be set even if SystemWindow has not been created. So it can also be set in the initializeWindow: method.

For example, To create a window that cannot be resized, create the initializeWindow: method in the subclass of SpPresenter.

initializeWindow: aWindow

    aWindow beNotResizable

To enable resizing, do the following.

self window beResizable.

Set window title string

To set a window title, do the following.

initializeWindow: aWindow

    aWindow
        title: 'a title string'

It may be meaningless because it will disappear if you set "Eliminate Window Decorations" described below.

Specify initial window size

For some reason, you may want to specify the window size within the SpPresenter object.

For example, if you want to make it 200px x 300px, set as follows.

initializeWindow: aWindow

    aWindow
        initialExtent: 200 @ 300

Eliminate window decorations

"Window decoration" refers to the title bar of a window (SystemWindow) in Pharo. The title bar includes the close button, maximize and minimize buttons, window title, and window menu.

To remove this, do the following.

self window withoutDecorations.

Like beResizable/beNotResizable, this setting can also be done in the initializeWindow: method.

To restore the removed title bar, do the following.

self window withDecorations.

Set hooks for when a window is closed

If you want to do something when the window is closed, describe the process in the initializeWindow: method as follows.

initializeWindow: aWindow

    aWindow
        whenClosedDo: [ "do something" ]

Set about text

To add a description of the application, do the following.

initializeWindow: aWindow

    aWindow
        aboutText: 'a description'

The text set here can be displayed by selecting About from the Window menu, or from the SpPresenter object as shown below.

self window showAbout.

Hide Pharo's menu

MenubarMorph showMenubar: false.

Hide Pharo's taskbar

TaskbarMorph showTaskbar: false.

Do not display the world menu

Do not show the World menu when clicking on Pharo's desktop.

PasteUpMorph shouldShowWorldMenu: false.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment