Sign in to follow this  
Followers 0
UnknownWarrior

Type in a GUI?

11 posts in this topic

#1 ·  Posted (edited)

Can this be accomplished using an InputBox?

I did try adjusting the height of the InputBox through Koda, and it would only do the width... It wouldn't allow it to be adjusted higher.

I'm sure with plain coding it can be done (as that is a function in the GUICtrlCreateInput).... But is this the best route to go?

Can you press Enter and type another line in the Input box like you would on a standard Notepad file?

*My plan for this is to create a nice little GUI that translates 'noob' language into AutoIt language... So if someone typed in:

If red appears at 300, 300 Then
LeftClick red
EndIf

Which it would have each word broken down into a translation to AutoIt code, etc etc.

Thanks for any advice :)

Edited by UnknownWarrior

Share this post


Link to post
Share on other sites



guictrlcreateedit() ?

Share this post


Link to post
Share on other sites

*My plan for this is to create a nice little GUI that translates 'noob' language into AutoIt language... So if someone typed in:

If red appears at 300, 300 Then
LeftClick red
EndIf

Which it would have each word broken down into a translation to AutoIt code, etc etc.

Thanks for any advice :)

Good luck with that. There are way tooooo many variables with what a newbie can type in.

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

guictrlcreateedit() ?

Hmm... I shall check that out.

Worked like a charm using $ES_WANTRETURN (So Enter could be pressed, etc)

Good luck with that. There are way tooooo many variables with what a newbie can type in.

8)

Yes of course, but in time adding maybe 5 keywords in a day to the database of translations... It would be a lot of beginning AutoIt covered with 'nooby' language.

And it will have each of these words on a side ComboList so they can just double click those and it inserts them into the code for them. (And also so they can just read what functions there are available)

Edited by UnknownWarrior

Share this post


Link to post
Share on other sites

Now, any ideas on how to READ what a user types in there? I just tried a simple MsgBox to read the first line of the GUIEdit, but it kept returning '3' to me lol... No idea where that came from...

Share this post


Link to post
Share on other sites

Here, you can even ask what you want to...

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#Include <GuiEdit.au3>
#include <date.au3>
#include <Array.au3>
#include <Color.au3>

opt("GUIOnEventMode", 1)

Demo()




Exit
;------------------------------------------------------------------------------------------------------
;-                                      C O N S O L E   D E M O
;------------------------------------------------------------------------------------------------------
Func Demo()
    Global $ConsoleID=0
    Global $about = StringSplit("*** Autoit Means ***,,Appreciation, Application, Amazing, Automation, Admirable, Awesome, Astonishing, Advanced, Academic," & _ 
    "Utility, Understandable, Unselfish, Unmatched, Universal, Unparalleled, Useful, Unequaled, Unique, Unsurpassed, Unlimited," & _ 
    "Thorough, Thoughtful, Timeless, Terrific, Tremendous, Transforming, Transcending, Topless," & _ 
    "Overriding, Outstanding, Overwhelming, Outdone, Overpowering, Originality, Overshadow, Overruling, Outshining, Overtaking, Outperform," & _ 
    "Inventiveness, Interactive, Intellectual, Incredible, Interface, Innovation, Imagination, Initiative, Impressive, Inspiring, Incomparable," & _  
    ".............................., A U T O I T,....................., , , , Thank you Jon!!!!,,Have a Wonderful Day!!!", ",")
    $about[0] = ""
    $ConsoleID = ConsoleWinCreate(-1, -1, 638, 326, "Age Demo...", "Starting demo..." & @CRLF, True)
    $answer1 = ConsoleWinInput($ConsoleID, "Please input your Year of Birth (example.. 1985) ?", 15, 1 )
    $Vanswer1 =ConsoleWinVerify($ConsoleID, $answer1, "Please input your Year of Birth (example.. 1985) ?", True, 4, 4) 
    ConsoleWinWrite($ConsoleID, "OK.. " & @CRLF, 30, 1)
    $answer2 = ConsoleWinInput($ConsoleID, "Please input your Month of Birth (example.. 3 = March) ?", 45, 1 )
    $Vanswer2 =ConsoleWinVerify($ConsoleID, $answer2, "Please input your Month of Birth (example.. 3 = March) ?", True, 1, 2) 
    ConsoleWinWrite($ConsoleID, "Good.. " & @CRLF, 60, 1)
    $answer3 = ConsoleWinInput($ConsoleID, "Please input your Day of Birth (ex.. 22) ?" , 75, 1 )
    $Vanswer3 =ConsoleWinVerify($ConsoleID, $answer3, "Please input your Month of Birth (example.. 22) ?", True, 1, 2) 
    ConsoleWinWrite($ConsoleID, "Great!.. Please wait while i calculate your age..." & @CRLF, 90, 1)
    Sleep(1000)
    ConsoleWinWrite($ConsoleID, " You have been alive " & _DateDiff( 'd',$Vanswer1 &"/"& $Vanswer2 &"/"& $Vanswer3,_NowCalc()) & " days!" & @CRLF, 100, 1)
    Sleep(5000)
    ;ConsoleWinWrite($ConsoleID, "Example: Clearing console in five seconds...Thanks Valuater 8) ")
    ;Sleep(5000)
    ;ConsoleWinClear($ConsoleID)
    ;ConsoleWinWrite($ConsoleID, "Demo finished! Exiting in five seconds...")
    Sleep(5000)
    ;Exit
    _txt_eff__about_messages ($ConsoleID, $ConsoleID[1], $about, 5, 10, 1, "modern") ; "raining", "right_to_left", "left_to_right", "right_to_right", "left_to_left", "enlarge_left", "enlarge_right", "modern"

