Thursday, August 28, 2014

nomacs, a free, small, fast and multi-format image viewer

nomacs is a free image viewer for windows, linux, and mac systems, which is licensed under the GNU General Public License v3. nomacs is small, fast and able to handle the most common image formats including RAW images. Additionally it is possible to synchronize multiple viewers. A synchronization of viewers running on the same computer or via LAN is possible. It allows to compare images and spot the differences (e.g. schemes of architects to show the progress).

To install nomacs on Ubuntu, add repository of ppa:nomacs/stable:
$ sudo add-apt-repository ppa:nomacs/stable

Then, enter the commands:
$ sudo apt-get update
$ sudo apt-get install nomacs


Monday, August 25, 2014

Linux command, lscpu, to get CPU architecture information

The Linux command lscpu  gathers  CPU  architecture  information  like  number  of  CPUs, threads, cores, sockets, NUMA nodes, information about CPU caches,  CPU family,  model,  bogoMIPS,  byte  order  and  stepping  from  sysfs and /proc/cpuinfo, and prints it in a human-readable format.   It  supports both online and offline CPUs.  It can also print out in a parsable for‐mat, including how different caches are shared by different CPUs, which can be fed to other programs.


Code::Blocks + wxWidgets + wxSmith, to open text file with wxFileDialog

This video show steps to create wxWidgets project in Code::Blocks, using wxSmith, to open text file with wxFileDialog.



The only programmatic code is in wxTextFileFrame::OnMenuOpenSelected() of the file wxTextFileMain.cpp.
void wxTextFileFrame::OnMenuOpenSelected(wxCommandEvent& event)
{
    wxTextFile file;
    wxString text;

    int result;
    result = FileDialog1->ShowModal();
    if(result==wxID_OK){
        SetTitle(FileDialog1->GetPath());

        file.Open(FileDialog1->GetPath());
        for(size_t i=0; i<file.GetLineCount(); i++){
            text << file.GetLine(i) << _T("\r\n");
        }
        file.Close();
        TextCtrl1->SetValue(text);
    }

}


And also include wx/textfile.h.
#include <wx/textfile.h>


Sunday, August 24, 2014

Hello World of Code::Blocks with wxSmith

"wxSmith plugin is not loaded, can not continue" in Code::Blocks

If you try to New a wxWidgets Project in Code::Blocls, with GUI Builder of wxSmith; may be you will be complained with error of "wxSmith plugin is not loaded, can not continue".



You have to install codeblocks-contrib, it is a contrib plugins for Code::Blocks IDE. To install it on Ubuntu, enter the command:

$ sudo apt-get install codeblocks-contrib

And then restart Code::Blocks.

Wednesday, August 20, 2014

Add Button to wxWidgets project

Create wxWidgets Project with Code::Blocks, as shown in last post.


To add a Buuton, modify HelloWxMain.h and HelloWxMain.h.cpp.

/***************************************************************
 * Name:      HelloWxMain.h
 * Purpose:   Defines Application Frame
 * Author:    Buddy ()
 * Created:   2014-08-21
 * Copyright: Buddy (linux-buddy.blogspot.com)
 * License:
 **************************************************************/

#ifndef HELLOWXMAIN_H
#define HELLOWXMAIN_H

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "HelloWxApp.h"

class HelloWxFrame: public wxFrame
{
    public:
        HelloWxFrame(wxFrame *frame, const wxString& title);
        ~HelloWxFrame();
    private:

        //add for "Hello Button"
        static const long idButtonHello;
        wxBoxSizer* m_MainBox;
        wxButton* m_ButtonHello;
        void onClickHello(wxCommandEvent& event);
        //end of "Hello Button"

        enum
        {
            idMenuQuit = 1000,
            idMenuAbout
        };
        void OnClose(wxCloseEvent& event);
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        DECLARE_EVENT_TABLE()
};


#endif // HELLOWXMAIN_H

/***************************************************************
 * Name:      HelloWxMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    Buddy ()
 * Created:   2014-08-21
 * Copyright: Buddy (linux-buddy.blogspot.com)
 * License:
 **************************************************************/

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "HelloWxMain.h"

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__WXMAC__)
        wxbuild << _T("-Mac");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

const long HelloWxFrame::idButtonHello = ::wxNewId();   //Hello Button

