Sign in to follow this  
Followers 0
PerryRaptor

Creating A Checklist & Answer System With Icons

5 posts in this topic

#1 ·  Posted (edited)

I want to create a checklist using GUICtrlCreateListView() and want to do two things.

1...I would like the full text of the question to appear below the GUICtrlCreateListView() box in the same GUI

2...I would like three buttons below the full text that will update column 2 in GUICtrlCreateListView() with either "PASS", "FAILED", or "OPERATION" without quotes of course.

The questions are in a *.txt file, one question per line. I would like to use the "|" charactor as the delimiter so that the question may contain commas, semicolons, and other puctuation.

Later, I would like to explore XML and HTML creating the report with a list of all of the questions. Instead of using "PASS" I would like to use a green circle with a white checkmark in it. For "FAILED" I would like to use a red circle or stop sign with a white "X" in it. Last, for "OPERATION" I would like to use a yellow circle :(

I will be creating functions to handle FileReadLine(), FileWriteLine(), FileOpenDialog(), FileSaveDialog(), FileSelectFolder() to open, read, and write a new *.txt file with the questions and the answers in it.

It would be cool if I could use emicons such as :) for "Failed", :think: for "operation", and ;) for "Pass" in the GUICtrlCreateListView() and in XML, but I don't know if it is possible.

Edited by PerryRaptor

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here's my start of code...I know...I know... I'm a slow coder!

#include <GUIConstants.au3>
#include <File.au3>

$in_filename = "Q_and_A.txt"
$file = FileOpen($in_filename, 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to locate or open Question / Answer File")
    Exit
EndIf
FileClose($file)

Dim $lines,$listview
_FileReadToArray($in_filename, $lines)
$Columns = StringSplit($lines[1], "|")
Dim $array[ $lines[0] ][ 3 ]
For $i = 1 To $lines[0]
    $Columns = StringSplit($lines[$i], "|")
    If $Columns[0] = 1 Then Continueloop
    For $j = 1 To $Columns[0]
        $array[$i-1][$j-1] = $Columns[$j]
    Next
Next
Refresh()
What()
Func What()
$timeDate = @HOUR & ":" & @MIN & ":" & @SEC & "  --  " & @MON & "/" & @MDAY & "/" & @YEAR
GUICreate("Question & Answer  --  " & $TimeDate,500,420,100,200,BitOr($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU),$WS_EX_ACCEPTFILES)
$listview = GuiCtrlCreateListView ("Question        |Answer      |Correct Y/N       ",0,0,500,300)
GUISetFont(12,600)
$Refresh = GuiCtrlCreatebutton("Refresh", 0, 300, 500, 25)
GUISetFont(11,500)
GUICtrlCreateLabel ( "...Full Text of Question Goes Here...", 10 , 330 , 490, 30)
GUISetFont(12,600,2,"Monotype Corsiva")
GUICtrlCreateLabel ( "version 0.0.0 by PerryRaptor",145,395,200,40)

For $i = 1 To $lines[0]

  GuiCtrlCreateListViewItem($array[$i-1][0] & "|" & $array[$i-1][1] & "|" & $array[$i-1][2],$listview)
Next

GuiCtrlSetState(-1,$GUI_DROPACCEPTED)
GuiSetState()

While 1
  $msg = GUIGetMsg()
  If $msg = $Listview Then MsgBox(0,"Q and A", "...help goes here... " & GuiCtrlGetState($listview),2)
  If $msg = $Refresh Then Step2()
;  If $msg = $Question Then GUICtrlCreateLabel ( "...Full Text of Question Goes Here...", 10 , 330 , 490, 30)
  If $msg = $GUI_EVENT_CLOSE then Exit
;  Select
;   Case $msg = $listview
;        MsgBox(0,"Header", "clicked="& GuiCtrlGetState($listview),2)
;   Case $msg = $Refresh
;        GuiDelete()
;        Refresh()
;  EndSelect
; Until $GUI_EVENT_CLOSE
Wend
EndFunc

Func Refresh()

ProgressOn("Q and A", "Updating System" & $lines[0],"0 percent")
$pbar = 3 
For $i = 1 To $lines[0]
    sleep(300)
    ProgressSet( $pbar, $pbar & " percent")
;  <.................................................................................>
;  <..............   I'm working right here now ..................................>   
;  <.................................................................................>
    $pbar = $pbar + Int(100 / $lines[0])
Next
$pbar = 100
Sleep(300)
ProgressOff()
What()
EndFunc

Func Step2()
GuiDelete()
Refresh()
EndFunc

Here is the contents of the file Q_and_A.txt

How many pecks of peppers did Peter Piper pick?|pass
You've attempted to code something in AutoIT and have hurt yourself.  Did you call a Doctor?| Failed
Obviously you've spent far too much time on AutoIT Forums. Did you get an Operation?|Operation 
How much longer will we need to wait until a new AutoIT version comes out?|soon
Edited by PerryRaptor

Share this post


Link to post
Share on other sites

Okay...I'm thinking about using GUICtrlCreateTreeView() instead of GuiCtrlCreateListView()...

I'm thinking it will be better; in case the question count is 50+

Share this post


Link to post
Share on other sites

; Events - ListView
#include <GuiConstants.au3>;Inclusion file for the GUI interface controls
#include <GuiListView.au3>
#include <File.au3>

Global $ListView
Global Const $WM_NOTIFY = 0x004E
Global Const $DebugIt = 0
Global $lbl_question

;ListView Events
Global Const $NM_FIRST = 0
Global Const $NM_LAST = (-99)
Global Const $NM_OUTOFMEMORY = ($NM_FIRST - 1)
Global Const $NM_CLICK = ($NM_FIRST - 2)
Global Const $NM_DBLCLK = ($NM_FIRST - 3)
;~ Global Const $NM_RETURN = ($NM_FIRST - 4)
;~ Global Const $NM_RCLICK = ($NM_FIRST - 5)
;~ Global Const $NM_RDBLCLK = ($NM_FIRST - 6)
;~ Global Const $NM_SETFOCUS = ($NM_FIRST - 7)
;~ Global Const $NM_KILLFOCUS = ($NM_FIRST - 8)
;~ Global Const $NM_CUSTOMDRAW = ($NM_FIRST - 12)
;~ Global Const $NM_HOVER = ($NM_FIRST - 13)
;~ Global Const $NM_NCHITTEST = ($NM_FIRST - 14)
;~ Global Const $NM_KEYDOWN = ($NM_FIRST - 15)
;~ Global Const $NM_RELEASEDCAPTURE = ($NM_FIRST - 16)
;~ Global Const $NM_SETCURSOR = ($NM_FIRST - 17)
;~ Global Const $NM_CHAR = ($NM_FIRST - 18)
;~ Global Const $NM_TOOLTIPSCREATED = ($NM_FIRST - 19)
#endregion End Global variables

$in_filename = "Q_and_A.txt"
$file = FileOpen($in_filename, 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to locate or open Question / Answer File")
    Exit
EndIf
FileClose($file)

Dim $lines, $ListView
_FileReadToArray($in_filename, $lines)
$Columns = StringSplit($lines[1], "|")
Dim $array[ $lines[0] ][ 3 ]
For $i = 1 To $lines[0]
    $Columns = StringSplit($lines[$i], "|")
    If $Columns[0] = 1 Then ContinueLoop
    For $j = 1 To $Columns[0]
        $array[$i - 1][$j - 1] = $Columns[$j]
    Next
Next
Refresh()
What()

Func What()
    $timeDate = @HOUR & ":" & @MIN & ":" & @SEC & "  --  " & @MON & "/" & @MDAY & "/" & @YEAR
    GUICreate("Question & Answer  --  " & $timeDate, 500, 420, 100, 200, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_ACCEPTFILES)
    $ListView = GUICtrlCreateListView("Question     |Answer      |Correct Y/N       ", 0, 0, 500, 300)
    GUISetFont(12, 600)
    $Refresh = GUICtrlCreateButton("Refresh", 0, 300, 500, 25)
    GUISetFont(11, 500)
    $lbl_question = GUICtrlCreateLabel("...Full Text of Question Goes Here...", 10, 330, 490, 30)
    $btn_pass = GUICtrlCreateButton("Pass",10,365,90,25)
    $btn_failed = GUICtrlCreateButton("FAILED",110,365,90,25)
    $btn_operation = GUICtrlCreateButton("OPERATION",210,365,90,25)
    GUISetFont(12, 600, 2, "Monotype Corsiva")
    GUICtrlCreateLabel("version 0.0.0 by PerryRaptor", 145, 395, 200, 40)
    For $i = 1 To $lines[0]
        
        GUICtrlCreateListViewItem($array[$i - 1][0] & "|" & $array[$i - 1][1] & "|" & $array[$i - 1][2], $ListView)
    Next
    
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    GUISetState()
    
;Register WM_NOTIFY  events
    GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
    
    While 1
        
        $msg = GUIGetMsg()
        
        Switch $msg
            
        ;-----------------------------------------------------------------------------------------
        ;This case statement exits and updates code if needed
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Refresh
                Step2()
            Case $btn_pass
                _GUICtrlListViewSetItemText($ListView,Int(_GUICtrlListViewGetSelectedIndices($ListView)),1,"Pass")
            Case $btn_failed
                _GUICtrlListViewSetItemText($ListView,Int(_GUICtrlListViewGetSelectedIndices($ListView)),1,"Failed")
            Case $btn_operation
                _GUICtrlListViewSetItemText($ListView,Int(_GUICtrlListViewGetSelectedIndices($ListView)),1,"Operation")
            ;-----------------------------------------------------------------------------------------
            ;put all the misc. stuff here
            Case Else
            ;;;
        EndSwitch
    WEnd
EndFunc  ;==>What

Func Refresh()
    
    ProgressOn("Q and A", "Updating System" & $lines[0], "0 percent")
    $pbar = 3
    For $i = 1 To $lines[0]
        Sleep(300)
        ProgressSet($pbar, $pbar & " percent")
    ;  <.................................................................................>
    ;  <..............   I'm working right here now ..................................>
    ;  <.................................................................................>
        $pbar = $pbar + Int(100 / $lines[0])
    Next
    $pbar = 100
    Sleep(300)
    ProgressOff()
    What()
EndFunc  ;==>Refresh

Func Step2()
    GUIDelete()
    Refresh()
EndFunc  ;==>Step2


Func ListView_Click()
    GUICtrlSetData($lbl_question,_GUICtrlListViewGetItemText($ListView, Int(_GUICtrlListViewGetSelectedIndices($ListView)),0))
;----------------------------------------------------------------------------------------------
    If $DebugIt Then    ConsoleWrite (_DebugHeader("$NM_CLICK"))
;~  MsgBox(0, "Q and A", "...help goes here... " & GUICtrlGetState($ListView), 2)
;----------------------------------------------------------------------------------------------
EndFunc  ;==>ListView_Click

Func ListView_DoubleClick()
;----------------------------------------------------------------------------------------------
    If $DebugIt Then    ConsoleWrite (_DebugHeader("$NM_DBLCLK"))
;----------------------------------------------------------------------------------------------
;~  MsgBox(0, "Double Clicked", _GUICtrlListViewGetItemText($ListView, _GUICtrlListViewGetSelectedIndices($ListView)))
EndFunc  ;==>ListView_DoubleClick

;
; WM_NOTIFY event handler
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Select
        Case $wParam = $ListView
            Select
                Case $event = $NM_CLICK
                    ListView_Click()
                Case $event = $NM_DBLCLK
                    ListView_DoubleClick()
            EndSelect
    EndSelect
    $tagNMHDR = 0
    $event = 0
    $lParam = 0
EndFunc  ;==>WM_Notify_Events

Func _DebugHeader($s_text)
    Return _
            "!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF
EndFunc  ;==>_DebugHeader


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Thanks a million Gary,

Do you have a moment to explain how you came about the Function WM_Notify_Events() and the value for $WM_NOTIFY = 0x004E. I've gone through it a couple of times, but I still do not understand how or why it works.

...And I'm in the same boat with the function _DebugHeader(). I'm thinking this is writing something to the console. I quess it returns if it was a single or double click.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0