ConsoleSpeak("Hayy, Birthday!, John!")
EndFunc

;------------------------------------------------------------------------------------------------------
;-                                      C O N S O L E   L I B R A R Y  
;------------------------------------------------------------------------------------------------------

;===============================================================================
; Description:      Create a Window console to display status text information with history
; Parameter(s):     $x                - x position of the window
;                    $y                - y position of the window
;                    $width            - Optional - Window width
;                    $height            - Optional - Window height
;                    $Title            - Optional - Console Window title
;                    $text            - Optional - Initial text to display.
;                    $CreateProgress    - Optional - Create Progress (True/False)
;                    $BgColor        - Optional - background color
;                    $FgColor        - Optional - Foreground color
;                    $Transparency    - Optional - Transparency (0=Invisible, 255=Visible)
; Requirement(s):   None
; Return Value(s):  The Console ID
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinCreate($x, $y, $width=638, $height=126, $Title="Console", $Text="", $CreateProgress=False, $BgColor=0xFFFFFF, $FgColor=0xFF0000, $Transparency=255)
    Dim $Console[3]
    $Console[0] = GuiCreate($Title, $width, $height, $x, $y, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "ConsoleWinExitEvent")
    If $CreateProgress Then $height -= 20
    $Console[1] = GuiCtrlCreateEdit($Text & @CRLF, 0, 0, $width-1, $height-1, BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL))
    GUICtrlSetBkColor($Console[1],    $BgColor)
    GUICtrlSetColor($Console[1],    $FgColor)
    GUICtrlSetResizing($Console[1],    $GUI_DOCKBORDERS)
    GUICtrlSetFont($Console[1], 12, 400, 0, "Courrier New")
    $Console[2] =0
    If $CreateProgress Then $Console[2] = GUICtrlCreateProgress(0, $height+5, $width-1, 12)
    WinSetTrans($Console[0], "", $Transparency)
    GuiSetState()
    Return $Console
EndFunc

Func ConsoleWinExitEvent()
    GUIDelete(@GUI_WinHandle)
    Exit
EndFunc

;===============================================================================
; Description:      Write a message to the console
; Parameter(s):     $ConsoleID        - Console ID returned by ConsoleWinCreate
;                    $text            - Text to display.
;                    $Progress        - Optional - Progress value (0-100)
;                    $NoCRLF            - Optional - Don't add CRLF and the end of text
;                    $Replace        - Optional - Replace last line
; Requirement(s):   ConsoleWinCreate called first
; Return Value(s):  None
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinWrite($ConsoleID, $Text, $Progress=-1, $Speak=False, $NoCRLF=False, $Replace=False)
    If $Replace Then
        $string = GUICtrlRead($ConsoleID[1])
        $pos = StringInStr($string, @CRLF, 0, -1)
        If $pos > 0 Then $pos += 1
        $end = StringLen($string)
        _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $end)
    Else
        $pos = StringLen(GUICtrlRead($ConsoleID[1]))
        _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos)
    EndIf
    If $NoCRLF = False Then $Text = $Text & @CRLF
    GUICtrlSetData ($ConsoleID[1], $Text, 1)
    If $Speak Then ConsoleSpeak($Text)
    If $ConsoleID[2] >0 And $Progress>=0 Then GUICtrlSetData($ConsoleID[2], $Progress)
