View source with raw comments or as raw
    1/*  Part of XPCE --- The SWI-Prolog GUI toolkit
    2
    3    Author:        Jan Wielemaker and Anjo Anjewierden
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org/packages/xpce/
    6    Copyright (c)  1985-2015, University of Amsterdam
    7                              VU University Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   37Module PCE.  This module defines the core   of  XPCE.  It is designed in
   38such a way that it  may  be   compiled  using  the SWI-Prolog qcompile/1
   39compiler, which makes XPCE an autoloadable module of SWI-Prolog.
   40
   41Various things are Prolog-implementation specific in this module and
   42therefore each Prolog system will require a different version of this
   43module.
   44
   45This module only defines some  paths,  some   things  to  make  the .qlf
   46compiler work on it and  finally  it   just  loads  the XPCE modules and
   47reexports the content of these files.
   48- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
   49
   50:- module(pce,
   51          [ new/2, free/1,              % pce_principal predicates
   52
   53            send/2, send/3, send/4, send/5, send/6, send/7,
   54            send/8,
   55
   56            get/3, get/4, get/5, get/6, get/7, get/8,
   57
   58            send_class/3,
   59            get_class/4,
   60            object/1, object/2,
   61
   62            pce_global/2,               % pce_global
   63            pce_autoload/2,             % pce_autoload
   64            pce_autoload_all/0,
   65
   66            pce_term_expansion/2,
   67            pce_compiling/1,            % -Class
   68            pce_compiling/2,            % -Class, -Path
   69            pce_begin_recording/1,
   70            pce_end_recording/0,
   71
   72            pce_register_class/1,
   73            pce_extended_class/1,
   74            pce_begin_class_definition/4,
   75            pce_prolog_class/1,
   76            pce_prolog_class/2,
   77
   78            pce_catch_error/2,          % pce_error
   79            pce_open/3,
   80            in_pce_thread/1,            % :Goal
   81            in_pce_thread_sync/1,       % :Goal
   82            set_pce_thread/0,
   83            pce_thread/1,               % -Thread
   84            pce_dispatch/0,
   85
   86            op(200, fy,  @),
   87            op(250, yfx, ?),
   88            op(800, xfx, :=)
   89          ]).   90
   91:- set_prolog_flag(generate_debug_info, false).   92
   93:- meta_predicate
   94    in_pce_thread_sync(0).   95
   96                /********************************
   97                *      LOAD COMMON PLATFORM     *
   98                ********************************/
   99
  100:- multifile user:file_search_path/2.  101
  102user:file_search_path(pce_boot, pce(prolog/boot)).
  103
  104:- load_files([ pce_boot(pce_expand),
  105                pce_boot(pce_pl),
  106                pce_boot(pce_principal),
  107                pce_boot(pce_error),
  108                pce_boot(pce_global),
  109                pce_boot(pce_expansion),
  110                pce_boot(pce_realise),
  111                pce_boot(pce_goal_expansion),
  112                pce_boot(pce_autoload),
  113                pce_boot(pce_editor),
  114                pce_boot(pce_keybinding),
  115                pce_boot(pce_portray)
  116              ],
  117              [ qcompile(part),         % compile boot files as part of pce.qlf
  118                silent(true)
  119              ]).  120:- use_module(pce_dispatch).
 pce_thread(-Thread) is det
True if Thread is the Prolog thread that runs the graphics message loop.
See also
- pce_dispatch/1.
  129:- create_prolog_flag(xpce_threaded, true, [keep(true)]).  130
  131:- dynamic
  132    pce_thread/1.  133
  134start_dispatch :-
  135    (   current_prolog_flag(xpce_threaded, true)
  136    ->  pce_dispatch([])
  137    ;   true
  138    ).
 in_pce_thread_sync(:Goal) is semidet
Same as in_pce_thread/1, but wait for Goal to be completed. Success depends on the success of executing Goal. If Goal throws an exception, this exception is re-thrown by in_pce_thread/1.

Possible bindings of Goal are returned, but be aware that the term has been copied. If in_pce_thread_sync/1 is called in the thread running pce, it behaves as once/1.

  150in_pce_thread_sync(Goal) :-
  151    thread_self(Me),
  152    pce_thread(Me),
  153    !,
  154    Goal,
  155    !.
  156in_pce_thread_sync(Goal) :-
  157    term_variables(Goal, Vars),
  158    pce_principal:in_pce_thread_sync2(Goal-Vars, Vars).
  159
  160:- initialization
  161    start_dispatch.  162
  163set_version :-
  164    current_prolog_flag(version_data, swi(Major, Minor, Patch, _)),
  165    format(string(PlId),
  166           'SWI-Prolog version ~w.~w.~w', [Major, Minor, Patch]),
  167    send(@prolog, system, PlId).
  168
  169:- initialization set_version.  170
  171get_pce_version :-
  172    (   current_prolog_flag(xpce_version, _)
  173    ->  true
  174    ;   get(@pce, version, name, Version),
  175        create_prolog_flag(xpce_version, Version, [])
  176    ).
  177
  178:- initialization get_pce_version.  179
  180
  181                 /*******************************
  182                 *           CONSOLE            *
  183                 *******************************/
  184
  185%:- send(@pce, console_label, 'XPCE/SWI-Prolog').
  186
  187
  188                /********************************
  189                *       PROLOG LIBRARIES        *
  190                ********************************/
  191
  192:- multifile
  193    user:file_search_path/2.  194
  195user:file_search_path(demo,    pce('prolog/demo')).
  196user:file_search_path(contrib, pce('prolog/contrib')).
  197user:file_search_path(image,   pce(bitmaps)).
  198
  199
  200                 /*******************************
  201                 *            HOOKS             *
  202                 *******************************/
  203
  204:- use_module(library(swi_hooks)).  205
  206                 /*******************************
  207                 *         EDIT HOOKS           *
  208                 *******************************/
  209
  210%       make sure SWI-Prolog edit/0 loads the XPCE edit hooks.
  211
  212:- multifile
  213    prolog_edit:load/0,
  214    prolog:locate_clauses/2.  215
  216prolog_edit:load :-
  217    ensure_loaded(library(swi_edit)).
  218
  219                 /*******************************
  220                 *          LIST HOOKS          *
  221                 *******************************/
 prolog:locate_clauses(Term, Refs)
Locate a list of clause-references from a method-specification like Class->Method.

see library(listing).

  230prolog:locate_clauses(Term, Refs) :-
  231    (   Term = ->(_,_)
  232    ;   Term = <-(_,_)
  233    ),
  234    !,
  235    findall(R, method_clause(Term, R), Refs).
  236
  237match_id(->(Class, Method), Id) :-
  238    atomic(Class), atomic(Method),
  239    !,
  240    atomic_list_concat([Class, (->), Method], Id).
  241match_id(->(_Class, _Method), _Id).
  242match_id(<-(Class, Method), Id) :-
  243    atomic(Class), atomic(Method),
  244    !,
  245    atomic_list_concat([Class, (<-), Method], Id).
  246match_id(<-(_Class, _Method), _Id).
  247
  248method_clause(->(Class, Send), Ref) :-
  249    match_id((Class->Send), Id),
  250    clause(pce_principal:send_implementation(Id, _M, _O), _B, Ref),
  251    atom(Id),
  252    atomic_list_concat([Class,Send], '->', Id).
  253method_clause(<-(Class, Get), Ref) :-
  254    match_id(<-(Class, Get), Id),
  255    clause(pce_principal:get_implementation(Id, _M, _O, _R), _B, Ref),
  256    atom(Id),
  257    atomic_list_concat([Class,Get], '->', Id)