Mailinglist Archive: yast-devel (55 mails)

< Previous Next >
Re: [yast-devel] Libyui How to use RadioButton and RadioGroupButton
Thanks.. It worked

Now I am trying to dynamically insert items but it seems that it does
not work.. can you have a look at it.

I have tried to options

1. Calling dialog->recalcLayout() and then inserting a YLable
2. Inserting a label and then calling dialog->recalcLayout()


2011/3/28 Josef Reidinger <jreidinger@xxxxxxx>:
Manu Gupta write:
Hi All

I have been trying to use RadioButton and RadioButtonGroup using
libyui but I am unable to do so Can anyone have a look at my code and
tell me how do I do it?


Hi,
at first thanks for feedback. At second I want to note that I am not author
of libyui and I just fix your code by looking in documentation and source
code.

Mistake you do is that addRadioButton should be called only in constructor by
documentation, but when I look in code it doesn't use at all. Actually
RadioButton detect its group just by searching its parents and match first
radioButtonGroup ( Yes, I also think that it is not perfect solution ).

So I attached modified your code which actually works.

Conclusion:
RadioButton use first RadioButtonGroup which it find as its parent.

Josef



--
Josef Reidinger
Appliance Toolkit team
maintainer of perl-Bootloader and parts of webyast and SLMS
author of rubygems - studio_api and net_observer (coauthor)




--
Regards
Manu Gupta
#include<iostream>
//#include<stdlib.h>
#define YUILogComponent "quizgame"
#include "YUILog.h"
#include "YUI.h"
#include "YWidgetFactory.h"
#include "YDialog.h"
#include "YLayoutBox.h"
#include "YRadioButtonGroup.h"
#include "YRadioButton.h"
#include "YLabel.h"
#include "YPushButton.h"
#include "YEvent.h"
#include "YAlignment.h"
#include "YMenuItem.h"
#include "YMenuButton.h"

//#include "base.h"

YItemCollection fillMenu(){
YItemCollection items;
items.push_back( new YMenuItem("&Close"));
return items;
}

