xpce file explorer open error -- xpce newbie question

15 views
Skip to first unread message

Brian Nolan

unread,
Jul 26, 2017, 5:04:36 PM7/26/17
to SWI-Prolog
I am trying to open the a file explorer from the following code:

:- pce_autoload(toc_window, library(pce_toc)).
:- pce_autoload(report_dialog, library(pce_report)).



:- pce_begin_class(explorer, frame, "Explore the filesystem").

initialise(E, Dir:directory) :->
        "Explore from directory"::
        send_super(E, initialise, 'Simple explorer'),
        send(E, append, new(DH, directory_hierarchy(Dir))),
        send(new(view), right, DH),
        send(new(report_dialog), below, DH).

open_node(E, Node:file) :->
        "Show file content of opened node"::
        get(E, member, view, View),
        send(View, load, Node).

:- pce_end_class.


:- pce_begin_class(directory_hierarchy, toc_window,
                   "Browser for a directory-hierarchy").

initialise(FB, Root:directory) :->
        send(FB, send_super, initialise),
        get(Root, name, Name),
        send(FB, root, toc_folder(Name, Root)).

expand_node(FB, D:directory) :->
        "Called if a node is to be expanded"::
        new(SubDirsNames, chain),
        new(FileNames, chain),
        send(D, scan, FileNames, SubDirsNames),

        get(SubDirsNames, map, ?(D, directory, @arg1), SubDirs),
        send(SubDirs, for_all,
             message(FB, son, D,
                     create(toc_folder, @arg1?name, @arg1))),
        get(FileNames, map, ?(D, file, @arg1), SubFiles),
        send(SubFiles, for_all,
             message(FB, son, D,
                     create(toc_file, @arg1?base_name, @arg1))).

open_node(FB, Node:file) :->
        "Called if a file is double-clicked"::
        send(FB?frame, open_node, Node).

:- pce_end_class.

file_explorer(Dir) :-
    new(E, explorer),
    send(E,initialise,Dir),
    send(E, open).


When I try to open with ?- file_explorer('.').  I get the error "ERROR: explorer ->initialise: Missing argument 1 (directory): `directory' expected".
I get the same error if I try something like ?- file_explorer(directory(.)).  Can anybody explain what I'm doing wrong--what incantation do I use to open the explorer on a given directory?

Thanks!

Jan Wielemaker

unread,
Jul 28, 2017, 11:04:05 AM7/28/17
to Brian Nolan, SWI-Prolog
This should be

file_explorer(Dir) :-
new(E, explorer(Dir)),
send(E, open).

When new/2 sees a term <class>(Arg ...) it allocates a new object for
class <class> and calls initialise using <Arg ...>. You should never
call the initialise method explicitly except for the send_super to
initialise the super class from a derived class.

Cheers --- Jan

P.s. xpce is still usable, but not actively maintained except for
serious bugs and portability. At least here, SWI-Prolog is
mostly used as a web server for interactive applications.


>
>
> When I try to open with ?- file_explorer('.'). I get the error "ERROR:
> explorer ->initialise: Missing argument 1 (directory): `directory'
> expected".
> I get the same error if I try something like ?-
> file_explorer(directory(.)). Can anybody explain what I'm doing
> wrong--what incantation do I use to open the explorer on a given directory?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages