Linux GTK ide Program Design (III)

Source: Internet
Author: User
Today, I chatted with Zhu again. This chat is a little far away. I have talked about marriage, but I just want to talk about it. How can I talk about marriage with my current strength ~

In the afternoon, I played several games of warcraft and lost the game. Then it was strange that she said that she was going to take a bath while chatting with Zhu. Then I said that I would continue to play the first game, then she suddenly said that if I win, I will be my wife ~

The result is yes. I won...
However, this girl died and did not recognize the account, saying that there was a wife who won by playing Warcraft.
However, if you say this, you have promised to regret it?
This is the benefit of being a girl. You have no choice but to regret it ~
The result is predictable.
Then she said, if I could write this software, I would be my wife ~~~
It sounds good, but I am still confused. It's hard to say this time that I can keep my account...
But it doesn't matter. Sooner or later, it's my wife ~ It also brings new significance to the compilation of this software.

This evening, the program took another step. It added a signal connection to the menu command and was able to read and write files.

In addition, I have also revised the code module to make the structure clearer ~ At least I think

But the problem also exists.
At present, it is still simple to open and save, but the implementation of the function does not add a lot of fault tolerance, and the design of human words...
I use fwrite in stdio for file writing. The compiler has a warning, but I have not figured out how to use Write, when I simply used it, there was a problem of insufficient permissions...
In addition, the file_selection dialog box shows that the file preview function is missing compared with other file opening dialog boxes in Ubuntu. It is quite uncomfortable. There is no solution yet. I am waiting for help.

