Fun with resources :-)

BlitzMax Forums/Brucey's Modules/Fun with resources :-)

Brucey(Posted 2008) [#1]
How's about this...

We take a little bit of XML
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
	<object class="wxFrame" name="MyFrame1">
		<style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
		<size>500,300</size>
		<title>Hello World</title>
		<centered>1</centered>
	</object>
</resource>


Add a touch of bmx
SuperStrict

Framework wx.wxApp
Import wx.wxXmlResource

New MyApp.Run()
 
Type MyApp Extends wxApp

	Method OnInit:Int()
	
		wxXmlResource.Get().InitAllHandlers()
		wxXmlResource.Get().Load("helloworld.xrc")
		
		Local frame:wxFrame = wxXmlResource.Get().LoadFrame(Null, "MyFrame1")
		frame.Show(True)
 
		Return True
	End Method

End Type


and end up with...



Difference(Posted 2008) [#2]
That's really great!

I'm looking to make some property grids based on XML input by transforming my own format xml into wxXmlResource xml.

Then I want to show and edit the properties and save out the xml.

In that context: Have you thought of a way to link the wxPropertyGrid (and maybe wxSheet and others) with your persistance mod?


Brucey(Posted 2008) [#3]
I'm not sure wxXmlResource is what you want for that? That class is designed for the creation of UI layouts. Most of the GUI Editors that support wxWidgets support the creation of .xrc files (those that wxXmlResource can load).

As for linking persistence to say a wxPropertyGrid, isn't it just a fancy Map of key/value pairs?.. property name = "mycolour", value = "#44ff00"...
You would need to build a kind of interface model which could sit between the property grid and a loaded object, mapping/creating properties based on content.

Plash's in-progress FryGUI editor implements some reflection mapping between his model and the property grid.


Difference(Posted 2008) [#4]
Thanks for the input

I'm pretty sure that something like wxXmlResource is what I want. I'll be reading *differently layed out* property lists in XML format, pretty much as in your own example property name = "mycolour", value = "#44ff00" type = HEXCOLOR.

For a given property set I need to create a wxPropertyGrid to edit the properties *at runtime*.

I can read the XML in code and create a wxPropertyGrid in code, but I think loading an wxXmlResource that descibes the wxPropertyGrid whould be another way to go.


Brucey(Posted 2008) [#5]
I'm still not convinced... but as I've only touched lightly on wxXmlResource so far, I will leave an open mind on it :-)


Brucey(Posted 2008) [#6]
The xrcdemo is running quite well now - barring the distinct lack of having added XRC support to *all* the controls.

wx.mod/samples/xrc/xrcdemo/xrcdemo.bmx


I'm reasonably happy about my implementation of it. Tis a little bit complicated : especially the creation of the correct class with associated BlitzMax Object. But it works, so who cares *how* !

:-)


Difference(Posted 2008) [#7]
Looking forward to testing this tomorrow.


Difference(Posted 2008) [#8]
I'm getting build errors on the latest svn version (503):

...
...
Compiling:wxgauge.bmx
flat assembler  version 1.66
3 passes, 23726 bytes.
Archiving:wxgauge.debug.win32.x86.a
ar: creating ..mypath/Blitzmax/mod/wx.mod/wxgauge.mod/wxgauge.debug.win32.x86.a
Compiling:glue.cpp
In file included from ..mypath/Blitzmax/mod/wx.mod/wxgcdc.mod/glue.cpp:23:
..mypath/Blitzmax/mod/wx.mod/wxgcdc.mod/glue.h:46: error: `wxGCDC' does not name a type
..mypath/Blitzmax/mod/wx.mod/wxgcdc.mod/glue.cpp: In constructor `MaxGCDC::MaxGCDC(const wxWindowDC&)':
..mypath/Blitzmax/mod/wx.mod/wxgcdc.mod/glue.cpp:28: error: class `MaxGCDC' does not have any field named `gcDC'
..mypath/Blitzmax/mod/wx.mod/wxgcdc.mod/glue.cpp:30: error: `gcDC' was not declared in this scope
..mypath/Blitzmax/mod/wx.mod/wxgcdc.mod/glue.cpp: In constructor `MaxGCDC::MaxGCDC(const wxMemoryDC&)':
..mypath/Blitzmax/mod/wx.mod/wxgcdc.mod/glue.cpp:35: error: class `MaxGCDC' does not have any field named `gcDC'
..mypath/Blitzmax/mod/wx.mod/wxgcdc.mod/glue.cpp:37: error: `gcDC' was not declared in this scope
Build Error: failed to compile ..mypath/Blitzmax/mod/wx.mod/wxgcdc.mod/glue.cpp
Process complete


[EDIT] I removed wx.mod and was able to compile, but now get
..mypath/Blitzmax/bin/ld.exe: cannot find -lgdiplus
Build Error: Failed to link ..mypath/Blitzmax/mod/wx.mod/samples/xrc/helloworld/helloworld.debug.exe
Process complete


[EDIT AGAIN] okay, getting new static libs... :)


Brucey(Posted 2008) [#9]
You'll need to update your static libs : See here.

The price of living on the bleeding edge, I'm afraid.

For interest, wxGCDC adds support for things like smooth GDI line drawing on Win32...


Difference(Posted 2008) [#10]
Got it working and it looks cool, but It seems there is not yet a handler for the wxPropertygrid object to test out my idea.
I don't know what the xml for individual properties in the grid looks like anyways yet so it's not the only showstopper.

What I got now is:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
	<object class="wxFrame" name="MyFrame1">
		<style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
		<size>500,618</size>
		<title></title>
		<object class="unknown" name="m_propertyGrid1" >
		<!-- Properties will go here-->	
		</object>
	</object>
</resource>



Brucey(Posted 2008) [#11]
It seems there is not yet a handler for the wxPropertygrid object to test out my idea.

Not yet... there are well over 60 widgets I need to add the XRC support to... I'll have a look at that one next. (the usual route here is, I look at header+source for the widget xrc stuff, then add the various framework bits to the existing blitz code, implementing a subclass of the widgets' xrc class, and overriding the bits that need extra tweaking... it's getting easier the more I do)
:-)

Stay tuned, I guess!


Difference(Posted 2008) [#12]
I realize it's a humongous task to get all the parts of wxWigets going.

BTW: I think you/someone should advertise your soulution on the wx wiki by making a dedicated page on http://wiki.wxwidgets.org/

Right now there is only the reference to wxMax under Language Bindings, but when I search for "BlitzMax" on the wiki, nothing comes up.

PS: I hope google wakes up and gives you the space you asked for too.


Brucey(Posted 2008) [#13]
I committed/checked in wxPropertyGrid support this morning. Tested only as far as checking it compiles.. ;-)


Difference(Posted 2008) [#14]
I'll have to wait for someone else to make a propertygrid xrc example, because I can't work it out.

wxFormbuilder lets me add the widget (I installed the additions), but I can't find a way to add properties to the wxProprtygrid and pressing F5 to see sample XRC window just gives a purple frame.

The C++ code generated is a little more usefull; - events are added if you type them into wxFormbuilders property editor while the XRC code stays as what I posted above and never changes.


sebas76(Posted 2011) [#15]
Hello,

The XRCdemo sample worked but there is a bug it displays :
wxWidgets Debug Alert :
/../src/common/sizer.cpp: assert failure in setDimension(): can't set size of uninitialized sizer item... ?

Any idea where is the problem ?

I use bmax 1.44b + gcc 4.6.1 + wxmax 2.9.1 (r692).

Thank a lot for your help.
Seb


sebas76(Posted 2011) [#16]
Hi,

I have modified the xrc demo for my own purposes but I have this bug with a xrc file taht displays fine but when I close the wxDialog I have this assert :
/src/common/ctrlsub.cpp(211) : assert
HasClientUntypeData() failed in GetClientData(): this window doesn't have void client data.
Do you want to stop the program ?...

Please someone can help me ?
It seems to be a bug when gagdet are freed ?

Thanks a lot
Seb