Share Tips, Code Samples, etc. with the Visual Prolog community.
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

My dialog tricks

Unread post by Ferenc Nagy »

Hi,

It's the time not only to ask something but to publish some tricks about dialog handling.
1. Validation of strings by length [after trimming] and allowed characters.
2. Comparison of two string which should contain V2>=V1 integer values.
3. Easy hangling of DIALOG_INTS e.g. in dialog_..._update procedures.
4. Usage of synchronized list boxed instead of grids or columns separated by tabulators.
4. a) Optional Integer control to enhance navigation.
5. Move selection in one or more list boxes based on an integer control.
6. Display explanation of the control in focus in the status line.

Usage:
Insert include statements into VIPTOOLS.PRE

Code: Select all

ifdef use_dlgpack   include "dialog\\dialog.pre"   include "mydialog.pre" enddef
and VPITOOL.PRO, respectively.

Code: Select all

ifdef use_dlgpack   include "dialog\\dialog.pro"   include "mydialog.pro" enddef
Declarations are in mydialog.pre:

Code: Select all

        % 30.4.2007 % **** Extensions to dialog pack **** GLOBAL PREDICATES                 trim_validate_str(STRING Input, STRING Corrected, INTEGER Min_Length, INTEGER Max_Length, char Lowest_Allowed, char Highest_Allowed, string Error_Message)                 -(       i    ,        o        ,         i         ,         i         ,      i             ,      i              ,        i            ) my_validate_str(STRING Corrected, INTEGER Min_Length, INTEGER Max_Length, char Lowest_Allowed, char Highest_Allowed, string Error_Message)               -(       i        ,         i         ,         i         ,      i             ,      i              ,        i            ) change_case(STRING Input, STRING Corrected, char Lowest_Allowed, char Highest_Allowed)           -(       i    ,        o        ,      i             ,      i              ) prohibited_char(STRING Entry, char Lowest_Allowed, char Highest_Allowed)   my_compare_int(STRING S1, STRING S2, dialog_int V1, dialog_int V2, string Error_Message)              -(       i ,        i ,            o ,            o ,        i            )                 procedure INTEGER my_dialog_GetInt(WINDOW,DIALOG_CONTROL_ID)   procedure INTEGER my_dialog_VLGetInt(DIALOG_CONTROL_ID,DIALOG_VAL_LIST)
Clauses are in mydialog.pro:

Code: Select all

% 30.4.2007 % **** Extensions to dialog pack **** CLAUSES   trim_validate_str(S, C, Min_Length, Max_Length, Lowest_Allowed, Highest_Allowed, Error_Message) if         fronttoken(S,Token,RestString),         concat(Token,RestString,F),         searchchar(F,' ',FoundPos),         Length=FoundPos-1,         frontstr(Length,F,K,_),         change_case(K, C, Lowest_Allowed, Highest_Allowed),         my_validate_str(C, Min_Length, Max_Length, Lowest_Allowed, Highest_Allowed, Error_Message).   change_case(S, C, _, Highest_Allowed) if         Highest_Allowed<='Z',         !,         upper_lower(S,C). change_case(S, C, Lowest_Allowed, Highest_Allowed) if         Lowest_Allowed>='a',         Highest_Allowed<='z',         !,         upper_lower(C,S). change_case(S, S, _, _).         my_validate_str(S, Min_Length, _, _, _, Error_Message) if         str_len(S,Length),         Length<Min_length,         dlg_Error("Too Short Entry", Error_Message),         fail. my_validate_str(S, _, Max_Length, _, _, Error_Message) if         str_len(S,Length),         Length>Max_length,         dlg_Error("Too Long Entry", Error_Message),         fail. my_validate_str(S, _, _, Lowest_Allowed, Highest_Allowed, Error_Message) if         prohibited_char(S, Lowest_Allowed, Highest_Allowed),         !,         dlg_Error("Invalid Characters", Error_Message),         fail. my_validate_str(_, _, _, _, _, _).   prohibited_char(Entry, Lowest_Allowed, _) if         frontchar(Entry,FrontChar,_),         Frontchar<Lowest_Allowed,         !. prohibited_char(Entry, _, Highest_Allowed) if         frontchar(Entry,FrontChar,_),         Frontchar>Highest_Allowed,         !. prohibited_char(Entry, Lowest_Allowed, Highest_Allowed) if         frontchar(Entry,_,RestString),         !,         prohibited_char(RestString, Lowest_Allowed, Highest_Allowed).         my_compare_int(S1, S2, _, _, Error_Message) if         str_int(S1,V1),         str_int(S2,V2),         V2<V1,         !,         dlg_Error("Invalid Values", Error_Message),         fail. my_compare_int(S1, S2, K1, K2, _) if         str_int(S1,V1),         str_int(S2,V2),         V2>=V1,         K1=i(V1),         K2=i(V2),         !. my_compare_int(S1, S2, void, void, _) if         not(str_int(S1,_)),         not(str_int(S2,_)),         !. my_compare_int(S1, S2, void, K2, _) if         not(str_int(S1,_)),         str_int(S2,V2),         K2=i(V2),         !. my_compare_int(S1, S2, K1, void, _) if         not(str_int(S2,_)),         str_int(S1,V1),         K1=i(V1),         !.   my_dialog_GetInt (WINDOW,DIALOG_CONTROL_ID,I) if V = dialog_GetInt (WINDOW,DIALOG_CONTROL_ID), V=i(I).   my_dialog_VLGetInt (DIALOG_CONTROL_ID,DIALOG_VAL_LIST,I) if V = dialog_VLGetInt (DIALOG_CONTROL_ID,DIALOG_VAL_LIST), V=i(I).
The above were written in version 5. The following tricks are in version 7.
myDialogTricks.cl

Code: Select all

/*****************************************************************************  % @Project:  SOAP  % @File name: myDialogTricks.cl  % @Written by: Copyright (c) Budapest, Hungary 2009 Ferenc Nagy PhD.  % @short My dialog tricks.  % @detail Typical dialog handling tricks for the project.  % @end ******************************************************************************/     class myDialogTricks     open core   domains     listBox_list = listbox*.   predicates     classInfo : core::classInfo.     % @short Class information  predicate.     % @detail This predicate represents information predicate of this class.     % @end   predicates     % Synchronize selection in two or more list boxes.     synchronizeListBoxes:(listBox Changed, listbox_list Followers, positive Index) procedure (i,i,o).       % Synchronize selection in two or more list boxes and the selection index in an integer control.     synchronizeListBoxesandInteger:(listBox Changed, listbox_list Followers, integercontrol) procedure (i,i,i).       % Move selection in one or more list boxes based on an integer control.     moveSelection:(integercontrol, listbox_list Followers) procedure (i,i).       % Fill rows of synchronized list boxes with list of strings.     fillListBoxes:(listbox_list Synchronized, core::string_list) procedure (i,i).       % Fill rows of synchronized list boxes with list of strings and     % change the count of found and index of selected rows.     fillListBoxesand2Integers:(listbox_list Synchronized, core::string_list, integercontrol Found, integercontrol Selected) procedure (i,i,i,i).       % Copy selected line of the list box to the status line.     copySelectedToStatusLine:(listBox LBox, vpiDomains::menuTag StatusField) determ (i,i).       % Initialize status line.     initializeStatusLine:(string Text, vpiDomains::menuTag StatusField) procedure (i,i).       % Display explanation of the control in focus in the status line.     explainInStatusLine:(string Dialog, string Control, string Explanation) procedure (i,i,i).   end class myDialogTricks
The clauses - myDialogTricks.pro

Code: Select all

