[Molby Document Home] [Contents]

Module: | Kernel

### Description

The methods described here are the extension of the standard "Kernel" module. They can be accessed from the top level, e.g. directly from the Molby console.

### Constant

MolbyResourcePath (deprecated)

This constant is now available as Molby::ResourcePath.

### Public Instance methods

ask(prompt, default = nil) → string

Open a modal dialog and get a line of text.

backquote(string) → string

Same as the built-in backquote operator, except that it does not show the console window on Windows platform.

bell

Ring the bell.

See Also: play_sound, stop_sound

call_subprocess(cmdline, cmdname, callback = nil) → Integer

Call a subprocess by the given command line. A progress window is shown, and the argument `cmdname` is used to show an appropriate message. If `callback` is given (as a Proc object), it will be called periodically during execution; if `callback` returns `nil` or `false`, execution of the subprocess is interrupted.

The standard output/error stream is directed to the Ruby Console. If stdout_file or stderr_file is given as a filename, the stdout/stderr output will be directed to that file. (If the filename begins with ">>", then the output will be appended to the end of the file; otherwise, the existing file will be replaced.) If it is "/dev/null" or "NUL", then the output will be lost.

Returns an integer value with the same meaning as `Kernel.system`.

See Also: Molecule#call_subprocess_async

check_interrupt → Integer

Returns 1 if interrupted, 0 if not, -1 if interrupt is disabled.

document_home → String

Get the directory suitable for storing user documents. On Windows it is the home directory + "My Documents". On other platforms it is the home directory.

error_message_box(str)

Show an error message box.

execute_script(fname)

Execute the script in the given file. If a molecule is active, then the script is evaluated as Molecule.current.instance_eval(script). Before entering the script, the current directory is set to the parent directory of the script.

exit(arg = nil)

Stop the execution of the script and return to the Molby application. Only usable when the script is invoked from the file or from the Console. Internally, this method is equivalent to `throw :molby_top, arg`. When a script is executed from file and from console, it is internally wrapped by `catch(:molby_top) { ... }`.

Standard implementation of `exit` (stop execution and quit) is not available, because it does not make much sense to stop execution of Molby application from inside the script.

export_to_clipboard(string)

Copy a string to the clipboard (so that it can be pasted in other applications).

get_global_settings(key) → value

Get a setting data for key from the application preferences.

get_interrupt_flag → boolean

Get the current interrupt flag. If interrupt is enabled, true is returned. Otherwise, false is returned.

hide_console_window

Hide the console window.

See Also: show_console_window

hide_progress_panel

Hide the progress panel. If the panel is not yet shown or already dismissed, do nothing.

See Also: show_progress_panel

lookup_menu(title) → Integer

Look up the title from the Script menu. If found, returns a non-negative integer. If not found, returns -1.

message_box(str, title, button = nil, icon = :info)

Show a message box. Button is nil ("OK" and "Cancel"), :ok ("OK" only) or :cancel ("Cancel" only). Icon is one of the following symbols; :info, :warning, :error.

play_sound(filename, flag = 0)

Play the sound (a WAV file) in the file. Flag: 0, pause until sound ends; 1, play the sound asynchronously; 3, play the sound with loop asynchronously. If flag = 1 or 3, the sound can be stopped by stop_sound, which is mandatory for flag = 3 (otherwise the sound will continue forever!).

See Also: bell, stop_sound

register_menu(title, method)

Register the method (specified as a symbol) in the script menu. The method must be either an instance method of Molecule with no argument, or a class method of Molecule with one argument (the current molecule). The menu associated with the class method can be invoked even when no document is open (the argument is set to nil in this case). On the other hand, the menu associated with the instance method can only be invoked when at least one document is active.

set_global_settings(key, value)

Set a setting data for key to the application preferences.

set_interrupt_flag(value) → old_value

Set the current interrupt flag (true to enable interrupt, false to disable interrupt). Returns the old interrupt flag.

set_progress_message(message)

Set the message for the progress panel. If the progress panel is not shown, do nothing.

set_progress_value(value)

Set the progress value. The value should be a Float. If 0 <= value <= 1, then the progress bar becomes determinant and shows the value as the length of the colored part (value 1 corresponds to 100% progress). If the value is negative, then the progress bar becomes indeterminant.

show_console_window

Show the console window.

See Also: hide_console_window

show_progress_panel

Show the progress panel. The panel can be dismissed by pressing the escape key, in which case Interrupt exception is thrown.

See Also: hide_progress_panel

stop_sound

Stop the sound if playing.

See Also: bell, play_sound