embedding glade with PROTO PRAGMA
Apr 19, 2013 16:52:48 GMT 1
Post by bigbass on Apr 19, 2013 16:52:48 GMT 1
Hey Guys
This was a tough nut to crack (converting to PROTO ,PRAGMA)
without using glade.bac as an include
but we can now embed glade directly
I converted Peter's wonderful demo
www.basic-converter.org/glade-demo.bac.html
and glade.bac to PROTO with PRAGMA
www.basic-converter.org/glade.bac.html
for the first example to
see what was needed to change
(other examples will follow later once its clear what needs to be modified )
since the focus here is using PROTO and PRAGMA with glade
this causes a compiler warning but it works fine it is the fault of $
result$ = gtk_entry_get_text(entry)
Added vovchik's string fix
glade-demo2-proto.bac
demo.glade
This was a tough nut to crack (converting to PROTO ,PRAGMA)
without using glade.bac as an include
but we can now embed glade directly
I converted Peter's wonderful demo
www.basic-converter.org/glade-demo.bac.html
and glade.bac to PROTO with PRAGMA
www.basic-converter.org/glade.bac.html
for the first example to
see what was needed to change
(other examples will follow later once its clear what needs to be modified )
since the focus here is using PROTO and PRAGMA with glade
this causes a compiler warning but it works fine it is the fault of $
result$ = gtk_entry_get_text(entry)
Added vovchik's string fix
glade-demo2-proto.bac
PRAGMA LDFLAGS `pkg-config --cflags --libs libglade-2.0`
'---
'--- Bacon and Glade and GTK.
'--- PvE - April 2009.
'---
'--- Improved August 18, 2009 - PvE.
'--- Improved February 20, 2010 - PvE.
'---
'--- Get functions from GLADE
'==========================================
'--- ported to PROTO and PRAGMA by bigbass
'--- April 19 2013 notice --libs libglade-2.0
'==========================================
'--- (char *) fix by vovchik April 19 2013
'--- Get needed functions from glade using PROTO
PROTO glade_require
PROTO glade_provide
PROTO glade_xml_new
PROTO glade_xml_new_from_buffer
PROTO glade_xml_construct
PROTO glade_xml_construct_from_buffer
PROTO glade_xml_signal_connect
PROTO glade_xml_signal_connect_data
PROTO glade_xml_signal_autoconnect
PROTO glade_xml_get_widget
PROTO glade_xml_get_widget_prefix
PROTO glade_get_widget_name
PROTO glade_get_widget_tree
PROTO glade_xml_signal_connect_full
PROTO glade_xml_signal_autoconnect_full
PROTO glade_set_custom_handler
PROTO glade_parser_parse_file
PROTO glade_parser_parse_buffer
PROTO glade_interface_destroy
PROTO glade_interface_dump
PROTO glade_xml_build_widget
PROTO glade_xml_handle_internal_child
PROTO glade_xml_set_common_params
PROTO glade_register_widget
PROTO glade_standard_build_widget
PROTO glade_xml_handle_widget_prop
PROTO glade_standard_build_children
PROTO glade_xml_set_packing_property
PROTO glade_register_custom_prop
PROTO glade_xml_relative_file
PROTO glade_enum_from_string
PROTO glade_flags_from_string
PROTO glade_xml_set_value_from_string
PROTO glade_xml_set_toplevel
PROTO glade_xml_ensure_accel
'--- Get needed functions from GTK using PROTO
PROTO gtk_main
PROTO gtk_exit
PROTO gtk_entry_get_text
PROTO gtk_init
PROTO g_signal_connect_data
PROTO gtk_main_quit
'--- Callback for closing window
SUB exit_prog
gtk_main_quit
END SUB
'--- Callback to get entry contents
SUB get_entry()
result$ = (char *)gtk_entry_get_text(entry)
PRINT result$
END SUB
'--- Setup GUI
gtk_init(0, 0)
'--- Get Glade file
xml = glade_xml_new("./demo.glade", 0, 0)
glade_xml_signal_autoconnect(xml)
'--- Get main window ID and connect signal
window = glade_xml_get_widget(xml, "window")
g_signal_connect_data(window, "delete-event", exit_prog, 0, 0, 0)
'--- Get exit button ID and connect signal
quit = glade_xml_get_widget(xml, "exit_button")
g_signal_connect_data(quit, "clicked", exit_prog, 0, 0, 0)
'--- Get entry
entry = glade_xml_get_widget(xml, "entry")
'--- Get print button ID and connect signal and pass entry as data to callback function
button = glade_xml_get_widget(xml, "print_button")
g_signal_connect_data(button, "clicked", get_entry, entry, 0, 0)
'--- Endless event handling by GTK
gtk_main
demo.glade
<?xml version="1.0" encoding="UTF-8"?>
<glade-interface>
<widget class="GtkWindow" id="window">
<property name="height_request">300</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Designed with Glade</property>
<property name="default_width">400</property>
<property name="default_height">400</property>
<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">12</property>
<property name="n_columns">11</property>
<child>
<widget class="GtkEntry" id="entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="text" translatable="yes">Enter some text here</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">8</property>
<property name="top_attach">4</property>
<property name="bottom_attach">6</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
</child>
<child>
<widget class="GtkStatusbar" id="statusbar1">
<property name="visible">True</property>
<property name="can_focus">False</property>
</widget>
<packing>
<property name="right_attach">11</property>
<property name="top_attach">11</property>
<property name="bottom_attach">12</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
</child>
<child>
<widget class="GtkButton" id="exit_button">
<property name="label" translatable="yes">Exit</property>
<property name="width_request">35</property>
<property name="height_request">45</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</widget>
<packing>
<property name="left_attach">5</property>
<property name="right_attach">7</property>
<property name="top_attach">9</property>
<property name="bottom_attach">11</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="print_button">
<property name="label" translatable="yes">Print</property>
<property name="width_request">35</property>
<property name="height_request">45</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">9</property>
<property name="bottom_attach">11</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkMenuBar" id="menubar1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkMenuItem" id="menuitem1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_File</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="menu1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkImageMenuItem" id="imagemenuitem1">
<property name="label">gtk-new</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="imagemenuitem2">
<property name="label">gtk-open</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="imagemenuitem3">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="imagemenuitem4">
<property name="label">gtk-save-as</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
<property name="can_focus">False</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="imagemenuitem5">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Edit</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="menu2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkImageMenuItem" id="imagemenuitem6">
<property name="label">gtk-cut</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="imagemenuitem7">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="imagemenuitem8">
<property name="label">gtk-paste</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="imagemenuitem9">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_View</property>
<property name="use_underline">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Help</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="menu3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkImageMenuItem" id="imagemenuitem10">
<property name="label">gtk-about</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="right_attach">9</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Design in Glade read *.ui file in Bacon</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">7</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>