Adsense code (2021-10-05)

Tuesday, December 31, 2013

GTK+ example: RadioButton

GTK+ example: RadioButton
GTK+ example: RadioButton

#include <gtk/gtk.h>

int main( int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *radioButton1;
    GtkWidget *radioButton2;
    GtkWidget *radioButton3;
    GtkWidget *radioButton4;
    GtkWidget *radioButton5;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 250);
    gtk_window_set_title(GTK_WINDOW(window), "Linux-buddy.blogspot.com");

    //new RadioButton1, 2, 3 in same group
    radioButton1 = gtk_radio_button_new_with_label (
        NULL, "Radio Button 1");
    radioButton2 = gtk_radio_button_new_with_label_from_widget (
        GTK_RADIO_BUTTON (radioButton1), "Radio Button 2");
    radioButton3 = gtk_radio_button_new_with_label_from_widget (
        GTK_RADIO_BUTTON (radioButton1), "Radio Button 3");

    //new RadioButton4, 5 in another group
    radioButton5 = gtk_radio_button_new_with_label (
        NULL, "Another Group Button 5");
    radioButton4 = gtk_radio_button_new_with_label_from_widget (
        GTK_RADIO_BUTTON (radioButton5), "Another Group Button 4");

    box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
    gtk_box_pack_start(GTK_BOX(box), radioButton1, FALSE, FALSE, 3);
    gtk_box_pack_start(GTK_BOX(box), radioButton2, FALSE, FALSE, 3);
    gtk_box_pack_start(GTK_BOX(box), radioButton3, FALSE, FALSE, 3);
    gtk_box_pack_start(GTK_BOX(box), radioButton4, FALSE, FALSE, 3);
    gtk_box_pack_start(GTK_BOX(box), radioButton5, FALSE, FALSE, 3);

    //Connects GCallback function gtk_main_quit to "destroy" signal for "window"
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_container_add(GTK_CONTAINER(window), box);
    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}



Next: Handle "toggled" signal of RadioButton and determine the active selected RadioButton in group

Monday, December 30, 2013

GTK+ example: LinkButton, button to open URL in browser

LinkButton
LinkButton

#include <gtk/gtk.h>

int main( int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *linkbutton_linuxbuddy;
    GtkWidget *linkbutton_google;
    GtkWidget *linkbutton_youtube;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 250);
    gtk_window_set_title(GTK_WINDOW(window), "Linux-buddy.blogspot.com");

    linkbutton_linuxbuddy = gtk_link_button_new ("linux-buddy.blogspot.com");
    gtk_link_button_set_uri(GTK_LINK_BUTTON(linkbutton_linuxbuddy), "http://linux-buddy.blogspot.com/");
    linkbutton_google = gtk_link_button_new ("Google");
    gtk_link_button_set_uri(GTK_LINK_BUTTON(linkbutton_google), "http://google.com/");
    linkbutton_youtube = gtk_link_button_new ("Youtube");
    gtk_link_button_set_uri(GTK_LINK_BUTTON(linkbutton_youtube), "http://www.youtube.com");

    box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
    gtk_box_pack_start(GTK_BOX(box), linkbutton_linuxbuddy, FALSE, FALSE, 3);
    gtk_box_pack_start(GTK_BOX(box), linkbutton_google, FALSE, FALSE, 3);
    gtk_box_pack_start(GTK_BOX(box), linkbutton_youtube, FALSE, FALSE, 3);

    gtk_container_add(GTK_CONTAINER(window), box);

    //Connects GCallback function gtk_main_quit to "destroy" signal for "window"
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}

Saturday, December 28, 2013

GTK+ example create menu bar

Example to create menu bar with GTK+ in C language.

GTK+ example create menu bar
GTK+ example create menu bar

#include <gtk/gtk.h>

static void open_activated(GtkWidget *f)
{
    g_print("File -> Open activated.\n");
}

static void quit_activated(GtkWidget *f)
{
    g_print("File -> Quit activated...bye.\n");
    gtk_main_quit();
}

static void another_activated(GtkWidget *widget, gpointer data)
{
    g_print("%s clicked.\n", (gchar*)data);
}

int main( int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *menubar;
    GtkWidget *filemenu;
    GtkWidget *file;
    GtkWidget *open;
    GtkWidget *quit;

    GtkWidget *anothermenu;
    GtkWidget *another;
    GtkWidget *anothermenuitem;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    //gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 250);
    gtk_window_set_title(GTK_WINDOW(window), "Linux-buddy.blogspot.com");

    menubar = gtk_menu_bar_new();
    
    filemenu = gtk_menu_new();
    file = gtk_menu_item_new_with_label("File");
    open = gtk_menu_item_new_with_label("Open");
    quit = gtk_menu_item_new_with_label("Quit");
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
    //Connects GCallback function open_activated to "activate" signal for "open" menu item
    g_signal_connect(G_OBJECT(open), "activate", G_CALLBACK(open_activated), NULL);
    //Connects GCallback function quit_activated to "activate" signal for "quit" menu item
    g_signal_connect(G_OBJECT(quit), "activate", G_CALLBACK(quit_activated), NULL);

    anothermenu = gtk_menu_new();
    another = gtk_menu_item_new_with_label("Another");
    anothermenuitem = gtk_menu_item_new_with_label("Another Menu Item");
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(another), anothermenu);
    gtk_menu_shell_append(GTK_MENU_SHELL(anothermenu), anothermenuitem);
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar), another);
    //Connects GCallback function another_activated to "activate" signal for another
    g_signal_connect(G_OBJECT(anothermenuitem), "activate", G_CALLBACK(another_activated), "anothermenuitem");
    g_signal_connect(G_OBJECT(another), "activate", G_CALLBACK(another_activated), "another");

    box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
    gtk_box_pack_start(GTK_BOX(box), menubar, FALSE, FALSE, 3);
    gtk_container_add(GTK_CONTAINER(window), box);

    //Connects GCallback function gtk_main_quit to "destroy" signal for "window"
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}

Example of using GtkBox

GtkBox
GtkBox

#include <gtk/gtk.h>

static void myButtonClicked(GtkWidget *widget, gpointer   data)
{
    g_print("Button clicked: Hello GTK+\n");
}

int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *myImage;
    GtkWidget *myButton;
    GtkWidget *box;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 250);

    /*
    warning: 
        ‘gtk_vbox_new’ is deprecated 
        Use 'gtk_box_new' instead
    */
    //box = gtk_vbox_new(FALSE, 0);
    box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);

    myImage = gtk_image_new_from_file ("Linux.png");

    myButton = gtk_button_new_with_label("Hello GTK+ from Linux-Buddy");
    g_signal_connect(myButton, "clicked", 
        G_CALLBACK(myButtonClicked), NULL);

    g_signal_connect (window, "destroy", 
        G_CALLBACK(gtk_main_quit), NULL);

    
    gtk_box_pack_start(GTK_BOX(box), myImage, TRUE, TRUE, 5);
    gtk_box_pack_end(GTK_BOX(box), myButton, TRUE, TRUE, 5);

    gtk_container_add(GTK_CONTAINER (window), box);
    gtk_widget_show_all (window);

    gtk_main();
    return(0);
}

Thursday, December 26, 2013

GTK+3 example of Grid

GTK+3 example of Grid
GTK+3 example of Grid

#include <gtk/gtk.h>

int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *myGrid;
    GtkWidget *button1, *button2, *button3, *button4, 
        *button5, *button6, *button7;


    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 250);

    g_signal_connect(window, "destroy", 
        G_CALLBACK(gtk_main_quit), NULL);

    myGrid = gtk_grid_new();

    button1 = gtk_button_new_with_label("Button 1");
    button2 = gtk_button_new_with_label("Button 2");
    button3 = gtk_button_new_with_label("Button 3");
    button4 = gtk_button_new_with_label("Button 4");
    button5 = gtk_button_new_with_label("Button 5");
    button6 = gtk_button_new_with_label("Button 6");
    button7 = gtk_button_new_with_label("Button 7");
    
    gtk_grid_attach(GTK_GRID(myGrid), button1, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(myGrid), button2, 1, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(myGrid), button3, 2, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(myGrid), button4, 3, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(myGrid), button5, 0, 1, 3, 1);
    gtk_grid_attach(GTK_GRID(myGrid), button6, 3, 1, 1, 2);
    gtk_grid_attach(GTK_GRID(myGrid), button7, 0, 2, 1, 1);

    gtk_container_add(GTK_CONTAINER (window), myGrid);
    gtk_widget_show_all (window);

    gtk_main();
    return(0);
}

GTK+ example with image

GTK+ example with image
GTK+ example with image

#include <gtk/gtk.h>

static void myButtonClicked(GtkWidget *widget, gpointer   data)
{
    g_print("Button clicked: Hello GTK+\n");
}

int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *myImage;
    GtkWidget *myButton;
    GtkWidget *myPaned;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 250);

    myPaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);

    myImage = gtk_image_new_from_file ("Linux.png");

    myButton = gtk_button_new_with_label("Hello GTK+ from Linux-Buddy");
    g_signal_connect(myButton, "clicked", 
        G_CALLBACK(myButtonClicked), NULL);

    g_signal_connect (window, "destroy", 
        G_CALLBACK(gtk_main_quit), NULL);

    gtk_paned_add1 (GTK_PANED(myPaned), myImage);
    gtk_paned_add2 (GTK_PANED(myPaned), myButton);

    gtk_container_add(GTK_CONTAINER (window), myPaned);
    gtk_widget_show_all (window);

    gtk_main();
    return(0);
}

