Jump to content

GUI with two inputboxes


Recommended Posts

Well, after a few days on the job, I've done enough to take some time off to tackle the final stages of a GUI that will increase my productivity and speed. I'm very pleased with it so far but I'm missing something as the text dumped into the clipboard doesn't vary, as it shoudl. No matter what I type into my two boxes, I get the number 3 in one, instead; and the second box always produces the number "7" instead of the text I've pasted into the box. Granted, I'm not a very gifted AutoIt user so it's probably something very simple but I can't find it.

So, first problem is to get the right user input dumped into the code that goes to the clipboard.

Second issue, is there a way to get a "text wrap" display into the first input box? I've had this happen before where text is truncated visually on the screen all onto one line no matter how large I make the height of the input box. In all other instances, I've just made the GUI or inputbox wider and made the box thinner to accommodate everything onto that one line to "fix" that but here, since there are multiple lines, need to see the entire paragraph of text instead.

Hoping it's not too difficult. Eveything else seems to work just fine.

Thanks! ;)

;#include <GUIConstants.au3>     ; not needed since I extracted $GUI_EVENT_CLOSE syntax below from the appropriate UDF
;#include <WindowsConstants.au3>     ; not needed since I extracted $WS_EX_TOPMOST syntax below from the appropriate UDF
#include <_PartitionLetters.au3>     ; this replaces drive letters
#include<_WEReplacement.au3>     ; references a Windows Explorer replacement program
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon("Shell32.dll", 24)     ; changes the icon displayed in the systray
AutoItSetOption("WinTitleMatchMode", 2)     ; this allows partial window titles to be valid!





;=================================================================================================================
;  URLs for image:
$URLimgAlt = "http://www.thedailygreen.com/cm/thedailygreen/images/Oi/cardboard-box-open-lg.jpg"
$URLimgSrc = $URLimgAlt
;=================================================================================================================




;=========================================================================
Global Const $GUI_EVENT_CLOSE = -3     ; by using this constant, could leave out reference to "#include <GUIConstants.au3>", which in turn referenced this variable, with this exact value, from "GUIConstantsEx.au3"
Global Const $WS_EX_TOPMOST    = 0x00000008     ;   put this in so that no need to have UDF present when compiling
Opt("GUIOnEventMode", 1)
$Form1_1 = GUICreate("Information Input.", 599, 232, 585, 7, -1, $WS_EX_TOPMOST)     ; width, height, left, top, "-1, $WS_EX_TOPMOST" makes GUI topmost
;----------------------------------------------------------
$Input1 = GUICtrlCreateInput("", 16, 32, 561, 64)     ; left, top, width, height
;----------------------------------------------------------
$Label1 = GUICtrlCreateLabel("Description:", 16, 8, 88, 22)     ; left, top, width, height
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetTip(-1, "The text from the ''Title'' column in the Excel spreadsheet goes into the box below ...")     ; button tooltip
;----------------------------------------------------------
$Button1 = GUICtrlCreateButton("Copy HTML code with above to the clipboard ...", 13, 188, 291, 25, 0)     ; left, top, width, height
GUICtrlSetOnEvent(-1, "OK_click")
$Button2 = GUICtrlCreateButton("Cancel", 335, 188, 75, 25, 0)     ; left, top, width, height
GUICtrlSetOnEvent(-1, "Cancel_click")
$Input2 = GUICtrlCreateInput("", 16, 136, 561, 21)     ; left, top, width, height
$Label2 = GUICtrlCreateLabel("Document link path (just put the URL itself, not HTML tags):", 16, 108, 407, 22)     ; left, top, width, height
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetTip(-1, "''Abstract'' information goes into the box below.")     ; button tooltip
; ---------------------------------------------------------
; CLOSE BUTTON on upper right-hand corner:
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")     ; "X" closes app, line "Global Const $GUI_EVENT_CLOSE = -3" above.  / You need to have a "Func Close()" below.
GUICtrlSetTip(-1, "Close this GUI.")     ; button tooltip
; ----------------------
GUISetState(@SW_SHOW)
;=========================================================================