EndFunc

;===============================================================================
; Description:      Ask for the user to input something
; Parameter(s):     $ConsoleID        - Console ID returned by ConsoleWinCreate
;                    $text            - Text to display, the question.
;                    $Progress        - Optional - Progress value (0-100)
; Requirement(s):   ConsoleWinCreate called first
; Return Value(s):  What user have typed.
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            $text could be an empty string
;===============================================================================
Func ConsoleWinInput($ConsoleID, $Text, $Progress=-1, $Speak = 0)
    WinSetOnTop($ConsoleID[0], "", 1)
    WinActivate($ConsoleID[0])
    $string = GUICtrlRead($ConsoleID[1])
    $pos = StringLen($string)
    _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos)
    GUICtrlSetData ($ConsoleID[1], $Text, 1)
    GUICtrlSetStyle($ConsoleID[1], BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_WANTRETURN))
    If $Speak Then ConsoleSpeak($Text)
    If $Text <> "" Then
       ; Wait for the user to input something
        While 1
            Sleep(100)
            $String=GUICtrlRead($ConsoleID[1])
            If StringRight($string, 2) = @CRLF Then ExitLoop
           ; Ensure that everything is typed at the end of edit control
            $pos = StringLen($String)
            _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos)
        WEnd
        $pos = StringInStr($string, $Text, 0, -1)
        If $pos >0 Then $pos += StringLen($Text)
    Else
        $str = $string
       ; Wait for the user to input something
        While 1
            Sleep(100)
            $String=GUICtrlRead($ConsoleID[1])
            If StringRight($string, 2) = @CRLF And $string <> $str Then ExitLoop
           ; Ensure that everything is typed at the end of edit control
            $pos = StringLen($String)
            _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos)
        WEnd
        $pos = StringInStr(StringLeft($string, StringLen($string)-2), @CRLF, 0, -1)
        If $pos > 0 Then $pos += 1
    EndIf
    $string = StringMid($string, $pos)
    $string = StringLeft($string, StringLen($string)-2)
    GUICtrlSetStyle($ConsoleID[1], BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL))
    If $ConsoleID[2] >0 And $Progress>=0 Then GUICtrlSetData($ConsoleID[2], $Progress)
    Return $string
    WinSetOnTop($ConsoleID[0], "", 0)
EndFunc

;===============================================================================
; Description:      Clear the console
; Parameter(s):     $ConsoleID    - The console ID
; Requirement(s):   None
; Return Value(s):  None
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinClear($ConsoleID)
    GUICtrlSetData ($ConsoleID[1], "")
    If $ConsoleID[2] >0 Then GUICtrlSetData($ConsoleID[2], 0)
EndFunc

;===============================================================================
; Description:      Save the content of the console to a file
; Parameter(s):     $ConsoleID    - The console ID
;                    $FileName    - The filename used to save
; Requirement(s):   None
; Return Value(s):  Write status, same as FileWrite
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinSave($ConsoleID, $FileName)
    $string = GUICtrlRead($ConsoleID[1])
    Return FileWrite($FileName, $string)
EndFunc

;===============================================================================
; Description:      Ask for the user to verify input something
; Parameter(s):     $ConsoleID      - Console ID returned by ConsoleWinCreate
;                   $VAns           - info to verify 
;                   $Text           - Text to display, the question.
;                   $VNum           - Optional - to verify an Intreger
;                   $VMin           - Optional - Minimum length of string
;                   $VMax           - Otional - Maximum length of string
; Requirement(s):   ConsoleWinCreate available and ConsoleWinInput called first
; Return Value(s):  What user has typed.
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Co - Author       Valuater
; Note(s):          $Text may not be an empty string
;===============================================================================
Func ConsoleWinVerify($ConsoleID, $VAns, $Text, $VNum = False, $VMin = 1, $VMax = 1000)
    While 1
        ConsoleWinWrite($ConsoleID, "You have answered: " & $VAns)
        $VLen = StringLen($VAns)
        If $VNum And Int($VAns) > 0 And $VLen >= $VMin And $VLen <= $VMax Then
            If ConsoleWinInput($ConsoleID, 'Is this Correct? "Y" or "N" ') = "y" Then Return $VAns
        ElseIf Not $VNum And $VLen >= $VMin And $VLen <= $VMax Then
            If ConsoleWinInput($ConsoleID, 'Is this Correct? "Y" or "N" ') = "y" Then Return $VAns
        EndIf
        $VAns = ConsoleWinInput($ConsoleID, $Text)
        Sleep(10)
    WEnd
