Hi,
I am now writing a little GUI application using glade. Glade is really cool, but as far as I see, I will have to distribute my xml "description" file along with my program, as libglade is using it to draw all menus, buttons, etc...
Is there any way I could include my xml glade file into my FreeBASIC source code?
I saw that I could maybe replace my "glade_xml_new" keyword (that is loading the xml description from within my program) by such one:
glade_xml_new_from_buffer(buffer, int size)
Unfortunately, I don't know how to use it, and have no clue about what a "buffer" is...
Any help from someone that already sorted this out would be appreciated :-)
How do I include a glade source file into my program?
I recomment to use GTK+tobac to generate the FB source. It can include the GUI-XML file into the basic source. Just check the button 'Glade in source' in the parameter tab and generate the .bas files.
Also I recomment to use GtkBuilder instead of deprecated libglade. GTK+tobac can handle both, libglade and GtkBuilder format. With GtkBuilder you neither need to ship the GUI-XML file nor libglade along with your binary.
Also I recomment to use GtkBuilder instead of deprecated libglade. GTK+tobac can handle both, libglade and GtkBuilder format. With GtkBuilder you neither need to ship the GUI-XML file nor libglade along with your binary.
Hi, thanks for the tip!TJF wrote:I recomment to use GTK+tobac to generate the FB source. It can include the GUI-XML file into the basic source. Just check the button 'Glade in source' in the parameter tab and generate the .bas files.
In fact, I don't think I need such tool like GTK+tobac (which is a really nice looking tool by the way!), as my project is ridiculously small. Also, I like to have to write some code, without relying on fully automated stuff ;-)
I studied the source code generate by GTK+tobac, and I found there the answer to my question. What I needed is that:
Code: Select all
DIM AS STRING xmlBuffer
xmlBuffer = "here the content of the glade xml file" + CHR(0)
DIM xml AS GladeXML PTR
xml = glade_xml_new_from_buffer(SADD(xmlBuffer), LEN(xmlBuffer), 0, 0)
You're wellcome!Fox wrote:Hi, thanks for the tip!
GTK+tobac doesn't write custom code for you. It just connects the Glade GUI-XML file to your source. That can be done in different ways, ie with external .glade file or with internal. But you still have to code the features of your app.Fox wrote:Also, I like to have to write some code, without relying on fully automated stuff ;-)
Take care, there are some pitfalls creating the xmlBuffer-STRING. BTW: GTK+tobac does some compression for the glade file, so big files gets smaller and faster when included into the source.What I needed is that:
Yeah, and it breaks comboboxes a the same occasion :)TJF wrote:BTW: GTK+tobac does some compression for the glade file, so big files gets smaller and faster when included into the source.
In fact, your converter is removing all end-of-line markers (CR, or CR/LF), and this is not a good thing...
When using comboboxes with libglade, there is an xml property called "items". This "items" section contains the list of selectable items in the combobox. This list is a raw list of lines, without any addidional markup stuff.
GTK+tobac is breaking this, because it removes all LFs, so the combobox end up being a combobox of only one, very long item.
I wrote my own, simplistic glade2bi tool that I use to convert my glade description into a *.bi file I can include into my project. My tool is very basic, and preserves end-of-line markers. Here it is:
Code: Select all
REM
REM This tool converts a glide XML file into a *.bi FreeBASIC file.
REM Written by Mateusz Viste // 09 Mar 2011
REM
#INCLUDE ONCE "file.bi"
FUNCTION txt2bas(rawtext AS STRING) AS STRING
DIM result AS STRING
DIM x AS UINTEGER
FOR x = 1 TO LEN(rawtext)
SELECT CASE MID(rawtext, x, 1)
CASE CHR(34) ' double quote
result += """"""
'CASE "a"
' result += "@"
CASE ELSE
result += MID(rawtext, x, 1)
END SELECT
NEXT x
RETURN result
END FUNCTION
IF LEN(COMMAND(1)) = 0 THEN
PRINT "Usage: glade2bi file.glade"
END
END IF
IF FileExists(COMMAND(1)) = 0 THEN
PRINT "The specified file could not be found"
END
END IF
DIM AS STRING Bufor
OPEN COMMAND(1) FOR INPUT AS #1
PRINT "DIM xmlBuffer AS STRING"
PRINT "xmlBuffer = """""
WHILE NOT EOF(1)
LINE INPUT #1, Bufor
PRINT "xmlBuffer += """ & txt2bas(Bufor) & """ & CHR(10)"
WEND
CLOSE #1
END
I know about libglade being deprecated... The reason I am using it is because I never did any GUI project before, and when I looked on the internet for some hints, I found mainly libglade tutorials... and when I figured out how the whole animal is supposed to work, it worked out of the box. Using GtkBuilder is still black magic to me.TJF wrote:BTW: Filling combo-boxes in the GUI-XML-file is libglade stuff. Its deprecated. I recomment to switch to GtkBuilder and create an GObject (GList) for your combo-box entries. (Do you use Glade 3.6 or above?)
I am using Glade v3.7.0 to draw my interface, and I did saw that it propose to save my file in GtkBuilder format. However, my attempts to use such xml file within FreeBASIC resulted in no window appearing, and libglade spitting many errors at me :) I suppose I missed some major point, because as I understand, libglade shouldn't be even involved in the GtkBuilder world... Also, I almost finished my project, and I am in the "polishing" phase now. Switching to GtkBuilder would probably involve some major changes, and make me go back to the point I was 1 week ago :-P