Topic: "Dialogs" in AppGraphics

As a simple example, I've written an example of how one might create a Windows-dialog-like experience using AppGraphics since there were multiple requests:

https://approximatrix.files.wordpress.com/2015/03/convert.png

The example is rather straightforward.  Hopefully this write-up will help some users get started with AppGraphics.  You can see the entire example, along with an explanation, at our Development Blog.  There is a link to the complete code at the bottom of the page.  I'll try to start making more posts there with some useful examples.

EDIT: A quick note to our users - to run the example, you'll need Simply Fortran 2.21 Build 1837 or higher.

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Good Job and Thanks

Re: "Dialogs" in AppGraphics

Hi Jeff,

Would it be possible to use AppGraphics to create a windows dialog as a 'progress bar' such that within a loop the progress bar expands after each iteration, or is this beyond the capability of AppGraphics?

The purpose is to maintain a visual of a active routine while it's running in the background.  Another addition would be to add a 'quit' or 'exit' button to the progress bar to prevent infinite loops.

If AppGraphics has such a capability, could you explain by example?

Frank

Re: "Dialogs" in AppGraphics

Frank,

You could certainly do something like you're describing.  The progress bar would have to be "self-drawn" since we don't have a ready-to-go progress bar.  However, creating a progress bar is relatively easy.  MATLAB actually does this as well; their progress bars (at least historically) are drawn as rectangles that are slowly expanding.

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Frank,

I've posted an example of a progress bar:

https://approximatrix.wordpress.com/201 … pgraphics/

You can download the source code at the end of the article.

Let me know if the above is what you had in mind.

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Jeff,

This is an outstanding example of a very functional progress bar.
I believe users of SF will find this small dialog routine extremely useful.
So many of my SF programs have routines in large iterative Do-Loops, and your Progress Bar is just the visual ticket needed to notify the user that an application is still running (crunching numbers) in the background.

Thank you for your time and creativity in developing this very function routine.

Sincerely,
Frank

Re: "Dialogs" in AppGraphics

I am new in graphics and can't write a routine to plot graphics. Do you have an example of the instruction set to make a plot of an equation or point data? Thanks.

Re: "Dialogs" in AppGraphics

Creating a plot of an equation or point data would probably best be handled by a dedicated library like PLPlot.  AppGraphics certainly can be used to create a plotting routine, but a general purpose plotting library tends to become quite complex quickly.

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Hi Jeff,
First of all the best wishes to the Approximatrix  crew and thanks for the fantastic tool SF!
Next there is a nice dialog dlgopenfile. I use it to open an file and also to select a directory by users. What I did not know is that this dlg also changes the working directory by this selection. I have to keep the first start up directory for use of some system settings in a new variable. The reason is that I have to make my program portable to other computers and other drives and directories. This can be done with the GNU intrinsic procedure getcwd. Is this the best solution or do you have an other suggestion?

Re: "Dialogs" in AppGraphics

Jeff,
Meanwhile I created a lot of dlg's and I am using common dlg's also like Dlgmessage.
First question regarding common dlg's especially Dlgmessage: a hit causes a beep or bell. Can I avoid it because not everyone likes my beeps.
Second question: In a dlg with several input boxes I want to switch to the next input item by tab or enter in stead to change box by mouse click only. Is must be possible, but do you have an example how to do it?
Regards, Klaus

Re: "Dialogs" in AppGraphics

Klaus,

I had thought I had answered your first question in the past, but perhaps I missed it.  The GETCWD intrinsic, while not part of the Fortran standard, is probably your best option.  There is no portable way to truly do what you asked.

I'll look into the beep, but I fear it is caused by windows itself.  The dlgmessage routine is a thin wrapper around the Windows MessageBox API call.

In regards to tabbing, supporting it would require a change to AppGraphics, but it should work.  I'll see that it is fixed.  The default would be to tab through controls in the order they are added.  Does that make sense?  Changing the order would definitely be non-trivial.

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Thanks Jeff,
GETCWD I had to apply several times and it's working fine! One reason is the GNU interpretation of  INQUIRE:
If the current working directory is changed to a sub directory the following is not working unless Path... is starting with the root i.e. C: 
    INQUIRE (   file = PATH120(:le), EXIST=EX)     !testing generally a file not a map or directory
    If(.not.EX)then
        call execute_command_line ("md"//path120(:le), exitstat=i,CMDSTAT=isys, CMDMSG=msg )
..........
But is is a GNU matter and it's important for programmers to realize in which directory the program is currently working

The tabbing order in dlg's is no problem for me. I suppose the same order as the ranking of input boxes !? The changing of the order as we know from CVF is not necessary

The matter of the beeps I made to a lower priority. later I will see what to do in windows.
Klaus

Re: "Dialogs" in AppGraphics

Hi Jeff,
Something is wrong with my design of a new dialog, but what ???
I declared some text boxes and check boxes as follows:

SUBROUTINE CSp_item_dlg
USE Appgraphics
use StrPartGlobals      ! contains declaration of derived parts
use W_ords_to_pixels    ! need because procedures in StrPartGlobals
    CHARACTER*4     STR(12)
    CHARACTER*4     STRG
    INTEGER dlg_screen, primary_fr
    integer box1, box2, box3, box4, box5, box6, box7, box8, box9, box10
    integer cbox1,cbox2
    integer Ignore, contin, settype
    logical*1 checked(3)
    Data checked/ 3*.false./
    external part_type_dlg
…...
…...test data....
…...
After setting the dlg window text and boxes are defined as follows:

settype = createbutton(315,20,70,20,"type", part_type_dlg)
  Call outtextxy(10, 20,'Title')
  box1 = createtextbox(10, 40, 180,16);    call Settextboxcontents(box1,CSP(isp)%title)     !Box1

  Call outtextxy(200, 20,'property')
  box2 = createtextbox(200, 40, 100,16);    call Settextboxcontents(box2,CSP(isp)%prop)     !box2
  Call outtextxy(310, 40,'(mm or profile)')

  Call outtextxy(10,60,'corrosion allowance')
  box3 = createtextbox(135, 60, 65,16);   call Settextboxcontents(box3,str(6))              !box3 -str(6)
  Call outtextxy(200, 60,'mm')

  Call outtextxy(10,80,' Material quality:')
  box4 = createtextbox(130, 80, 65,16);   call Settextboxcontents(box4,CSP(isp)%grd)        !box4

  Call outtextxy(10,100,'Part is on frame:')
  box5 = createtextbox(130, 100, 40,16);   call Settextboxcontents(box5,str(2))             !box5

  Call outtextxy(180,100,'Primary frame:');Write(strg,'(i4)')primary_fr
  box6 = createtextbox(270, 100, 40,16);   call Settextboxcontents(box6,strg)               !box6
  !preliminary to be found from the repeat rules

  Call outtextxy(10,120,'number of parts P+S:')
  box7 = createtextbox(130, 120, 40,16);   call Settextboxcontents(box7,str(3))             !box7

  Call outtextxy(10,140,'conection poin 1:')
  box8 = createtextbox(130, 140, 40,16);   call Settextboxcontents(box8,str(4))             !box8

  Call outtextxy(10,160,'conection poin 2:')
  box9 = createtextbox(130, 160, 40,16);   call Settextboxcontents(box9,str(5)) !if plate, otherwise disableed

  Call outtextxy(10,180,'profile rotation:')
  box10= createtextbox(130, 180, 40,16);   call Settextboxcontents(box10,str(5))!if profile, otherwise disableed

  cbox1 = createcheckbox (180,  180, 200,20,'Mirror x-dir', update1)
  cbox2 = createcheckbox (280,  180, 250,20,'Mirror y-dir', update2)

  Call checkboxsetchecked (cbox1,checked(1)) 
  Call checkboxsetchecked (cbox2,checked(2))

  Call outtextxy(10,200,'profile rotation anti clockwize against upright position')
  Call outtextxy(10,280,'Parts on current frame are repeated on every frame exept primary frame')

!___________ enable / disable parts depending on type ____________________
  Call enabletextbox (box6, .false.) !______________ also disable primary frame / no user input
select case (CSP(isp)%typ)
    CASE (101,111)
    Call enabletextbox (box10, .true.) !if plate
    Call enabletextbox (box9, .false.)  !if profile
CASE default
    Call enabletextbox (box9, .true.)!true.)
    Call enabletextbox (box10, .false.) !if plate
end select

    contin = createbutton(15,420,50,20,"OK", cont)
    Ignore = createbutton(65,420,50,20,"cancel", quit_dlg)
call loop
Call closewindow(CURRENT_WINDOW)
Call setcurrentwindow (initW)

Three odd behaviors:
Now Box 6 has to be disabled but the test program shows box 5 disabled
Independent on part type always Box9 is disabled
At least  only chekbox 1 can be checked/unchecked
There must be something wrong with the box numbers I suppose. But I cannot find what.
Debugging shows  12 unique numbers for all boxes!
Do you have any suggestion what I am doing wrong?

Re: "Dialogs" in AppGraphics

Klaus,

Looking at the code, I don't see anything wrong.  It sounds like the internal AppGraphics arrays are being corrupted somehow as more items are added, which would explain why the wrong controls are being enable/disabled. Let me try some more complicated examples on my end to see if I can replicate this issue.

Jeff Armstrong
Approximatrix, LLC

15 (edited by jeff 2017-03-02 16:03:54)

Re: "Dialogs" in AppGraphics

Klaus,

I've started debugging your issues, and I can address at least one of your problems immediately.  You described that only one check box can be checked/unchecked by the user.  This behavior is because of the width you've specified for both check boxes.  The first checkbox, cbox1, measures 200 pixels wide, meaning it is actually taking up space from x=180 to x=380.  The second check box, though, is being placed in this same space, at x=280.  I think your problem should go away if you change the code to:

    cbox1 = createcheckbox (180,  180, 99,20,'Mirror x-dir', update1)
    cbox2 = createcheckbox (280,  180, 99,20,'Mirror y-dir', update2)

Additionally, the overlap had caused drawing issues on Windows 10, but the above change fixes that as well.

I'm still looking at the incorrect box enable/disable behavior you're describing.

EDIT: added your callbacks to the checkbox changes that I had deleted in my code

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Klaus,

There is a bug in the windows controls enable/disable code that causes the identifier to improperly map to a memory pointer internal to the library.  The problem wouldn't occur if you, for example, added all your text boxes to the window first, then added any other controls.  It's a sneaky, little bug.

I'll have a new Windows build available tomorrow fixing the issue, and I'll post here as soon as its available.

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Thanks Jeff,
The check box problem is fixed with your advice.

Klaus

Re: "Dialogs" in AppGraphics

Klaus,

Build 2396 is now available that should fix the enable/disable bugs you've described.  Let me know if you run into any issues.

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Thanks Jeff,
I shall try it asap, but:
Unfortunately an other problem occurred: After installing version 2.35 all returns from child windows did no longer work unless that there was nothing changed! Sometimes a message came that there was no graphic window open or graphics where shown in an window for other tasks.
After reloading update 2.33 everything did it as suspected.
What is wrong? Is it a bug?  Ore have I to recompile all libraries  with 2.35 again??
Klaus

Re: "Dialogs" in AppGraphics

Klaus,

I'll have to look into it.  I don't know why anything concerning windows would have broken between 2.33 and now.

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Jeff,
Here is additional info:
I installed 2.35 latest version again!
Without recompiling the main program, every thing is working well; after clean/rebuild the following happens:
The change of different windows with menus is OK. Even some dlg windows, but some others will not return to the calling procedure, i.e. my edit sheet; there is no more response; but it did work in2.33!
I shall look into my edit sheet and make an overview about all not working child windows. First question: is the ESC key working well; because he is the exit of my edit sheet.
Regards, Klaus

Re: "Dialogs" in AppGraphics

Jeff,
May be this leads to the source where it went wrong: I did check the whole program and found that directly only my edit sheet is not more working as suspected: After entering the sheet only the mouse is active in select a cell. No key of the keyboard gives response until the mouse is moved. After that <ESC> causes a duplicate of the current line instead of exit the sheet.
May be any thing is going wrong with threads????
regards Klaus

Re: "Dialogs" in AppGraphics

Klaus,

There is currently a major bug in message processing in AppGraphics that came about as a result of our adding the ability to tab between controls. We've fixed the basic issue, but the change is clobbering arrow keys (and possibly others) within an AppGraphics program.  We're working to fix everything, but I suspect that change is the origin of your problem.

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Klaus,

There is a new build (2398) of version 2.35 that should fix your new issue.  However, by default, you cannot tab between text boxes, buttons, etc.  You'll first need to call a new subroutine setdialoghotkeys(.TRUE.) to enable dialog-like behavior.  The reason for the new call is that enabling dialog hotkeys will basically consume all tab and arrow key presses, which some AppGraphics programs may not like.

Let me know if your issues persist.

Jeff Armstrong
Approximatrix, LLC

Re: "Dialogs" in AppGraphics

Thanks Jeff!!!
It's OK! I had to clean and recompile the main program for good working. I suppose that it should be wise to recompile all my libraries also with the new version (2398).
The CAll setdialoghotkeys(.TRUE.) i am testing in a project where i am building and testing dialogs prior to use it in the main program. I suppose that i have to call setdialoghotkeys(.false.) prior to closing the dlg window.

Klaus