linux用gtk写了一个小应用,如何封装真正的软件那样?

linux用gtk写了一个小应用,如何封装真正的软件那样?,第1张

不同的包管理,方法不同。比如deb的。

建立一个目录,把文件分布进去,比如

deb/DEBIAN

deb/usr/share/applications

deb/usr/bin

写一个control文件,指名版本等信息。

然后进入目录。

dpkg-deb -b deb .

gtk_widget_set_sensitive()可以设置button为禁用。按你的要求我写了一个小程序。

fedora17,gcc4.7.2,gtk+-3.0

gcc main.c `pkg-config --libs --cflags gtk+-3.0`编译

#include <gtk/gtk.h>

static gboolean empty=TRUE

void

entry_buffer_inserted(GtkEntryBuffer *entryBuffer,/* entry有输入时调用 */

guint position,gchar *chars,guint n_chars,

gpointer data){

if(empty==TRUE){

gtk_button_set_label(GTK_BUTTON(data),"Ok")

gtk_widget_set_sensitive(GTK_WIDGET(data),TRUE) /* 启用button */

empty=FALSE

}

}

void

entry_buffer_deleted(GtkEntryBuffer *entryBuffer,/* entry有删除时调用 */

guint position,guint n_chars,gpointer data){

if(gtk_entry_buffer_get_bytes(entryBuffer)==0){/* 如果entry为空 */

gtk_button_set_label(GTK_BUTTON(data),"")

gtk_widget_set_sensitive(GTK_WIDGET(data),FALSE) /* 禁用button */

empty=TRUE

}

}

void

button_clicked(GtkButton *button,gpointer data){

GtkWidget *dialog

const gchar *buffer

dialog=gtk_message_dialog_new(NULL,

GTK_DIALOG_MODAL,GTK_MESSAGE_INFO,

GTK_BUTTONS_OK_CANCEL,"你输入了:")

buffer=gtk_entry_buffer_get_text(GTK_ENTRY_BUFFER(data))

gtk_window_set_title(GTK_WINDOW(dialog),"提示")

gtk_message_dialog_format_secondary_text(

GTK_MESSAGE_DIALOG(dialog),"%s",buffer)

if(gtk_dialog_run(GTK_DIALOG(dialog))==GTK_RESPONSE_OK)

g_printf("clicked ok!\n")

else

g_printf("clicked cancel!\n")

gtk_widget_destroy(dialog)

}

int

main(int argc,char *argv[]){

GtkWidget *window

GtkWidget *grid

GtkWidget *button

GtkWidget *entry

GtkEntryBuffer *entryBuffer /* GtkEntryBuffer 保存了GtkEntry里的文本内容 */

gtk_init(&argc,&argv)

window=gtk_window_new(GTK_WINDOW_TOPLEVEL)

gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_MOUSE)

gtk_window_set_default_size(GTK_WINDOW(window),400,200)

gtk_container_set_border_width(GTK_CONTAINER(window),10)

button=gtk_button_new()

gtk_widget_set_vexpand(button,TRUE)

gtk_widget_set_sensitive(button,FALSE)

entry=gtk_entry_new()

entryBuffer=gtk_entry_get_buffer(GTK_ENTRY(entry))

grid=gtk_grid_new()

gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE)

gtk_grid_set_row_spacing(GTK_GRID(grid),10)

gtk_grid_attach(GTK_GRID(grid),entry,0,0,1,1)

gtk_grid_attach(GTK_GRID(grid),button,0,1,1,1)

gtk_container_add(GTK_CONTAINER(window),grid)

g_signal_connect(G_OBJECT(entryBuffer),"inserted-text",

G_CALLBACK(entry_buffer_inserted),button)

g_signal_connect(G_OBJECT(entryBuffer),"deleted-text",

G_CALLBACK(entry_buffer_deleted),button)

g_signal_connect(G_OBJECT(button),"clicked",

G_CALLBACK(button_clicked),entryBuffer)

g_signal_connect(G_OBJECT(window),"destroy",

G_CALLBACK(gtk_main_quit),NULL)

gtk_widget_show_all(window)

gtk_main()

return 0

}

很容易,网上资料也多。

#include <gtk/gtk.h>

int main( int argc, char *argv[])

{

GtkWidget *window

gtk_init(&argc, &argv)

window = gtk_window_new(GTK_WINDOW_TOPLEVEL)

gtk_widget_show(window)

gtk_main()

return 0

}

这个例子就是为我们显示了一个空白的窗口。

gcc -o simple simple.c `pkg-config --libs --cflags gtk+-2.0`


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7970798.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存