![]() |
| cal command |
Adsense code (2021-10-05)
Tuesday, January 28, 2014
cal - Linux command to display calendar
Monday, January 27, 2014
GtkColorChooser example
![]() |
| GtkColorChooser |
#include <gtk/gtk.h>
static void
chooser_color_activated(GtkColorChooser *chooser,
GdkRGBA *color, gpointer user_data)
{
GtkLabel *label = user_data;
gtk_label_set_text (label, gdk_rgba_to_string(color));
}
int main( int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *box;
GtkWidget *label;
GtkWidget *chooser;
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");
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
label = gtk_label_new("label");
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 3);
//Create GtkColorChooser
chooser = gtk_color_chooser_widget_new();
gtk_box_pack_start(GTK_BOX(box), chooser, FALSE, FALSE, 3);
g_signal_connect (GTK_COLOR_CHOOSER(chooser),
"color-activated",
G_CALLBACK (chooser_color_activated),
label);
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;
}
Note: double click the color buttons to activate color change.
Saturday, January 25, 2014
View hiden file start with a "."
Filenames which start with a "." (dot) are normally not shown. Use 'ls .*' or 'ls -a ...' to see them.
Wednesday, January 22, 2014
GTK+ example: Scale
![]() |
| GTK+ example: Scale |
#include <gtk/gtk.h>
static gboolean
scale_changed (GtkRange *range, gpointer data)
{
gchar *text;
gdouble value;
GtkLabel *label;
label = data;
value = gtk_range_get_value (range);
text = g_strdup_printf ("%.1f", value);
gtk_label_set_text (label, text);
g_free (text);
return TRUE;
}
int main( int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *box;
GtkWidget *label;
GtkWidget *spinButton;
GtkWidget *scale;
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");
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
//Create Label
label = gtk_label_new("label");
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 3);
//Create Scale
scale = gtk_scale_new_with_range (
GTK_ORIENTATION_HORIZONTAL,
0, //gdouble min
10, //gdouble max
0.5); //gdouble step
gtk_widget_set_hexpand (scale, TRUE);
g_signal_connect(G_OBJECT(scale), "value-changed",
G_CALLBACK(scale_changed), label);
gtk_box_pack_start(GTK_BOX(box), scale, 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;
}
Saturday, January 11, 2014
GTK+ example: SpinButton
![]() |
| SpinButton displayed on Ubuntu |
#include <gtk/gtk.h>
static gboolean
spinButton_changed (GtkSpinButton *spin, gpointer data)
{
gchar *text;
int value;
GtkLabel *label;
label = data;
value = gtk_spin_button_get_value_as_int (spin);
text = g_strdup_printf ("%02d", value);
gtk_label_set_text (label, text);
g_free (text);
return TRUE;
}
int main( int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *box;
GtkWidget *label;
GtkWidget *spinButton;
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");
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
//Create Label
label = gtk_label_new("label");
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 3);
//Create SpinButton
spinButton = gtk_spin_button_new_with_range (
0, //gdouble min
10, //gdouble max
2); //gdouble step
gtk_widget_set_hexpand (spinButton, TRUE);
g_signal_connect(G_OBJECT(spinButton), "value-changed",
G_CALLBACK(spinButton_changed), label);
gtk_box_pack_start(GTK_BOX(box), spinButton, 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;
}
Remark: wrong icon displayed on Lubuntu:
![]() |
| SpinButton with wrong icon displayed on Lubuntu |
Thursday, January 9, 2014
Download file using SSH with scp command
The Linux command scp, securely copying files, uses ssh for data transfer, to copy file to, from, or between different hosts.
To download file from server using ssh, using the command:
$ scp user@hostname:file local-directory
example:
$ scp pi@192.168.111.109:~/log1 ~/PiLog
where pi is user name in server with IP 192.168.111.109, copy ~/log1 from server to local directory ~/PiLog.
To download file from server using ssh, using the command:
$ scp user@hostname:file local-directory
example:
$ scp pi@192.168.111.109:~/log1 ~/PiLog
where pi is user name in server with IP 192.168.111.109, copy ~/log1 from server to local directory ~/PiLog.
![]() |
| scp |
Redirect command output to both stdout and file
The linux command tee read from standard input and write to standard output and files.
Example:
$ ls | tee filelist.txt
Example:
$ ls | tee filelist.txt
Subscribe to:
Posts (Atom)