The detailed code is as follows:
# Include <GTK/GTK. h>
# Include <fcntl. h>
# Include <stdio. h>
/* =================================== */
/* Definition space */
/* =================================== */
# Define MAIN_WINDOW_WIDTH 790
# Define main_window_highly 590
/* =================================== */
/* The place of fuction declear */
/* =================================== */
Void main_window_init (void );
Void show_init (void );
Void interface_init ();
Void menu_init ();
Gint delete_event (GtkWidget * widget, GdkEvent * event, gpointer data );
Gint file_open (GtkWidget * widget, GdkEvent * event, gpointer data );
Gint file_open_ OK (GtkWidget * widget, GdkEvent * event, gpointer data );
Gint file_save (GtkWidget * widget, GdkEvent * event, gpointer data );
Gint file_save_ OK (GtkWidget * widget, GdkEvent * event, gpointer data );
Gint debug_function (GtkWidget * widget, GdkEvent * event, gpointer data );
/* ===================================== */
/* Global symbol declear */
/* ===================================== */
GtkWidget * main_window;
GtkWidget * window;
GtkWidget * main_menu;
GtkWidget * main_menu_bar;
GtkWidget * main_file_item;
GtkWidget * file;
GtkWidget * view;
GtkWidget * table;
GtkWidget * view_scroll;
GtkWidget * main_menu_box;
GtkWidget * project_box;
GtkWidget * debug_box;
GtkWidget * view_box;
GtkWidget * default_box;
GtkWidget * menu_items;
GtkWidget * tmp1;
GtkWidget * tmp2;
GtkWidget * tmp3;
GtkWidget * tmp4;
Const gchar * file_name = NULL;
GtkTextBuffer * code = NULL;
/*********************************/
/* The access of program */
/*********************************/
Int main (int argc, char * argv [])
{

/* Init */
Gtk_init (& argc, & argv );
/* Init */
Main_window_init ();
Menu_init ();
View_scroll = gtk_scrolled_window_new (NULL, NULL );
Tmp1 = gtk_button_new_with_label ("project_space ");
Tmp2 = gtk_button_new_with_label ("debug_space ");
Tmp3 = gtk_button_new_with_label ("default_space ");
Tmp4 = gtk_button_new_with_label ("view_space ");
G_signal_connect (G_OBJECT (tmp3), "clicked", G_CALLBACK (debug_function), NULL );
Main_menu_box = gtk_hbox_new (FALSE, 0 );
Project_box = gtk_hbox_new (FALSE, 0 );
Debug_box = gtk_hbox_new (FALSE, 0 );
View_box = gtk_hbox_new (FALSE, 0 );
Default_box = gtk_hbox_new (FALSE, 0 );
View = gtk_text_view_new ();
Code = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view ));
/* Set attribute */
Gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
/* Display set */
Interface_init ();
/* Show */
Show_init ();
Gtk_main ();
Return 0;
}
Gint debug_function (GtkWidget * widget, GdkEvent * event, gpointer data)
{
GtkTextIter end;
G_print ("aaa/n ");
Gtk_text_buffer_set_text (code, "1234567", 2 );
Gtk_text_buffer_get_end_iter (code, & end );
Gtk_text_buffer_insert (code, & end, "insert", sizeof ("insert")-1 );

Return TRUE;
}
/*************************************** *********/
/* Answer the file_open of the main_menu's signal */
/*************************************** *********/
Gint file_open (gtkwidget * widget, gdkevent * event, gpointer data)
{
File = gtk_file_selection_new ("Open File ");
G_signal_connect (gtk_file_selection (File)-> OK _button, "clicked", g_callback (file_open_ OK), file );
Gtk_widget_show (File );
G_printf ("file_open/N ");
Return true;
}
/*************************************** **********************/
/* Answer the file_open's OK _clicked OF THE main_menu's signal */
/*************************************** **********************/
Gint file_open_ OK (gtkwidget * widget, gdkevent * envet, gpointer data)
{
Int read_file = 0;
Int len = 0;
GtkTextIter end;
Char buf [1024] = {0 };
/* Clear the code buffer */
Gtk_text_buffer_set_text (code, "NULL", 0 );
File_name = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file ));
Read_file = open (file_name, O_RDONLY );
While (len = read (read_file, buf, sizeof (buf)> 0)
{

Gtk_text_buffer_get_end_iter (code, & end );
Gtk_text_buffer_insert (code, & end, buf, len );
}
Close (read_file );
G_printf ("% s open/n", file_name );
Gtk_widget_destroy (file );
Return TRUE;
}
/*************************************** *********/
/* Answer the file_save of the main_menu's signal */
/*************************************** *********/
Gint file_save (GtkWidget * widget, GdkEvent * event, gpointer data)
{
File = gtk_file_selection_new ("open file ");
G_signal_connect (GTK_FILE_SELECTION (file)-> OK _button, "clicked", G_CALLBACK (file_save_ OK), file );
Gtk_widget_show (file );
G_printf ("file_save/n ");
Return TRUE;
}
/*************************************** **********************/
/* Answer the save_open's OK _clicked of the main_menu's signal */
/*************************************** **********************/
Gint file_save_ OK (GtkWidget * widget, GdkEvent * envet, gpointer data)
{
FILE * fp = NULL;
Int write_file = 0;
Int len = 0;
GtkTextIter start;
GtkTextIter end;
Char * buf = NULL;
Char cmd [10000] = {0 };
/* Clear the code buffer */
// Gtk_text_buffer_set_text (code, "NULL", 0 );
File_name = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file ));
Write_file = open (file_name, O_WRONLY );
Sprintf (cmd, "rm % s", file_name );
If (write_file! =-1)
{
System (cmd );
}
Close (write_file );
Fp = fopen (file_name, "w ");
Gtk_text_buffer_get_start_iter (code, & start );
Gtk_text_buffer_get_end_iter (code, & end );
Buf = gtk_text_buffer_get_text (code, & start, & end, FALSE );

