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

Tuesday, August 19, 2014

Install Code::Blocks on Ubuntu

Code::Blocks is a cross-platform Integrated Development Environment (IDE). To install Code::Blocks on Ubuntu, simple search Code::Blocks in Ubuntu Software Center, or click this link.


Create Hello World (hello.cpp) using Code::Blocks


Create Hello World Project using Code::Blocks


Hello World Project with multiple files, Code::Blocks



- With Code::Blocks installed, you can create wxWidgets Project.

Friday, August 15, 2014

Display info kernel module of with modinfo command

To display info kernel module, enter the command:

$ modinfo hello.ko

where hello.ko is the kernel object file.


Develop Hello World of Linux Kernel Module

To create Linux Kernel Module, install the development tools:

$ sudo apt-get install gcc
$ sudo apt-get install kernel-package
$ sudo apt-get install make




Make and switch to a fold for your works. Create a c program, hello.c, and Makefile file. Please notice that both hello.c and Makefile have to be in the same folder.

hello.c
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>

static int __init hello_init(void)
{
 printk(KERN_INFO "Hello World! pid = %d\n", current->pid);
 return 0;
}

static void __exit hello_exit(void)
{
 printk(KERN_INFO "Hello Bye!\n");
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Linux-Buddy: linux-buddy.blogspot.com");
MODULE_DESCRIPTION("Test Module: Hello World");
MODULE_VERSION("1.0");

Makefile
obj-m += hello.o

all:
 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean



Make the kernel module by enter the command:
$ make

Then insert the module with:
$ sudo insmod hello.ko

You can use the dmesg to view the kermel message printed by the code printk() in c program.
$ dmesg

List installed modules:
$ lsmod

To remove the module:
$ sudo rmmod hello.ko


Wednesday, August 13, 2014

Install Adobe Reader on Ubuntu 14.04

To install Adobe Reader (version 9.5.5) on Ubuntu 14.04, download from http://ardownload.adobe.com/pub/adobe/reader/unix/9.x/9.5.5/enu/AdbeRdr9.5.5-1_i386linux_enu.deb, then install with Ubuntu Software Center by right clicking on the file.

Adobe Reader run on Ubuntu 14.04