Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 24th August 2006, 13:42   #1
OsmanY22
Junior Member
 
Join Date: Aug 2006
Posts: 20
if checked, then disable a "Field"

Hi.

I have a custom Page. In this Custom Page, there are some Fields (Label, Text, Password) and Checkbox. Now I want to do, that, when a checkbox is checked, then an of the Fields (Text) should be disabled!

Lood at the Picture "enabled&disabled.jpg"


Thx @all


PHP Code:
ReadINIStr $"$PLUGINSDIR\setup.ini" "Field 3" "State"
        
StrCpy $OCIP $0
ReadINIStr 
$"$PLUGINSDIR\setup.ini" "Field 5" "State"
        
StrCpy $OCUSER $0
ReadINIStr 
$"$PLUGINSDIR\setup.ini" "Field 7" "State"
        
StrCpy $OCPWD $0
ReadINIStr 
$"$PLUGINSDIR\setup.ini" "Field 10" "State"
        
StrCpy $DINAME $0
ReadINIStr 
$"$PLUGINSDIR\setup.ini" "Field 12" "State"
        
StrCpy $DIUSER $0
ReadINIStr 
$"$PLUGINSDIR\setup.ini" "Field 14" "State"
        
StrCpy $DIPWD $0
ReadINIStr 
$"$PLUGINSDIR\setup.ini" "Field 16" "State"  
        
StrCmp $0 0 done
    ExecWait 
"$INSTDIR\wrapper\bin\Install_MediaServer.bat" 
    
Delete "$INSTDIR\wrapper\conf\password.conf"
done
Attached Images
File Type: jpg enabled&disabled.jpg (17.0 KB, 238 views)
OsmanY22 is offline   Reply With Quote
Old 24th August 2006, 14:21   #2
Comperio
Major Dude
 
Comperio's Avatar
 
Join Date: Jan 2005
Location: Oregon Coast
Posts: 737
First, make sure you have the notify flag set on your checkbox. Then, in the page's callback function, so this: (PS: your original code was missing a backslash between $PLUGINSDIR and the name of your page file.)

code:

Function callback
push $0
push $1
ReadIniStr "$PLUGINSDIR\setup.ini" "Settings" "State"
; compare $0 to the field of your checkbox.
; (This example assumes field 8 is your checkbox)
StrCpy $0 8 changestate 0
; *** normal callback code goes here ***

changestate:
; the next lines assume that your field to
; gray out is field 9
ReadIniStr $0 "$PLUGINSDIR\Setup.ini" "Field 9" "HWND"
ReadIniStr $1 "$PLUGINSDIR\Setup.ini" "Field 8" "state"
StrCmp $1 1 disable enable

disable:
EnableWindow $0 0
; and write the value just in case the user returns to this screen:
WriteIniStr "$PLUGINGSDIR\Setup.ini" "Field 9" "Flags" "DISABLED"
pop $1
pop $0
abort

enable:
EnableWindow $0 1
; and write the value just in case the user returns to this screen:
WriteIniStr "$PLUGINGSDIR\Setup.ini" "Field 9" "Flags" ""
pop $1
pop $0
abort
FunctionEnd



***EDIT: I changed the code above to check for the state of the checkbox and enable/disable as needed. (minor details...)
Comperio is offline   Reply With Quote
Old 24th August 2006, 14:41   #3
OsmanY22
Junior Member
 
Join Date: Aug 2006
Posts: 20
sorry, but i don't understand, where I should give the function "callback"?

This my Code now ... Field 16 is my checkbox and Field 12 and 14 must be disabled, when this checkbox ist NOT checked.

Do you know, what i mean?
code:

ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 3" "State"
StrCpy "$OCIP" $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 5" "State"
StrCpy $OCUSER $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 7" "State"
StrCpy $OCPWD $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 10" "State"
StrCpy $DINAME $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 12" "State"
StrCpy $DIUSER $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 14" "State"
StrCpy $DIPWD $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 16" "State"
StrCmp $0 0 done
ExecWait "$INSTDIR\wrapper\bin\Install_MediaServer.bat"
Delete "$INSTDIR\wrapper\conf\password.conf"
done:



I don't forget "/" ... but the editor of PHP doesn't show it.
OsmanY22 is offline   Reply With Quote
Old 25th August 2006, 03:22   #4
Comperio
Major Dude
 
Comperio's Avatar
 
Join Date: Jan 2005
Location: Oregon Coast
Posts: 737
Any custom page you insert has a show function and a leave function (also called a callback function).

Use them in your page command like this:
code:

Page custom showfunction leavefunction