Fwrite (buf, strlen (buf), 1, fp );
Fclose (fp );
G_printf ("% s save/n", file_name );
Gtk_widget_destroy (file );
Return TRUE;
}
/* = */
/* A common function to answer */
/* Window_main */
/* = */
Gint delete_event (GtkWidget * widget, GdkEvent * event, gpointer data)
{
If (data = "main_window ")
{
G_print ("main_window send quit! /N ");
}
// System ("ls ");
Gtk_main_quit ();
// Gtk_widget_destroy (widget );
Return TRUE;
}
/***************************/
/* Init the main window */
/***************************/
Void main_window_init (void)
{
Main_window = gtk_window_new (gtk_window_toplevel );
Gtk_window_set_title (gtk_window (main_window), "flyli ");
Gtk_window_set_default_size (gtk_window (main_window), main_window_width, main_window_high );
Gtk_widget_show (main_window );
G_signal_connect (g_object (main_window), "delete_event", g_callback (delete_event), "main_window ");
}
/**********************************/
/* Init the menu of the main window */
/**********************************/
Void menu_init (void)
{
Main_menu = gtk_menu_new ();
Main_file_item = gtk_menu_item_new_with_label ("file ");
Gtk_widget_show (main_file_item );

Menu_items = gtk_menu_item_new_with_label ("open ");
Gtk_menu_shell_append (gtk_menu_shell (main_menu), menu_items );
Gtk_widget_show (menu_items );
Gtk_menu_item_set_submenu (gtk_menu_item (main_file_item), main_menu );
G_signal_connect (g_object (menu_items), "Activate", g_callback (file_open), "main_file_item ");

Menu_items = gtk_menu_item_new_with_label ("save ");
Gtk_menu_shell_append (gtk_menu_shell (main_menu), menu_items );
Gtk_widget_show (menu_items );
Gtk_menu_item_set_submenu (gtk_menu_item (main_file_item), main_menu );
G_signal_connect (g_object (menu_items), "Activate", g_callback (file_save), "main_file_item ");

Main_menu_bar = gtk_menu_bar_new ();
Gtk_menu_shell_append (gtk_menu_shell (main_menu_bar), main_file_item );
Gtk_widget_show (main_menu_bar );
}

/*************************************/
/* Init the layout of the main window */
/*************************************/
Void interface_init (void)
{
Table = gtk_table_new (100,100, true );
Gtk_container_add (gtk_container (main_window), table );

Gtk_table_attach_defaults (gtk_table (table), main_menu_box, 0,100, 0, 5 );
Gtk_table_attach_defaults (GTK_TABLE (table), project_box, 5,100 );
Gtk_table_attach_defaults (GTK_TABLE (table), debug_box, 0,100, 85,100 );
Gtk_table_attach_defaults (GTK_TABLE (table), default_box, 85,100, 5, 85 );
Gtk_table_attach_defaults (GTK_TABLE (table), view_scroll, 15, 85, 5, 85 );

Gtk_container_add (GTK_CONTAINER (view_scroll), view );
Gtk_box_pack_start (GTK_BOX (project_box), tmp1, TRUE, TRUE, 0 );
Gtk_box_pack_start (GTK_BOX (debug_box), tmp2, TRUE, TRUE, 0 );
Gtk_box_pack_start (GTK_BOX (default_box), tmp3, TRUE, TRUE, 0 );
Gtk_box_pack_start (GTK_BOX (main_menu_box), main_menu_bar, TRUE, TRUE, 0 );
Gtk_widget_show (table );
Gtk_widget_show (main_menu_box );
Gtk_widget_show (project_box );
Gtk_widget_show (debug_box );
Gtk_widget_show (view_box );
Gtk_widget_show (default_box );
}
/***********************/
/* Init show */
/***********************/
Void show_init (void)
{
Gtk_widget_show (tmp1 );
Gtk_widget_show (tmp2 );
Gtk_widget_show (tmp3 );
Gtk_widget_show (tmp4 );
Gtk_widget_show (view );
Gtk_widget_show (view_scroll );
Gtk_widget_show (view );
}
Below is

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.