示例#1
0
int main(int argc,char *argv[ ])
{

	GtkWidget *window;
	GtkWidget *event_box;

	/*window*/
	gtk_init(&argc,&argv);
	window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(GTK_OBJECT(window), "destroy",
			G_CALLBACK(gtk_main_quit),NULL);
	gtk_window_set_default_size(GTK_WINDOW(window), 800,550);

	/*eventbox*/
	event_box=gtk_event_box_new();
	g_signal_connect(event_box, "expose-event",
			G_CALLBACK(on_expose_event), NULL);
	
	update_widget_bg(event_box, IMG_BG_FILE);
	gtk_container_add (GTK_CONTAINER (window), event_box);
	/*没有这句话不能绘图*/
	gtk_widget_set_app_paintable(event_box, TRUE);
	gtk_widget_show(event_box);

	g_timeout_add(500,changeDraw,event_box);

	gtk_widget_show_all(window);

	gtk_main();
}
示例#2
0
gboolean watchCount(gpointer data)
{
	//static gint frame = 1;
	gint watcher = winCount;
	gint curCount = getWindowCount();
	GtkWidget *widget = GTK_WIDGET(data);
	if(curCount != watcher)
	{
		//恢复背景颜色
		update_widget_bg(widget, IMG_BG_FILE);
		//恢复信号阻塞
		g_signal_handler_unblock(GTK_WIDGET(widget), pressSig);
		g_signal_handler_unblock(GTK_WIDGET(widget), releaseSig);
		g_signal_handler_unblock(GTK_WIDGET(widget), motionSig);
		//g_signal_handler_unblock_by_func不行么?
		return FALSE;
	}
	//闪烁画出LOADING......
	//showLoading(widget, "Loading......");
	
	//动态绘制图片
	showLoadingIMG(widget);
	/*switch(frame)
	{
		case 1:
			showLoadingIMG(widget, IMG_LOADING_FILE1);
			++frame;
			break;
		case 2:
			showLoadingIMG(widget, IMG_LOADING_FILE2);
			++frame;
			break;
		case 3:
			showLoadingIMG(widget, IMG_LOADING_FILE3);
			++frame;
			break;
		case 4:
			showLoadingIMG(widget, IMG_LOADING_FILE4);
			++frame;
			break;
		case 5:
			showLoadingIMG(widget, IMG_LOADING_FILE5);
			++frame;
			break;
		case 6:
			showLoadingIMG(widget, IMG_LOADING_FILE6);
			frame = 1;
			break;
		default:
			frame = 1;
	}*/
	return TRUE;
}
示例#3
0
int main( int   argc,
          char *argv[] )
{
  /* GtkWidget 是构件的存储类型 */
  GtkWidget *window;
  GtkWidget *fixed;
  GtkWidget *button;

  /* 初始化 */
  gtk_init (&argc, &argv);
    
  /* 创建一个新窗口 */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Fixed Container");
  update_widget_bg(window, "./bg1.jpg");

  /* 为窗口的 "destroy" 事件设置一个信号处理函数 */ 
  g_signal_connect (G_OBJECT (window), "destroy",
		    G_CALLBACK (gtk_main_quit), NULL);
  /* 设置窗口的边框宽度 */
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  /* 创建一个固定容器 */
  fixed = gtk_fixed_new ();
  gtk_container_add (GTK_CONTAINER (window), fixed);
  //update_widget_bg(fixed, "./bg1.jpg");//给fixbox添加背景不管用
 
  /*按钮1*/
  button = gtk_button_new_with_label("button1");
  //gtk_widget_size_request(button, 60,80);
  gtk_fixed_put(GTK_FIXED(fixed), button, 100,200);
  g_signal_connect(G_OBJECT(button), "clicked",
		  G_CALLBACK(my_button1), NULL);

  /*按钮2*/
  button = gtk_button_new_with_label("button2");
  gtk_fixed_put(GTK_FIXED(fixed), button, 400,200);
  g_signal_connect(G_OBJECT(button), "clicked",
		  G_CALLBACK(my_button2), NULL);

  /* 显示窗口 */
  gtk_widget_show_all(window);
    
  /* 进入事件循环 */
  gtk_main ();
    
  return 0;
}
示例#4
0
int startWifi(GtkWidget *widget)
{
	//改变背景为灰暗
	update_widget_bg(widget, IMG_BG_LOADING_FILE);
	//阻塞点击按扭的事件
	g_signal_handler_block(GTK_WIDGET(widget), pressSig);
	g_signal_handler_block(GTK_WIDGET(widget), releaseSig);
	g_signal_handler_block(GTK_WIDGET(widget), motionSig);
	//g_signal_handlers_block_by_func不行么?

	//获取当前窗口数目
	winCount = getWindowCount();//函数现写
	//g_print("count is %d", winCount);
	g_timeout_add(500,watchCount,widget);
	//启动程序
	launchApp_simple("StartWifi.sh");
}
示例#5
0
int main(int argc,char *argv[ ])
{

	GtkWidget *window;
	GtkWidget *event_box;

	/*window*/
	gtk_init(&argc,&argv);
	window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(GTK_OBJECT(window), "destroy",
			G_CALLBACK(gtk_main_quit),NULL);
	gtk_window_set_default_size(GTK_WINDOW(window), 800,550);
	gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
	gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DESKTOP);
	//gtk_container_set_border_width(GTK_CONTAINER(window),10);

	/*eventbox*/
	event_box=gtk_event_box_new();
	
	/*如果没有这个只有单击的时候移动才有响应*/
	gtk_widget_add_events (event_box, GDK_POINTER_MOTION_MASK);
	gtk_widget_add_events (event_box, GDK_POINTER_MOTION_HINT_MASK);
	pressSig = g_signal_connect(GTK_OBJECT(event_box),"button_press_event",
			G_CALLBACK(my_button_press),NULL);
	releaseSig = g_signal_connect(GTK_OBJECT(event_box),"button_release_event",
			G_CALLBACK(my_button_release),NULL);
	motionSig = g_signal_connect(GTK_OBJECT(event_box),"motion_notify_event",
			G_CALLBACK(my_mouse_motion),NULL);
	g_signal_connect(event_box, "expose-event",
			G_CALLBACK(on_expose_event), NULL);
	update_widget_bg(event_box, IMG_BG_FILE);
	gtk_container_add (GTK_CONTAINER (window), event_box);
	/*没有这句话不能绘图*/
	gtk_widget_set_app_paintable(event_box, TRUE);
	gtk_widget_show(event_box);

	gtk_widget_show_all(window);

	gtk_main();
}
示例#6
0
//login_window
int login_window()
{
    GtkWidget *table;
    GtkWidget *username;
    GtkWidget *passwd;
    GtkWidget *logo;
    GtkWidget *submit,*quit;
    GtkWidget *hbox;

    //登陆窗口初始化
    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request (win, WIN_W, WIN_H);//设置主窗口默认打开大小
    gtk_window_set_position(GTK_WINDOW(win),GTK_WIN_POS_CENTER);
    gtk_window_set_decorated (GTK_WINDOW(win), FALSE);	//包含标题栏,右边界
    //gtk_window_set_title (GTK_WINDOW(win), "login");
    gtk_window_set_resizable ((GtkWindow *)win,FALSE);	//固定窗口显示大小
    gtk_container_set_border_width(GTK_CONTAINER(win),0);//窗口空白边界大小
    gtk_window_set_deletable(GTK_WINDOW(win),FALSE);	//禁止叉叉可以关闭

//    g_signal_connect (G_OBJECT(win), "destroy",
//                        G_CALLBACK(gtk_main_quit), NULL);//X可关闭
    //添加背景
    update_widget_bg(win, LOGIN_WIN);

    //创建table容器,并添加到窗口中
    table =  gtk_table_new(WIN_W,WIN_H,TRUE);
    gtk_container_add(GTK_CONTAINER(win),table);
    //创建文本框和登陆按钮
    username = gtk_entry_new();
    passwd = gtk_entry_new();
    gtk_entry_set_visibility (GTK_ENTRY(passwd),FALSE);	//密码文字不可见

    submit = gtk_button_new_with_label("登陆");
    quit = gtk_button_new_with_label("退出");
    //将按钮放入vbox
    hbox = gtk_hbox_new(TRUE,5);
    gtk_box_pack_start(GTK_BOX(hbox),submit,TRUE,TRUE,0);
    gtk_box_pack_start(GTK_BOX(hbox),quit,TRUE,TRUE,0);
    //构件大小设置
    gtk_widget_set_size_request(username, 205, 30);		//设置大小
    gtk_widget_set_size_request(passwd, 205, 30);		//设置大小
//	gtk_widget_set_size_request(hbox, 145, 40);		//设置大小

    //添加构件到容器中
    gtk_table_attach_defaults(GTK_TABLE(table),username,95,250, 140 ,177);
    gtk_table_attach_defaults(GTK_TABLE(table),passwd,95,250, 180 ,217);
    gtk_table_attach_defaults(GTK_TABLE(table),hbox,100,245, 240 ,280);
    g_signal_connect(G_OBJECT(quit),"clicked",G_CALLBACK(hide_child_window),GTK_WINDOW(win));
    g_signal_connect(G_OBJECT(submit),"clicked",G_CALLBACK(login_submit_callback),GTK_WINDOW(win));

    //鼠标事件捕获

    gtk_widget_set_events(win,  // 设置窗体获取鼠标事件
                          GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK
                          | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
                          | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
    gtk_signal_connect(GTK_OBJECT(win), "button_press_event",
                       (GtkSignalFunc) button_press_event, win);       // 加入事件回调
    gtk_signal_connect(GTK_OBJECT(win), "motion_notify_event",
                       (GtkSignalFunc) motion_notify_event, win);
    gtk_signal_connect(GTK_OBJECT(win), "button_release_event",
                       (GtkSignalFunc) button_release_event, win);

    gtk_widget_show_all(win);

    return 0;
}
示例#7
0
int main(int argc, char *argv[])
{
    GError *error = NULL;
    GdkPixbuf *icon_pixbuf = NULL;
    char bar_buf[64]={0};
    char nameBuffer[32]={0};
    GtkWidget *window;
    GtkWidget *fixed;
    PangoFontDescription *pfd;
    GdkColor color;
    
    //g_setenv ("GTK_MODULES", "", TRUE);
    //g_setenv ("GTK2_RC_FILES", "/dev/null", TRUE);
    //gtk_disable_setlocale();
    
    //g_setenv (LC_ALL, "utf8", FALSE);
    //setlocale (LC_ALL, "utf8");
    //setenv(LC_ALL,"C",0);
    //gtk_rc_parse("rc/rc.txt");
#ifdef WIN32
    WSADATA wsaData;
    WSAStartup(MAKEWORD(2, 2), &wsaData);
#endif
    if(0)
    {
        char host_name[256];
        int i = 0;
        HOSTENT *host_entry;  
        gethostname(host_name,sizeof(host_name));  //获取本地主机名称  
        host_entry=gethostbyname(host_name);   //从主机名数据库中得到对应的“主机”  
        for(i = 0; host_entry!= NULL && host_entry->h_addr_list[i]!= NULL; i++ )  
        //循环得出本地机器所有IP地址  
        {  
            const char *pszAddr=inet_ntoa (*(struct in_addr *)host_entry->h_addr_list[i]);  
            g_print("pszAddr = %s\n",pszAddr);  
        }
    }
    else
    {
        FILE *f=fopen("res/ip.txt","rb");
        if(f)
        {
            int l;
            fgets(ip,16,f);
            l = strlen(ip);
            if(l > 0 && (ip[l-1] == '\n' || ip[l-1] == '\r'))
            {
                ip[l-1] = 0;
            }
            l = strlen(ip);
            if(l > 0 && (ip[l-1] == '\n' || ip[l-1] == '\r'))
            {
                ip[l-1] = 0;
            }
            g_print("ip = %s\n",ip);
            fclose(f);
        }
    }

    gtk_init (&argc, &argv);
    setlocale (LC_ALL, "C");
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    snprintf(bar_buf,64,"版权所有 2013-08-28");
    gtk_window_set_title(GTK_WINDOW(window),bar_buf);
    gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
    
    gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
    gtk_widget_set_size_request(window,800,400);
    gtk_container_set_border_width(GTK_CONTAINER(window),10);
    
    update_widget_bg(window,"res/bg.jpg");
    
    icon_pixbuf = gdk_pixbuf_new_from_file("res/logo.jpg",&error);
    if (icon_pixbuf) 
    {
        gtk_window_set_icon(GTK_WINDOW(window), icon_pixbuf);
        g_object_unref(icon_pixbuf);
    }
    else
    {
        printf("%s\n",error->message);
        g_error_free(error);
    }
    
    g_signal_connect (G_OBJECT(window),"destroy",G_CALLBACK (destroy),NULL);
    
    

    //======================================================================
    fixed = gtk_fixed_new();
    gtk_container_add(GTK_CONTAINER(window), fixed);
    //======================================================================
    
    
    //button1
    //======================================================================
    button1 = gtk_button_new_with_label("发送");
    gtk_widget_set_size_request(button1, 80, 50);
    gtk_fixed_put(GTK_FIXED(fixed), button1, 680, 240+80);
    gtk_widget_show(button1);
    gtk_container_foreach (GTK_CONTAINER(button1), button_set_text, NULL);
    g_signal_connect (G_OBJECT (button1), "clicked",G_CALLBACK (button_clicked),NULL);
    //======================================================================
    
    
    //button2
    //======================================================================
    button2 = gtk_button_new_with_label("清空");
    gtk_widget_set_size_request(button2, 80, 50);
    gtk_fixed_put(GTK_FIXED(fixed), button2, 560, 240+80);
    gtk_widget_show(button2);
    gtk_container_foreach (GTK_CONTAINER(button2), button_set_text, NULL);
    g_signal_connect (G_OBJECT (button2), "clicked",G_CALLBACK (button_clicked1),NULL);
    //======================================================================
    
	//scroll
	scrolled=gtk_scrolled_window_new(NULL,NULL); /*创建滚动窗口构件*/
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC/*GTK_POLICY_ALWAYS*/);
	gtk_widget_show(scrolled);
	gtk_widget_set_size_request(scrolled,760,100);
	gtk_fixed_put(GTK_FIXED(fixed),scrolled, 6, 180);
	//entry
    //======================================================================
    //entry =  gtk_entry_new();
    entry = gtk_text_view_new();
	gtk_text_view_set_wrap_mode((GtkTextView *)entry,GTK_WRAP_CHAR);
	gtk_text_view_set_accepts_tab((GtkTextView *)entry,FALSE);
	/*将文本视图构件加入滚动窗口*/
	
	//gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled),entry);
	
	gtk_container_add(GTK_CONTAINER(scrolled), entry);
	
	//gtk_widget_set_size_request(entry,760,100);
    //gtk_entry_set_max_length (GTK_ENTRY (entry), 36);
    snprintf(nameBuffer,32,"widget%d",0+1);
    gtk_widget_set_name(entry, nameBuffer);
    //g_signal_connect (G_OBJECT(entry),"activate",G_CALLBACK (enter_callback),entry);
    //gtk_fixed_put(GTK_FIXED(fixed),entry, 6, 180);
    
    pfd = pango_font_description_from_string("Simsun");
    pango_font_description_set_size (pfd, 20 * PANGO_SCALE);
    gtk_widget_modify_font(GTK_WIDGET(entry),pfd);
    pango_font_description_free(pfd);
    
    //gtk_container_foreach (GTK_CONTAINER(entry), button_set_text1, NULL);
    
    
    gdk_color_parse ("RED", &color);
    gtk_widget_modify_fg (entry, GTK_STATE_NORMAL, &color);
    gdk_color_parse ("RED", &color);
    gtk_widget_modify_bg (entry, GTK_STATE_NORMAL, &color);
    gdk_color_parse ("GRAY", &color);
    gtk_widget_modify_base (entry, GTK_STATE_NORMAL, &color);
    gtk_widget_show(entry);
    //======================================================================
    
    
    
    //combo
    //======================================================================
    if(0)
    {
        combo = gtk_combo_box_text_new_with_entry();
        gtk_widget_set_size_request(combo,600,50);
        fill_cmbo(combo);
        gtk_widget_show(combo);
        gtk_fixed_put(GTK_FIXED(fixed), combo, 160, 60);
    }
    else
    {
        combo = create_combobox_with_model();
        gtk_combo_box_set_active((GtkComboBox *)combo,0);
        gtk_widget_set_size_request(combo,600,50);
        gtk_widget_show(combo);
        gtk_fixed_put(GTK_FIXED(fixed), combo, 160, 60);
    }
    
    lable11 = gtk_label_new ("包房号:");
    //gtk_widget_set_size_request(lable11,160,50);
    gtk_fixed_put(GTK_FIXED(fixed),lable11, 6, 60+15);
    pfd = pango_font_description_from_string("Simsun");
    pango_font_description_set_size (pfd, 20 * PANGO_SCALE);
    gtk_widget_modify_font(GTK_WIDGET(lable11),pfd);
    pango_font_description_free(pfd);
    gtk_widget_show(lable11);
    
    lable12 = gtk_label_new ("信息发送:");
    //gtk_widget_set_size_request(lable12,100,50);
    gtk_fixed_put(GTK_FIXED(fixed),lable12, 6, 120+15);
    pfd = pango_font_description_from_string("Simsun");
    pango_font_description_set_size (pfd, 20 * PANGO_SCALE);
    gtk_widget_modify_font(GTK_WIDGET(lable12),pfd);
    pango_font_description_free(pfd);
    gtk_widget_show(lable12);
    
    lable13 = gtk_label_new ("管理工具");
    pfd = pango_font_description_from_string("Simsun");
    pango_font_description_set_size (pfd, 20 * PANGO_SCALE);
    gtk_widget_modify_font(GTK_WIDGET(lable13),pfd);
    pango_font_description_free(pfd);
    gtk_fixed_put(GTK_FIXED(fixed),lable13, 0, 0);
    gtk_widget_show(lable13);
    
    
    lable14 = gtk_label_new (""/*"信息已经送出"*/);
    pfd = pango_font_description_from_string("Simsun");
    pango_font_description_set_size (pfd, 20 * PANGO_SCALE);
    gtk_widget_modify_font(GTK_WIDGET(lable14),pfd);
    pango_font_description_free(pfd);
    gdk_color_parse ("RED", &color);
    gtk_widget_modify_fg (lable14, GTK_STATE_NORMAL, &color);
    //gdk_color_parse ("GREEN", &color);
    //gtk_widget_modify_bg (entry, GTK_STATE_NORMAL, &color);
    //gdk_color_parse ("RED", &color);
    //gtk_widget_modify_base (entry, GTK_STATE_NORMAL, &color);
    gtk_fixed_put(GTK_FIXED(fixed),lable14, 0, 240+10+80);
    gtk_widget_show(lable14);
    
    
    hseparator1 = gtk_hseparator_new ();
    gtk_widget_set_size_request(hseparator1,800,1);
    gtk_fixed_put(GTK_FIXED(fixed),hseparator1, 0, 120);
    gtk_widget_show(hseparator1);
    
    hseparator2 = gtk_hseparator_new ();
    gtk_widget_set_size_request(hseparator2,800,1);
    gtk_fixed_put(GTK_FIXED(fixed),hseparator2, 0, 50);
    gtk_widget_show(hseparator2);
    
    //======================================================================
    //provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
    //g_signal_connect (provider,"parsing-error",G_CALLBACK (show_parsing_error),
    //  gtk_text_view_get_buffer (GTK_TEXT_VIEW (combo)));
    //apply_css (window, provider);
    //show
    //======================================================================
    gtk_widget_show(fixed);
    gtk_widget_show (window);
    //======================================================================
    gtk_main ();
    return 0;
}