/*****************************************************************************  % @Project:  SOAP  % @File name: myDialogTricks.pro  % @Written by: Copyright (c) Budapest, Hungary 2009 Ferenc Nagy PhD.  % @short My dialog tricks.  % @detail Typical dialog handling tricks for the project.  % @end ******************************************************************************/       implement myDialogTricks     open core   constants     className = "com/visual-prolog/myDialogTricks/myDialogTricks".     classVersion = "$JustDate: $$Revision: $".   clauses     classInfo(className, classVersion).         % Synchronize selection in two or more list boxes.     synchronizeListBoxes(Changed, Followers, Index) :-         Index=Changed:tryGetSelectedIndex(),         foreach Elem = list::getMember_nd(Followers) do             Elem:selectAt(Index, true)         end foreach,         !.     synchronizeListBoxes(_, _,0).       % Synchronize selection in two or more list boxes and the selection index in an integer control.     synchronizeListBoxesandInteger(Changed, Followers, Ictl) :-         synchronizeListBoxes(Changed, Followers, Index),         Index1=Index+1,         Ictl:setInteger(Index1).         % Move selection in one or more list boxes based on an integer control.     moveSelection(IntegerControl, Followers) :-         Index=IntegerControl:getInteger()-1,         foreach Elem = list::getMember_nd(Followers) do             Elem:selectAt(Index, true)         end foreach.       % Fill rows of synchronized list boxes with list of strings.     fillListBoxes([ ],  _) :- !.     fillListBoxes( _ , [ ]) :- !.     fillListBoxes([Lbox1|RestSynchronized], [Head|Tail]) :-         Lbox1:add(Head),         fillListBoxes(RestSynchronized, Tail).     % Fill rows of synchronized list boxes with list of strings and     % change the count of found and index of selected rows.     fillListBoxesand2Integers([Lbox1|RestSynchronized], String_List, Found, Selected) :-         fillListBoxes([Lbox1|RestSynchronized], String_List),         Found:setInteger(LBox1:getCount()),         Selected:setInteger(1),         !.    fillListBoxesand2Integers(_, _, _, _).      % Copy selected line of the list box to the status line.    copySelectedToStatusLine(LBox, StatusField) :-        [Sel1|_]=LBox:getSelectedItems(),        Task = vpi::getTaskWindow(),        vpiToolbar::setValue(Task, StatusField, vpitoolbar::text_value(Sel1)).       % Initialize status line.     initializeStatusLine(Text, StatusField) :-         Task = vpi::getTaskWindow(),         vpiToolbar::setValue(Task, StatusField, vpitoolbar::text_value(Text)).       % Display explanation of the control in focus in the status line.     explainInStatusLine(Dialog, Control, Explanation) :-         Task = vpi::getTaskWindow(),         DC=string::format("% %",Dialog,Control),         vpiToolbar::setValue(Task, resourceIdentifiers::idt_1, vpitoolbar::text_value(DC)),         vpiToolbar::setValue(Task, resourceIdentifiers::idt_help_line,vpitoolbar::text_value(Explanation)).       end implement myDialogTricks
TIA, Regards,
Frank Nagy
User avatar
Remuar
Posts: 4
Joined: 2 Dec 2012 18:29

Unread post by Remuar »

Hello Frank,

I start to go through the labyrinth of ViP and found your post interesting so I tryed to make it work, but no surprise, some infos are missing for a beginner like me....
Have you some hints how to test your "tricks"

thank's
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Test of my dialog tricks

Unread post by Ferenc Nagy »

Hi,
Suppose you have a table of data of N entries and 3 fields for each entries.
Yo can populate a list box control of N choices from the first fields, another list box of N choices from the second fields, and a third list box control from the third field. Suppose that data in the first field are strings having maximal length of 10 characters but the second a third fields may contain 50 characters.
You can scroll horizontally the second and the third list box. Anyway the code is much simpler than the grid example.
Make a dialog with the above three list boxes, three input boxes, an [Add], a [Delete], a [Modify] buttons.
TIA, Regards,
Frank Nagy
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Excerpt showing the usage of my dialog tricks

Unread post by Ferenc Nagy »

Hello Remuar,

I send you forms toolbars and modules from my program Solution of Alphametic Puzzles.
http://wiki.visual-prolog.com/index.php?title=3rd:SOAP
I hope this helps.
Attachments
myDialogTricks.zip
Usage of my dialog tricks. Excerpt from my program Solution of Alphametic Puzzles
(20.31 KiB) Downloaded 1615 times
Report form with synchronized list boxed
Report form with synchronized list boxed
Report window.png (46.31 KiB) Viewed 66622 times
TIA, Regards,
Frank Nagy
User avatar
Remuar
Posts: 4
Joined: 2 Dec 2012 18:29

Unread post by Remuar »

Hi Ferenc,

Thank's for your response but trying to build it (in 7.3 or 7.4) I got

error c100 : The file 'pfc\vpi\vpidialog\vpidialog.ph' is not found

so seems there is a lost file... do you know where to find it?
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Go back to 7.2

Unread post by Ferenc Nagy »

Remuar,
Go back to 7.2.
Try to find out from the

Code: Select all

pfc
folder of version 7.2 where it is.
Try to copy it to 7.3 or 7.4.
Report me the result.
TIA, Regards,
Frank Nagy
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Ask the gurus in the main forum

Unread post by Ferenc Nagy »

Thank's for your response but trying to build it (in 7.3 or 7.4) I got

error c100 : The file 'pfc\vpi\vpidialog\vpidialog.ph' is not found
Remuar,
1. Forget my previous answer.
2. Try

Code: Select all

simply pfc\vpi\vpi.ph
.
3. Ask the gurus on the main Visual Prolog Forum. I regret that the library of7.4 PE is truncated compared to 7.2 but dialog ought not to be omitted.
TIA, Regards,
Frank Nagy
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Look at my upgraded dialog tricks

Unread post by Ferenc Nagy »

I have upgraded my dialog tricks to 7.3. I wrote a test project and a slideshow showing the steps what I have done. http://franknagy.atw.hu/Tipp/dialogtricksdemo.zip
TIA, Regards,
Frank Nagy
User avatar
Thomas Linder Puls
VIP Member
Posts: 1442
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

Here it is updated it to 7.4 (without a fine slide show ;-)).
Attachments
dialogtricksdemo.zip
Tricks Dialog 7.4
(42.94 KiB) Downloaded 1636 times
Regards Thomas Linder Puls
PDC
User avatar
Remuar
Posts: 4
Joined: 2 Dec 2012 18:29

Unread post by Remuar »

Thank's Ferenc & Thomas,

But by now what i get as nothing todo with ur post from 22 Dec 2012 11:59

There is only one test "Kinks" I will investigate further tomorow...

good night

PS: your sugestion with
simply pfc\vpi\vpi.ph
give so much error I hat to abandon
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

A suggested last minute change

Unread post by Ferenc Nagy »

Remuar,
I hope that you understand the slide show and I need not to make another example form where

Code: Select all

  % Synchronize selection in two or more list boxes and the selection index in an integer control.     synchronizeListBoxesandInteger:(listBox Changed, listbox_list Followers, integercontrol) procedure (i,i,i).
is demonstrated.
I have worked enough on this demo. It is your turn to add the corresponding sultans of your country in a fourth list box and write an (n+1)th procedure which displays their picture and CV.
Don't forget to publish here your results.
....
Thomas,
I do not see to much differences within the program. OK.
A suggested last minute change
Let the font name and size not constants from task window but parameters of the redefineMessages procedure.
MyDialogTricks.cl

Code: Select all

predicates % [Re]Define Messages window. redefineMessages:(string FontName, positive Fontsize, positive Num_Msg_Lines) procedure (i,i,i).
MyDialogTricks.pro

Code: Select all

clauses     classInfo(className, classVersion). % This is the header of the implementation. % [Re]Define Messages window. redefineMessages(FontName,FontSize,Num_Msg_Lines) :-     TaskWindow=applicationWindow::get(),     MessageForm = messageForm::display(TaskWindow),     MessageForm:setVerticalSize(messageForm::parentRelative(1.0)),     MessageControl = MessageForm:getMessageControl(),     MessageControl:setLines(Num_Msg_Lines),     MessageControl:setFont(vpi::fontCreateByName(FontName, FontSize)).
Attachments
Differences found by the Total Commander.
Differences found by the Total Commander.
pick 002.png (3.34 KiB) Viewed 66470 times
TIA, Regards,
Frank Nagy
Post Reply