总想把简单东西系统性写好,但简单实用的表述还是挺动脑筋的,今天写的拖放式Glade界面设计与 FreeBASIC编程 + linuxMint,边拉界面边编程,让FreeBASIC程序运行在 Linux平台上。
很简单地做个窗体,默认标题是 GtkBuilder; 放个 label,显示 A Label for Nothing; 放个 button标签是 buttonabc; 放个 button标题是 Quit
拟定功能:按buttonabc,窗体标题由 GtkBuilder改变为 FreeBASIC menu,label标签变为 Yes, I got it!; 点击放大窗体到最大,布局跟着变化; 点击 Quit,退出程序。
atom 代码编译器; glade3.22;gtk3.0; FreeBASIC1.09的fbc编译器。
按图修改二个红圈标注的地方
common页标记“可见”,见红圈。
布局器数据,纵向三栏。!勾选“统一大小” --- 漏掉了标记的红圈
摆放个 label 并按红圈修改
左侧栏选择button,改这两个涂红圈的地方
signal页上定义 button click
Quit 按如下改
保存界面文件为 mytest.ui,相配合的FreeBASIC程序名为 gladefbc.bas
说明:最右侧有glade设计器程序缩略图,点击它可视化修改界面保存后atom上右侧的文件内容即刻跟着变化,左侧是配合的FreeBASIC代码。下面是全部源代码。
#INCLUDE ONCE "gtk/gtk3.bi"
#DEFINE Ui_filename "mytest.ui"
DIM SHARED AS GtkBuilder PTR xml1
DIM SHARED AS GObject PTR window1
DIM SHARED AS GObject PTR button1
DIM SHARED AS GObject PTR button2
DIM SHARED AS GObject PTR combo1
DIM SHARED AS GObject PTR label1
SUB on_ClickButton_clicked CDECL ALIAS "on_ClickButton_clicked" ( _
BYVAL button AS GtkButton PTR, _
BYVAL user_data AS gpointer) EXPORT
gtk_label_set_text(GTK_LABEL(label1), @"Yes, I got it!")
gtk_window_set_title(GTK_WINDOW(window1), @"FreeBASIC Menu")
g_message("ClickButton clicked!")
END SUB
gtk_init(@__FB_ARGC__, @__FB_ARGV__)
xml1 = gtk_builder_new()
DIM AS GError PTR mess
IF 0 = gtk_builder_add_from_file(xml1, Ui_filename, @mess) THEN
?"Fehler/Error (GTK-Builder):"
?*mess->message
END 2
END IF
window1 = gtk_builder_get_object(xml1, "mAIn_win")
button1 = gtk_builder_get_object(xml1, "main_box_button1")
button2 = gtk_builder_get_object(xml1, "main_box_button2")
label1 = gtk_builder_get_object(xml1, "main_box_label")
gtk_builder_connect_signals( xml1, NULL )
gtk_main( )
g_object_unref( xml1 )
END 0
在atom上F9,通过build插件自动编译gladefbc.bas为gladefbc并自动运行。
界面设计与代码编写连动,连gale设计界面,边在atom上查看界面代码,边写FreeBASIC配合代码,随时设计随时改写。