(in this example, the "leavefunction" is what I'm calling the "callback" function.)

Refer to the documentation and the examples for more info. (${NSISDIR}\examples\InstallOptions\testnotify.nsi offers a good example of how to use page callbacks.)
Comperio is offline   Reply With Quote
Old 25th August 2006, 10:29   #5
OsmanY22
Junior Member
 
Join Date: Aug 2006
Posts: 20
Thx a lot man!!!

it workssss!!!

FALSE: "$PLUGINGSDIR"
RIGHT: "$PLUGINSDIR"
OsmanY22 is offline   Reply With Quote
Old 25th August 2006, 10:37   #6
OsmanY22
Junior Member
 
Join Date: Aug 2006
Posts: 20
What does this text mean??
code:

; compare $0 to the field of your checkbox.
; (This example assumes field 8 is your checkbox)
StrCpy $0 8 changestate 0




It works with to disable an Field, but i cant continue with the install.

What is the problem??

code:


Function callback
push $0
push $1
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 3" "State"
StrCpy "$OCIP" $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 5" "State"
StrCpy $OCUSER $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 7" "State"
StrCpy $OCPWD $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 10" "State"
StrCpy $DINAME $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 12" "State"
StrCpy $DIUSER $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 14" "State"
StrCpy $DIPWD $0

ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 16" "State"
StrCmp $0 8 changestate 0

changestate:
; gray out is field 14
ReadIniStr $0 "$PLUGINSDIR\Setup.ini" "Field 14" "HWND"
ReadIniStr $1 "$PLUGINSDIR\Setup.ini" "Field 16" "state"
StrCmp $1 0 disable enable

disable:
EnableWindow $0 0
; and write the value just in case the user returns to this screen:
WriteIniStr "$PLUGINSDIR\Setup.ini" "Field 14" "Flags" "DISABLED"
pop $1
pop $0
abort

enable:
EnableWindow $0 1
; and write the value just in case the user returns to this screen:
WriteIniStr "$PLUGINSDIR\Setup.ini" "Field 14" "Flags" ""
pop $1
pop $0
abort
FunctionEnd





Now last question...how can I "disable" more Fields??

I want to disable Filed 12 and 14.

Last edited by OsmanY22; 25th August 2006 at 13:20.
OsmanY22 is offline   Reply With Quote
Old 26th August 2006, 14:01   #7
Comperio
Major Dude
 
Comperio's Avatar
 
Join Date: Jan 2005
Location: Oregon Coast
Posts: 737
oops! My bad..
It was a typo on my part--sorry 'bout that!

The line
code:

StrCpy $0 8 changestate 0



should have been:
code:

StrCmp $0 8 changestate 0



And thanks for catching my other typo.

Edit:
OsmanY22, I sent you a PM explaining the nuts and bolts of this script a little better so that you'd have a better understanding of how to implement it in your situation.

Last edited by Comperio; 26th August 2006 at 14:18.
Comperio is offline   Reply With Quote
Old 21st November 2006, 08:51   #8
TheShadowHawk
Junior Member
 
Join Date: Jun 2006
Location: Brisbane, Australia
Posts: 12
Angry

Please can someone help me! I have a custom page with 2 fields. a checkbox (field 2) and a text box (field 4)

I want to make it so if the checkbox is ticked, the textbox is enabled, and if unticked the textbox is disabled. I have followed code snippets from this forum and yet cannot make it work. I know I am close! Any helpers?

Thanks!

code:

; get value of checkbox
!insertmacro MUI_INSTALLOPTIONS_READ $R4 "OptionDetails.ini" "Field 2" "State"
; get the field triggered
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "OptionDetails.ini" "Settings" "State"

${if} $R0 == "2" ; if field 2 clicked

ReadIniStr $R3 "OptionDetails.ini" "Field 4" "HWND"

${if} $R4 == "1"

EnableWindow $R3 1
WriteIniStr "OptionDetails.ini" "Field 4" "Flags" ""
${else}

EnableWindow $R3 0
WriteIniStr "OptionDetails.ini" "Field 4" "Flags" "DISABLED"
${EndIf}

abort ; return to page
${EndIf}

TheShadowHawk is offline   Reply With Quote
Old 21st November 2006, 17:37   #9
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,338
ReadIniStr requires a full path. Use $PLUGINSDIR\optionDetails.ini or the MUI macros. Same goes to WriteIniStr.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 21st November 2006, 21:57   #10
TheShadowHawk
Junior Member
 
Join Date: Jun 2006
Location: Brisbane, Australia
Posts: 12
Talking fixed!

Thanks very much kichik! That fixed it for me!
TheShadowHawk is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump