がんばって英語で書くブログ
英語勉強中なので、ブログも英語で書こうかと。
スポンサーサイト
上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

new books
I bought two books today. one of book is computer technology book and the other is I don't know what category is suite.

This book's title is FREAKONOMICS.(it cost $7.99)
Why I bought it because it looks interesting.
for example, I want to know why drug dialers living with their moms, and etc.

I thought this book is not serious so I should be able to enjoy reading.



スポンサーサイト

テーマ:英語日記 - ジャンル:学問・文化・芸術

Japanese test
I took it.
that result was 51(16/30) points, no wonder.
actually, I could get good score as much as I expected :-)






テーマ:英語日記 - ジャンル:学問・文化・芸術

bug fix
I read main-menu.c (it's one of d-i components) this afternoon. I found a memory leak bug.
so I wrote a patch then send a bug report with the patch.
the patch was accepted. so it's my pleasure:-)


テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying11
This is GTK+ memo. using label and fork(), pipe().


#include <gtk/gtk.h>

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>

static gchar *get_uname(void)
{
int fd[2];

pid_t pid;
char buf[256];
gchar *p = NULL;

memset(buf, 0, sizeof(buf));

pipe(fd);

if ((pid = fork()) == -1)
perror("fork()");

if (pid == 0) { /* chiled */
dup2(fd[1], 1);

close(fd[0]);
close(fd[1]);

execl("/bin/uname", "uname", "-sr", NULL);
_exit(0);
} else {
close(fd[1]);

read(fd[0], &buf, sizeof(buf) - 1);
p = g_strdup(buf);
}

return p;
}

static gboolean button_clicked(GtkWidget *widget,
gpointer data)
{
GtkWidget *label = (GtkWidget *) data;
gchar *p = get_uname();

gtk_label_set_text(GTK_LABEL(label), p);
g_free(p);

return FALSE;
}

static GtkWidget *create_button(void *data)
{
GtkWidget *button;

button = gtk_button_new_with_label("ok");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(button_clicked), data);

return button;
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *button;
GtkWidget *separator;
GtkWidget *label;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "label test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

vbox1 = gtk_vbox_new(FALSE,0);
vbox2 = gtk_vbox_new(FALSE, 0);

label = gtk_label_new("default text");

gtk_box_pack_start(GTK_BOX(vbox1), label, TRUE, TRUE, 0);
gtk_widget_set_size_request(GTK_WIDGET(label), 180, 200);

gtk_widget_show(label);

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

separator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, TRUE, 0);
gtk_widget_show(separator);

button = create_button(label);
gtk_box_pack_start(GTK_BOX(vbox2), button, TRUE, TRUE, 0);
gtk_widget_show(button);

gtk_container_add(GTK_CONTAINER(vbox1), vbox2);
gtk_widget_show(vbox2);

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}


テーマ:英語日記 - ジャンル:学問・文化・芸術

cats and credit card
According to this
.
That would be funny if there could get a credit card:-)
if she didn't tell truth, cat got it.
then, her cat buy cats food at super market. of course she use her credit card:-)



テーマ:英語日記 - ジャンル:学問・文化・芸術

trial lession
I went to some English school to take a trial lesson.
I had level check test, lesson and so on.
That test's result was not bad. btw, if I spoke English every day I could get more good result.
anyway, lesson was good also lesson fee is _very_ important.
so I can't decide yet.

maybe I'll take another school's trial lesson then I'll decide school.


テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying10
This is GTK+ memo. using progress bar.


#include <gtk/gtk.h>

struct progress_data {
GtkWidget *bar;
int counter;
int timer;
};

static inline gchar *make_string(struct progress_data *progress)
{
return g_strdup_printf("count is %d\n", progress->counter++);
}

static gboolean progressbar_timeout(gpointer data)
{
struct progress_data *progress = (struct progress_data *) data;
gdouble new_val;
gchar *p = NULL;

new_val = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progress->bar)) + 0.01;
if (new_val > 1.0)
new_val = 0.0;

gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->bar), new_val);

p = make_string(progress);
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->bar), p);
g_free(p);

if (progress->counter > 100) {
GtkWidget *dlg;

gtk_timeout_remove(progress->timer);
dlg = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"finished");
gtk_dialog_run(GTK_DIALOG(dlg));

g_free(progress);

gtk_main_quit();
}


return TRUE;
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *vbox1;
GtkWidget *align;
gchar *p;
struct progress_data *progress;

progress = g_malloc(sizeof(struct progress_data));
progress->counter = 0;
progress->timer = 0;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "progress bar test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

vbox1 = gtk_vbox_new(FALSE,0);

align = gtk_alignment_new(0.5, 0.5, 0, 0);
gtk_box_pack_start(GTK_BOX(vbox1), align, FALSE, FALSE, 0);
gtk_widget_show(align);

progress->bar = gtk_progress_bar_new();
gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(progress->bar), GTK_PROGRESS_LEFT_TO_RIGHT);

p = make_string(progress);
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->bar), p);
g_free(p);

gtk_container_add(GTK_CONTAINER(align), progress->bar);
gtk_widget_show(progress->bar);

progress->timer = gtk_timeout_add(10, progressbar_timeout, progress);

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

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}



テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying9
This is GTK+ memo. using vpaned.


#include <gtk/gtk.h>

static void insert_text(GtkTextBuffer *buffer,
char *text)
{
GtkTextIter ite;
gchar *p;

p = g_strdup_printf("This window is %s\nabcde\nfghij\nklmno\npqrst\nuvwsyz\n", text);

gtk_text_buffer_get_iter_at_offset(buffer, &ite, 0);

gtk_text_buffer_insert(buffer, &ite, p, -1);

g_free(p);

}

static GtkWidget *create_scrolled_window(void)
{
GtkWidget *win;

win = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(win),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);

return win;
}

static GtkWidget *create_text_common(char *text)
{
GtkWidget *win;
GtkWidget *view;
GtkTextBuffer *buffer;

view = gtk_text_view_new();
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));

win = create_scrolled_window();

gtk_container_add(GTK_CONTAINER(win), view);

insert_text(buffer, text);

gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE);

gtk_widget_show_all(win);

return win;

}

static GtkWidget *create_text2(void)
{
return create_text_common("test2");
}

static GtkWidget *create_text1(void)
{
return create_text_common("test1");
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *vbox1;
GtkWidget *vpaned;
GtkWidget *text1;
GtkWidget *text2;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "vpaned test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

vbox1 = gtk_vbox_new(FALSE,0);

vpaned = gtk_vpaned_new();

gtk_container_add(GTK_CONTAINER(vbox1), vpaned);

gtk_widget_show(vpaned);

text1 = create_text1();
gtk_paned_add1(GTK_PANED(vpaned), text1);
gtk_widget_show(text1);

text2 = create_text2();
gtk_paned_add2(GTK_PANED(vpaned), text2);
gtk_widget_show(text2);

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

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}


テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying8
This is GTK+ memo. using tree view(it can single and multi select)


#include <gtk/gtk.h>
#define USE_MULTI_SELECT 1

static void print_selected_text(gpointer data, gpointer user_data)
{
gchar *text;
GtkTreePath *path = (GtkTreePath *) data;
GtkTreeModel *model = (GtkTreeModel *) user_data;
GtkTreeIter ite;
int idx = 0;

idx = gtk_tree_path_get_indices(path)[0];
gtk_tree_model_get_iter(model, &ite, path);

gtk_tree_model_get(model, &ite, 0, &text, -1);

g_print("selected text is [%d:%s]\n", idx, text);
}

static gboolean button_clicked(GtkWidget *widget,
gpointer data)
{
GList *list;
GtkWidget *tree = (GtkWidget *) data;
GtkTreeSelection *selection;
GtkTreeModel *model;

selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));

#ifdef USE_MULTI_SELECT
list = gtk_tree_selection_get_selected_rows(selection, &model);
g_list_foreach(list, print_selected_text, model);
#else
if (gtk_tree_selection_get_selected(selection, &model, &ite)) {
gchar *text;

gtk_tree_model_get(model, &ite, 0, &text, -1);
g_print("selected value is [%s]\n",text);
g_free(text);
}
#endif /* USE_MULTI_SELECT */

return FALSE;
}

static GtkWidget *create_button(void *data)
{
GtkWidget *button;

button = gtk_button_new_with_label("ok");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(button_clicked), data);

return button;
}

static GtkWidget *create_tree(void)
{
GtkWidget *tree;
GtkTreeViewColumn *col;
GtkListStore *model;
GtkTreeIter ite;
GtkCellRenderer *cell;
int i = 0;
model = gtk_list_store_new(1, G_TYPE_STRING);

tree = gtk_tree_view_new();
gtk_tree_view_set_model(GTK_TREE_VIEW(tree),
GTK_TREE_MODEL(model));

for (i = 0; i < 5; i++) {
gchar *msg = g_strdup_printf("test%d", i);

gtk_list_store_append(GTK_LIST_STORE(model), &ite);
gtk_list_store_set(GTK_LIST_STORE(model), &ite,
0, msg, -1);
g_free(msg);
}

cell = gtk_cell_renderer_text_new();
col = gtk_tree_view_column_new_with_attributes("messages",
cell,
"text",
0,
NULL);

gtk_tree_view_append_column(GTK_TREE_VIEW(tree),
GTK_TREE_VIEW_COLUMN(col));

return tree;
}

static gboolean cursor_changed(GtkWidget *widget,
gpointer data)
{
GtkTreeSelection *selection;
gint cnt = 0;

selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
cnt = gtk_tree_selection_count_selected_rows(selection) + 1;

g_print("count is %d\n", cnt);

return TRUE;
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *hbox;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *button;
GtkWidget *separator;
GtkWidget *tree;
GtkTreeSelection *selection;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "tree view test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

hbox = gtk_hbox_new(FALSE, 0);
vbox1 = gtk_vbox_new(FALSE,0);
vbox2 = gtk_vbox_new(FALSE, 0);

gtk_container_add(GTK_CONTAINER(vbox1), hbox);

tree = create_tree();
gtk_widget_set_size_request(GTK_WIDGET(tree), 180, 200);

selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));

#ifdef USE_MULTI_SELECT
/* we can multi select */
gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
#endif /* USE_MULTI_SELECT */
g_signal_connect(G_OBJECT(tree), "cursor-changed",
G_CALLBACK(cursor_changed), NULL);

gtk_box_pack_start(GTK_BOX(hbox), tree, TRUE, TRUE, 0);

gtk_widget_show(tree);

gtk_widget_show(hbox);

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

separator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, TRUE, 0);
gtk_widget_show(separator);

button = create_button(tree);
gtk_box_pack_start(GTK_BOX(vbox2), button, TRUE, TRUE, 0);
gtk_widget_show(button);

gtk_container_add(GTK_CONTAINER(vbox1), vbox2);
gtk_widget_show(vbox2);

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}



テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying7
This is GTK+ memo. using combo box.


#include <gtk/gtk.h>

static gboolean button_clicked(GtkWidget *widget,
gpointer data)
{
GtkWidget *combo = (GtkWidget *) data;

gchar *str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo));
gint idx = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
g_print("active text is [%s(index:%d)]\n", str, idx);

return FALSE;
}

static GtkWidget *create_button(void *data)
{
GtkWidget *button;

button = gtk_button_new_with_label("ok");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(button_clicked), data);

return button;
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *hbox;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *button;
GtkWidget *separator;
GtkWidget *combo;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "combo box test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

hbox = gtk_hbox_new(FALSE, 0);
vbox1 = gtk_vbox_new(FALSE,0);
vbox2 = gtk_vbox_new(FALSE, 0);

gtk_container_add(GTK_CONTAINER(vbox1), hbox);

combo = gtk_combo_box_new_text();
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "test1");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "test2");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "test3");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "test4");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "test5");
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);

gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0);

gtk_widget_show(combo);

gtk_widget_show(hbox);

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

separator = gtk_hseparator_new ();
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, TRUE, 0);
gtk_widget_show(separator);

button = create_button(combo);
gtk_box_pack_start(GTK_BOX(vbox2), button, TRUE, TRUE, 0);
gtk_widget_show(button);

gtk_container_add(GTK_CONTAINER(vbox1), vbox2);
gtk_widget_show(vbox2);

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}



テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying6
This is GTK+ memo. using spin button.


#include <gtk/gtk.h>

static gboolean button_clicked(GtkWidget *widget,
gpointer data)
{
GtkWidget *spin = (GtkWidget *) data;

gint value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));

g_print("selected value is [%d]\n", value);

