.. include:: headings.inc ========================================================================= **Core** Functions ========================================================================= The functions and macros defined in the **Core** module are described here: you can look up a function using the alphabetical listing of them. Function Summary ================ :ref:`B ` | :ref:`C ` | :ref:`D ` | :ref:`E ` | :ref:`F ` | :ref:`G ` | :ref:`H ` | :ref:`I ` | :ref:`K ` | :ref:`L ` | :ref:`M ` | :ref:`N ` | :ref:`O ` | :ref:`P ` | :ref:`Q ` | :ref:`R ` | :ref:`S ` | :ref:`U ` | :ref:`V ` | :ref:`W ` | :ref:`Y ` .. _Core B: B ^ * :func:`BeginBusyCursor` * :func:`Bell` * :func:`BitmapFromBuffer` * :func:`BitmapFromBufferRGBA` .. _Core C: C ^ * :func:`CallAfter` * :func:`ClientDisplayRect` * :func:`ColourDisplay` .. _Core D: D ^ * :func:`date2pydate` * :func:`DateTimeFromDMY` * :func:`DateTimeFromHMS` * :func:`DateTimeFromJDN` * :func:`DateTimeFromTimeT` * :func:`DirSelector` * :func:`DisplayDepth` * :func:`DisplaySize` * :func:`DisplaySizeMM` .. _Core E: E ^ * :func:`EmptyBitmap` * :func:`EmptyBitmapRGBA` * :func:`EmptyImage` * :func:`EnableTopLevelWindows` * :func:`EndBusyCursor` * :func:`Execute` * :func:`Exit` .. _Core F: F ^ * :func:`FFont` * :func:`FileSelector` * :func:`FileSelectorEx` * :func:`FindMenuItemId` * :func:`FindWindowAtPoint` * :func:`FindWindowAtPointer` * :func:`FindWindowByLabel` * :func:`FindWindowByName` .. _Core G: G ^ * :func:`GetActiveWindow` * :func:`GetApp` * :func:`GetBatteryState` * :func:`GetClientDisplayRect` * :func:`GetColourFromUser` * :func:`GetDisplayPPI` * :func:`GetDisplaySize` * :func:`GetDisplaySizeMM` * :func:`GetEmailAddress` * :func:`GetFullHostName` * :func:`GetHomeDir` * :func:`GetHostName` * :func:`GetKeyState` * :func:`GetLibraryVersionInfo` * :func:`GetMousePosition` * :func:`GetMouseState` * :func:`GetOsDescription` * :func:`GetOsVersion` * :func:`GetPowerType` * :func:`GetProcessId` * :func:`GetSingleChoice` * :func:`GetTopLevelParent` * :func:`GetTopLevelWindows` * :func:`GetTranslation` * :func:`GetUserHome` * :func:`GetUserId` * :func:`GetUserName` .. _Core H: H ^ * :func:`HandleFatalExceptions` .. _Core I: I ^ * :func:`ImageFromBitmap` * :func:`ImageFromBuffer` * :func:`ImageFromData` * :func:`ImageFromDataWithAlpha` * :func:`InfoMessageBox` * :func:`InitAllImageHandlers` * :func:`IsBusy` * :func:`IsDragResultOk` * :func:`IsPlatform64Bit` * :func:`IsPlatformLittleEndian` .. _Core K: K ^ * :func:`Kill` .. _Core L: L ^ * :func:`LaunchDefaultApplication` * :func:`LaunchDefaultBrowser` * :func:`LoadFileSelector` * :func:`LogDebug` * :func:`LogError` * :func:`LogFatalError` * :func:`LogGeneric` * :func:`LogMessage` * :func:`LogStatus` * :func:`LogSysError` * :func:`LogVerbose` * :func:`LogWarning` .. _Core M: M ^ * :func:`MacThemeColour` * :func:`MessageBox` * :func:`MicroSleep` * :func:`MilliSleep` .. _Core N: N ^ * :func:`NewEventType` * :func:`NewId` * :func:`Now` .. _Core O: O ^ * :func:`operator!=` * :func:`operator==` .. _Core P: P ^ * :func:`PostEvent` * :func:`pydate2wxdate` .. _Core Q: Q ^ * :func:`QueueEvent` .. _Core R: R ^ * :func:`RegisterId` .. _Core S: S ^ * :func:`SafeShowMessage` * :func:`SafeYield` * :func:`SaveFileSelector` * :func:`Shell` * :func:`Shutdown` * :func:`Sleep` * :func:`StripMenuCodes` * :func:`SysErrorCode` * :func:`SysErrorMsg` .. _Core U: U ^ * :func:`Usleep` .. _Core V: V ^ * :func:`version` .. _Core W: W ^ * :func:`WakeUpIdle` .. _Core Y: Y ^ * :func:`Yield` Functions ============= .. function:: BeginBusyCursor(cursor=HOURGLASS_CURSOR) Changes the cursor to the given cursor for all windows in the application. Use :func:`EndBusyCursor` to revert the cursor back to its previous state. These two calls can be nested, and a counter ensures that only the outer calls take effect. :param `cursor`: :type `cursor`: Cursor .. seealso:: :func:`IsBusy`, :ref:`BusyCursor` .. function:: Bell() Ring the system bell. .. note:: This function is categorized as a GUI one and so is not thread-safe. .. function:: BitmapFromBuffer(width, height, dataBuffer, alphaBuffer=None) A compatibility wrapper for Bitmap.FromBuffer and Bitmap.FromBufferAndAlpha .. function:: BitmapFromBufferRGBA(width, height, dataBuffer) A compatibility wrapper for Bitmap.FromBufferRGBA .. function:: CallAfter(callableObj, *args, **kw) Call the specified function after the current and pending event handlers have been completed. This is also good for making GUI method calls from non-GUI threads. Any extra positional or keyword args are passed on to the callable when it is called. :param PyObject callableObj: the callable object :param args: arguments to be passed to the callable object :param kw: keywords to be passed to the callable object .. seealso:: :class:`CallLater` .. function:: ClientDisplayRect() Returns the dimensions of the work area on the display. On Windows this means the area not covered by the taskbar, etc. Other platforms are currently defaulting to the whole display until a way is found to provide this info for all window managers, etc. :rtype: `tuple` :returns: ( `x`, `y`, `width`, `height` ) .. function:: ColourDisplay() Returns ``True`` if the display is colour, ``False`` otherwise. :rtype: `bool` .. function:: date2pydate(date) Convert a wx.DateTime object to a Python datetime. .. function:: DateTimeFromDMY(day, month, year=DateTime.Inv_Year, hour=0, minute=0, second=0, millisecond=0) Compatibility wrapper for DateTime.FromDMY .. function:: DateTimeFromHMS(hour, minute=0, second=0, millisecond=0) Compatibility wrapper for DateTime.FromHMS .. function:: DateTimeFromJDN(jdn) Compatibility wrapper for DateTime.FromJDN .. function:: DateTimeFromTimeT(timet) Compatibility wrapper for DateTime.FromTimeT .. function:: DirSelector(message=DirSelectorPromptStr, default_path='', style=0, pos=DefaultPosition, parent=None) Pops up a directory selector dialog. The arguments have the same meaning as those of :meth:`DirDialog.__init__` . The message is displayed at the top, and the default_path, if specified, is set as the initial selection. The application must check for an empty return value (if the user pressed Cancel). For example: :: selector = wx.DirSelector("Choose a folder") if selector.strip(): # Do something with the folder name print selector :param `message`: :type `message`: string :param `default_path`: :type `default_path`: string :param `style`: :type `style`: long :param `pos`: :type `pos`: Point :param `parent`: :type `parent`: Window :rtype: `string` .. function:: DisplayDepth() Returns the depth of the display (a value of 1 denotes a monochrome display). :rtype: `int` .. function:: DisplaySize() Returns the display size in pixels. For the version taking `width` and `header` arguments, either of them can be ``None`` if the caller is not interested in the returned value. :rtype: `tuple` :returns: ( `width`, `height` ) .. function:: DisplaySizeMM() Returns the display size in millimeters. For the version taking `width` and `header` arguments, either of them can be ``None`` if the caller is not interested in the returned value. :rtype: `tuple` :returns: ( `width`, `height` ) .. seealso:: :func:`GetDisplayPPI` .. function:: EmptyBitmap(width, height, depth=BITMAP_SCREEN_DEPTH) A compatibility wrapper for the wx.Bitmap(width, height, depth) constructor .. function:: EmptyBitmapRGBA(width, height, red=0, green=0, blue=0, alpha=0) A compatibility wrapper for Bitmap.FromRGBA .. function:: EmptyImage(width=0, height=0, clear=True) A compatibility wrapper for the wx.Image(width, height) constructor .. function:: EnableTopLevelWindows(enable=True) This function enables or disables all top level windows. It is used by :func:`SafeYield`. :param `enable`: :type `enable`: bool .. function:: EndBusyCursor() Changes the cursor back to the original cursor, for all windows in the application. Use with :func:`BeginBusyCursor`. .. seealso:: :func:`IsBusy`, :ref:`BusyCursor` .. function:: Execute(command, flags=EXEC_ASYNC, callback=None, env=None) Executes another program in Unix or Windows. In the overloaded versions of this function, if `flags` parameter contains ``EXEC_ASYNC`` flag (the default), flow of control immediately returns. If it contains ``EXEC_SYNC`` , the current application waits until the other program has terminated. In the case of synchronous execution, the return value is the exit code of the process (which terminates by the moment the function returns) and will be -1 if the process couldn't be started and typically 0 if the process terminated successfully. Also, while waiting for the process to terminate, :func:`Execute` will call :func:`Yield`. Because of this, by default this function disables all application windows to avoid unexpected reentrancies which could result from the users interaction with the program while the child process is running. If you are sure that it is safe to not disable the program windows, you may pass ``EXEC_NODISABLE`` flag to prevent this automatic disabling from happening. For asynchronous execution, however, the return value is the process id and zero value indicates that the command could not be executed. As an added complication, the return value of -1 in this case indicates that we didn't launch a new process, but connected to the running one (this can only happen when using ``DDE`` under Windows for command execution). In particular, in this case only, the calling code will not get the notification about process termination. If `callback` isn't ``None`` and if execution is asynchronous, :meth:`Process.OnTerminate` will be called when the process finishes. Specifying this parameter also allows you to redirect the standard input and/or output of the process being launched by calling :meth:`Process.Redirect` . Under Windows, when launching a console process its console is shown by default but hidden if its ``IO`` is redirected. Both of these default behaviours may be overridden: if ``EXEC_HIDE_CONSOLE`` is specified, the console will never be shown. If ``EXEC_SHOW_CONSOLE`` is used, the console will be shown even if the child process ``IO`` is redirected. Neither of these flags affect non-console Windows applications or does anything under the other systems. Under Unix the flag ``EXEC_MAKE_GROUP_LEADER`` may be used to ensure that the new process is a group leader (this will create a new session if needed). Calling :func:`Kill` passing ``KILL_CHILDREN`` will kill this process as well as all of its children (except those which have started their own session). Under MSW, this flag can be used with console processes only and corresponds to the native ``CREATE_NEW_PROCESS_GROUP`` flag. The ``EXEC_NOEVENTS`` flag prevents processing of any events from taking place while the child process is running. It should be only used for very short-lived processes as otherwise the application windows risk becoming unresponsive from the users point of view. As this flag only makes sense with ``EXEC_SYNC`` , ``EXEC_BLOCK`` equal to the sum of both of these flags is provided as a convenience. :param `command`: The command to execute and any parameters to pass to it as a single string, i.e. "emacs file.txt". :type `command`: string :param `flags`: Must include either ``EXEC_ASYNC`` or ``EXEC_SYNC`` and can also include ``EXEC_SHOW_CONSOLE``, ``EXEC_HIDE_CONSOLE``, ``EXEC_MAKE_GROUP_LEADER`` (in either case) or ``EXEC_NODISABLE`` and ``EXEC_NOEVENTS`` or ``EXEC_BLOCK``, which is equal to their combination, in ``EXEC_SYNC`` case. :type `flags`: int :param `callback`: An optional pointer to :ref:`Process`. :type `callback`: Process :param `env`: An optional pointer to additional parameters for the child process, such as its initial working directory and environment variables. This parameter is available in wxWidgets 2.9.2 and later only. :type `env`: ExecuteEnv :rtype: `long` .. note:: Currently :func:`Execute` can only be used from the main thread, calling this function from another thread will result in an assert failure in debug build and won't work. .. seealso:: :func:`Shell`, :ref:`Process`, :func:`LaunchDefaultApplication`, :func:`LaunchDefaultBrowser` .. function:: Exit() Exits application after calling :meth:`App.OnExit` . Should only be used in an emergency: normally the top-level frame should be deleted (after deleting all other frames) to terminate the application. See :ref:`CloseEvent` and :ref:`App`. .. function:: FFont(pointSize, family, flags=FONTFLAG_DEFAULT, faceName='', encoding=FONTENCODING_DEFAULT) .. function:: FileSelector(message, default_path='', default_filename='', default_extension='', wildcard=FileSelectorDefaultWildcardStr, flags=0, parent=None, x=DefaultCoord, y=DefaultCoord) Pops up a file selector box. In Windows, this is the common file selector dialog. In X, this is a file selector box with the same functionality. The path and filename are distinct elements of a full file pathname. If path is empty, the current directory will be used. If filename is empty, no default filename will be supplied. The wildcard determines what files are displayed in the file selector, and file extension supplies a type extension for the required filename. Flags may be a combination of ``FD_OPEN``, ``FD_SAVE``, ``FD_OVERWRITE_PROMPT`` or ``FD_FILE_MUST_EXIST``. Both the Unix and Windows versions implement a wildcard filter. Typing a filename containing wildcards (, ?) in the filename text item, and clicking on Ok, will result in only those files matching the pattern being displayed. The wildcard may be a specification for multiple types of file with a description for each, such as: :: wildcard = "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif" The application must check for an empty return value (the user pressed Cancel). For example: :: filename = wx.FileSelector("Choose a file to open") if filename.strip(): # work with the file print filename # else: cancelled by user :param `message`: :type `message`: string :param `default_path`: :type `default_path`: string :param `default_filename`: :type `default_filename`: string :param `default_extension`: :type `default_extension`: string :param `wildcard`: :type `wildcard`: string :param `flags`: :type `flags`: int :param `parent`: :type `parent`: Window :param `x`: :type `x`: int :param `y`: :type `y`: int :rtype: `string` .. note:: ``FD_MULTIPLE`` can only be used with :ref:`FileDialog` and not here since this function only returns a single file name. .. function:: FileSelectorEx(message=FileSelectorPromptStr, default_path='', default_filename='', indexDefaultExtension=None, wildcard=FileSelectorDefaultWildcardStr, flags=0, parent=None, x=DefaultCoord, y=DefaultCoord) An extended version of FileSelector. :param `message`: :type `message`: string :param `default_path`: :type `default_path`: string :param `default_filename`: :type `default_filename`: string :param `indexDefaultExtension`: :type `indexDefaultExtension`: int :param `wildcard`: :type `wildcard`: string :param `flags`: :type `flags`: int :param `parent`: :type `parent`: Window :param `x`: :type `x`: int :param `y`: :type `y`: int :rtype: `string` .. function:: FindMenuItemId(frame, menuString, itemString) Find a menu item identifier associated with the given frame's menu bar. :param `frame`: :type `frame`: Frame :param `menuString`: :type `menuString`: string :param `itemString`: :type `itemString`: string :rtype: `int` .. function:: FindWindowAtPoint(pt) Find the deepest window at the given mouse position in screen coordinates, returning the window if found, or ``None`` if not. This function takes child windows at the given position into account even if they are disabled. The hidden children are however skipped by it. :param `pt`: :type `pt`: Point :rtype: :ref:`Window` .. function:: FindWindowAtPointer(pt) Find the deepest window at the mouse pointer position, returning the window and current pointer position in screen coordinates. :param `pt`: :type `pt`: Point :rtype: :ref:`Window` .. function:: FindWindowByLabel(label, parent=None) Find a window by its label. Depending on the type of window, the label may be a window title or panel item label. If `parent` is ``None``, the search will start from all top-level frames and dialog boxes; if not ``None``, the search will be limited to the given window hierarchy. The search is recursive in both cases. :param `label`: :type `label`: string :param `parent`: :type `parent`: Window :rtype: :ref:`Window` .. deprecated:: 2.9.4 Replaced by :meth:`Window.FindWindowByLabel` . .. function:: FindWindowByName(name, parent=None) Find a window by its name (as given in a window constructor or `Create` function call). If `parent` is ``None``, the search will start from all top-level frames and dialog boxes; if not ``None``, the search will be limited to the given window hierarchy. The search is recursive in both cases. If no such named window is found, :func:`FindWindowByLabel` is called. :param `name`: :type `name`: string :param `parent`: :type `parent`: Window :rtype: :ref:`Window` .. deprecated:: 2.9.4 Replaced by :meth:`Window.FindWindowByName` . .. function:: GetActiveWindow() Gets the currently active window (implemented for MSW and GTK only currently, always returns ``None`` in the other ports). :rtype: :ref:`Window` .. function:: GetApp() Returns the current application object. :rtype: :ref:`PyApp` .. function:: GetBatteryState() Returns battery state as one of ``BATTERY_NORMAL_STATE`` , ``BATTERY_LOW_STATE`` , ``BATTERY_CRITICAL_STATE`` , ``BATTERY_SHUTDOWN_STATE`` or ``BATTERY_UNKNOWN_STATE`` . ``BATTERY_UNKNOWN_STATE`` is also the default on platforms where this feature is not implemented (currently everywhere but MS Windows). :rtype: :ref:`BatteryState` .. function:: GetClientDisplayRect() :rtype: :ref:`Rect` .. function:: GetColourFromUser(parent, colInit, caption='', data=None) Shows the colour selection dialog and returns the colour selected by user or invalid colour (use :meth:`Colour.IsOk` to test whether a colour is valid) if the dialog was cancelled. :param `parent`: The parent window for the colour selection dialog. :type `parent`: Window :param `colInit`: If given, this will be the colour initially selected in the dialog. :type `colInit`: Colour :param `caption`: If given, this will be used for the dialog caption. :type `caption`: string :param `data`: Optional object storing additional colour dialog settings, such as custom colours. If none is provided the same settings as the last time are used. :type `data`: ColourData :rtype: :ref:`Colour` .. function:: GetDisplayPPI() Returns the display resolution in pixels per inch. The ``x`` component of the returned :ref:`Size` object contains the horizontal resolution and the ``y`` one -- the vertical resolution. :rtype: :ref:`Size` .. versionadded:: 2.9.0 .. function:: GetDisplaySize() :rtype: :ref:`Size` .. function:: GetDisplaySizeMM() :rtype: :ref:`Size` .. function:: GetEmailAddress(*args, **kw) Copies the user's email address into the supplied buffer, by concatenating the values returned by :func:`GetFullHostName` and :func:`GetUserId`. :returns: ``True`` if successful, ``False`` otherwise. .. function:: GetFullHostName() Returns the ``FQDN`` (fully qualified domain host name) or an empty string on error. :rtype: `string` .. seealso:: :func:`GetHostName` .. function:: GetHomeDir() Return the (current) user's home directory. :rtype: `string` .. seealso:: :func:`GetUserHome`, :ref:`StandardPaths` .. function:: GetHostName(*args, **kw) Copies the current host machine's name into the supplied buffer. Please note that the returned name is `not` fully qualified, i.e. it does not include the domain name. Under Windows or NT, this function first looks in the environment variable ``SYSTEM_NAME``; if this is not found, the entry **HostName** in the wxWidgets section of the WIN.INI file is tried. :returns: The hostname if successful or an empty string otherwise. .. seealso:: :func:`GetFullHostName` .. function:: GetKeyState(key) For normal keys, returns ``True`` if the specified key is currently down. For togglable keys (Caps Lock, Num Lock and Scroll Lock), returns ``True`` if the key is toggled such that its ``LED`` indicator is lit. There is currently no way to test whether togglable keys are up or down. Even though there are virtual key codes defined for mouse buttons, they cannot be used with this function currently. :param `key`: :type `key`: KeyCode :rtype: `bool` .. function:: GetLibraryVersionInfo() Get wxWidgets version information. :rtype: :ref:`VersionInfo` .. versionadded:: 2.9.2 .. seealso:: :ref:`VersionInfo` .. function:: GetMousePosition() Returns the mouse position in screen coordinates. :rtype: :ref:`Point` .. function:: GetMouseState() Returns the current state of the mouse. Returns a :ref:`MouseState` instance that contains the current position of the mouse pointer in screen coordinates, as well as boolean values indicating the up/down status of the mouse buttons and the modifier keys. :rtype: :ref:`MouseState` .. function:: GetOsDescription() Returns the string containing the description of the current platform in a user-readable form. For example, this function may return strings like "Windows NT Version 4.0" or "Linux 2.2.2 i386". :rtype: `string` .. seealso:: :func:`GetOsVersion` .. function:: GetOsVersion() Gets the version and the operating system ``ID`` for currently running OS. The returned OperatingSystemId value can be used for a basic categorization of the OS family; the major and minor version numbers allows to detect a specific system. For Unix-like systems ( ``OS_UNIX`` ) the major and minor version integers will contain the kernel major and minor version numbers (as returned by the 'uname -r' command); e.g. "2" and "6" if the machine is using kernel 2.6.19. For Mac OS X systems ( ``OS_MAC`` ) the major and minor version integers are the natural version numbers associated with the OS; e.g. "10" and "6" if the machine is using Mac OS X Snow Leopard. For Windows-like systems ( ``OS_WINDOWS`` ) the major and minor version integers will contain the following values: ============================= ===================== ===================== **Windows OS name** **Major version** **Minor version** ============================= ===================== ===================== Windows 7 6 1 Windows Server 2008 ``R2`` 6 1 Windows Server 2008 6 0 Windows Vista 6 0 Windows Server 2003 ``R2`` 5 2 Windows Server 2003 5 2 Windows XP 5 1 Windows 2000 5 0 ============================= ===================== ===================== | See the`MSDN `_ for more info about the values above. :rtype: `tuple` :returns: ( :ref:`OperatingSystemId`, `major`, `minor` ) .. seealso:: :func:`GetOsDescription`, :ref:`PlatformInfo` .. function:: GetPowerType() Returns the type of power source as one of ``POWER_SOCKET`` , ``POWER_BATTERY`` or ``POWER_UNKNOWN`` . ``POWER_UNKNOWN`` is also the default on platforms where this feature is not implemented (currently everywhere but MS Windows). :rtype: :ref:`PowerType` .. function:: GetProcessId() Returns the number uniquely identifying the current process in the system. If an error occurs, 0 is returned. :rtype: `int` .. function:: GetSingleChoice(*args, **kw) |overload| **Overloaded Implementations**: **~~~** **GetSingleChoice** `(message, caption, aChoices, parent=None, x=DefaultCoord, y=DefaultCoord, centre=True, width=CHOICE_WIDTH, height=CHOICE_HEIGHT, initialSelection=0)` Pops up a dialog box containing a message, OK/Cancel buttons and a single-selection listbox. The user may choose an item and press ``OK`` to return a string or Cancel to return the empty string. Use :func:`GetSingleChoiceIndex` if empty string is a valid choice and if you want to be able to detect pressing Cancel reliably. You may pass the list of strings to choose from either using ``choices`` which is an array of `n` strings for the listbox or by using a single ``aChoices`` parameter of type `ArrayString`. If ``centre`` is ``True``, the message text (which may include new line characters) is centred; if ``False``, the message is left-justified. :param `message`: :type `message`: string :param `caption`: :type `caption`: string :param `aChoices`: :type `aChoices`: list of strings :param `parent`: :type `parent`: Window :param `x`: :type `x`: int :param `y`: :type `y`: int :param `centre`: :type `centre`: bool :param `width`: :type `width`: int :param `height`: :type `height`: int :param `initialSelection`: :type `initialSelection`: int :rtype: `string` **~~~** **GetSingleChoice** `(message, caption, choices, initialSelection, parent=None)` :param `message`: :type `message`: string :param `caption`: :type `caption`: string :param `choices`: :type `choices`: list of strings :param `initialSelection`: :type `initialSelection`: int :param `parent`: :type `parent`: Window :rtype: `string` **~~~** .. function:: GetTopLevelParent(window) Returns the first top level parent of the given window, or in other words, the frame or dialog containing it, or ``None``. :param `window`: :type `window`: Window :rtype: :ref:`Window` .. function:: GetTopLevelWindows() Returns a list-like object of the the application's top-level windows, (frames,dialogs, etc.) :rtype: `WindowList` .. function:: GetTranslation(*args, **kw) |overload| **Overloaded Implementations**: **~~~** **GetTranslation** `(string, domain='')` This function returns the translation of `string` in the current ``locale()`` . If the string is not found in any of the loaded message catalogs (see :ref:`Internationalization `), the original string is returned. In debug build, an error message is logged -- this should help to find the strings which were not yet translated. If `domain` is specified then only that domain/catalog is searched for a matching string. As this function is used very often, an alternative (and also common in Unix world) syntax is provided: the :func:`_` macro is defined to do the same thing as :func:`GetTranslation`. This function calls :meth:`Translations.GetString` . :param `string`: :type `string`: string :param `domain`: :type `domain`: string :rtype: `string` .. note:: This function is not suitable for literal strings in Unicode builds since the literal strings must be enclosed in :func:`T` macro which makes them unrecognised by ``xgettext`` , and so they are not extracted to the message catalog. Instead, use the :func:`_` and ``PLURAL`` macro for all literal strings. .. seealso:: :func:`GetTranslation` **~~~** **GetTranslation** `(string, plural, n, domain='')` This is an overloaded version of :func:`GetTranslation`, please see its documentation for general information. This version is used when retrieving translation of string that has different singular and plural forms in English or different plural forms in some other language. Like :func:`GetTranslation`, the `string` parameter must contain the singular form of the string to be converted and is used as the key for the search in the catalog. The `plural` parameter is the plural form (in English). The parameter `n` is used to determine the plural form. If no message catalog is found, `string` is returned if "n == 1", otherwise `plural` is returned. See ``GNU`` gettext Manual for additional information on plural forms handling: <`http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms `_> For a shorter alternative see the ``PLURAL`` macro. This function calls :meth:`Locale.GetString` . :param `string`: :type `string`: string :param `plural`: :type `plural`: string :param `n`: :param `domain`: :type `domain`: string :rtype: `string` **~~~** .. function:: GetUserHome(user='') Returns the home directory for the given user. If the `user` is empty (default value), this function behaves like :func:`GetHomeDir` (i.e. returns the current user home directory). If the home directory couldn't be determined, an empty string is returned. :param `user`: :type `user`: string :rtype: `string` .. function:: GetUserId(*args, **kw) This function returns the "user id" also known as "login name" under Unix (i.e. something like "jsmith"). It uniquely identifies the current user (on this system). Under Windows or NT, this function first looks in the environment variables ``USER`` and ``LOGNAME``; if neither of these is found, the entry **UserId** in the **wxWidgets** section of the WIN.INI file is tried. :returns: The login name if successful or an empty string otherwise. .. seealso:: :func:`GetUserName` .. function:: GetUserName(*args, **kw) This function returns the full user name (something like "Mr. John Smith"). Under Windows or NT, this function looks for the entry UserName in the wxWidgets section of the WIN.INI file. If PenWindows is running, the entry Current in the section User of the PENWIN.INI file is used. :returns: The full user name if successful or an empty string otherwise. .. seealso:: :func:`GetUserId` .. function:: HandleFatalExceptions(doIt=True) If `doIt` is ``True``, the fatal exceptions (also known as general protection faults under Windows or segmentation violations in the Unix world) will be caught and passed to :meth:`App.OnFatalException` . By default, i.e. before this function is called, they will be handled in the normal way which usually just means that the application will be terminated. Calling :func:`HandleFatalExceptions` with `doIt` equal to ``False`` will restore this default behaviour. Notice that this function is only available if ``USE_ON_FATAL_EXCEPTION`` is 1 and under Windows platform this requires a compiler with support for ``SEH`` (structured exception handling) which currently means only Microsoft Visual ``C++`` or a recent Borland ``C++`` version. :param `doIt`: :type `doIt`: bool :rtype: `bool` .. function:: ImageFromBitmap(bitmap) Create a wx.Image from a wx.Bitmap .. function:: ImageFromBuffer(width, height, dataBuffer, alphaBuffer=None) Creates a `wx.Image` from the data in dataBuffer. The dataBuffer parameter must be a Python object that implements the buffer interface, such as a string, array, etc. The dataBuffer object is expected to contain a series of RGB bytes and be width*height*3 bytes long. A buffer object can optionally be supplied for the image's alpha channel data, and it is expected to be width*height bytes long. The wx.Image will be created with its data and alpha pointers initialized to the memory address pointed to by the buffer objects, thus saving the time needed to copy the image data from the buffer object to the wx.Image. While this has advantages, it also has the shoot-yourself-in-the-foot risks associated with sharing a C pointer between two objects. To help alleviate the risk a reference to the data and alpha buffer objects are kept with the wx.Image, so that they won't get deleted until after the wx.Image is deleted. However please be aware that it is not guaranteed that an object won't move its memory buffer to a new location when it needs to resize its contents. If that happens then the wx.Image will end up referring to an invalid memory location and could cause the application to crash. Therefore care should be taken to not manipulate the objects used for the data and alpha buffers in a way that would cause them to change size. .. function:: ImageFromData(width, height, data) Compatibility wrapper for creating an image from RGB data .. function:: ImageFromDataWithAlpha(width, height, data, alpha) Compatibility wrapper for creating an image from RGB and Alpha data .. function:: InfoMessageBox(parent) Shows a message box with the information about the wxWidgets build used, including its version, most important build parameters and the version of the underlying GUI toolkit. This is mainly used for diagnostic purposes and can be invoked by Ctrl-Alt-middle clicking on any :ref:`Window` which doesn't otherwise handle this event. :param `parent`: :type `parent`: Window .. versionadded:: 2.9.0 .. seealso:: :func:`GetLibraryVersionInfo` .. function:: InitAllImageHandlers() Initializes all available image handlers. This function calls :meth:`Image.AddHandler` for all the available image handlers (see :ref:`Available image handlers ` for the full list). Calling it is the simplest way to initialize :ref:`Image` but it creates and registers even the handlers your program may not use. If you want to avoid the overhead of doing this you need to call :meth:`Image.AddHandler` manually just for the handlers that you do want to use. .. seealso:: :ref:`Image`, :ref:`ImageHandler` .. function:: IsBusy() Returns ``True`` if between two :func:`BeginBusyCursor` and :func:`EndBusyCursor` calls. :rtype: `bool` .. seealso:: :ref:`BusyCursor`. .. function:: IsDragResultOk(res) Returns ``True`` if res indicates that something was done during a DnD operation, i.e. is neither error nor none nor cancel. :param `res`: :type `res`: DragResult :rtype: `bool` .. function:: IsPlatform64Bit() Returns ``True`` if the operating system the program is running under is 64 bit. The check is performed at run-time and may differ from the value available at compile-time (at compile-time you can just check if ``sizeof(void*) == 8`` ) since the program could be running in emulation mode or in a mixed 32/64 bit system (bi-architecture operating system). :rtype: `bool` .. note:: This function is not 100% reliable on some systems given the fact that there isn't always a standard way to do a reliable check on the OS architecture. .. function:: IsPlatformLittleEndian() Returns ``True`` if the current platform is little endian (instead of big endian). The check is performed at run-time. :rtype: `bool` .. function:: Kill(pid, sig=SIGTERM, rc=None, flags=KILL_NOCHILDREN) Equivalent to the Unix kill function: send the given signal `sig` to the process with ``PID`` `pid`. The valid signal values are: :: # Signal enumeration wx.SIGNONE # verify if the process exists under Unix wx.SIGHUP wx.SIGINT wx.SIGQUIT wx.SIGILL wx.SIGTRAP wx.SIGABRT wx.SIGEMT wx.SIGFPE wx.SIGKILL # forcefully kill, dangerous! wx.SIGBUS wx.SIGSEGV wx.SIGSYS wx.SIGPIPE wx.SIGALRM wx.SIGTERM # terminate the process gently ``SIGNONE`` , ``SIGKILL`` and ``SIGTERM`` have the same meaning under both Unix and Windows but all the other signals are equivalent to ``SIGTERM`` under Windows. Returns 0 on success, -1 on failure. If the `rc` parameter is not ``None``, it will be filled with a value from the ``KillError`` enum: :: # KillError enumeration wx.KILL_OK # no error wx.KILL_BAD_SIGNAL # no such signal wx.KILL_ACCESS_DENIED # permission denied wx.KILL_NO_PROCESS # no such process wx.KILL_ERROR # another, unspecified error The `flags` parameter can be ``KILL_NOCHILDREN`` (the default), or ``KILL_CHILDREN``, in which case the child processes of this process will be killed too. Note that under Unix, for ``KILL_CHILDREN`` to work you should have created the process by passing ``EXEC_MAKE_GROUP_LEADER`` to :func:`Execute`. :param `pid`: :type `pid`: long :param `sig`: :type `sig`: Signal :param `rc`: :type `rc`: KillError :param `flags`: :type `flags`: int :rtype: `int` .. seealso:: :meth:`Process.Kill` , :meth:`Process.Exists` , .. function:: LaunchDefaultApplication(document, flags=0) Opens the `document` in the application associated with the files of this type. The `flags` parameter is currently not used Returns ``True`` if the application was successfully launched. :param `document`: :type `document`: string :param `flags`: :type `flags`: int :rtype: `bool` .. seealso:: :func:`LaunchDefaultBrowser`, :func:`Execute` .. function:: LaunchDefaultBrowser(url, flags=0) Opens the `url` in user's default browser. If the `flags` parameter contains ``BROWSER_NEW_WINDOW`` flag, a new window is opened for the ``URL`` (currently this is only supported under Windows). And unless the `flags` parameter contains ``BROWSER_NOBUSYCURSOR`` flag, a busy cursor is shown while the browser is being launched (using :ref:`BusyCursor`). The parameter `url` is interpreted as follows: - if it has a valid scheme (e.g. ``"file:"`` , ``"http:"`` or ``"mailto:"`` ) it is passed to the appropriate browser configured in the user system. - if it has no valid scheme (e.g. it's a local file path without the ``"file:"`` prefix), then :func:`FileExists` and :func:`DirExists` are used to test if it's a local file/directory; if it is, then the browser is called with the `url` parameter eventually prefixed by ``"file:"`` . - if it has no valid scheme and it's not a local file/directory, then ``"http:"`` is prepended and the browser is called. Returns ``True`` if the application was successfully launched. :param `url`: :type `url`: string :param `flags`: :type `flags`: int :rtype: `bool` .. note:: For some configurations of the running user, the application which is launched to open the given ``URL`` may be URL-dependent (e.g. a browser may be used for local URLs while another one may be used for remote URLs). .. seealso:: :func:`LaunchDefaultApplication`, :func:`Execute` .. function:: LoadFileSelector(what, extension, default_name='', parent=None) Ask for filename to load. :param `what`: :type `what`: string :param `extension`: :type `extension`: string :param `default_name`: :type `default_name`: string :param `parent`: :type `parent`: Window :rtype: `string` .. function:: LogDebug(message) The right functions for debug output. They only do something in debug mode (when the preprocessor symbol ``__WXDEBUG__`` is defined) and expand to nothing in release mode (otherwise). :param `message`: :type `message`: string .. function:: LogError(message) The functions to use for error messages, i.e. the messages that must be shown to the user. The default processing is to pop up a message box to inform the user about it. :param `message`: :type `message`: string .. function:: LogFatalError(message) Like :func:`LogError`, but also terminates the program with the exit code 3. Using `abort()` standard function also terminates the program with this exit code. :param `message`: :type `message`: string .. function:: LogGeneric(level, message) Logs a message with the given LogLevel. E.g. using ``LOG_Message`` as first argument, this function behaves like :func:`LogMessage`. :param `level`: :type `level`: LogLevel :param `message`: :type `message`: string .. function:: LogMessage(message) For all normal, informational messages. They also appear in a message box by default (but it can be changed). :param `message`: :type `message`: string .. function:: LogStatus(*args, **kw) |overload| **Overloaded Implementations**: **~~~** **LogStatus** `(frame, message)` Messages logged by this function will appear in the statusbar of the `frame` or of the top level application window by default (i.e. when using the second version of the functions). If the target frame doesn't have a statusbar, the message will be lost. :param `frame`: :type `frame`: Frame :param `message`: :type `message`: string **~~~** **LogStatus** `(message)` :param `message`: :type `message`: string **~~~** .. function:: LogSysError(message) Mostly used by wxWidgets itself, but might be handy for logging errors after system call (API function) failure. It logs the specified message text as well as the last system error code (`errno` or `GetLastError()` depending on the platform) and the corresponding error message. The second form of this function takes the error code explicitly as the first argument. :param `message`: :type `message`: string .. seealso:: :func:`SysErrorCode`, :func:`SysErrorMsg` .. function:: LogVerbose(message) For verbose output. Normally, it is suppressed, but might be activated if the user wishes to know more details about the program progress (another, but possibly confusing name for the same function could be ``LogInfo`` ). :param `message`: :type `message`: string .. function:: LogWarning(message) For warnings - they are also normally shown to the user, but don't interrupt the program work. :param `message`: :type `message`: string .. function:: MacThemeColour(themeBrushID) :rtype: :ref:`Colour` .. function:: MessageBox(message, caption=MessageBoxCaptionStr, style=OK|CENTRE, parent=None, x=DefaultCoord, y=DefaultCoord) Show a general purpose message dialog. This is a convenient function which is usually used instead of using :ref:`MessageDialog` directly. Notice however that some of the features, such as extended text and custom labels for the message box buttons, are not provided by this function but only by :ref:`MessageDialog`. The return value is one of: ``YES`` , ``NO`` , ``CANCEL`` , ``OK`` or ``HELP`` (notice that this return value is **different** from the return value of :meth:`MessageDialog.ShowModal` ). For example: :: answer = wx.MessageBox("Quit program?", "Confirm", wx.YES_NO | wx.CANCEL, main_frame) if answer == wx.YES: main_frame.Close() `message` may contain newline characters, in which case the message will be split into separate lines, to cater for large messages. :param `message`: Message to show in the dialog. :type `message`: string :param `caption`: The dialog title. :type `caption`: string :param `style`: Combination of style flags described in :ref:`MessageDialog` documentation. :type `style`: int :param `parent`: Parent window. :type `parent`: Window :param `x`: Horizontal dialog position (ignored under MSW). Use ``DefaultCoord`` for `x` and `y` to let the system position the window. :type `x`: int :param `y`: Vertical dialog position (ignored under MSW). :type `y`: int :rtype: `int` .. function:: MicroSleep(microseconds) Sleeps for the specified number of microseconds. The microsecond resolution may not, in fact, be available on all platforms (currently only Unix platforms with nanosleep(2) may provide it) in which case this is the same as calling :func:`MilliSleep` with the argument of `microseconds/1000`. :param `microseconds`: :type `microseconds`: long .. function:: MilliSleep(milliseconds) Sleeps for the specified number of milliseconds. Notice that usage of this function is encouraged instead of calling usleep(3) directly because the standard `usleep()` function is not ``MT`` safe. :param `milliseconds`: :type `milliseconds`: long .. function:: NewEventType() Generates a new unique event type. Usually this function is only used by ``DEFINE_EVENT`` and not called directly. :rtype: `EventType` .. function:: NewId() Generates an integer identifier unique to this run of the program. :rtype: `long` .. deprecated:: 2.9.4 Ids generated by it can conflict with the Ids defined by the user code, use ``ID_ANY`` to assign ids which are guaranteed to not conflict with the user-defined ids for the controls and menu items you create instead of using this function. .. function:: Now() Returns a string representing the current date and time. :rtype: `string` .. function:: operator!= :param `left`: :type `left`: TreeItemId :param `right`: :type `right`: TreeItemId .. function:: operator== :param `left`: :type `left`: TreeItemId :param `right`: :type `right`: TreeItemId .. function:: PostEvent(dest, event) In a GUI application, this function posts `event` to the specified `dest` object using :meth:`EvtHandler.AddPendingEvent` . Otherwise, it dispatches `event` immediately using :meth:`EvtHandler.ProcessEvent` . See the respective documentation for details (and caveats). Because of limitation of :meth:`EvtHandler.AddPendingEvent` this function is not thread-safe for event objects having `String` fields, use :func:`QueueEvent` instead. :param `dest`: :type `dest`: EvtHandler :param `event`: :type `event`: Event .. function:: pydate2wxdate(date) Convert a Python date or datetime to a wx.DateTime object .. function:: QueueEvent(dest, event) Queue an event for processing on the given object. This is a wrapper around :meth:`EvtHandler.QueueEvent` , see its documentation for more details. :param `dest`: The object to queue the event on, can't be ``NULL`` . :type `dest`: EvtHandler :param `event`: The heap-allocated and non- ``NULL`` event to queue, the function takes ownership of it. :type `event`: Event .. function:: RegisterId(id) Ensures that Ids subsequently generated by :func:`NewId` do not clash with the given `id`. :param `id`: :type `id`: long .. function:: SafeShowMessage(title, text) This function shows a message to the user in a safe way and should be safe to call even before the application has been initialized or if it is currently in some other strange state (for example, about to crash). Under Windows this function shows a message box using a native dialog instead of :func:`MessageBox` (which might be unsafe to call), elsewhere it simply prints the message to the standard output using the title as prefix. :param `title`: The title of the message box shown to the user or the prefix of the message string. :type `title`: string :param `text`: The text to show to the user. :type `text`: string .. seealso:: :func:`LogFatalError` .. function:: SafeYield(win=None, onlyIfNeeded=False) Calls :meth:`App.SafeYield` . :param `win`: :type `win`: Window :param `onlyIfNeeded`: :type `onlyIfNeeded`: bool :rtype: `bool` .. function:: SaveFileSelector(what, extension, default_name='', parent=None) Ask for filename to save. :param `what`: :type `what`: string :param `extension`: :type `extension`: string :param `default_name`: :type `default_name`: string :param `parent`: :type `parent`: Window :rtype: `string` .. function:: Shell(command='') Executes a command in an interactive shell window. If no command is specified, then just the shell is spawned. :param `command`: :type `command`: string :rtype: `bool` .. seealso:: :func:`Execute`, .. function:: Shutdown(flags=SHUTDOWN_POWEROFF) This function shuts down or reboots the computer depending on the value of the `flags`. :param `flags`: One of ``SHUTDOWN_POWEROFF`` , ``SHUTDOWN_REBOOT`` or ``SHUTDOWN_LOGOFF`` (currently implemented only for MSW) possibly combined with ``SHUTDOWN_FORCE`` which forces shutdown under MSW by forcefully terminating all the applications. As doing this can result in a data loss, this flag shouldn't be used unless really necessary. :type `flags`: int :rtype: `bool` :returns: ``True`` on success, ``False`` if an error occurred. .. note:: Note that performing the shutdown requires the corresponding access rights (superuser under Unix, ``SE_SHUTDOWN`` privilege under Windows NT) and that this function is only implemented under Unix and MSW. .. function:: Sleep(secs) Sleeps for the specified number of seconds. :param `secs`: :type `secs`: int .. function:: StripMenuCodes(str, flags=Strip_All) Strips any menu codes from `str` and returns the result. By default, the functions strips both the mnemonics character ( ``'&'`` ) which is used to indicate a keyboard shortkey, and the accelerators, which are used only in the menu items and are separated from the main text by the ``\t`` (``TAB``) character. By using `flags` of ``Strip_Mnemonics`` or ``Strip_Accel`` to strip only the former or the latter part, respectively. Notice that in most cases :meth:`MenuItem.GetLabelFromText` or :meth:`Control.GetLabelText` can be used instead. :param `str`: :type `str`: string :param `flags`: :type `flags`: int :rtype: `string` .. function:: SysErrorCode() Returns the error code from the last system call. This function uses ``errno`` on Unix platforms and ``GetLastError`` under Win32. :rtype: `int` .. seealso:: :func:`SysErrorMsg`, :func:`LogSysError` .. function:: SysErrorMsg(errCode=0) Returns the error message corresponding to the given system error code. If `errCode` is 0 (default), the last error code (as returned by :func:`SysErrorCode`) is used. :param `errCode`: :type `errCode`: long :rtype: `string` .. seealso:: :func:`SysErrorCode`, :func:`LogSysError` .. function:: Usleep(milliseconds) Sleeps for the specified number of milliseconds. :param `milliseconds`: :type `milliseconds`: long .. deprecated:: 2.9.4 This function is deprecated because its name is misleading: notice that the argument is in milliseconds, not microseconds. Please use either :func:`MilliSleep` or :func:`MicroSleep` depending on the resolution you need. .. function:: version() Returns a string containing version and port info .. function:: WakeUpIdle() This function wakes up the (internal and platform dependent) idle system, i.e. it will force the system to send an idle event even if the system currently `is` idle and thus would not send any idle event until after some other event would get sent. This is also useful for sending events between two threads and is used by the corresponding functions :func:`PostEvent` and :meth:`EvtHandler.AddPendingEvent` . .. function:: Yield() Calls :meth:`AppConsole.Yield` . :rtype: `bool` .. deprecated:: 2.9.4 This function is kept only for backwards compatibility. Please use the :meth:`AppConsole.Yield` method instead in any new code.