Enigma1 THE BIBLE - Lesson3: MessageBox

转载 2008年05月01日 12:42:00
Lesson3: MessageBox

| The Bible Enigma1 Tutorial
| ========================================
| By: Bacicciosat aka Meo aka Luponero
| Enigma 1 API GUI tutorial with Sources Code and Comments
| (c) august 2006 by Meo

Lesson3: MessageBox

You can find in attach:
- the cfg file (Bibledemo.cfg)
- the compiled and working plugin (Bibledemo.so)
- the source file (bibledemo.cpp)
- the makefile (nedeed to compile code if you want to modify source)

Ok this is the third lesson.
We will add to our window two buttons to call two different messageboxes.
You can see the example in the screenshot.

You can test this application simply uploading in your dreambox (/var/tuxbox/plugins) the files that you can find in attach: Bibledemo.cfg and Bibledemo.so

You can modify this application editing the source file bibledemo.cpp and recompiling it to have a new Bibledemo.so file.

The Enigma API we will explain in this lesson is the messaagebox creation.
These are the main Api about messagebox creation and managing:
// create messagebox
eMessageBox(eString string, eString caption, int flags=btOK, int def=btOK, int timeout=0 );
// Flags: Buttons
btOK=1, btCancel=2, btYes=4, btNo=8, btMax
// Flags: Icons
iconInfo=16, iconWarning=32, iconQuestion=64, iconError=128
// Functions:
Ok now that we have listed the main API we can write the code.
You can fnd the complete application code in the attach package
(bibledemo.cpp). Here i will comment only the code added in this


bibledemo.cpp additions:

First of all we have to add to our include files the Enigma button library:
#include <lib/gui/emessage.h>
Ok Now we have to add two functions to our main class:
void message1();
void message2();
we will connect the execution of these functions to the buttons.
In this way when a butto will be pressed one of these functions will be called and it will show one messagebox.
This is our new main class declaration:
// The Class declaration of our Main Window
class eBibleMainWindow: public eWindow
    // the label to show the text
    eLabel *label;
    // the function to call when button 1 is pushed
    void message1();
    // the function to call when button 2 is pushed
    void message2();
        // the constructor.
        // the destructor.
Perfect !! Now we have to add the two buttons in our main function code to call the functions that will show the messageboxes.
This is our new main Function:
eBibleMainWindow::eBibleMainWindow(): eWindow(1)
        // move our dialog to 100.100...
    cmove(ePoint(100, 100));
        // ...and give x and y dimensions.
    cresize(eSize(520, 376));
        // set a title.
    setText("Enigma Bible Lesson 3: MessageBox");
    // create a label to show a text.
    label=new eLabel(this);
    // give a position
    label->move(ePoint(20, 50));
    // set the label dimensions
    label->resize(eSize(400, 100));
    // set the label text
    label->setText("Push a button to show a MessageBox");

    // create buttons and set properties
    eButton * ok = new eButton(this);
    ok->move(ePoint((clientrect.width() - 200)/2, clientrect.height() - 60));
    ok->resize(eSize(90, 40));
    // function to call when button1 is pushed
    CONNECT(ok->selected, eBibleMainWindow::message1);

    eButton * ok2 = new eButton(this);
    ok2->move(ePoint((clientrect.width())/2, clientrect.height() - 60));
    ok2->resize(eSize(90, 40));
    // function to call when button2 is pushed
    CONNECT(ok2->selected, eBibleMainWindow::message2);
    // set focus on 1 button

Ok Now we have to add the function that will show the first MessageBox (Simply messagebox with only one button):
void eBibleMainWindow::message1()
    // create messagebox
    eMessageBox msg("Hi by Bacicciosat :-)", "Info", eMessageBox::iconInfo|eMessageBox::btOK);
        // show it
        // execute
        // hide after execution (button pressed)
Finally we have to add the function that will show the second MessageBox (modal messagebox with two buttons):
void eBibleMainWindow::message2()
    // create messagebox (two buttons yes/no)
    eMessageBox box("Do you want to exit?", "Question", eMessageBox::btYes|eMessageBox::btNo|eMessageBox::iconQuestion, eMessageBox::btYes);
    // show it
    // execute code and store in the variable button the result (button pressed)
    int button = box.exec();
    // hide it after execution
    // exit if button yes was pushed.
    if (button == eMessageBox::btYes)

As you can see is very simply.
You can now exercise to compile source you find in the attach package and to modify it.

- Change the icons text and buttons of MessageBoxes
- Add another Messagebox

That's all, and this is the application shot and the complete package.
(to be continued in lesson 4 ... )
Attached Images
File Type: png osdshot.png (14.1 KB, 62 views)
Attached Files
File Type: zip lesson3.zip (9.4 KB, 45 views)

The Bible Enigma1 Tutorial

Enigma1 THE BIBLE /*+--------------------------------------------------------------------------| The...
  • tiantian2999
  • tiantian2999
  • 2008年05月01日 12:36
  • 209

Enigma1 THE BIBLE - Lesson5: Checkbox

Lesson5: Checkbox /*+--------------------------------------------------------------------------| The...
  • tiantian2999
  • tiantian2999
  • 2008年05月01日 12:44
  • 292

Enigma1 THE BIBLE - Lesson4: TextInput

Lesson4: TextInput /*+--------------------------------------------------------------------------| Th...
  • tiantian2999
  • tiantian2999
  • 2008年05月01日 12:43
  • 324

Enigma1 THE BIBLE - Lesson7: Combobox

Lesson7: Combobox /*+--------------------------------------------------------------------------| The...
  • tiantian2999
  • tiantian2999
  • 2008年05月01日 12:46
  • 400

Enigma1 THE BIBLE - Lesson6: Listbox

Lesson6: Listbox /*+--------------------------------------------------------------------------| The ...
  • tiantian2999
  • tiantian2999
  • 2008年05月01日 12:45
  • 324

Enigma1 THE BIBLE - Lesson2: Buttons

Lesson2: Buttons /*+--------------------------------------------------------------------------| The ...
  • tiantian2999
  • tiantian2999
  • 2008年05月01日 12:40
  • 419

Enigma1 THE BIBLE - Application Structure Overview

Application Structure Overview /*+------------------------------------------------------------------...
  • tiantian2999
  • tiantian2999
  • 2008年05月01日 12:39
  • 199

Enigma1 THE BIBLE - Lesson1: Hello World Window

Lesson1: Hello World Window /*+---------------------------------------------------------------------...
  • tiantian2999
  • tiantian2999
  • 2008年05月01日 12:40
  • 587

Enigma1 THE BIBLE - Environment setup to compile your code

Enviroment setup to compile your code Environment setup to compile your code Before to start to ...
  • tiantian2999
  • tiantian2999
  • 2008年05月01日 12:37
  • 237

Enigma1 THE BIBLE - Lesson8: Http Connection and Download

Lesson8: Http Connection and Download /*+-----------------------------------------------------------...
  • tiantian2999
  • tiantian2999
  • 2008年05月01日 12:47
  • 724
您举报文章:Enigma1 THE BIBLE - Lesson3: MessageBox