Load layout works. Load project: exception: No root. SOLVED

Senzin

04-05-2013 08:42:43

I have a .layout with a window named "_Main". When I generate code and run my program, the window appears and works just fine. The code generated has this declaration:
ATTRIBUTE_CLASS_LAYOUT(Settings, "Settings.layout");


However, when I create a project and add the layout to it, the code generated has this declaration:
ATTRIBUTE_CLASS_LAYOUT(Settings, "Settings.xml|0");
I assume the "|0" part means use the first resource in the file.

When I run my program using this version, I get the following MyGUI exception: "No root widget. ['Settings.project|0]"

Is the name supposed to be something other than "_Main"? Is it different for every layout in the project?

Senzin

05-05-2013 00:39:16

I think I've found where the problem starts: line 100 of BaseLayout.h:

mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix, _parent);
It's trying to load the file "Settings.xml|0", which of course doesn't exist.

I tried changing the code to:

ATTRIBUTE_CLASS_LAYOUT(Settings, "Settings.xml");
But that doesn't work either. I'm guessing the format of the xml file prevents it from being a proper resource.

Line 102 of MyGUI_LayoutManager.cpp is where the resource manager is queried for the resource:

IResource* result = ResourceManager::getInstance().getByName(skinName, false);
When called on the regular Settings.layout, this returns a valid pointer. But for Settings.xml and of course Settings.xml|0, this returns null.

So I'm really confused by this. I don't see anything in this code that supports loading of a project file, but that's what the Code Generator creates. How exactly is this supposed to use? I notice none of the demos use a project file. Is that because it doesn't work?

my.name

05-05-2013 19:41:25

Look at demos

Senzin

05-05-2013 21:20:21

Look at demos
Thanks for the reply, but...
I notice none of the demos use a project file. Is that because it doesn't work?
I looked at the demos but couldn't find one using a project file. It looked like they all just used lots of layout files.

To double check, I just opened up the .h/.cpp files for every single demo in Notepad++ so I could easily search them all.

I searched for "ATTRIBUTE_CLASS_LAYOUT" and got 6 hits:


Search "ATTRIBUTE_CLASS_LAYOUT" (6 hits in 6 files)
MyGUI_3.2.0\Demos\Demo_Colour\EditPanel.h (1 hits)
Line 15: ATTRIBUTE_CLASS_LAYOUT(EditPanel, "EditPanel.layout");
MyGUI_3.2.0\Demos\Demo_Colour\ColourPanel.h (1 hits)
Line 15: ATTRIBUTE_CLASS_LAYOUT(ColourPanel, "ColourPanel.layout");
MyGUI_3.2.0\Demos\Demo_PluginBerkeliumWidget\BerkeliumBrowser.h (1 hits)
Line 16: ATTRIBUTE_CLASS_LAYOUT(BerkeliumBrowser, "BerkeliumBrowser.layout");
MyGUI_3.2.0\Demos\Demo_Pointers\EnemyPanel.h (1 hits)
Line 15: ATTRIBUTE_CLASS_LAYOUT(EnemyPanel, "EnemyPanel.layout");
MyGUI_3.2.0\Demos\Demo_Pointers\FriendPanel.h (1 hits)
Line 15: ATTRIBUTE_CLASS_LAYOUT(FriendPanel, "FriendPanel.layout");
MyGUI_3.2.0\Demos\Demo_Pointers\ControlPanel.h (1 hits)
Line 16: ATTRIBUTE_CLASS_LAYOUT(ControlPanel, "ControlPanel.layout");

I inspected them and they are all just simple layout files, not project files.

I also tried searching for ".xml", which is the file extension LayoutEditor uses when loading and saving projects.


