Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dialog box with Time out. ?
#1
Can I do a Yes/No Dialog box with a time out (say pick the default value if the user doesn't choose within a specific interval) ?
Reply
#2
(07-26-2024, 12:44 AM)ahenry3068 Wrote: Can I do a Yes/No Dialog box with a time out (say pick the default value if the user doesn't choose within a specific interval) ?
Sure. Pcopy your screen to another page, draw your dialog box and yes/no buttons, and then have code that checks for mouse input along with a timer. When the timer runs out Pcopy the other page back to your screen to remove the dialog box and choose the default value.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#3
Here is something I whipped up real quick to give you an idea of how to accomplish this.

Code: (Select All)
Inputbox = _NEWIMAGE(300, 100, 32)
_DEST Inputbox
CLS , _RGB32(255, 255, 255)
LINE (5, 5)-(294, 94), _RGB32(127, 127, 127), BF
' YES button
LINE (50, 55)-(100, 85), _RGB32(192, 192, 192), BF
LINE (52, 57)-(98, 83), _RGB32(64, 64, 64), BF
' NO button
LINE (200, 55)-(250, 85), _RGB32(192, 192, 192), BF
LINE (202, 57)-(248, 83), _RGB32(64, 64, 64), BF
' text
COLOR _RGB32(255, 255, 255), _RGB32(127, 127, 127)
LOCATE 2, 11: PRINT "Pete For President?";
COLOR _RGB32(255, 255, 255), _RGB32(64, 64, 64)
LOCATE 5, 9: PRINT "YES";
LOCATE 5, 28: PRINT "NO";

SCREEN _NEWIMAGE(640, 480, 32)
CLS
FOR i = 10 TO 640 STEP 20 '      awesome background
    FOR j = 10 TO 480 STEP 20
        CIRCLE (i, j), 10
NEXT j, i
SLEEP 2
PCOPY 0, 1 '                     save current screen
Frames = 0
Answer$ = ""
DO '                                 display inputbox and get input
    _LIMIT 10
    WHILE _MOUSEINPUT: WEND
    _PUTIMAGE (170, 100), Inputbox ' restore inputbox image
    x = _MOUSEX: y = _MOUSEY
    IF x >= 220 AND x <= 270 AND y >= 155 AND y <= 185 THEN ' mouse over YES button
        LINE (220, 155)-(270, 185), _RGB32(0, 0, 0), B
        IF _MOUSEBUTTON(1) THEN Answer$ = "YES"
    END IF
    IF x >= 370 AND x <= 420 AND y >= 155 AND y <= 185 THEN ' mouse over NO button
        LINE (370, 155)-(420, 185), _RGB32(0, 0, 0), B
        IF _MOUSEBUTTON(1) THEN Answer$ = "NO"
    END IF
    Frames = Frames + 1
    _DISPLAY
LOOP UNTIL Answer$ <> "" OR Frames = 50 ' 5 second timer
_AUTODISPLAY
PCOPY 1, 0 '                              restore screen
IF Frames = 50 THEN Answer$ = "YES"
SLEEP 2
CLS
PRINT
PRINT " The chosen button was "; Answer$
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#4
I found one error in Terry's code...


Code: (Select All)
LOCATE 5, 28: PRINT "NO";
Change to...


Code: (Select All)
LOCATE 5, 28: PRINT "HELL YES";
Other than that, it looks good! Big Grin

Basically the IDE uses this pcopy method for all of the drop-down menus. Things that take very creative solutions are timers for INPUT and _MESSAGEBOX. These pause your program until a reply is made. The way around that is to make two programs. Program 1 calls the second _MESSAGEBOX program via a SHELL statement. When the timer in program 1 runs out, the message box is terminated by a SHELL to TASKKILL. You also need a small database to communicate, or a TCP/IP connection. _SCREENHIDE, Win32 AP minimization, etc. can be used to make it seem like only one program is running.
 
Pete
Reply
#5
You could do task dialogs, too.
Tread on those who tread on you

Reply
#6
it could probably be done with _messagebox. if the user didn't have to supply an answer, then _notifydialog is good enough.

if not, on linux could use Zenity or probably Yad.

Yad is more complicated for me.

either one is an external separate program which will require using shell _hide.

this is from man zenity. the last item has the most interest.

Quote:General options

--title=TITLE
  Set the dialog title

--window-icon=ICONPATH
  Set the window icon with the path to an image. Alternatively, one of the four stock
  icons can be used: 'error', 'info', 'question' or 'warning'

--icon-name=ICONNAME
  The name of the icon to display on the dialog to override the default stock icons

--width=WIDTH
  Set the dialog width

--height=HEIGHT
  Set the dialog height

--timeout=TIMEOUT
  Set the dialog timeout in seconds
also the type of dialog. (choose yes or no)

Quote:--question
        Display question dialog
one disadvantage is that Zenity might not be installed with linux distribution "by default." Yad is present in even fewer distributions such as endeavouros.
Reply




Users browsing this thread: 3 Guest(s)