"Hello World" of GTK+ 3 with C language

"Hello World" of GTK+ 3 with C language
"Hello World" of GTK+ 3 with C language
hello.c
#include <gtk/gtk.h>

static void myButtonClicked(GtkWidget *widget, gpointer   data)
{
    g_print("Button clicked: Hello GTK+\n");
}

int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *myButton;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 250);

    myButton = gtk_button_new_with_label("Hello GTK+ from Linux-Buddy");
    g_signal_connect(myButton, "clicked", 
        G_CALLBACK(myButtonClicked), NULL);

    g_signal_connect (window, "destroy", 
        G_CALLBACK(gtk_main_quit), NULL);

    gtk_container_add(GTK_CONTAINER (window), myButton);
    gtk_widget_show(myButton);
    gtk_widget_show(window);

    gtk_main();
    return(0);
}
Compile with:
gcc hello.c -o hello `pkg-config --cflags --libs gtk+-3.0`
Run:
./hello

Install GTK+3 on Ubuntu

To install GTK+3 development tools on Ubuntu Linux, enter the command in terminal:

sudo apt-get install libgtk-3-dev


Change computer name for Ubuntu Linux

To change your computer name in Ubuntu Linux, you have to be the administrator of your system. Enter the command in Terminal:

gksudo gedit /etc/hostname

Edit the file /etc/hostname, replace the original computer name with new one. Then save and exit.

And also need to edit /etc/hosts, replace the entry of the original computer name with the new name.

$ gksudo gedit /etc/hosts

Then reboot your computer.

Thursday, December 19, 2013

Sublime Text, a sophisticated text editor for code, markup and prose

Sublime Text is a sophisticated text editor for code, markup and prose. It is available for OS X, Windows and Linux.

Sublime Text uses a custom UI toolkit, optimized for speed and beauty, while taking advantage of native functionality on each platform.

link: http://www.sublimetext.com/

Sublime Text
Sublime Text, a sophisticated text editor for code, markup and prose



Tuesday, December 17, 2013

Geany - small and fast code editor and IDE

Geany is a text editor using the GTK2 toolkit with basic features of an integrated development environment. It was developed to provide a small and fast IDE, which has only a few dependencies from other packages. It supports many filetypes and has some nice features.


To install geany:
$sudo apt-get install geany

Thursday, November 21, 2013

Get running Ubuntu version

To print the version of your running Ubuntu, enter the command:
$ lsb_release -a


Monday, September 9, 2013

Set title of Terminal

To saet title of Terminal, click Terminal option -> Set Title...

Set title of Terminal
Set title of Terminal

How to set command prompt in Ubuntu Linux

Enter the command to change command prompt in Ubuntu:

$PS1="<new prompt>"

set command prompt in Ubuntu Linux
set command prompt in Ubuntu Linux


Saturday, August 17, 2013

Check cpu temperature

To check CPU temperature in Linux:

$acpi -t
Check cpu temperature with acpi -t
Check cpu temperature with acpi -t
To install acpi, run the command in Terminal:

$sudo apt-get install acpi


Saturday, July 27, 2013

How to check version of Ubuntu

To check the version of Ubuntu system, you can use the command "lsb_release" to print distribution specific information.
$ lsb_release -a

lsb_release -a
lsb_release -a

Saturday, May 18, 2013

Install Google Chrome browser on Ubuntu 13.04

If you download and install the current version of Google Chrome browser on frash new Ubuntu, you will be complained with error of:

Dependency is not satisfiable: libudev0(>=147)

Dependency is not satisfiable: libudev0(>=147)
Error when install Google Chrome on Ubuntu 13.04


To fix it, follow the links to download and install libudev0:

32bit .deb:
http://launchpadlibrarian.net/132294322/libudev0_175-0ubuntu19_i386.deb

64bit .deb
http://launchpadlibrarian.net/132294155/libudev0_175-0ubuntu19_amd64.deb


Monday, April 22, 2013

Speedometer, Measure network connection

Speedometer
Speedometer

Speedometer is a application to measure and display the rate of data across a network connection or data being stored in a file. The current version is 2.8.

To install on Ubuntu, run the command in Terminal:

$sudo apt-get install speedometer

Friday, March 15, 2013

Ubuntu Rescue Remix: data recovery software toolkit based on Ubuntu



Ubuntu Rescue Remix provides a Free-Libre Open-Source data recovery software toolkit based on Ubuntu.

Ubuntu-Rescue-Remix provides a robust yet lean system for data recovery and forensics. No graphical interface is used; the live system can boot and function normally on machines with very little memory or processor power. Following Ubuntu's six-month release schedule, all the software is up-to-date, stable and supported.

Ubuntu-Rescue-Remix features a full command-line environment with the newest versions of the most powerful free/libre open-source data recovery software including GNU ddrescue, Photorec, The Sleuth Kit, Gnu-fdisk and Clamav.


Tuesday, March 12, 2013

Intel Linux Graphics Installer 1.0

Intel Linux Graphics Installer allows you to easily install the latest graphics drivers for your Intel graphics hardware. This allows you to stay current with the latest enhancements, optimizations, and fixes to ensure the best user experience with your Intel graphics hardware.

https://01.org/linuxgraphics/

Intel Linux Graphics Installer
Intel Linux Graphics Installer

Sunday, February 17, 2013

MCU 8051 IDE


MCU 8051 IDE

MCU 8051 IDE is integrated development enviroment for microcontrollers based on 8051.

Supported programming languages are C and assembly. It has its own assembler and support for 2 external assemblers. For C language it uses SDCC compiler.

This program is intended for Linux systems, other POSIX systems and Microsoft® Windows® system. There are packages for various Linux distributions (.RPM , .DEB and .ebuild) and an installer for MS Windows®.

This IDE contains simulator, source code editor, assembler, HW programmer and much other tools. Simulator supports over 79 MCU primarily from Atmel.

HW programmer supports 8 ISP programmable MCUs from Atmel (AT89Sxx, AT89LSxx).

There is also support for simple hardware simulation (like LEDs, keys, etc.).

MCU 8051 IDE Screenshot
MCU 8051 IDE Screenshot


Friday, February 8, 2013

LibreOffice 4.0.0 Final released



LibreOffice 4.0.0 is the first release from the 4.0 branch of LibreOffice. It contains many exciting new features, and is suitable for early adopters and private power users.

GIMP 2.8.4 released



GIMP 2.8.4 is out! This is a release in the stable GIMP 2.8 series, featuring lots of bug fixes and translation updates. For the complete list of changes please see the NEWS file.

Thursday, January 17, 2013

How to format USB drive on Ubuntu

Search and run the application Disks.


Select the USB driver, Click the gear icon, and select Format Disk...



Wednesday, January 16, 2013

Entangle: Tethered Camera Control & Capture

Entangle provides a graphical interface for “tethered shooting”, aka taking photographs with a digital camera completely controlled from the computer.

Pinta: Painting Made Simple

Pinta is a free, open source drawing/editing program modeled after Paint.NET. Its goal is to provide users with a simple yet powerful way to draw and manipulate images on Linux, Mac, and Windows.

Pinta 1.4 has been released for Windows, Linux, and Mac!

Web site: http://pinta-project.com/

Ubuntu Studio

Ubuntu Studio is a free, open, and powerful operating system for creative people to create their art.

Whether your focus is audio, video, photography, or graphic design, Ubuntu Studio is both productive and rewarding to use.

  • Audio

    With a full suite of audio applications and documented work flows, Ubuntu Studio can support you with record, mix, and many more.
  • Graphics

    Graphic design and modeling applications including The GIMP, Inkscape and Blender. Along with plugins like dcraw to help with RAW camera files and wacom-tools for people with Wacom drawing tablets.
  • Video

    Ubuntu Studio supports you all the way to final render for your video.

    Ubuntu Studio also provides an application suite for 3D modeling, animation, and compositing.

    Post production effects, like lens flares, color grading, and chroma key/alpha over, are available to support your creative vision.
  • Photography

    Import pictures from your camera or other devices.

    Edit, process and organize your photos with such applications as Openshot and Darktable, and publish them to social web sites.
  • Publishing

    Whether you’re heading for the printing press, or need to have a particular format for a phone reader, it is possible to achieve professional results on Ubuntu Studio.

Link: http://ubuntustudio.org/

Tuesday, January 15, 2013

How to set the Launcher Bar auto-hide on Ubuntu 12.10

To set the Launcher oh Ubuntu 12.10 auto-hide:

Right click on the screen, select Change Desktop Background.


Select Behavior, set Auto-hide the Launcher to ON.


Friday, January 4, 2013

Install GCC 4.7.2 on Ubuntu Linux

To try the new of C++11 on Ubuntu, we can install GCC 4.7 or later. GCC 4.7.2 have been release.

To install GCC 4.7 on Ubuntu, open a Terminal and type the command:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test 
sudo apt-get update 
sudo apt-get install g++-4.7 c++-4.7

To made the g++4.7 as default, type the command:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7 20
sudo update-alternatives --config gcc
sudo update-alternatives --config g++