While 1
    Sleep(100)
WEnd

Func Cancel_click()
    Exit     ; finished
EndFunc
Func OK_click()
    ;----------------------------------------------------------------------------------------------------------------------------------------------------------
    ;  Sends input and html text to the clipboard:
    ClipPut('<body><p>' & $Input1 & _
                '</p>' & @CRLF & _
                '<p> </p>' & @CRLF & _
                '<p><a href="' & $Input2 & '" target="_blank"><img alt="' & $URLimgAlt & '" class="jive-image" src="' & $URLimgSrc & '" /></a></p></body>')
    ;----------------------------------------------------------------------------------------------------------------------------------------------------------
EndFunc



Func Close()
    Exit     ; finished
EndFunc  ;==>close
Link to comment
Share on other sites

Try it this way instead:

Func OK_click()
    ;----------------------------------------------------------------------------------------------------------------------------------------------------------
    ;  Sends input and html text to the clipboard:
    ClipPut('<body><p>' & GUICtrlRead($Input1) & _
                '</p>' & @CRLF & _
                '<p> </p>' & @CRLF & _
                '<p><a href="' & GUICtrlRead($Input2) & '" target="_blank"><img alt="' & $URLimgAlt & '" class="jive-image" src="' & $URLimgSrc & '" /></a></p></body>')
    ;----------------------------------------------------------------------------------------------------------------------------------------------------------
EndFunc

When you create a control, such as your inputs, the variable you assign to it gets the ControlID of the control, not the contents of it. You need to use the GUICtrlRead() function to read the contents, it does this by using the ControlID to find which control you want to read from.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Try it this way instead:

Func OK_click()
    ;----------------------------------------------------------------------------------------------------------------------------------------------------------
    ;  Sends input and html text to the clipboard:
    ClipPut('<body><p>' & GUICtrlRead($Input1) & _
                '</p>' & @CRLF & _
                '<p> </p>' & @CRLF & _
                '<p><a href="' & GUICtrlRead($Input2) & '" target="_blank"><img alt="' & $URLimgAlt & '" class="jive-image" src="' & $URLimgSrc & '" /></a></p></body>')
    ;----------------------------------------------------------------------------------------------------------------------------------------------------------
EndFunc

When you create a control, such as your inputs, the variable you assign to it gets the ControlID of the control, not the contents of it. You need to use the GUICtrlRead() function to read the contents, it does this by using the ControlID to find which control you want to read from.

<chuckle> Knew you guys would find it easy to fix. Lordy but that GUICtrlRead is good to know. Thanks for the education. Putting this info into my Tips folder right now.

This is much easier than what I was doing before. But on using this a couple of times, I find that I need to clear the input boxes once I send the text to the clipboard. What will do that, pls?

Also, the issue of the word wrap with regards to the display of the first box, is it possible to have the text wrapped, by any chance so that the paragraph shows up completely in the box?

Oh, and just using it again, thought it would save time if after clearing the boxes, the cursor could automatically go back into the first input box (now empty)? Is this possible to do?

Thanks!! ;)

Link to comment
Share on other sites

Oh, and just using it again, thought it would save time if after clearing the boxes, the cursor could automatically go back into the first input box (now empty)? Is this possible to do?

I kept looking and found out how to clear the boxes using GUICtrlSetData (http://www.autoitscript.com/forum/index.php?showtopic=11891). At least, it seems to do the job yet the clipboard information remains intact:

Func OK_click()
    ;----------------------------------------------------------------------------------------------------------------------------------------------------------
    ;  Sends input and html text to the clipboard:
    ClipPut('<body><p>' & GUICtrlRead($Input1) & _
                '</p>' & @CRLF & _
                '<p> </p>' & @CRLF & _
                '<p><a href="' & GUICtrlRead($Input2) & '" target="_blank"><img alt="' & $URLimgAlt & '" class="jive-image" src="' & $URLimgSrc & '" /></a></p></body>')
    Sleep(100)
    ;  Clears input boxes of data:
    GUICtrlSetData($Input1,"")
    GUICtrlSetData($Input2,"")
    ;----------------------------------------------------------------------------------------------------------------------------------------------------------
EndFunc

So, just need to fix the "text wrap" issue so that the text in the first box is completely displayed and not all jammed onto one line so that you can't see it all. And then, need to address the focus issue, as I think it's called, to get the cursor back into the first box after sending text to clipboard and clearing input boxes.

Getting there. ;)

Edited by Diana (Cda)
Link to comment
Share on other sites

GUICtrlSetState($Input1, $GUI_FOCUS)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

;#include <GUIConstants.au3>     ; not needed since I extracted $GUI_EVENT_CLOSE syntax below from the appropriate UDF
;#include <WindowsConstants.au3>     ; not needed since I extracted $WS_EX_TOPMOST syntax below from the appropriate UDF
#include <_PartitionLetters.au3>     ; this replaces drive letters
#include<_WEReplacement.au3>     ; references a Windows Explorer replacement program
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon("Shell32.dll", 24)     ; changes the icon displayed in the systray
AutoItSetOption("WinTitleMatchMode", 2)     ; this allows partial window titles to be valid!





;=================================================================================================================
;  URLs for image:
$URLimgAlt = "http://www.thedailygreen.com/cm/thedailygreen/images/Oi/cardboard-box-open-lg.jpg"
$URLimgSrc = $URLimgAlt
;=================================================================================================================




;=========================================================================
Global Const $GUI_EVENT_CLOSE = -3     ; by using this constant, could leave out reference to "#include <GUIConstants.au3>", which in turn referenced this variable, with this exact value, from "GUIConstantsEx.au3"
Global Const $WS_EX_TOPMOST    = 0x00000008     ;   put this in so that no need to have UDF present when compiling
Global Const $GUI_FOCUS = 256     ;   put this in so that no need to have UDF present when compiling / From GUIConstants so that line "GUICtrlSetState($Input1, $GUI_FOCUS)" below works.
Opt("GUIOnEventMode", 1)
$Form1_1 = GUICreate("Information Input.", 599, 232, 585, 7, -1, $WS_EX_TOPMOST)     ; width, height, left, top, "-1, $WS_EX_TOPMOST" makes GUI topmost
;----------------------------------------------------------
$Input1 = GUICtrlCreateInput("", 16, 32, 561, 64)     ; left, top, width, height
;----------------------------------------------------------
$Label1 = GUICtrlCreateLabel("Description:", 16, 8, 88, 22)     ; left, top, width, height
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetTip(-1, "The text from the ''Title'' column in the Excel spreadsheet goes into the box below ...")     ; button tooltip
;----------------------------------------------------------
$Button1 = GUICtrlCreateButton("Copy HTML code with above to the clipboard ...", 13, 188, 291, 25, 0)     ; left, top, width, height
GUICtrlSetOnEvent(-1, "OK_click")
$Button2 = GUICtrlCreateButton("Cancel", 335, 188, 75, 25, 0)     ; left, top, width, height
GUICtrlSetOnEvent(-1, "Cancel_click")
$Input2 = GUICtrlCreateInput("", 16, 136, 561, 21)     ; left, top, width, height
$Label2 = GUICtrlCreateLabel("Document link path (just put the URL itself, not HTML tags):", 16, 108, 407, 22)     ; left, top, width, height
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetTip(-1, "''Abstract'' information goes into the box below.")     ; button tooltip
; ---------------------------------------------------------
; CLOSE BUTTON on upper right-hand corner:
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")     ; "X" closes app, line "Global Const $GUI_EVENT_CLOSE = -3" above.  / You need to have a "Func Close()" below.
GUICtrlSetTip(-1, "Close this GUI.")     ; button tooltip
; ----------------------
GUISetState(@SW_SHOW)
;=========================================================================




While 1
    Sleep(100)
WEnd

Func Cancel_click()
    Exit     ; finished
EndFunc
Func OK_click()
    ;----------------------------------------------------------------------------------------------------------------------------------------------------------
    ;  Sends input and html text to the clipboard:
    ClipPut('<body><p>' & GUICtrlRead($Input1) & _
                '</p>' & @CRLF & _
                '<p> </p>' & @CRLF & _
                '<p><a href="' & GUICtrlRead($Input2) & '" target="_blank"><img alt="' & $URLimgAlt & '" class="jive-image" src="' & $URLimgSrc & '" /></a></p></body>')
    Sleep(100)
    ;  Clears input boxes of data:
    GUICtrlSetData($Input1,"")
    GUICtrlSetData($Input2,"")
    GUICtrlSetState($Input1, $GUI_FOCUS)  ; from GUIConstants UDF; referenced in "Global Const $GUI_FOCUS = 256" above.
    ;----------------------------------------------------------------------------------------------------------------------------------------------------------
EndFunc



Func Close()
    Exit     ; finished
EndFunc  ;==>close

I'm fairly new to GUIs and I just found a problem and wondering what determines the constraints ... The first input box seems to have a limit to how many characters can be entered. I just found that a long paragraph was just truncated (glad I caught it). I never knew this could/would happen. What determines the amount of text that can be entered?

Since the problem of the "text wrap" hasn't been addressed, and all the text gets dumped into the first line without seeing the end of it, was wondering how you all deal with this limitation in GUIs? There must be a way to fix it.

Please, 1. where do we increase the number of characters the input box can hold and, 2. how can we display _all_ the text and not just that they cram onto the first line of the box.

Thanks so much! This is working very well except for those 2 problems.

Cheers. ;)

Link to comment
Share on other sites

Please, 1. where do we increase the number of characters the input box can hold and, 2. how can we display _all_ the text and not just that they cram onto the first line of the box.

Thanks so much! This is working very well except for those 2 problems.

Cheers. ;)

I've looked extensively again today after looking a couple of times yesterday before posting the above question regarding this issue in Koda (one of the 2 GUI builders I know of). In the boxes to the left in Koda (the Object Inspector) where you can determine several factors in the components of your GUI I couldn't find anything that seems to limit the # of characters an "input box" can contain. Is this controlled by the width of the input box itself, perhaps? The MaxLength value says "0" (?). The funny thing also is that no matter how high you make your input box, it snaps back to 21 units in height. Is this a limitation built into this? I manually set the box to 64 but since there's no word wrap, can't see how this works. I would have thought that working with GUIs would allow us more freedom that this so I guess that again, it must be because of something I don't know.

I tried working with the "Edit" feature instead of "Input" but no luck. No word wrap there, either, and ran a long length of single line instead but it didn't seem to be the right feature to use.

How do you guys work with larger input boxes, or are we limited to a single line?

Thanks.

Edited by Diana (Cda)
Link to comment
Share on other sites

I tried working with the "Edit" feature instead of "Input" but no luck. No word wrap there, either, and ran a long length of single line instead but it didn't seem to be the right feature to use.

How do you guys work with larger input boxes, or are we limited to a single line?

Thanks.

Diana, you need to play with the Style parameter in GUICtrlCreateEdit. I think you might want your $Input1 to be like this:

$Input1 = GUICtrlCreateInput("", 16, 32, 561, 64, BitOR( $ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL)) ; left, top, width, height

or maybe add the $WS_HSCROLL like this: (but then the lines will scroll instead of word wrapping to next line)

$Input1 = GUICtrlCreateInput("", 16, 32, 561, 64, BitOR( $ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL)) ; left, top, width, height

I hope this helps or at least points you to the right direction.

Ed

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...