内容发布更新时间 : 2024/11/13 15:28:29星期一 下面是文章的全部内容请认真阅读。
PangoLayout *layout = gtk_widget_create_pango_layout( da, buf );
PangoFontDescription *fontdesc = pango_font_description_from_string( \ pango_layout_set_font_description( layout, fontdesc ); gdk_draw_layout( drawable,gc_text,5, 5, layout ); pango_font_description_free( fontdesc ); g_object_unref( layout );
g_object_unref( G_OBJECT(gc_chart) ); g_object_unref( G_OBJECT(gc_text) );
return TRUE; }
////////////////////////Draw Graph Function End/////////////////////////
////////////////////////Draw MM Function//////////////////////////////// void cb_quit1() {
gtk_timeout_remove (timer1); gtk_main_quit(); }
float cal_load1 (void) {
long total1; long free1; float scale; char buf1[50]; char buf2[50];
DevInfo(8,buf1);//Total DevInfo(9,buf2);//Free
sscanf(buf1, \ %ld kB\ sscanf(buf2, \ %ld kB\
scale=(float)free1/(float)total1; return scale; }
gint Repaint1 (gpointer da) {
GtkWidget * drawing_area = (GtkWidget *)da;
GdkDrawable * drawable = drawing_area->window;
GdkGC *gc_chart, *gc_text; GdkColor color;
static unsigned coory[201]; int da_width, da_height; int x; float load; char buf[30];
// set chart green
gc_chart = gdk_gc_new (drawing_area->window); color.red = 0;
color.green = 0xffff;
31
color.blue = 0;
gdk_gc_set_rgb_fg_color(gc_chart, &color ); // set text red
gc_text = gdk_gc_new (drawing_area->window); color.red = 0xffff; color.green = 0; color.blue = 0;
gdk_gc_set_rgb_fg_color(gc_text, &color );
// getting size of drawing area
da_width = drawing_area->allocation.width; da_height = drawing_area->allocation.height;
gdk_draw_rectangle (drawable, drawing_area->style->white_gc,TRUE,0,0,da_width,da_height);
// chart cpu load
for (x=0; x<200; x++)
coory[x] = coory[x+1];
load = cal_load1();
coory[x] = (int)(load * da_height);
for(x=0;x gdk_draw_line (drawable, gc_chart, x, da_height, x, da_height - coory[x+1]); } // following code for drawing text sprintf (buf, \ PangoLayout *layout = gtk_widget_create_pango_layout( da, buf ); PangoFontDescription *fontdesc = pango_font_description_from_string( \ pango_layout_set_font_description( layout, fontdesc ); gdk_draw_layout( drawable,gc_text,5, 5, layout ); pango_font_description_free( fontdesc ); g_object_unref( layout ); g_object_unref( G_OBJECT(gc_chart) ); g_object_unref( G_OBJECT(gc_text) ); return TRUE; } ////////////////////////Draw MM Function End//////////////////////////////// void create_sys(GtkWidget* button, gpointer i) { GtkWidget *win, *box; GtkWidget *label0,*label1,*label2,*label3,*label4,*label5; char buf0[300]; char buf1[300]; char buf2[300]; char buf3[300]; char buf4[300]; char buf5[300]; win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(win),\ box = gtk_vbox_new(FALSE,0); gtk_container_set_border_width(GTK_CONTAINER(win),10); 32 gtk_container_add(GTK_CONTAINER(win),box); //new_label label0 = gtk_label_new(\ label1 = gtk_label_new(\ label2 = gtk_label_new(\ label3 = gtk_label_new(\ label4 = gtk_label_new(\ label5 = gtk_label_new(\ //hostname strcpy(buf0,\ DevInfo(0,buf0+strlen(\//uptime strcpy(buf1,\ GetUptime(0,buf1+strlen(\//uptime2 strcpy(buf2,\ GetUptime(1,buf2+strlen(\//system type & version strcpy(buf3,\ DevInfo(2,buf3+strlen(buf3)); DevInfo(3,buf3+strlen(buf3)); //Cpu Info strcpy(buf4,\ DevInfo(5,buf4); //current time strcpy(buf5,\ DevInfo(6,buf5+strlen(\ gtk_label_set_text(GTK_LABEL(label0),buf0); gtk_label_set_text(GTK_LABEL(label1),buf1); gtk_label_set_text(GTK_LABEL(label2),buf2); gtk_label_set_text(GTK_LABEL(label3),buf3); gtk_label_set_text(GTK_LABEL(label4),buf4); gtk_label_set_text(GTK_LABEL(label5),buf5); gtk_box_pack_start(GTK_BOX(box), label0, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(box), label1, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(box), label2, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(box), label3, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(box), label4, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(box), label5, TRUE, TRUE, 5); gtk_widget_show_all(win); } void create_MM(GtkWidget* button, gpointer aa) { GtkWidget *window; GtkWidget *drawing_area; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW(window), \ drawing_area = gtk_drawing_area_new (); 33 gtk_container_add (GTK_CONTAINER(window), drawing_area); gtk_signal_connect(GTK_OBJECT (window), \ g_signal_connect( drawing_area, \ G_CALLBACK(Repaint1), NULL ); gtk_drawing_area_size (GTK_DRAWING_AREA(drawing_area), 200, 100); gtk_widget_show (drawing_area); gtk_widget_show_all(window); timer1 = gtk_timeout_add (1000, Repaint1, (gpointer) drawing_area); } void create_Pro(GtkWidget* button, gpointer aa) { GtkWidget *window; GtkWidget *clist; char ttt[3][10]; gchar *text[3]; text[0]=(gchar *)ttt[0]; text[2]=(gchar *)ttt[2]; text[1]=(gchar *)ttt[1]; //text[3]=(gchar *)ttt[3]; char pp_info[50]; char buf_name[50]; int i=0; int k=0; strcpy(buf_name,\ strcpy(buf_name+strlen(\ strcpy(buf_name+strlen(buf_name),\ GetInfo(buf_name,pp_info); while(pp_info[i]!=' ') { ttt[0][i]=pp_info[i]; i++; } ttt[0][i]='\\0'; //printf(\ while(pp_info[i]!='(') i++; i++; while(pp_info[i]!=')') { ttt[1][k++]=pp_info[i++]; } ttt[1][k]='\\0'; //printf(\ i=i+2; k=0; ttt[2][0]=pp_info[i]; ttt[2][1]='\\0'; window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_signal_connect(GTK_OBJECT(window),\ gtk_widget_set_size_request(window,200,150); gtk_container_set_border_width(GTK_CONTAINER(window),10); clist=gtk_clist_new(3); 34 gtk_clist_set_column_title(GTK_CLIST(clist),0,\ \ gtk_clist_set_column_title(GTK_CLIST(clist),1,\ gtk_clist_set_column_title(GTK_CLIST(clist),2,\ gtk_clist_prepend(GTK_CLIST(clist),text);/*将列表项数据添加到列表*/ //gtk_clist_prepend(GTK_CLIST(clist),text2); gtk_signal_connect(GTK_OBJECT(clist),\捕捉select_row信号*/ gtk_clist_column_titles_show(GTK_CLIST(clist)); gtk_container_add(GTK_CONTAINER(window),clist); gtk_widget_show(clist); gtk_widget_show(window); gtk_main(); } void KillPro(GtkWidget* button, gpointer i) { char buf[300]; strcpy(buf,\ strcpy(buf+strlen(buf),process_text); system(buf); } void create_FindPro(GtkWidget* button, gpointer i) { GtkWidget *window; GtkWidget *spinButton; GtkWidget *label; GtkWidget *hbox; GtkWidget *button1; GtkWidget *button2; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), \ gtk_window_set_default_size(GTK_WINDOW(window), 250, 50); spinButton = gtk_spin_button_new_with_range(0, 10000, 1.00); label = gtk_label_new(\ hbox = gtk_hbox_new(TRUE, 5); button1 = gtk_button_new_with_label(\ button2 = gtk_button_new_with_label(\ gtk_box_pack_start(GTK_BOX(hbox), spinButton, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(hbox),button1,FALSE,FALSE,3); gtk_box_pack_start(GTK_BOX(hbox),button2,FALSE,FALSE,3); gtk_container_add(GTK_CONTAINER(window), hbox); g_signal_connect(G_OBJECT(button1),\ G_CALLBACK(create_Pro),GINT_TO_POINTER(1)); g_signal_connect(G_OBJECT(button2),\ G_CALLBACK(KillPro),GINT_TO_POINTER(1)); g_signal_connect(GTK_OBJECT(spinButton), \ 35