return FALSE;
}

static GtkWidget *create_button(void *data)
{
GtkWidget *button;

button = gtk_button_new_with_label("ok");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(button_clicked), data);

return button;
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *hbox;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *button;
GtkWidget *separator;
GtkWidget *spin;
GtkObject *adjstment;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "spin button test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

hbox = gtk_hbox_new(FALSE, 0);
vbox1 = gtk_vbox_new(FALSE,0);
vbox2 = gtk_vbox_new(FALSE, 0);

gtk_container_add(GTK_CONTAINER(vbox1), hbox);

/* range is 0 to 10 */
adjstment = gtk_adjustment_new(0.0, 0.0, 10.0, 1.0, 1.0, 0.0);

spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjstment), 0, 0);

gtk_box_pack_start(GTK_BOX(hbox), spin, TRUE, TRUE, 0);
gtk_widget_show(spin);

gtk_widget_show(hbox);

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

separator = gtk_hseparator_new ();
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, TRUE, 0);
gtk_widget_show(separator);

button = create_button(spin);
gtk_box_pack_start(GTK_BOX(vbox2), button, TRUE, TRUE, 0);
gtk_widget_show(button);

gtk_container_add(GTK_CONTAINER(vbox1), vbox2);
gtk_widget_show(vbox2);

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}


テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying5
This is GTK+ memo. using multi line text and scrolled window.


#include <gtk/gtk.h>

static gboolean button_clicked(GtkWidget *widget,
gpointer data)
{
GtkWidget *text = (GtkWidget *) data;
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
GtkTextIter start, end;

/* i need start and end position */
gtk_text_buffer_get_start_iter(buffer, &start);
gtk_text_buffer_get_end_iter(buffer, &end);

gchar *str = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);

g_print("text is [%s]\n", str);

return TRUE;
}

static GtkWidget *create_button(void *data)
{
GtkWidget *button;

button = gtk_button_new_with_label("ok");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(button_clicked), data);

return button;
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *button;
GtkWidget *separator;
GtkWidget *text;
GtkWidget *scrollWindow;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "multiline text test");
gtk_widget_set_size_request(GTK_WIDGET(window), 200, 250);

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

vbox1 = gtk_vbox_new(FALSE, 7);
vbox2 = gtk_vbox_new(FALSE, 5);

/* create scrolled window */
scrollWindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollWindow),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);

gtk_box_pack_start(GTK_BOX(vbox1), scrollWindow, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(vbox1), scrollWindow);

text = gtk_text_view_new();

gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), TRUE);
gtk_widget_set_size_request(GTK_WIDGET(scrollWindow), 180, 200);

gtk_widget_show(scrollWindow);

gtk_container_add(GTK_CONTAINER(scrollWindow), text);
gtk_widget_show(text);

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

separator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, TRUE, 0);
gtk_widget_show(separator);

button = create_button(text);
gtk_box_pack_start(GTK_BOX(vbox2), button, TRUE, TRUE, 0);
gtk_widget_show(button);

gtk_container_add(GTK_CONTAINER(vbox1), vbox2);
gtk_widget_show(vbox2);

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}



テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying4
This my gtk+ memo. using text entry.


#include <gtk/gtk.h>

static gboolean button_clicked(GtkWidget *widget,
gpointer data)
{
GtkWidget *entry = (GtkWidget *) data;

const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));

g_print("text is [%s]\n", text);

return FALSE;
}

static GtkWidget *create_button(void *data)
{
GtkWidget *button;

button = gtk_button_new_with_label("ok");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(button_clicked), data);

return button;
}

static gboolean toggled_check_button(GtkWidget *widget,
gpointer data)
{
GtkWidget *entry = (GtkWidget *) data;

gtk_editable_set_editable(GTK_EDITABLE(entry),
GTK_TOGGLE_BUTTON(widget)->active);

return TRUE;
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *hbox;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *button;
GtkWidget *separator;
GtkWidget *entry;
GtkWidget *check;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "button-test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

hbox = gtk_hbox_new(FALSE, 0);
vbox1 = gtk_vbox_new(FALSE,0);
vbox2 = gtk_vbox_new(FALSE, 0);

gtk_container_add(GTK_CONTAINER(vbox1), hbox);

entry = gtk_entry_new();

/* default text is Hello World */
gtk_entry_set_text(GTK_ENTRY(entry), "Hello World");
gtk_editable_select_region(GTK_EDITABLE(entry),
0,
GTK_ENTRY(entry)->text_length);

/* default: you can't change text */
gtk_editable_set_editable(GTK_EDITABLE(entry), FALSE);
gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
gtk_widget_show(entry);

/* if you toggled this checkbox, you'll be able to change text */
check = gtk_check_button_new_with_label("editable");
g_signal_connect(G_OBJECT(check), "toggled",
G_CALLBACK(toggled_check_button), entry);

gtk_box_pack_start(GTK_BOX(hbox), check, TRUE, TRUE, 0);
gtk_widget_show(check);

gtk_widget_show(hbox);

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

separator = gtk_hseparator_new ();
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, TRUE, 0);
gtk_widget_show(separator);

button = create_button(entry);
gtk_box_pack_start(GTK_BOX(vbox2), button, TRUE, TRUE, 0);
gtk_widget_show(button);

gtk_container_add(GTK_CONTAINER(vbox1), vbox2);
gtk_widget_show(vbox2);

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}



テーマ:英語日記 - ジャンル:学問・文化・芸術

pbuilder on stable
if you want to use pbuilder on stable machine, I recommend you do this.

$ sudo pbuilder create --distribution sarge
$ sudo pbuilder login --save-after-login
change /etc/apt/sources.list
chroot# apt-get update
chroot# exit
$

at first, you create sarge environment, then change to unstable.
it's easy way I think.


テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying3
GTK+ memo part3. radio button.

if you want to know object's label, you'll be able to gtk_button_get_label().

g_slist_foreach() is uses GFUNC.
GFUNC's first argument is real data what is in list.


#include <gtk/gtk.h>


static void check_active(gpointer data, gpointer user_data)
{
GtkWidget *radio = (GtkWidget *) data;

if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)))
g_print("%s is active\n", gtk_button_get_label(GTK_BUTTON(radio)));

}

static gboolean button_clicked(GtkWidget *widget,
gpointer data)
{
GSList *list = (GSList *) data;

g_slist_foreach(list, check_active, NULL);

return FALSE;
}

static GtkWidget *create_button(void *data)
{
GtkWidget *button;

button = gtk_button_new_with_label("ok");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(button_clicked), data);

return button;
}

static GtkWidget *create_radio_button(GSList *list,
GtkWidget *box,
char *label,
gboolean active)
{
GtkWidget *radio;

radio = gtk_radio_button_new_with_label(list, label);

if (active)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);

gtk_box_pack_start(GTK_BOX(box), radio, TRUE, TRUE, 0);
gtk_widget_show(radio);

return radio;
}

static GSList *get_list(GtkWidget *radio)
{
GSList *ret = NULL;

if (radio)
ret = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio));

return ret;
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *hbox;
GtkWidget *button;
GtkWidget *radio = NULL;
GtkWidget *separator;
GSList *list = NULL;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "button-test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);


vbox1 = gtk_vbox_new(FALSE,0);
vbox2 = gtk_vbox_new(FALSE, 0);
hbox = gtk_hbox_new(TRUE, 5);

gtk_container_add(GTK_CONTAINER(vbox1), hbox);

gtk_widget_show(hbox);

radio = create_radio_button(get_list(radio), hbox, "radio1", FALSE);
radio = create_radio_button(get_list(radio), hbox, "radio2", TRUE);
radio = create_radio_button(get_list(radio), hbox, "radio3", FALSE);

list = get_list(radio);
gtk_container_add(GTK_CONTAINER(window), vbox1);
gtk_widget_show(vbox1);

separator = gtk_hseparator_new ();
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, TRUE, 0);
gtk_widget_show(separator);

button = create_button(list);
gtk_box_pack_start(GTK_BOX(vbox2), button, TRUE, TRUE, 0);
gtk_widget_show(button);

gtk_container_add(GTK_CONTAINER(vbox1), vbox2);
gtk_widget_show(vbox2);

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}



テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying2
GTK+ memo part2.
this is check button test.


#define _GNU_SOURCE
#include <stdio.h>
#include <gtk/gtk.h>

struct check_button_array {
GtkWidget *button[3];
};

static gboolean button_clicked(GtkWidget *widget,
gpointer data)
{
struct check_button_array *p = (struct check_button_array *) data;
int i = 0;
int size = sizeof(p->button) / sizeof(p->button[0]);

for (i = 0; i < size; i++) {
GtkWidget *chk = p->button[i];
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk)))
g_print("button % is active\n", i);
}


return FALSE;
}

static GtkWidget *create_button(struct check_button_array *check_buttons)
{
GtkWidget *button;

button = gtk_button_new_with_label("ok");
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(button_clicked), check_buttons);

return button;
}

static GtkWidget *create_check_button(char *label)
{
return gtk_check_button_new_with_label(label);
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *hbox;
GtkWidget *button;
GtkWidget *separator;

int i = 0;
static struct check_button_array check_buttons;
int size = sizeof(check_buttons.button) / sizeof(check_buttons.button[0]);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "button-test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);


vbox1 = gtk_vbox_new(FALSE,0);
vbox2 = gtk_vbox_new(FALSE, 0);
hbox = gtk_hbox_new(TRUE, 5);

gtk_container_add(GTK_CONTAINER(vbox1), hbox);

for (i = 0; i < size; i++) {
char *title = NULL;

asprintf(&title, "check%d", i);
check_buttons.button[i] = create_check_button(title);

gtk_box_pack_start(GTK_BOX(hbox), check_buttons.button[i], TRUE, TRUE, 0);

gtk_widget_show(check_buttons.button[i]);
}

gtk_widget_show(hbox);

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

separator = gtk_hseparator_new ();
gtk_box_pack_start(GTK_BOX(vbox1), separator, FALSE, TRUE, 0);
gtk_widget_show(separator);

button = create_button(&check_buttons);
gtk_box_pack_start(GTK_BOX(vbox2), button, TRUE, TRUE, 0);
gtk_widget_show(button);

gtk_container_add(GTK_CONTAINER(vbox1), vbox2);
gtk_widget_show(vbox2);

gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}



テーマ:英語日記 - ジャンル:学問・文化・芸術

GTK+ studying
This is my memo.

How do I create button?.
warning! I didn't call free() because I use asprintf().
so this program will have memory leak problem.


#define _GNU_SOURCE
#include <stdio.h>
#include <gtk/gtk.h>

static gboolean button_clicked(GtkWidget *widget,
gpointer data)
{
g_print("%s\n", (gchar *) data);
return FALSE;
}

static GtkWidget *create_button(char *label, char *value)
{
GtkWidget *button;

button = gtk_button_new_with_label(label);
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(button_clicked), value);

return button;
}

static GtkWidget *create_hbox(void)
{
return gtk_hbox_new(TRUE, 5);
}

void create_window(void)
{
GtkWidget *window;
GtkWidget *hbox;
GtkWidget *button[3];
int i = 0;

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "button-test");

gtk_container_set_border_width(GTK_CONTAINER(window), 5);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);


hbox = create_hbox();

for (i = 0; i < sizeof(button) / sizeof(button[0]); i++) {
char *title = NULL;
char *value = NULL;

asprintf(&title, "button%d", i);
asprintf(&value, "button%d clicked", i);

button[i] = create_button(title, value);

gtk_box_pack_start(GTK_BOX(hbox), button[i], TRUE, TRUE, 0);

gtk_widget_show(button[i]);
}


gtk_container_add(GTK_CONTAINER(window), hbox);

gtk_widget_show(hbox);
gtk_widget_show(window);

}

int main(int argc, char **argv)
{
gtk_init(&argc, &argv);

create_window();

gtk_main();

return 0;
}



This is Makefile

CC=gcc

CFLAGS = -Wall
CFLAGS += -O2
CFLAGS += -g
CFLAGS += `pkg-config --cflags gtk+-2.0`

LDFLAGS = `pkg-config --libs gtk+-2.0`

target = button-test

objs = button-test.o

all: $(objs)
$(CC) $(LDFLAGS) $(objs) -o $(target)

.c.o:
$(CC) $(CFLAGS) -c $<
clean:
-rm -fr core *~ *.o $(target)





テーマ:英語日記 - ジャンル:学問・文化・芸術

Happy new year!
Happy new year!
be happy:-)

テーマ:英語日記 - ジャンル:学問・文化・芸術



上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。