Imam Ferianto Blogs

sekedar catatan kecil saja

Panel adalah jendela atau kotak tempat kontrol ditempatkan, dapat juga disebut bingkai. wxPanel memisahkan tampilan dalam kotak terpisah dengan induk nya masing-masing panel tersendiri. wxPanel merupakan turunan dari wxWindow sehingga mewarisi semua attribut parent. Sejak wxWidgets 2.9, ada dukungan baik untuk traversal TAB yang diimplementasikan oleh wxWidgets sendiri maupun traversal TAB asli (seperti untuk GTK 2.0).

Pada tulisan kali ini , kita akan membuat panel dalam sebuah frame wxwidget

C++ Code:

#include <wx/wxprec.h>
#include <wx/wx.h>
#include <wx/textctrl.h>
#include <wx/bookctrl.h>
#include <wx/toplevel.h>
#include <iostream>

#ifdef __WXMAC__
#include <ApplicationServices/ApplicationServices.h>
ProcessSerialNumber PSN;
//GetCurrentProcess(&PSN);
//TransformProcessType(&PSN,kProcessTransformToForegroundApplication);
#endif

//#define FormUtama_STYLE wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU | wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX
//#define FormUtama_STYLE wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU | wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX

// Declare some IDs. These are arbitrary.
const int BOOKCTRL = 100;
const int BUTTON1 = 101;
const int BUTTON2 = 102;
const int LISTBOX1 = 103;
const int TEXTBOX1 = 104;
const int FILE_QUIT = wxID_EXIT;
const int HELP_ABOUT = wxID_ABOUT;

const int ID_WXPANEL3 = 1003;
const int ID_WXPANEL2 = 1002;
const int ID_WXPANEL1 = 1001;


class MyFrame : public wxFrame {
public:
 MyFrame(const wxString& title,const wxSize& size); //,long style);
 void OnButton1( wxCommandEvent& event );
 void OnButton2( wxCommandEvent& event );
 void OnQuit(wxCommandEvent& event);
 void OnAbout(wxCommandEvent& event);
private:
 DECLARE_EVENT_TABLE();
};


// Attach the event handlers. Put this after MyFrame declaration.
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 EVT_BUTTON(BUTTON1, MyFrame::OnButton1)
 EVT_BUTTON(BUTTON2, MyFrame::OnButton2)
 EVT_MENU(FILE_QUIT, MyFrame::OnQuit)
 EVT_MENU(HELP_ABOUT, MyFrame::OnAbout)
END_EVENT_TABLE();


MyFrame::MyFrame(const wxString& title,const wxSize& size): //,long style):
 wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, size) //, style)
{


  //SetIcon(wxICON(sample));
  SetBackgroundColour(wxColour(77,77,77));

  //top menubar
  wxMenu *fileMenu = new wxMenu;
  wxMenu *helpMenu = new wxMenu;
  helpMenu->Append(HELP_ABOUT, _T("&About...\tF1"), _T("Show about dialog"));
  fileMenu->Append(FILE_QUIT, _T("E&xit\tAlt-X"),  _T("Quit this program"));

  wxMenuBar *menuBar = new wxMenuBar();
  menuBar->Append(fileMenu, _T("&File"));
  menuBar->Append(helpMenu, _T("&Help"));  
  
  

  //bottom statusbar 2 column
  CreateStatusBar(2);
  SetStatusText(_T("So far so good."), 0);
  SetStatusText(_T("Welcome."), 1);

 
  wxPanel *WxPanel1 = new wxPanel(this, ID_WXPANEL1, wxPoint(20, 20), wxSize(280, 281));
  WxPanel1->SetBackgroundColour(wxColour(55,55,55));

  //add sizer
  wxBoxSizer *mysizer = new wxBoxSizer( wxVERTICAL );
  WxPanel1->SetSizer(mysizer);

  wxPanel *WxPanel2 = new wxPanel(this, ID_WXPANEL2, wxPoint(320, 20), wxSize(180, 136));
  WxPanel2->SetBackgroundColour(wxColour(44,44,44));

  //wxPoint(int x, int y)
  //wxSize(int width, int height)
  wxPanel *WxPanel3 = new wxPanel(this, ID_WXPANEL3, wxPoint(320, 165), wxSize(180, 136));
  WxPanel3->SetBackgroundColour(wxColour(55,55,55));


  wxPanel *WxPanel4 = new wxPanel(this, ID_WXPANEL3, wxPoint(20, 310), wxSize(480, 50));
  WxPanel4->SetBackgroundColour(wxColour(55,55,55));


  //add button to panel 4
  wxButton *button1=new wxButton(WxPanel4, BUTTON1, _T("Start &1"), wxPoint(10,10), wxSize(100,30) );
  wxButton *button2=new wxButton(WxPanel4, BUTTON2, _T("Stop &2"), wxPoint(130,10), wxSize(100,30) );


  

  SetIcon(wxNullIcon);
  SetSize(8,8,550,400);
  Center();

 
  SetMenuBar(menuBar);
  Show(true);
  
}


void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
 Close(true);
}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
  wxString msg;
  msg.Printf( _T("About.\n")
  _T("Selamat Datang di %s"), wxVERSION_STRING);

  wxMessageBox(msg, _T("About My Program"), wxOK | wxICON_INFORMATION, this);
}


void MyFrame::OnButton1(wxCommandEvent& WXUNUSED(event))
{
  wxMessageBox("Click1", "Click", wxOK | wxICON_INFORMATION, this);
};


void MyFrame::OnButton2(wxCommandEvent& WXUNUSED(event))
{
  wxMessageBox("Click2", "Click", wxOK | wxICON_INFORMATION, this);
}



class MyApp : public wxApp {
  public: bool OnInit(){
  
    MyFrame *frame = new MyFrame(_T("Layout Frame"),wxSize(600, 400)); //,FormUtama_STYLE);
  
    return true;
  }
};


IMPLEMENT_APP(MyApp);

 

Compile command:

g++ -ggdb -std=c++11 \
`pkg-config --cflags opencv4` \
frame.cpp -o frame \
`pkg-config --cflags --libs opencv4` \
`wx-config --cxxflags --libs`

Run : ./frame

Output: