The console window allows you to interact with the built-in Python interpreter. You can issue commands, execute Python scripts, import modules, examine block data, etc.
The console window is not a regular MDI child window like for example the screen or log windows. It can have one of three states: Floating, Pinned, Closed. Check in the chapter on Desktop Management for more information. The console window can be easily displayed and hidded with the View menu, the Console window tool bar button or the F9 hotkey. The console window is associated with a file and all output written to the console window is also logged to this file when the console window is closed or the application is shut down.
The Python icon on the tool bar allows you to open/close the console window:
The file name of the Console window can be specified in the gseos.ini configuration file. The entry FileName in the [Console] section specifies the file the console window contents will be written to. If you do not supply this file name it defaults to ProjectName[Instance].con, where the ProjectName is the name of you project as configured in the [Project] section. When the system restarts the console file from the previous session will be restored and any new text will be appended to the file. The maximum size of this file can be configured in the [Console] section as well. The console file will not grow beyond this size and the oldest content will be discarded. The default value is 512KB.
The picture below shows a typical console window:
The >>> is the Python command prompt and indicates that the system is ready for input. The caption bar indicates the current console file associated with the console window.
In case the console window is not opened or iconized and new data is written to the console window this activity is flagged to the user by flashing the caption bar of the console window if it is iconized and by highlighting the toolbar button of the Console window:
Command History:
The console window provides two different mechanisms to retrieve previously entered commands. If you position the cursor on any but the current input line and press Enter that line will be copied to the current input line. There you can modify the command as necessary and issue it.
If you have a lot of output in the console window the commands you entered previously may be scrolled out of sight or burried somewhere in the output. In this case you can use the ESC history. If you type the first letters of any command and press the ESC key a menu with all matching previously typed commands pops up. Here you can select the command you are interested in. Upcon selection the command is copied into the current input line and you can modify and issue the command from there.
The above example show the history menu on typing: 'im' + ESC.
Programmatic Access:
You can programmatically monitor the console output. The system generates the ConsoleOut block (if it is defined in the system.blk block definition file) every time output is written to the console window. Here the block definition:
ConsoleOut INTEL
{
Len ,,, 32;
Truncated ,,, 8;
WindowState ,,, 8;
Text [1024] 0,,, 8;
}
You can set the length of the Text item to any size appropriate, the default is 1024. If the text that is inserted into the Console window exceeds this length the content in the Text item is truncated and the field Truncated is set to 1. The Len field indicates the number of valid characters in the Text field. To detect if the console window toolbar button has been flagged you can check the WindowState field. The WindowState field is set to 0 if the window is visible, to 1 if it is closed and to 2 if it is open but iconized. So if the WindowState field is not equal to 0 the console window toolbar button is flagged. This block can be used to write a simple Monitor to notify the user of new activity in the console window. The sample below implements a monitor that plays a sound to notify the user of new console activity when the window is not visible or iconized:
import Gseos
import GseosCmd
import GseosMonitor
from __main__ import ConsoleOut
# ------------------------------------------------------------------------- #
# - Monitor the ConsoleOut block. If we see one, play a sound if the - #
# - window is not visible or iconized. - #
# ------------------------------------------------------------------------- #
def MonConsoleOut(oBlock):
if oBlock.WindowState <> 0:
GseosCmd.PlaySound('boing.wav')
ConsoleOut.Monitors.append(GseosMonitor.TMonitor('Console Activity', MonConsoleOut))
For more information about programmatic access to the console window check the Gseos.ConsoleWrite() function.