BEGIN_EVENT_TABLE(HelloWxFrame, wxFrame)
    EVT_CLOSE(HelloWxFrame::OnClose)
    EVT_MENU(idMenuQuit, HelloWxFrame::OnQuit)
    EVT_MENU(idMenuAbout, HelloWxFrame::OnAbout)
    EVT_BUTTON(idButtonHello, HelloWxFrame::onClickHello) //Hello Button
END_EVENT_TABLE()

HelloWxFrame::HelloWxFrame(wxFrame *frame, const wxString& title)
    : wxFrame(frame, -1, title)
{
#if wxUSE_MENUS
    // create a menu bar
    wxMenuBar* mbar = new wxMenuBar();
    wxMenu* fileMenu = new wxMenu(_T(""));
    fileMenu->Append(idMenuQuit, _("&Quit\tAlt-F4"), _("Quit the application"));
    mbar->Append(fileMenu, _("&File"));

    wxMenu* helpMenu = new wxMenu(_T(""));
    helpMenu->Append(idMenuAbout, _("&About\tF1"), _("Show info about this application"));
    mbar->Append(helpMenu, _("&Help"));

    SetMenuBar(mbar);
#endif // wxUSE_MENUS

#if wxUSE_STATUSBAR
    // create a status bar with some information about the used wxWidgets version
    CreateStatusBar(2);
    SetStatusText(_("Hello Code::Blocks user!"),0);
    SetStatusText(wxbuildinfo(short_f), 1);
#endif // wxUSE_STATUSBAR

    //Hello Button
    this->SetSizeHints(wxDefaultSize, wxDefaultSize);
    m_MainBox = new wxBoxSizer(wxHORIZONTAL);

    m_ButtonHello = new wxButton(
                            this,
                            idButtonHello,
                            _T("Hello...!"),
                            wxDefaultPosition,
                            wxDefaultSize,
                            0);
    m_MainBox->Add(m_ButtonHello,
                    0,
                    wxALL,
                    5);

    this->SetSizer(m_MainBox);
    this->Layout();
}


HelloWxFrame::~HelloWxFrame()
{
}

void HelloWxFrame::OnClose(wxCloseEvent &event)
{
    Destroy();
}

void HelloWxFrame::OnQuit(wxCommandEvent &event)
{
    Destroy();
}

void HelloWxFrame::OnAbout(wxCommandEvent &event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

//Hello Button Clicked
void HelloWxFrame::onClickHello(wxCommandEvent &event)
{
    wxString msg = _T("Hello World");
    wxString info = _T("linux-buddy");
    wxMessageBox(msg,
                info,
                wxOK | wxICON_INFORMATION,
                this);
}

No modify on HelloWxApp.h and HelloWxApp.cpp

/***************************************************************
 * Name:      HelloWxApp.h
 * Purpose:   Defines Application Class
 * Author:    Buddy ()
 * Created:   2014-08-21
 * Copyright: Buddy (linux-buddy.blogspot.com)
 * License:
 **************************************************************/

#ifndef HELLOWXAPP_H
#define HELLOWXAPP_H

#include <wx/app.h>

class HelloWxApp : public wxApp
{
    public:
        virtual bool OnInit();
};

#endif // HELLOWXAPP_H

/***************************************************************
 * Name:      HelloWxApp.cpp
 * Purpose:   Code for Application Class
 * Author:    Buddy ()
 * Created:   2014-08-21
 * Copyright: Buddy (linux-buddy.blogspot.com)
 * License:
 **************************************************************/

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "HelloWxApp.h"
#include "HelloWxMain.h"

IMPLEMENT_APP(HelloWxApp);

bool HelloWxApp::OnInit()
{
    HelloWxFrame* frame = new HelloWxFrame(0L, _("wxWidgets Application Template"));
    
    frame->Show();
    
    return true;
}

Create wxWidgets Project with Code::Blocks

With Code::Blocks installed, you can create wxWidgets Project by new a wxWidgets project (File > Project... > Category GUI > wxWidgets Project).

If you have error of:
fatal error: wx/app.h: No such file or directory

You need to install wx-common, and also libwxgtk2.8-dev or libwxgtk3.0-dev.

sudo apt-get install wx-common
sudo apt-get install libwxgtk2.8-dev
sudo apt-get install libwxgtk3.0-dev

The videos show how to install and run, on Ubuntu Linux.




Next:
Add Button to wxWidgets project