1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
|
\documentstyle[sli,pceslide,psfig]{article}
\renewcommand{\slinote}{Programming in XPCE/Prolog}
\psdirectories{figs,../../userguide/figs,../../../TeX/figs}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INTRO %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Overview}
Part 1
\begin{itemize}
\item Introduction
\item Prolog interface
\item Programming Environment
\end{itemize}
Part 2
\begin{itemize}
\item Application control structure
\item Using XPCE Executable Objects
\item User-Defined Classes
\end{itemize}
\end{sli}
\begin{sli}{Its Authors and History}
\begin{itemize}
\item{PCE Versions 1 \& 2 By Anjo Anjewierden.}
\begin{itemize}
\item Basic architecture and interface
\item Connected to SunView
\item KADS-PowerTools \& internal UvA projects
\item Comercialised to ProWindows-2
\end{itemize}
\item{PCE Version 3 By Anjo Anjewierden \& Jan Wielemaker}
\begin{itemize}
\item KADS-Shelley, KEW
\item Various internal and external projects
\item object-level programming techniques
\end{itemize}
\item{XPCE Version 4 By Jan Wielemaker}
\begin{itemize}
\item KADS-II WB, KEW (ported)
\item X11 interface
\item Integration of menu's and graphics
\item Advanced text, process and network management
\item Class-level programming
\item Comercialised to ProWindows-3/XPCE
\end{itemize}
\end{itemize}
\end{sli}
\begin{sli}{Aims of XPCE}
\begin{itemize}
\item Language independent (GU)I toolkit
\begin{itemize}
\item Prolog (QP, SICStus, SWI)
\item CommonLisp (Lucid, Harlequin)
\item C++ (g++)
\end{itemize}
\item Communication in hybrid systems
\item Interactive diagrams
\item GUI prototyping environment
\item `Kitchen-sink' environment
\end{itemize}
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INTERFACE %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Accessing XPCE from Prolog}
\begin{itemize}
\item \index{new/2}\predrefer{new}{2}: Creating objects
\item \index{send/[2-12]}\predrefer{send}{[2-12]}: Changing objects
\item \index{get/[3-13]}\predrefer{get}{[3-13]}: Getting status
\item \index{free/1}\predrefer{free}{1}: Removing objects
\end{itemize}
\end{sli}
\begin{sli}{Creating XPCE Objects: \index{new/2}\predrefer{new}{2}}
Synopsis: new({\it ?Reference}, {\it +NewTerm})
Examples:
\begin{itemize}
\item ?- new(X, point(5,6)).
\item ?- new(\index{@newline}\objectname{newline}, string('\verb$\n$')).
\item ?- new(X, picture('Hello World')).
\item ?- new(X, text_item(name, '', \\
message(\index{@pce}\objectname{pce}, write_ln, \index{@arg1}\objectname{arg1}))).
\item ?- new(X, chain(new(A, bitmap('pce.bm')))).
\end{itemize}
\end{sli}
\begin{sli}{Manipulating objects: \index{send/[2-12]}\predrefer{send}{[2-12]}}
Synopsis: send({\it +Reference, +Selector, +Arg ...})
Examples:
\begin{itemize}
\item send(Point, x, 9)
\item ?- send(new(P, picture), open).
\item send(Picture, display, new(T, text(hello)), point(30,20))
\item ?- send(file(hello), exists).
\end{itemize}
Optional arguments ('[...]') may be omitted.
\end{sli}
\begin{sli}{Querying objects: \index{get/[3-13]}\predrefer{get}{[3-13]}}
Synopsis: get(({\it +Reference, +Selector, +Arg .... -Result})
\begin{itemize}
\item get(Point, x, X)
\item get(Graphical, size, size(X, Y))
\item get(Sheet, value, name, Name)
\item ?- get(file(hello), size, Size).
\end{itemize}
\end{sli}
\begin{sli}{Discarding objects: \index{free/1}\predrefer{free}{1}}
\begin{itemize}
\item free(+Reference)
\begin{itemize}
\item If `toplevel' object
\end{itemize}
\item send(+Rereference, free)
\begin{itemize}
\item Error if object does not exist
\end{itemize}
\item send(+Reference, done)
\begin{itemize}
\item Discarding answers
\item Normally leave this to GC
\end{itemize}
\end{itemize}
\end{sli}
\begin{sli}{Lazy creation: \index{pce_global/2}\predrefer{pce_global}{2}}
Synopsis: :- pce_global(+Ref, +NewTerm$\|$Goal).
Examples:
\begin{itemize}
\item :- pce_global(\index{@newline}\objectname{newline}, new(string('\verb$\n$'))).
\item :- pce_global(\index{@mainwindow}\objectname{mainwindow}, make_main_window).
\begin{code}
make_main_window(W) :-
send(new(W, picture('Main Window'), open)).
\end{code}
\noindent
\end{itemize}
\end{sli}
\begin{sli}{Named arguments}
Synopsis: ArgumentName := ArgumentValue
Applicable to all methods that take many arguments. Examples:
\begin{itemize}
\item :- pce_global(\index{@bold}\objectname{bold}, new(style(bold := \index{@on}\objectname{on}))).
\item send(Popup, append, menu_item(clear, end_group := \index{@on}\objectname{on})).
\end{itemize}
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PROGRAM ENVIRONMENT %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Programming Environment (Overview)}
\begin{itemize}
\item Accessible from Manual (\index{manpce/0}\predrefer{manpce}{0}; PW3: \index{user_help/0}\predrefer{user_help}{0})
\item Demo Programs
\begin{itemize}
\item Graphics (PceDraw)
\item Text (PceEmacs, ISpell)
\item Resources (Fonts, Images, Cursors)
\end{itemize}
\item ChangeLog
\item Class Hierarchy
\item Class Browser
\begin{itemize}
\item Find Classes, Methods and Variables
\end{itemize}
\item Group Overview
\begin{itemize}
\item Access by functional categories
\end{itemize}
\item Keyword Access
\item Inpector
\begin{itemize}
\item Examine Object Structure
\end{itemize}
\item Visual Hierarchy
\begin{itemize}
\item Consists-of hierarchy of interface
\end{itemize}
\end{itemize}
\end{sli}
\begin{sli}{Class Browser}
\slifig{\textwidth}{classbrowser}
\end{sli}
\begin{sli}{Class Hierarchy}
\slifig{\textwidth}{hierarchy}
\end{sli}
\begin{sli}{Visual Hierarchy}
\slifig{\textwidth}{vishierarchy}
\end{sli}
\begin{sli}{Inspector Tool}
\slifig{\textwidth}{inspector}
\end{sli}
\begin{sli}{PceEmacs}
\slifig{\textwidth}{pceemacs}
\begin{itemize}
\item Well integrated with the PCE/Prolog environment
\item Automatic Prolog Indentation
\item Close to accepted GNU-Emacs interface
\item Programmable in PCE/Prolog
\end{itemize}
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ARCHITECTURE %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{XPCE/Prolog architecture overview}
\slifig{\textwidth}{control}
\end{sli}
\begin{sli}{XPCE as integrating server}
\slifig{\textwidth}{multilang}
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% STRUCTURE OF APPS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Event-driven structure}
\begin{verbatim}
initialise :-
initialise_database,
create_GUI_components.
call_back_when_GUI_xyz_is_operated(Context ...) :-
change_application_database(Context ...),
update_and_create_GUI_components.
\end{verbatim}
\noindent
\end{sli}
\begin{sli}{Modal Windows}
\begin{verbatim}
application :-
initialise(Heap),
create_GUI_components(Heap),
process_events_until_computation_may_proceed,
proceed(Heap),
...
\end{verbatim}
\noindent
Note: during `process_events_until_computation_may_proceed' the system
can handle call-backs on Prolog.
\end{sli}
\begin{sli}{Which structure to use}
Event-driven if:
\begin{itemize}
\item App data is global state
\item Editors
\end{itemize}
Modal Windows if:
\begin{itemize}
\item Ongoing task with status on stack
\item Problem solvers
\end{itemize}
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% EXECUTABLE OBJECTS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Executable Objects (aim)}
\begin{itemize}
\item Define call-back of GUI component
\item `Lambda' function:
\begin{itemize}
\item send(Chain, sort, ?(\index{@arg1}\objectname{arg1}, compare, \index{@arg2}\objectname{arg2}))
\item get(Win?graphicals, find, \index{@arg1}\objectname{arg1}?pen == 5, Gr)
\end{itemize}
\item Method implementation
\begin{itemize}
\item User Defined Classes
\item Object-level methods
\end{itemize}
\end{itemize}
\end{sli}
\begin{sli}{Executable Objects (procedures)}
Returns `success' or `failure'
\begin{itemize}
\item message(Receiver, Selector, Arg ...)
\item assign(Var, Value)
\item if(Condition, [Then], [Else])
\item or(Statement ...)
\item and(Statement ...)
\item not(Statement)
\item while(Condition, [Statement])
\item Value1 \verb$==$ Value2
\item Value1 \verb$\==$ Value2
\item Int1 \verb$>, =, =<, >, >=$ Int2
\end{itemize}
\end{sli}
\begin{sli}{Executable Objects (functions)}
Returns a value or `failure'
\begin{itemize}
\item ?(Receiver, Selector, Arg ...)
\item Receiver?Selector
\item progn(Statement ..., Function|Value)
\item when(Condition, Function1|Value1, Function2|Value2)
\item var
\item \verb$*, +, -, /$ (Integer arithmetic)
\end{itemize}
Executed iff
\begin{itemize}
\item Receiver of send() or get() iff not defined on class of
function
\item Type-checking
\item Appears as argument to other executable object
\end{itemize}
\end{sli}
\begin{sli}{Executable Objects (example 1)}
Change the font of all text objects in `Device' to `Font':
\begin{verbatim}
...
send(Device?graphicals, for_all,
if(message(@arg1, instance_of, text),
message(@arg1, font, Font)))
...
\end{verbatim}
\noindent
\end{sli}
\begin{sli}{Executable Objects (example 2)}
Find graphicals overlapping `Me' in the same device:
\begin{verbatim}
...
get(Me?device, find_all,
message(Me, overlap, @arg1),
ChainOfOverlapping)
...
\end{verbatim}
\noindent
Or, excluding myself:
\begin{verbatim}
...
get(Me?device, find_all,
and(message(Me, overlap, @arg1),
Me \== @arg1),
ChainOfOverlapping)
...
\end{verbatim}
\noindent
\end{sli}
\begin{sli}{Executable Objects (example 3)}
Find all classes implementing the send-method `report':
\begin{verbatim}
?- new(Hits, chain),
send(@classes, for_all,
if(?(@arg2?send_methods, find,
@arg1?name == report),
message(Hits, append, @arg2))).
\end{verbatim}
\noindent
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TYPES %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Types}
\begin{itemize}
\item First-class objects
\item \index{type,\send{validate}}`type \send{validate}' and \index{type,\get{convert}}`type \get{convert}'
\item Method argument specification
\item instance-variable type
\end{itemize}
Aims
\begin{itemize}
\item Documentation
\item Early trap of errors
\item Compile-time checks (TBD)
\item Ensure data-consistency
\end{itemize}
\end{sli}
\begin{sli}{Types | Syntax}
\begin{tabular}{ll}
\tt Name=Type &Argument named `Name' of type `Type' \\
\tt Type ... &Zero or more of these arguments \\
\verb$Type1|Type2$ &Disjunction (either of the types) \\
\tt Type* &The type or the constant \index{@nil}\objectname{nil} \\
\tt [Type] &The type or \index{@default}\objectname{default} (optional argument) \\
\tt \{Name1,Name2\} &One of these names \\
\tt object &Any true object, except for functions \\
\tt any &Anything (int|object) \\
\tt int &An integer (the only non-object datum) \\
\tt 3..5 &An integer 3 $\leq$ value $\leq$ 5 \\
\tt 3.2..5.6 &A real (float) in this range \\
\tt 3.. &An integer $\geq$ 3 \\
\tt ClassName &Any instance of this class (or sub-class) \\
\tt alien:char * &Alien (C) data. In this case a char *
\end{tabular}
\end{sli}
\begin{sli}{Types | Examples}
\begin{tabular}{ll}
\verb$any|function$ &Anything, may be function \\
\verb$[code]*$ &Executable object, \index{@default}\objectname{default} or \index{@nil}\objectname{nil} \\
\verb$graphical$ &Any graphical object (also dialog item) \\
\verb${none,send,get,both}$ &Any of these names \\
\end{tabular}
Method examples:
\begin{code}
point ->initialise: x=[int], y=[int]
menu ->append: menu_item (conversion)
\end{code}
\noindent
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% USER-DEFINED-CLASSES %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{User-defined Classes}
Classes, methods, variables, etc.\ are normal XPCE objects and
thus:
\begin{itemize}
\item May be created using new()
\item Manipulated using send()
\item Analysed using get()
\item ... but currently {\em not} removed using free()
\end{itemize}
The Prolog front-end:
\begin{itemize}
\item Prolog-style declaration of classes
\item Full Prolog implemented methods
\end{itemize}
\end{sli}
\begin{sli}{Skeleton}
\begin{verbatim}
:- pce_begin_class(ClassName[(TermArg...)],
SuperClass, [Summary]).
variable(Name, Type, Access, [Summary]).
...
SendMethod(Self, Arg:Type ...) :->
["Summary"::]
send(Self, send_super, SendMethod, SArg ...),
NormalPrologCode.
...
GetMethod(Self, Arg:Type ..., String:string) :<-
["Summary"::]
NormalPrologCodeBinding(String).
:- pce_end_class.
\end{verbatim}
\noindent
\end{sli}
\begin{sli}{User-defined classes. Example 1a}
\begin{verbatim}
:- pce_begin_class(matrix(width, height), vector,
"Two-dimensional array").
variable(width, int, get, "Width of the matrix").
variable(height, int, get, "Height of the matrix").
initialise(M, Width:int, Height:int) :->
"Create matrix fom width and and height"::
send(M, send_super, initialise),
send(M, slot, width, Width),
send(M, slot, height, Height),
Size is Width * Height,
send(M, fill, @nil, 1, Size).
\end{verbatim}
\noindent
\end{sli}
\begin{sli}{User-defined classes. Example 1b}
\begin{verbatim}
element(M, X:int, Y:int, Value:any) :->
"Set element at X-Y to Value"::
get(M, width, W),
get(M, height, H),
between(1, W, X),
between(1, H, Y),
Location is X + (Y-1) * W,
send(M, send_super, element,
Location, Value).
:- pce_end_class.
\end{verbatim}
\noindent
\end{sli}
\begin{sli}{Commonly redefined methods (1)}
Object management:
\begin{itemize}
\item \send{initialise} (initialise new instance)
\item \get{lookup} (new() to return existing instance)
\item \send{unlink} (detach from environment)
\end{itemize}
Message passing:
\begin{itemize}
\item \both{slot} (access slot without side-effects)
\item \send{send_super} (invoke super-method)
\item \get{get_super} (invoke super-method)
\end{itemize}
\end{sli}
\begin{sli}{Commonly redefined methods (2)}
Graphics:
\begin{itemize}
\item \send{event} (event-processing)
\item \send{geometry} (resize/move)
\item \send{device} (device I'm displayed on)
\item \send{displayed} (visibility)
\end{itemize}
\end{sli}
\begin{sli}{User Defined Classes: Do I need them?}
\begin{itemize}
\item Specialise XPCE to your applications needs
\item Some things can only be redefined at the class-level
\item Exploit XPCE's open structure and tools
\item Use classes for the overall control
\end{itemize}
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INTRO-2 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Overview (2)}
Part 3
\begin{itemize}
\item Tracing and debugging
\item Dialog windows in Depth
\item Error/status reporting
\end{itemize}
Part 4
\begin{itemize}
\item Graphics
\item Data representation
\end{itemize}
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TRACING AND DEBUGGING %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Tracing and Debugging XPCE}
\begin{itemize}
\item All active objects in XPCE are instances of a subclass of
class program_object.
\item Trace- and Break-points may be set on any program-object.
\item On any `port' (enter, exit, fail)
\item May be conditional
\item \index{@pce}\objectname{pce} \send{trace}: {never,user,always}
\begin{itemize}
\item Never: Normal execution mode
\item User: Watch user-level objects
\item Always: Watch any object executing
\end{itemize}
\item Class vmi (Virtual Machine Instruction) defines the objects
\begin{itemize}
\item \index{@vmi_send}\objectname{vmi_send}, \index{@vmi_get}\objectname{vmi_get}, \index{@vmi_new}\objectname{vmi_new}, \index{@vmi_free}\objectname{vmi_free}
\end{itemize}
\end{itemize}
\end{sli}
\begin{sli}{Tracing and debugging:\\ example 1}
\begin{verbatim}
?- new(@m, message(@prolog, @arg1)).
?- send(@m, forward, true). ===> yes
?- send(@m, trace, @on).
%%% Trace @m, switch tracer to user-level if it was off
?- send(@m, forward, true).
PCE: 3 enter: message(@prolog/host, @arg1/var)
PCE: 3 exit: message(@prolog/host, @arg1/var)
\end{verbatim}
\noindent
\end{sli}
\begin{sli}{Controlling groups of objects}
\begin{itemize}
\item \index{object,\send{trace}}`object \send{trace}: \index{@default}\objectname{default}' $\longrightarrow$ Use class \get{trace}
\item \index{class,\send{trace}}`class \send{trace}: \index{@default}\objectname{default}' $\longrightarrow$ Use super-class \get{trace}
\end{itemize}
Thus:
\begin{itemize}
\item send(class(program_object), trace, \index{@on}\objectname{on}).
\end{itemize}
Switches the tracer fully on (in user mode).
\end{sli}
\begin{sli}{Tracing methods}
Trace-points set to individual program objects are {\em always} honoured
if trace-level is \verb$user$ or \verb$system$.
Utility predicates for method trace-points:
\begin{itemize}
\item tracepce((+Class \get{Method})).
\item tracepce((+Class \send{Method})).
\item tracepce(+Class -Variable).
\end{itemize}
\end{sli}
\begin{sli}{Conditional Trace-points}
\index{program_object,\send{trace}}`program_object \send{trace}: [bool], [\{full,enter,exit,fail\}], [code]'
Variables for code:
\begin{itemize}
\item \index{@receiver}\objectname{receiver} (receiver of action)
\item \index{@selector}\objectname{selector} (referred selector)
\item \index{@arg1}\objectname{arg1}, \index{@arg2}\objectname{arg2}, ... (arguments)
\end{itemize}
Thus:
?- send(\index{@vmi_send}\objectname{vmi_send}, trace, \index{@on}\objectname{on}, exit, \index{@selector}\objectname{selector} == event).
will print all successful exits from sending \send{event} to any object.
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DIALOG WINDOWS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Dialog Windows}
\begin{itemize}
\item Layout
\item Modal Windows
\item Prompting for values
\item Editing attributes
\item Errors and status information
\end{itemize}
\end{sli}
\begin{sli}{Symbolic Layout}
\begin{itemize}
\item dialog \send{append}: Item, [\{right,below,next_row\}]
\begin{itemize}
\item Relative to last appended item
\item Buttons left-to-right, rest top-to-bottom
\end{itemize}
\item Fine Tuning:
\begin{itemize}
\item dialog_item \send{alignment}: {column,center,left,right}
\item dialog_item \send{auto_label_align}: bool
\item dialog_item \send{auto_value_align}: bool
\item dialog_item \send{reference}: point
\end{itemize}
\end{itemize}
\end{sli}
\begin{sli}{Symbolic layout (why?)}
\begin{itemize}
\item Fast specification
\item Program-generated dialog windows
\item Independent of user font preferences
\item Independent of user `look-and-feed'
\item Consistent feel over applications
\begin{itemize}
\item Native XPCE
\item OpenLook
\item ... MS-Windows, Motif
\end{itemize}
\end{itemize}
\end{sli}
\begin{sli}{Modal Windows}
\begin{itemize}
\item Event-subloop to preserve context on the stack
\item Normal user-level:
\begin{itemize}
\item get(Frame, confirm, Value)
\item send(Frame, return, Value)
\end{itemize}
\end{itemize}
\begin{code}
ask_name(Name) :-
new(D, dialog('Please enter name')),
send(D, append, new(N, text_item(name))),
send(D, append,
button(ok, message(D, return,
N?selection))),
send(D, append,
button(cancel, message(D, return, @nil))),
get(D, confirm_centered, RVal),
send(D, destroy),
RVal \== @nil,
RVal = Name.
\end{code}
\noindent
\end{sli}
\begin{sli}{Editing values (methods)}
Relevant methods for dialog_item:
\begin{itemize}
\item \both{default}: value|function\hfill\\
Normally initialisation argument
\item \both{restore}\hfill\\
Restore \get{selection} to \get{default}
\item \both{apply}: always:[bool]\hfill\\
Execute \get{message} if \get{selection} is changed or always: \index{@on}\objectname{on}.
\end{itemize}
\end{sli}
\begin{sli}{Editing values (example)}
%)
\begin{code}
edit_error(Id) :-
get(@pce, convert, Id, error, E),
new(D, dialog(string('Error %s', Id))),
send(D, append,
new(F, text_item(format, E?format,
message(E, format, @arg1)))),
send(F, length, 50),
send(D, append,
new(K, menu(kind, choice,
message(E, kind, @arg1)))),
send_list(K, append,
[status,inform,warning,
error,fatal,ignored]),
send(K, default, E?kind),
send(D, append, button(apply)),
send(D, append, button(restore)),
send(D, append, button(cancel,
message(D, destroy))),
send(D, default_button, apply),
send(D, open).
\end{code}
\noindent
\end{sli}
\begin{sli}{The result ...}
\slifig{\textwidth}{editvalue}
\end{sli}
\begin{sli}{Error and status reports (reporting)}
\slifig{\textwidth}{error}
\end{sli}
\begin{sli}{Reports (types)}
\begin{itemize}
\item status\hfill\\
Short message telling what is happening. Only display
if there is a place for it.
\item inform\hfill\\
Short message that must be displayed somehow.
\item progress\hfill\\
Short message to indicate progress of an operation.
Displayed as `status', but immediately updates display.
\item done\hfill\\
Any sequence of `progress' must be followed by `done'
to allow removing the message or writing `done' behind
it.
\item warning\hfill\\
Short message informing a non-severe problem. If it
cannot be displayed, invoke \send{alert} on the offending
visual object (bell or flash).
\item error\hfill\\
Short message informing a severe problem. If it cannot
be displayed, use a confirmer window.
\item fatal\hfill\\
Fatal error. Inform in Prolog window, print the stacks
and abort to Prolog toplevel.
\end{itemize}
\end{sli}
\begin{sli}{Error objects}
\begin{itemize}
\item Id
\item Format
\item Feedback: \{report,print\}
\item Kind: \{warning,error,fatal,ignored\}
\end{itemize}
User errors are normally \send{report}'ed, application-programmer errors
are printed.
Catching: pce_catch_error(+Error, +Goal):
?- pce_catch_error(no_behaviour, send(\index{@pce}\objectname{pce}, hello)).
no
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CUSTOM ITEMS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Custom Dialog Items}
\begin{itemize}
\item Subclasses existing dialog items
\begin{itemize}
\item Alternative for setting attributes
\item Reprogramming aspects: event-handling, completion
\end{itemize}
\item Defining as compoung graphical
\begin{itemize}
\item using class device
\item define standard interaction methods
\item see course-notes and library pce_font_item.pl
\end{itemize}
\end{itemize}
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% GRAPHICS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Graphics: Overview}
\begin{itemize}
\item Primitives (box, circle, text, bitmap)
\item Compound graphicals: devices
\item Event-handling (graphical \send{event}, gestures)
\item Relations (connection)
\item Attributes (pen, texture, font, ...)
\item Resources (interface to ~/.Xdefaults)
\item Redraw (animation: \send{flush})
\end{itemize}
\end{sli}
\begin{sli}{Compound graphicals: devices}
\begin{itemize}
\item Defining application-specific graphics
\item Generally used with user-defined classes
\end{itemize}
\end{sli}
\begin{sli}{A simple icon class}
\begin{code}
:- pce_begin_class(icon, device).
initialise(I, Image:image, Label:name) :->
"Create from image and label"::
send(I, send_super, initialise),
send(I, display, bitmap(Image)),
send(I, display, text(Label, center)),
send(I, reposition).
reposition(I) :->
get(I, member, bitmap, Bitmap),
get(I, member, text, Text),
get(Bitmap, center_x, CX),
get(Bitmap, bottom_side, BS),
get(Text, width, W),
TX is CX - W//2,
send(Text, set, TX, BS).
label(I, Text:name) :->
"Change the label"::
get(I, member, text, Text),
send(Text, string, Text).
:- pce_end_class.
\end{code}
\noindent
\end{sli}
\begin{sli}{Event-handling: move and select}
\begin{code}
:- pce_global(@icon_recogniser,
new(handler_group(
click_gesture(left, '', single,
message(@receiver?device,
selection,
@receiver)),
new(move_gesture)))).
event(I, Ev:event) :->
"Process event"::
( send(I, send_super, event, Ev)
; send(@icon_recogniser, event, Ev)
).
\end{code}
\noindent
\end{sli}
\begin{sli}{Refining gestures}
A gesture for just moving objects vertically:
\begin{code}
:- pce_begin_class(vertical_move_gesture,
move_gesture).
drag(G, Ev:event) :->
"Only use Y-coordinate"::
get(Ev, receiver, Graphical),
get(Graphical, device, Dev),
get(Ev, y, Dev, Y),
get(G?offset, y, OY),
GY is Y - OY,
send(Graphical, y, GY).
terminate(G, Ev:event) :->
"Just call ->drag"::
send(G, drag, Ev).
:- pce_end_class.
\end{code}
\noindent
\end{sli}
\begin{sli}{Test}
\begin{code}
test :-
send(new(P, picture), open),
send(P, display, new(B, box(50,50))),
send(B, recogniser,
new(vertical_move_gesture)).
\end{code}
\noindent
\end{sli}
\begin{sli}{Using Connections}
\begin{itemize}
\item A connection is a line between two {\em handles}
\item Handles are connected to graphical objects
\end{itemize}
Example:
\begin{code}
:- pce_global(@in_out_link, make_in_out_link).
make_in_out_link(L) :-
new(L, link(in, out, line(0,0,0,0,second))).
linked_box_demo :-
new(P, picture('Linked Box demo')),
send(P, open),
send(P, display,
new(B1, box(50,50)), point(20,20)),
send(P, display,
new(B2, box(25,25)), point(100,100)),
send(B1, handle, handle(w, h/2, in)),
send(B2, handle, handle(w/2, 0, out)),
send(B1, connect, B2, @in_out_link).
\end{code}
\noindent
\end{sli}
\begin{sli}{Result ...}
\slifig{3in}{link}
\end{sli}
\begin{sli}{Why Connections?}
\begin{itemize}
\item Little geometry calculations in your application
\item They update if one of the graphicals move
\item They are destroyed if one of the graphicals is destroyed
\item You can easily {\em read} the diagram in terms of nodes
and arcs
\item Exploited by \index{graphical,\send{layout}}`graphical \send{layout}'
\end{itemize}
\end{sli}
\begin{sli}{Graphics Attributes}
Generic attributes (available on many graphical classes):
\begin{itemize}
\item colour
\item pen (thickness of drawing pen)
\item texture (dash-pattern)
\item shadow (box, ellipse, figure)
\item radius (rounded corner: box, figure)
\item font (predefined, access to all 8-bit X11 fonts)
\end{itemize}
\end{sli}
\begin{sli}{X11-Resources (user-preferences)}
\begin{itemize}
\item Specify: \verb$~/.Xdefaults$:\hfill\\
Pce.$<$CapitalisedClassName$>$.$<$resource$>$: $<$value$>$
\item Access: \index{object,\get{resource_value}}`object \get{resource_value}: resource $\longrightarrow$ Value'
\end{itemize}
Example:
\begin{code}
:- pce_begin_class(file_icon, icon).
resource(image, image, 'file.bm', "Default image").
variable(file, file, get, "Associated file").
initialise(I, File:file) :->
"Create icon for file"::
get(I, resource_value, image, Image),
send(I, send_super, initialise,
Image, File?base_name),
send(I, slot, file, File).
:- pce_end_class.
\end{code}
\noindent
\end{sli}
\begin{sli}{Redraw Strategy}
\begin{itemize}
\item Change of graphical attribute implies:
\begin{itemize}
\item If recompute necessary: \send{request_compute}
\item If redraw necessary: notify changed area to window
\end{itemize}
\item top-level-loop of XPCE:
\begin{code}
forever
{ while ( events-in-queue )
process event;
redraw(all-displays);
}
\end{code}
\noindent
\end{itemize}
\end{sli}
\begin{sli}{Consequences}
\begin{itemize}
\item Automatic redraw after changes
\item Efficient handling of multiple changes
\item Only need to force redraw
\begin{itemize}
\item If redraw is required during ongoing computation
\end{itemize}
\end{itemize}
Methods for explicit redraw:
\begin{itemize}
\item \index{@display}\objectname{display} \send{flush} (redraws the display)
\item \index{@display}\objectname{display} \send{synchronise} (handle all pending events and redraw)
\end{itemize}
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PROCESS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Interprocess communication}
Building blocks:
\begin{itemize}
\item Class process: inferior processes (c.f.\ GNU-Emacs)
\item Sockets: Unix- or ethernet domain sockets.
\end{itemize}
Communication:
\begin{itemize}
\item Synchronous (blocks event-handling)
\item Asynchronous (Executable object handles input)
\item User-definable input records (regex)
\end{itemize}
\end{sli}
\begin{sli}{Calling Simple Unix App}
\begin{code}
call_unix(Utl, Args, Output) :-
NewTerm =.. [process, Utl | Args],
new(P, NewTerm),
send(P, use_tty, @off),
new(OS, string),
send(P, record_separator, @nil),
send(P, input_message,
message(OS, append, @arg1)),
send(P, open),
send(P, wait),
pce_string_to_list(OS, Output),
send(P, done),
send(OS, done).
\end{code}
\noindent
\end{sli}
\begin{sli}{Server}
\begin{verbatim}
pce_server(Addr) :-
new(S, socket(Addr)),
send(S, input_message,
message(@prolog, call_atom,
@receiver, @arg1)),
send(S, accept_message,
message(@arg1, format, '(pce) ')),
send(S, listen).
call_atom(Socket, Command) :-
get(Command, value, Atom),
( CommandAtom == ''
-> send(Socket, format, '\n(pce) ')
; ( atom_to_term(Atom, Term, Bindings)
-> ( call(Term)
-> write_bindings(Bindings, Socket),
send(Socket, format, 'yes\n(pce) ')
; send(Socket, format, 'no\n(pce) ')
)
; send(Socket, format, 'Syntax error\n(pce) ')
)
).
\end{verbatim}
\noindent
\end{sli}
\begin{sli}{Graphical front-end for ftp}
\slifig{\textwidth}{ftp}
\end{sli}
\begin{sli}{Graphical front-end for ftp}
Complete sources in the course-notes. Highlights here.
\begin{code}
:- pce_begin_class(ftp_process, process,
"Wrapper around ftp").
variable(state, name, get,
"Current command state").
variable(login, name, get,
"Login name").
variable(action_message,[code], get,
"Message to handle output").
initialise(P, Host:name, Login:[name]) :->
"Create ftp process and connect"::
send(P, send_super, initialise, ftp, Host),
send(P, record_separator,
string('^ftp> \\|^Password:\\|\n')),
send(P, input_message,
message(P, input, @arg1)),
send(P, slot, action_message, @default),
send(P, open).
\end{code}
\noindent
\end{sli}
\begin{sli}{FTP front-end: input (1)}
\begin{code}
input(P, Input:string) :->
get(P, state, State),
pattern(State, Pattern, Action),
to_regex(Pattern, Regex),
send(Regex, match, Input), !,
Action =.. [Selector|Args],
maplist(map_pattern_arg(Regex, Input),
Args, NArgs),
Message =.. [send, P, Selector | NArgs],
Message.
pattern(_,
'^ftp> $',
prompt).
pattern(pwd,
'257[^"]*"\\([^"]+\\)',
action(1:name)).
...
\end{code}
\noindent
\end{sli}
\begin{sli}{FTP front-end: input (2)}
\begin{code}
wait_for_prompt(P) :->
"Process input till prompt"::
send(P, report, progress, 'Waiting for ftp prompt'),
repeat,
( get(P, state, prompt)
-> !,
send(P, report, done)
; send(@display, dispatch),
fail
).
\end{code}
\noindent
\end{sli}
\begin{sli}{FTP front-end: input (3)}
\begin{code}
action(P, Args:any...) :->
"Perform action"::
get(P, action_message, Msg),
( Msg == @default
-> send(@pce, send_vector, write_ln, Args)
; send(Msg, forward_vector, Args)
).
pwd(P, Msg:[code]) :->
send(P, wait_for_prompt),
send(P, slot, state, pwd),
send(P, slot, action_message, Msg),
send(P, format, 'pwd\n').
\end{code}
\noindent
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DATA REPRESENTATION %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Data Representation: Alternatives}
\begin{itemize}
\item Prolog Stacks
\begin{itemize}
\item Generally `case' data
\item Visualisation will often require modal windows
\end{itemize}
\item Prolog recorded or asserted DB
\begin{itemize}
\item When a lot of access is needed from Prolog
\end{itemize}
\item External (relational) DB
\begin{itemize}
\item When data is available in this format
\item Distributed databases
\end{itemize}
\item XPCE Objects
\begin{itemize}
\item Manipulation of data closely connected to the interface
\end{itemize}
\end{itemize}
\end{sli}
\begin{sli}{XPCE Primitives}
Data Organisers:
\begin{itemize}
\item chain (linked list)
\item vector (one-dimensional array, dynamic)
\item hash_table (mapping from object to object)
\end{itemize}
`Frames':
\begin{itemize}
\item sheet (list of name-value pairs, untyped)
\item user-defined class (typed attribute-values)
\end{itemize}
`Relations':
\begin{itemize}
\item table (multicolumn; relational database table)
\item hyper (2-directional link between two objects)
\item user-defined classes
\end{itemize}
\end{sli}
\begin{sli}{Example choices}
Workbenches for Knowledge Engineering
\begin{itemize}
\item Shelley (XPCE-3)
\begin{itemize}
\item Frames using sheet objects
\item Relations using tables
\item Program in Prolog-defined OO-layer
\end{itemize}
\item KADS-II (XPCE-4)
\begin{itemize}
\item Entirely XPCE user-defined classes
\end{itemize}
\item KEW (CommonLisp, XPCE-3, ported to XPCE-4)
\begin{itemize}
\item Frames using sheet objects
\item Relations using tables
\item Program in CLOS
\end{itemize}
\item CUE (CommonLisp, XPCE-4)
\begin{itemize}
\item Integration of existing CLOS packages
\item Data and program in CLOS
\end{itemize}
\end{itemize}
\end{sli}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEVELOPMENT %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{sli}{Prowindows-3/XPCE Plans}
Realised in research version:
\begin{itemize}
\item C++ interface
\begin{itemize}
\item Stand-alone XPCE/C++ programs
\item Mixed XPCE/Prolog/C++ programs
\end{itemize}
\item Display windows on windows
\item Full integration of graphical and dialog_item
\item Full 8-bit character-set support
\item Interactive dialog-window editor
\end{itemize}
\end{sli}
\begin{sli}{Prowindows-3/XPCE Plans}
Plans (no time-schedule, no warranty):
\begin{itemize}
\item Motif emulation
\item 16-bit character-set support
\item MS-Windows/Windows-NT port
\item Stand-alone XPCE language
\begin{itemize}
\item Language-independent XPCE libraries
\item Optional interpreted GUI toplevel for compiled environments (C++)
\end{itemize}
\item Libraries
\end{itemize}
\end{sli}
\end{document}
|