int main(){
// item("Manu","Gagan","Tiger","Lion","Duck",4).getAnswer(4);

YUILog::setLogFileName("/tmp/quiz/quiz.log");
YUILog::enableDebugLogging();


YDialog * dialog = YUI::widgetFactory()->createPopupDialog();
YAlignment * minSize =
YUI::widgetFactory()->createMinSize(dialog,100,4);
YLayoutBox * mbox = YUI::widgetFactory()->createVBox(minSize);

YAlignment * margin = YUI::widgetFactory()->createMarginBox(mbox,1,1);


YLayoutBox * vbox = YUI::widgetFactory()->createVBox(margin);

YMenuButton * mFile =
YUI::widgetFactory()->createMenuButton(YUI::widgetFactory()->createLeft(vbox),"&File");
//MenuItem * item = new YMenuItem("&Close");
mFile->addItems(fillMenu());

YLabel * question =
YUI::widgetFactory()->createLabel(YUI::widgetFactory()->createLeft(vbox),"Manu
akjsdhkashd adsk askdjksahd ksa dkhdsakjdsa dsa");


YRadioButtonGroup * ansGroup =
YUI::widgetFactory()->createRadioButtonGroup(YUI::widgetFactory()->createLeft(vbox));
YLayoutBox * vbox2 = YUI::widgetFactory()->createVBox(ansGroup);
YRadioButton * ans1 =
YUI::widgetFactory()->createRadioButton(YUI::widgetFactory()->createLeft(vbox2),"ANS
1dasda da dsa daslk sad lsakjd ldks ");
YRadioButton * ans2 =
YUI::widgetFactory()->createRadioButton(YUI::widgetFactory()->createLeft(vbox2),"ANS
2dasda da dsa daslk sad lsakjd ldks ");
YRadioButton * ans3 =
YUI::widgetFactory()->createRadioButton(YUI::widgetFactory()->createLeft(vbox2),"ANS
3dasda da dsa daslk sad lsakjd ldks ");
YRadioButton * ans4 =
YUI::widgetFactory()->createRadioButton(YUI::widgetFactory()->createLeft(vbox2),"ANS
4dasda da dsa daslk sad lsakjd ldks ");

YPushButton * nextButton =
YUI::widgetFactory()->createPushButton(YUI::widgetFactory()->createRight(vbox),"&Next");
YEvent * event = dialog->waitForEvent();

return 0;
}
#include<iostream>
#include<sstream>
//#include<stdlib.h>
#define YUILogComponent "quizgame"
#include "YUILog.h"
#include "YUI.h"
#include "YWidgetFactory.h"
#include "YDialog.h"
#include "YLayoutBox.h"
#include "YRadioButtonGroup.h"
#include "YRadioButton.h"
#include "YLabel.h"
#include "YPushButton.h"
#include "YEvent.h"
#include "YAlignment.h"
#include "YMenuItem.h"
#include "YMenuButton.h"

#include "base.h"

YItemCollection fillMenu(){
YItemCollection items;
items.push_back( new YMenuItem("&Close"));
return items;
}

void Items(vector<item> &V){

V.push_back(item("Q1 asmdnasd asdnlksda ","op1","op2","op3","op4",1));
V.push_back(item("Q2","op1","op2","op3","op4",2));
V.push_back(item("Q3","op1","op2","op3","op4",3));

}
int main(){
// item("Manu","Gagan","Tiger","Lion","Duck",4).getAnswer(4);
//
vector<item> V;
unsigned i =0;

YUILog::setLogFileName("/tmp/quiz/quiz.log");
YUILog::enableDebugLogging();

Items(V);
yuiMilestone()<<V.size()<<endl;
YDialog * dialog = YUI::widgetFactory()->createPopupDialog();
YAlignment * minSize =
YUI::widgetFactory()->createMinSize(dialog,100,4);
YLayoutBox * mbox = YUI::widgetFactory()->createVBox(minSize);

YAlignment * margin = YUI::widgetFactory()->createMarginBox(mbox,1,1);


YLayoutBox * vbox = YUI::widgetFactory()->createVBox(margin);

YMenuButton * mFile =
YUI::widgetFactory()->createMenuButton(YUI::widgetFactory()->createLeft(vbox),"&File");
//MenuItem * item = new YMenuItem("&Close");
mFile->addItems(fillMenu());

YLabel * question =
YUI::widgetFactory()->createLabel(YUI::widgetFactory()->createLeft(vbox),"Manu
akjsdhkashd adsk askdjksahd ksa dkhdsakjdsa dsa");


YRadioButtonGroup * ansGroup =
YUI::widgetFactory()->createRadioButtonGroup(YUI::widgetFactory()->createLeft(vbox));
YLayoutBox * vbox2 = YUI::widgetFactory()->createVBox(ansGroup);
YRadioButton * ans1 =
YUI::widgetFactory()->createRadioButton(YUI::widgetFactory()->createLeft(vbox2),"ANS
1dasda da dsa daslk sad lsakjd ldks ");
YRadioButton * ans2 =
YUI::widgetFactory()->createRadioButton(YUI::widgetFactory()->createLeft(vbox2),"ANS
2 sadkjhsakjd sakdhj dsakasdhk sadhlkdsa");
YRadioButton * ans3 =
YUI::widgetFactory()->createRadioButton(YUI::widgetFactory()->createLeft(vbox2),"ANS
3 asdljsald sad lasjdlkas d adlsjlkd ");
YRadioButton * ans4 =
YUI::widgetFactory()->createRadioButton(YUI::widgetFactory()->createLeft(vbox2),"ANS
4");


YLayoutBox * LBox = YUI::widgetFactory()->createHBox(vbox);
YLabel * ans =
YUI::widgetFactory()->createLabel(YUI::widgetFactory()->createLeft(LBox),"CORRECT
ANSWER TO THE LAST QUESTION WILL BE DISPLAYED HERE");
YPushButton * nextButton =
YUI::widgetFactory()->createPushButton(YUI::widgetFactory()->createRight(LBox),"Next");

YEvent * event;
for(i=0;i<V.size();i++){
question->setValue(V[i].getQuestion());
ans1->setLabel(V[i].getO1());
ans2->setLabel(V[i].getO2());
ans3->setLabel(V[i].getO3());
ans4->setLabel(V[i].getO4());

event = dialog->waitForEvent();
if(event){


if(event->eventType()==YEvent::MenuEvent){
break;
}


if(event->widget()==ans1){
ansGroup->uncheckOtherButtons(ans1);
}

if(event->widget()==nextButton){
yuiMilestone()<<"Button Clicked"<<endl;

stringstream answer;
answer<<"The Correct Answer is option
"<<V[i].getAnswer();
ans->setLabel(answer.str());
if(ans1 == ansGroup->currentButton()){
yuiMilestone()<<"RadioBUTTON1"<<endl;
if(V[i].getAnswer()==1){
yuiMilestone()<<"Correct Answer
Selected"<<endl;
}
}

if(ans2 == ansGroup->currentButton()){
yuiMilestone()<<"RadioBUTTON2"<<endl;

if(V[i].getAnswer()==2){
yuiMilestone()<<"Correct Answer
Selected"<<endl;
}
}
if(ans3 == ansGroup->currentButton()){
yuiMilestone()<<"RadioBUTTON3"<<endl;
if(V[i].getAnswer()==3){
yuiMilestone()<<"Correct Answer
Selected"<<endl;
}
}
if(ans4 == ansGroup->currentButton()){
yuiMilestone()<<"RadioBUTTON4"<<endl;
if(V[i].getAnswer()==4){
yuiMilestone()<<"Correct Answer
Selected"<<endl;
}
}
}

}

}

delete vbox2;
delete LBox;
delete question;

YUI::widgetFactory()->createLabel(vbox,"Trying Out ")
dialog->recalcLayout();

// YUI::widgetFactory()->createLabel(vbox,"THANKS FOR PLAYING :D");
// question->setValue("Thanks For Playing :D");
event = dialog->waitForEvent();



return 0;
}
< Previous Next >
List Navigation
Follow Ups