Search ".xml" (14 hits in 6 files)
MyGUI_3.2.0\Demos\Demo_Colour\DemoKeeper.cpp (1 hits)
Line 32: MyGUI::ResourceManager::getInstance().load("ColourSliderSkin.xml");
MyGUI_3.2.0\Demos\Demo_ItemBox\DemoKeeper.cpp (2 hits)
Line 106: MyGUI::ResourceManager::getInstance().load("Resources.xml");
Line 107: //MyGUI::ResourceManager::getInstance().load("ItemBox_skin.xml");
MyGUI_3.2.0\Demos\Demo_PanelView\DemoKeeper.cpp (1 hits)
Line 35: MyGUI::ResourceManager::getInstance().load("FrameworkSkin.xml");
MyGUI_3.2.0\Demos\Demo_Picking\DemoKeeper.cpp (1 hits)
Line 38: MyGUI::ResourceManager::getInstance().load("Resources.xml");
MyGUI_3.2.0\Demos\Demo_Pointers\DemoKeeper.cpp (4 hits)
Line 48: MyGUI::ResourceManager::getInstance().load("Contexts.xml");
Line 51: MyGUI::ResourceManager::getInstance().load("DemoPointers.xml");
Line 53: MyGUI::ResourceManager::getInstance().load("DemoPointersW32.xml");
Line 55: MyGUI::ResourceManager::getInstance().load("DemoPointersW32.xml");
MyGUI_3.2.0\Demos\Demo_Themes\DemoKeeper.cpp (5 hits)
Line 25: MyGUI::ResourceManager::getInstance().load("MyGUI_BlueWhiteTheme.xml");
Line 29: MyGUI::ResourceManager::getInstance().load("MyGUI_BlackBlueTheme.xml");
Line 33: MyGUI::ResourceManager::getInstance().load("MyGUI_BlackOrangeTheme.xml");
Line 37: MyGUI::LanguageManager::getInstance().loadUserTags("core_theme_grayscale_tag.xml");
Line 38: MyGUI::ResourceManager::getInstance().load("core_skin.xml");

None of those xml files were project files either.

I also tried searching the tools (LayoutEditor, SkinEditor, etc.) with the same results.

So I really don't think any of the demos or tools use a project file. If I missed one, please tell me where to look and I'll gladly check it out. Otherwise, please tell me how to use project files correctly.

Altren

06-05-2013 12:09:00

Project files are not supposed to be used this way. They are used only for skins and templates (templates are complex skins used for not simple widgets, f.e. Window, that is built using several widgets).

Altren

06-05-2013 12:12:31

From the other hand you can use project item name instead of file name.

Senzin

06-05-2013 22:15:06

Project files are not supposed to be used this way. They are used only for skins and templates (templates are complex skins used for not simple widgets, f.e. Window, that is built using several widgets).
In my case, I am working on a Settings window that is built using several widgets. It's the keybindings window that dynamically generates rows which are duplicates of a "PanelSetKey" widget for all the keybindings listed in a file. (See project file below.)

The point is, the PanelSetKey and the Settings window are separate widgets, but are used together. So I liked the idea of having them both in a single project file instead of as separate layout files. It also makes it easy to switch between them in the LayoutEditor since they are listed in the Project tab on the right.

One thing that confuses me is why does the LayoutEditor's Code Generator create this code if it's not even supposed to be used this way? Is it a bug?

From the other hand you can use project item name instead of file name.
Can you please tell me how? I tried using "ATTRIBUTE_CLASS_LAYOUT(SettingsBase, "Settings");", where "Settings" is the name of the resource in the project file, but it didn't work.

Below is the code generated by LayoutEditor's Code Generator and the actual project file. The first resource called "Settings" is what is supposed to be loaded.


#pragma once

#include "BaseLayout/BaseLayout.h"

namespace SettingsNamespace
{

ATTRIBUTE_CLASS_LAYOUT(SettingsBase, "Settings.xml|0");
class SettingsBase : public wraps::BaseLayout
{
public:
SettingsBase(MyGUI::Widget * parent = nullptr);
virtual ~SettingsBase();

protected:
//%LE Widget_Declaration list start
ATTRIBUTE_FIELD_WIDGET_NAME(SettingsBase, mRoot, "Root");
MyGUI::Window* mRoot;
ATTRIBUTE_FIELD_WIDGET_NAME(SettingsBase, mScrollViewSetKey, "ScrollViewSetKey");
MyGUI::ScrollView* mScrollViewSetKey;
//%LE Widget_Declaration list end
};

} // namespace SettingsNamespace