EndFunc

Func ConsoleSpeak($S_text)
    Local $oi_speech = ObjCreate("SAPI.SpVoice")
    $oi_speech.Speak ($S_text)
    $oi_speech = ""
EndFunc  



Func _txt_eff__about_messages($winhandle, $control_id, $texts, $delay = 50, $showtime = 2000, $pause = 750, $type = "right_to_left")
    
        Local $static = _IsStatic($winhandle, $control_id)
        
        If $static = 1 Then GUISetState(@SW_LOCK, $winhandle)
        ControlSetText($winhandle, "", $control_id, "")
        If $static = 1 Then GUISetState(@SW_UNLOCK, $winhandle)
        If ($type = "right_to_left") or ($type = "left_to_right") or ($type = "left_to_left") or ($type = "right_to_right") Then
            $text_min_width = 14
            For $i = 0 To UBound($texts) - 1
                If StringLen($texts[$i]) > $text_min_width Then $text_min_width = StringLen($texts[$i])
            Next
            $text_min_width = $text_min_width + 5
            
        ElseIf $type = "modern" Then
            
            ; ------- parameters -------
            Local $_l_height = 20 ; height of a single line (label)
            Local $_no_color = 0xECE9D8
            Local $_black = 0x000000
            Local $_messages = 5
            Dim $_labels[$_messages]
            
            ; enlarge Arrray
            For $k = 1 To $_messages
                _ArrayInsert($texts, 0, "")
                _ArrayInsert($texts, UBound($texts), "")
            Next
            
            $_txt_eff_about_gui = GUICreate("About", 250, $_l_height + 20 + $_l_height * $_messages + 60) ; the about win's title, width and height here
            $_txt_eff_gui_ok_button = GUICtrlCreateButton("&Ok", 10, $_l_height + 20 + $_l_height * $_messages + 25, 230, 25, $BS_DEFPUSHBUTTON )
                
            
            For $k = 1 To $_messages
                $_style = $SS_CENTER ; styles are located here!
                $_labels[$k - 1] = GUICtrlCreateLabel("[Error]", 10, 50 + 25 * $k, 210, $_l_height, $_style)
            Next
            
            GUISetState(@SW_SHOW)
                        
            
            For $k = 0 To UBound($texts) - $_messages
                
                GUICtrlSetColor($_labels[$_messages - 1], 0xECE9D8)
                For $p = 0 To $_messages - 1
                    GUICtrlSetPos($_labels[$p], 19, $_l_height + 20 + $_l_height * $p, 210, $_l_height)
                    GUICtrlSetData($_labels[$p], $texts[$k + $p])
                Next
                
                For $c = 0 To - $_l_height Step - 1   ; control's height is here again
                    Sleep($delay)
                    
                    GUISetState(@SW_LOCK)
                    ; move
                    For $z = 0 To $_messages - 1
                        GUICtrlSetPos($_labels[$z], 19, $_l_height + 20 + $_l_height * $z + $c, 210, $_l_height)
                    Next
                    
                    ; fade
                    $red_diff = _ColorGetRed($_black) - _ColorGetRed($_no_color)
                    $green_diff = _ColorGetGreen($_black) - _ColorGetGreen($_no_color)
                    $blue_diff = _ColorGetBlue($_black) - _ColorGetBlue($_no_color)
                    $red_res = Hex(_ColorGetRed($_black) + Round($red_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    $green_res = Hex(_ColorGetGreen($_black) + Round($green_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    $blue_res = Hex(_ColorGetBlue($_black) + Round($blue_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    GUICtrlSetColor($_labels[0], "0x" & $red_res & $green_res & $blue_res)
                    
                    $red_diff = _ColorGetRed($_no_color) - _ColorGetRed($_black)
                    $green_diff = _ColorGetGreen($_no_color) - _ColorGetGreen($_black)
                    $blue_diff = _ColorGetBlue($_no_color) - _ColorGetBlue($_black)
                    $red_res = Hex(_ColorGetRed($_black) + Round($red_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    $green_res = Hex(_ColorGetGreen($_black) + Round($green_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    $blue_res = Hex(_ColorGetBlue($_black) + Round($blue_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    GUICtrlSetColor($_labels[$_messages - 1], "0x" & $red_res & $green_res & $blue_res)
                    
                    GUISetState(@SW_UNLOCK)
                    
                    ; check if close event is there
                    $_about_msg = GUIGetMsg()
                    If $_about_msg = $GUI_EVENT_CLOSE Or $_about_msg = $_txt_eff_gui_ok_button Then ExitLoop 2
                Next
            Next
            GUIDelete($_txt_eff_about_gui)
        EndIf
EndFunc
Func _IsStatic($winhandle, $control_id)
    Local $ret = DllCall("user32.dll", "int", "GetClassName", "hwnd", ControlGetHandle($winhandle, "", $control_id), "str", "", "int", 128)
    If StringInStr($ret[2], "Static") <> 0 Then Return 1
    Return 0
EndFunc   ;==>_IsStatic

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

You need GuiCtrlRead....

(I suck at GUI... horribly) But... I didn't think you would need to do that if you just used a Msgbox according to the GuiEdit its reading from...

like

MsgBox(0,"",$guiedit)

The only other problem I would encounter... How could I read each individual line? Would I need to write like a 'footnote' to the side like Scite does, and have it read line 1, then line 2, etc... Or is there way to read each line without creating that 'footnote'?

Here, you can even ask what you want to...

8)

Well a little over done :party:. But I might be able to work off of that. I want to try going in the direction of GUI'ing because I know more about GUI than I do Console stuff (I don't know too much about GUI the way it is... That shows how much I know about console :)).

Share this post


Link to post
Share on other sites

Check the helpfile for GuiCtrlEdit then you would notice:

Return Value

Success: Returns the identifier (controlID) of the new control.

Which should make it quite obvious why you got the number 3 instead of the text. Now about your other issue, if you want to read individual lines try _GUICtrlEdit_GetLine()

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Check the helpfile for GuiCtrlEdit then you would notice:

Which should make it quite obvious why you got the number 3 instead of the text. Now about your other issue, if you want to read individual lines try _GUICtrlEdit_GetLine()

Works like a charm... Thanks :)

(I admit I didn't look at the help file... But how was I suppose to know what to look for... In my eyes, you just gotta kinda 'know' the functions, then look them up on how to use them... :S)

Edit: I did read the help file on the GUICtrlCreateEdit... But didn't bother searching and guessing to look for _GUICtrlEdit_GetLine()... Cause I would have had no idea :party:

EDIT:

As a last note before I get started... This is how I have it planned out so far (If you catch something that won't work, please tell me! xD)

-_FileCreate("noob.au3")

-FileWrite(*The translation from the GUIEdit for the 'noob' language)

Thats basically all it, other than all the loops I'll have to go through to break down each word, translate it, and then write it down from the translated form.

Does anyone have any ideas on how to create my 'library' of 'noob language'

Do you suggest making just a separate #include file with all the translation variables in there to keep it neat on the main script? (Can I use an #include like this right?)

And last... The only way I see of obtaining the translation method is to do something like:

$myedit = GUICtrlCreateEdit("" & @CRLF, 176, 32, 121, 97, $ES_WANTRETURN)

    GUISetState()

    Send("{END}")

    Sleep(5000)
    $x = GUICtrlRead($myedit)
    $y = _GUICtrlEdit_GetLine($myedit, 0)
        If $y = "if" Then
             FileWrite("noob.au3", "If")
        ElseIf $y = "LeftClick at" Then
             FileWrite("noob.au3", "MouseClick("left", x, y)")
         EndIf

I suppose doing that method wouldn't require me to have an #include...

1. Would that above script be one of the easiest ways to do the translation?

2. Would that even work doing the If $y = "if"... If I think I'm right, "if" would just mean text... So when it obtains the text 'if' from _GetLine() it would trigger that $y = "if" statement..... correct? :S

3. I just can't figure it out.... But what the heck is the Send( End ) used for... I tried taking it out and then it would start at the second line on the EditBox... Does sending 'End' trigger it to start at the first one for some odd reason? xD

Edited by UnknownWarrior

Share this post


Link to post
Share on other sites

Bump.... :)

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