- NSIS Discussion
- Change radiobutton in .oninit function
Archive: Change radiobutton in .oninit function
Satsuki
31st July 2004 11:28 UTC
Change radiobutton in .oninit function
Thank for this very good forum, i've learned a lot with it.
Sorry for my bad english, i'm not english native.
so here's my problem:
in my scrip i use radiobutton in a .onselchange function:
section $(SecHP20Name) hp20
WriteRegDWORD ....
WriteRegDWORD ....
sectionend
section /o $(SecHP21Name) hp21
WriteRegDWORD ....
WriteRegDWORD ....
sectionend
section /o $(SecHP51Name) hp51
WriteRegDWORD ....
WriteRegDWORD ....
sectionend
Function .onSelChange
!insertmacro StartRadioButtons $8
!insertmacro RadioButton ${hp20}
!insertmacro RadioButton ${hp21}
!insertmacro RadioButton ${hp51}
!insertmacro EndRadioButtons
FunctionEnd
this works great, but in .oninit function i need to change the default selected radiobutton but if i use sectionsetflags or !insertmacro SelectSection, it select one of the radiobutton without unselect the others one (like if the radiobutton wasn't active).
i hope i've been clear (if not i'll try to be more acurate)
thanks in advance
++
mumuri
31st July 2004 13:26 UTC
You only have to use sectionsetflags to unset the others button
SectionSetFlags 0 0x10 ; this button is inactive
SectionSetFlags 1 0x10 ; this button is inactive too
SectionSetFlags 2 0x01 ; this button is active
i don't know if you want to disable the button or only unselect it. 0x10 is to disable it. Look in the doc to find the code to unselect them ;).
Comm@nder21
31st July 2004 13:33 UTC
simply include the sections header file:
!include Sections.nsh
inside this, u'll find some macros for radio-button behaviour. works really good.
Satsuki
31st July 2004 13:51 UTC
if i use sectionsetflags to unsheck radiobutton it's buggy, the sction is unshecked but the radiobutton works as if it is checked, for exemple i see:
[0]
[0]
[X]
but when i sheck the first one:
[X]
[0]
[X]
and i want:
[X]
[0]
[0]
what i mean is when i use sectionsetflags, the sections are shecked but the radiobuton consider that the section are as they are before the use of sectionsetflags... so it's no use.
i just want a way to change the default shecked button, that all, but all the way i've found to change it make the radiobutton bug
++
kichik
31st July 2004 13:58 UTC
From Sections.nsh:
; You should pass a variable that keeps the selected section
; as the first parameter for this macro. This variable should
; be initialized to the default section's index.
mumuri
31st July 2004 14:00 UTC
have you read this ????
http://forums.winamp.com/showthread....hreadid=188384
he has the same problems as you ;).
Satsuki
31st July 2004 14:34 UTC
thanks i'm going to read all that ^^
++
Satsuki
31st July 2004 15:03 UTC
i got exactly the same bug when i change the default with
Push $0
StrCpy $8 ${hp21}
SectionGetFlags ${hp21} $0
IntOp $0 $0 | ${SF_SELECTED}
SectionSetFlags ${hp21} $0
SectionGetFlags ${hp20} $0
IntOp $0 $0 & ${SECTION_OFF}
SectionSetFlags ${hp20} $0
SectionGetFlags ${hp51} $0
IntOp $0 $0 & ${SECTION_OFF}
SectionSetFlags ${hp51} $0
Pop $0
this code unselect the first option and select the second option but when i sheck an other radiobuton i get :
[0]
[X]
[X]
instead of :
[0]
[0]
[X]
++
pengyou
31st July 2004 15:38 UTC
If you want to change the default "radiobutton" section in .onInit you'll also need to change the line
section $(SecHP20Name) hp20
to
section /o $(SecHP20Name) hp20
(i.e. ensure none of the sections are selected by default)
otherwise you could end up with two sections selected at the same time.
mumuri
31st July 2004 15:43 UTC
lol, sorry,i was just saying that you should watch the one-section.nsi .
Your problem come from the fact that you have to use a variable to keep the selected option (like kichik said)
All is explain in one section.nsi ;).
Satsuki
31st July 2004 17:31 UTC
section /o $(SecHP20Name) hp20
WriteRegDWORD ...
WriteRegDWORD ...
sectionend
section /o $(SecHP21Name) hp21
WriteRegDWORD ...
WriteRegDWORD ...
sectionend
section /o $(SecHP51Name) hp51
WriteRegDWORD ...
WriteRegDWORD ...
sectionend
Function .onInit
ReadRegStr $R9 .....
StrCmp $R9 "..." goto20 goto21c
goto20:
StrCpy $8 ${hp20}
!insertmacro SelectSection ${hp20}
goto21c:
StrCmp $R9 "..." goto21 goto51c
goto21:
StrCpy $8 ${hp21}
!insertmacro SelectSection ${hp21}
goto51c:
StrCmp $R9 "..." goto51 gotofinal
goto51:
StrCpy $8 ${hp51}
!insertmacro SelectSection ${hp51}
gotofinal:
FunctionEnd
Function .onSelChange
!insertmacro StartRadioButtons $8
!insertmacro RadioButton ${hp20}
!insertmacro RadioButton ${hp21}
!insertmacro RadioButton ${hp51}
!insertmacro EndRadioButtons
FunctionEnd
same bug here, i've read a lot the one-section.nsi but if i want to change the default radiobutton in it, it make the same bug to ...
sorry for bother you but i don't understand at all why it doesn't work (if you can explain with a concret exemple instead of some abstract definition (i'm not english native so thecnical english is not easy to understand for me))
thanks again
++
kichik
31st July 2004 17:36 UTC
Your code works just fine for me, after replacing all of the triple dots with something meaningful, of course... There must be something else in the script. You should attach your entire script.
Satsuki
31st July 2004 18:14 UTC
my script is ok if hp20 is the radiobutton by default.
if it's not, when you try to select an other radiobutton, it bugg.
i'm going to simplifie my scrip, and post it here after that (more than 1200 lines of code)
++
Satsuki
31st July 2004 18:29 UTC
must realy have something bad in my script, i've tested this script and it works perfectly well:
!include "MUI.nsh"
!include "Sections.nsh"
Name "test1"
OutFile "test1.exe"
InstallDir "$PROGRAMFILES\test1"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "French"
section /o "HP2.0" hp20
WriteRegDWORD HKCU "Software\test" "remind" "20"
sectionend
section /o "HP2.1" hp21
WriteRegDWORD HKCU "Software\test" "remind" "21"
sectionend
section /o "HP5.1" hp51
WriteRegDWORD HKCU "Software\test" "remind" "51"
sectionend
Function .onInit
ReadRegStr $R9 HKCU "Software\test" "remind"
StrCmp $R9 "20" goto20 goto21c
goto20:
StrCpy $8 ${hp20}
!insertmacro SelectSection ${hp20}
goto21c:
StrCmp $R9 "21" goto21 goto51c
goto21:
StrCpy $8 ${hp21}
!insertmacro SelectSection ${hp21}
goto51c:
StrCmp $R9 "51" goto51 gotofinal
goto51:
StrCpy $8 ${hp51}
!insertmacro SelectSection ${hp51}
goto endsel
gotofinal:
StrCpy $8 ${hp20}
!insertmacro SelectSection ${hp20}
endsel:
functionend
Function .onSelChange
!insertmacro StartRadioButtons $8
!insertmacro RadioButton ${hp20}
!insertmacro RadioButton ${hp21}
!insertmacro RadioButton ${hp51}
!insertmacro EndRadioButtons
FunctionEnd
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_FUNCTION_DESCRIPTION_END
thanks for all, i'm going to verif my script ^^
++
[EDIT] bug spotted, i had a bad command in my .oninit function (400 lines of code that looks like a mess so that my fault).
thank for all, i learned a lot about radiobutton.