<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Resource">
<Resource type="ResourceLayout" name="Settings" version="3.2.0">
<Widget type="Window" skin="WindowCS" position="275 270 570 235" layer="Overlapped" name="Root">
<Property key="MinSize" value="570 100"/>
<Property key="MaxSize" value="570 1000"/>
<Property key="Caption" value="Settings"/>
<Widget type="TabControl" skin="TabControl" position="1 0 559 198" align="Stretch">
<Widget type="TabItem" skin="" position="2 24 553 170">
<Property key="Caption" value="Key Bindings"/>
<Widget type="ScrollView" skin="ScrollView" position="0 -1 555 173" align="Stretch" name="ScrollViewSetKey">
<Property key="CanvasSize" value="530 230"/>
<Property key="CanvasAlign" value="Left Top"/>
</Widget>
</Widget>
<Widget type="TabItem" skin="" position="2 24 553 170">
<Property key="Caption" value="Other"/>
<Widget type="Button" skin="Button" position="11 10 532 26" align="HStretch Top">
<Property key="Caption" value="Other"/>
</Widget>
</Widget>
</Widget>
</Widget>
<CodeGeneratorSettings>
<Property key="IncludeDirectory" value="D:\Zytrex-Development\VisualStudio11\TestUI\include"/>
<Property key="PanelName" value="SettingsBase"/>
<Property key="PanelNamespace" value="SettingsNamespace"/>
<Property key="SourceDirectory" value="D:\Zytrex-Development\VisualStudio11\TestUI\src"/>
</CodeGeneratorSettings>
</Resource>
<Resource type="ResourceLayout" name="PanelSetKey" version="3.2.0">
<Widget type="Widget" skin="PanelEmpty" position="250 415 520 25" layer="Overlapped" name="PanelSetKey">
<Widget type="Button" skin="Button" position="210 0 150 25" name="ButtonSetKey1"/>
<Widget type="Button" skin="Button" position="370 0 150 25" name="ButtonSetKey2"/>
<Widget type="Widget" skin="PanelSkin" position="0 0 200 25">
<Widget type="TextBox" skin="TextBox" position="5 0 190 25" name="TextSetKey">
<Property key="Caption" value="Forward"/>
<Property key="TextAlign" value="Left VCenter"/>
</Widget>
</Widget>
</Widget>
<CodeGeneratorSettings/>
</Resource>
</MyGUI>

Altren

08-05-2013 09:43:22

I tried using "ATTRIBUTE_CLASS_LAYOUT(SettingsBase, "Settings");", where "Settings" is the name of the resource in the project file, but it didn't work.This variant is correct, but I forgot to mention one more important thing. Since you are looking for resource in some file you need to load this file before using resources from it. So you need to either
1)add your Settings.xml into MyGUI_Core.xml (or whatever you use as xml with all resource files)
or
2)load Settings.xml from code after MyGUI initialisation or whenever you are going to use something from Settings.xml:
MyGUI::ResourceManager::getInstance().load("Settings.xml");

Senzin

08-05-2013 10:09:59

I tried using "ATTRIBUTE_CLASS_LAYOUT(SettingsBase, "Settings");", where "Settings" is the name of the resource in the project file, but it didn't work.This variant is correct, but I forgot to mention one more important thing. Since you are looking for resource in some file you need to load this file before using resources from it. So you need to either
1)add your Settings.xml into MyGUI_Core.xml (or whatever you use as xml with all resource files)
or
2)load Settings.xml from code after MyGUI initialisation or whenever you are going to use something from Settings.xml:
MyGUI::ResourceManager::getInstance().load("Settings.xml");

That did the trick! Thank you very much for helping me out with this! :D

The only thing left is that the LayoutEditor's Code Generator creates "ATTRIBUTE_CLASS_LAYOUT(SettingsBase, "Settings.xml|0");" instead of "ATTRIBUTE_CLASS_LAYOUT(SettingsBase, "Settings");". I think I'll take a look at the code and see if I can fix it myself.

Altren

08-05-2013 15:42:46

I think I'll take a look at the code and see if I can fix it myself.I just committed fix for that.

Senzin

09-05-2013 05:51:22

I think I'll take a look at the code and see if I can fix it myself.I just committed fix for that.
Sweet! :)

Although, maybe I'm just looking in the wrong place, but the most recent changes I see in the SVN repo (http://my-gui.svn.sourceforge.net/) are from two months ago.

Any chance you could tell me what to change or maybe provide a patch file?

Altren

10-05-2013 14:58:34

We did sourceforge project upgrade (whatever that mean) about two months ago and it seems, that it worked wrong.
Our current svn repository is
http://svn.code.sf.net/p/my-gui/code/trunk

I need to check why sourceforge not blocked old repo.

Senzin

11-05-2013 02:45:04

We did sourceforge project upgrade (whatever that mean) about two months ago and it seems, that it worked wrong.
Our current svn repository is
http://svn.code.sf.net/p/my-gui/code/trunk
I need to check why sourceforge not blocked old repo.


Thank you! :) The new version is fixed, just like you said. When I generate code from a layout file, it uses the name of the layout file. When I generate code from a project file, it uses the resource name. :D


Sadly, I found a new bug that wasn't in the previous version. :( Before, I was using the "Latest Stable Release" from http://mygui.info/. In that version, the Code Generator settings (IncludeDirectory, SourceDirectory, PanelName, PanelNamespace) were stored in the .layout file, or in the project file with separate configurations for each resource. But this new version stores the Code Generator settings globally in the le_user_settings.xml file. So now, if I set the Code Generator settings for one layout, it changes it for all of them. And obviously I have different layouts and project resources that are supposed to export to different places.

BEFORE: MyProject.xml

<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Resource">
<Resource type="ResourceLayout" name="Settings" version="3.2.0">
<Widget type="Window" skin="WindowCS" position="275 270 570 235" layer="Overlapped" name="Root">
<Property key="MinSize" value="570 100"/>
<Property key="MaxSize" value="570 1000"/>
<Property key="Caption" value="Settings"/>
<Widget type="TabControl" skin="TabControl" position="1 0 559 198" align="Stretch">
<Widget type="TabItem" skin="" position="2 24 553 170">
<Property key="Caption" value="Key Bindings"/>
<Widget type="ScrollView" skin="ScrollView" position="0 -1 555 173" align="Stretch" name="ScrollViewSetKey">
<Property key="CanvasSize" value="530 230"/>
<Property key="CanvasAlign" value="Left Top"/>
</Widget>
</Widget>
<Widget type="TabItem" skin="" position="2 24 553 170">
<Property key="Caption" value="Other"/>
<Widget type="Button" skin="Button" position="11 10 532 26" align="HStretch Top">
<Property key="Caption" value="Other"/>
</Widget>
</Widget>
</Widget>
</Widget>
<CodeGeneratorSettings>
<Property key="IncludeDirectory" value="D:\Zytrex-Development\VisualStudio11\TestUI\include"/>
<Property key="PanelName" value="SettingsBase"/>
<Property key="PanelNamespace" value="SettingsNamespace"/>
<Property key="SourceDirectory" value="D:\Zytrex-Development\VisualStudio11\TestUI\src"/>
</CodeGeneratorSettings>
</Resource>
<Resource type="ResourceLayout" name="PanelSetKey" version="3.2.0">
<Widget type="Widget" skin="PanelEmpty" position="250 415 520 25" layer="Overlapped" name="PanelSetKey">
<Widget type="Button" skin="Button" position="210 0 150 25" name="ButtonSetKey1"/>
<Widget type="Button" skin="Button" position="370 0 150 25" name="ButtonSetKey2"/>
<Widget type="Widget" skin="PanelSkin" position="0 0 200 25">
<Widget type="TextBox" skin="TextBox" position="5 0 190 25" name="TextSetKey">
<Property key="Caption" value="Forward"/>
<Property key="TextAlign" value="Left VCenter"/>
</Widget>
</Widget>
</Widget>
<CodeGeneratorSettings>
<Property key="IncludeDirectory" value="D:\Zytrex-Development\VisualStudio11\TestUI\include"/>
<Property key="PanelName" value="PanelSetKeyBase"/>
<Property key="PanelNamespace" value="SettingsNamespace"/>
<Property key="SourceDirectory" value="D:\Zytrex-Development\VisualStudio11\TestUI\src"/>
</CodeGeneratorSettings>
</Resource>
</MyGUI>


AFTER: le_user_settings.xml

<?xml version="1.0" encoding="utf-8"?>
<Settings>
<Files>
<LastProjectName>Settings.xml</LastProjectName>
<LastProjectPath>D:\Dev\Libs\Ogre\OgreSDK_vc10_v1-8-1\mediaMain\layout</LastProjectPath>
<RecentProject.List>
<Value>D:\Dev\Libs\Ogre\OgreSDK_vc10_v1-8-1\mediaMain\layout\Settings.xml</Value>
</RecentProject.List>
<RecentFolder>D:\Dev\Libs\Ogre\OgreSDK_vc10_v1-8-1\mediaMain\layout</RecentFolder>
<RecentFolder.List>
<Value>D:\Dev\Libs\Ogre\OgreSDK_vc10_v1-8-1\mediaMain\layout</Value>
</RecentFolder.List>
<RecentFile.List />
</Files>
<Settings>
<CodeGenerator>
<PanelName>SettingsBase</PanelName>
<PanelNamespace>SettingsNamespace</PanelNamespace>
<IncludeDirectory>D:\Dev\VisualStudio11\TestUI\include</IncludeDirectory>
<SourceDirectory>D:\Dev\VisualStudio11\TestUI\src</SourceDirectory>
</CodeGenerator>
<LayoutVersion>3.2.0</LayoutVersion>
</Settings>
<Controls>
<WidgetsWindow>
<LastSkinGroup>Default</LastSkinGroup>
</WidgetsWindow>
<Main>
<Maximized>false</Maximized>
<Coord>120 55 1696 1088</Coord>
</Main>
</Controls>
</Settings>

Altren

12-05-2013 12:26:21

Fixed.

Senzin

13-05-2013 01:31:06

Fixed.
Thank you! Looks like everything is working perfectly now. Thanks for all your help, Altren! :D