PDA

View Full Version : Climbing back out of a subwindow to the calling window



irpagan
June 3rd, 2015, 16:47
Presently I am going back and adding reference windows; I added the "quirks" window. It populates fine, can save it and reload it at will. I had an idea the idea of trying to duplicate the functionality I've seen in a couple of places where when the subwindow is opened it is populated with the name of the quirk.

In the onInit() which calls update() I wrote the following;



function update()

local bReadOnly = WindowManager.getReadOnlyState(getDatabaseNode());
local nodeSource = getDatabaseNode();

if value.getValue() ~= DB.getValue(nodeSource, "name", "") then
value.setValue(DB.getValue(nodeSource, "name", ""));
end

value.setReadOnly(bReadOnly);

end


Sometimes when I open the reference class window sometimes the name populates and sometimes it doesn't. I believe this is because the database hasn't updated yet. What I would like to do is to obtain a reference to the parent or opening window so I can do something like; window.name.getValue() and assign it to value;

I can dump self which returns a window instance windowinstance = { class = quirk_header, node = charsheet.id-00002.quirkslist.id-00006, x,y,w,h = 775,368,370,0 } and I can use .getClass() to return quirk_header but I can't seem to use anything like getParent(), getChild(), getChildren() etc nor can I reference it through dot notation (that I've figured out)

How do I traverse back out of the subwindow hole to the parent window?

Any assistance would be greatly appreciated.

Regards,
-d0gb0y

Trenloe
June 3rd, 2015, 17:23
How do I traverse back out of the subwindow hole to the parent window?
Is it actually a subwindow - i.e. a window within another window? For example, the "Inventory" tab in most CoreRPG based rulesets is a subwindow of the charsheet windowclass.

Or, is this a completely separate (new) window launched from another window? If this is the case then you can't get to the parent window as they are separate.

However, if you are using <subwindow> or other windows within windows, then you can use the GUI variables or the windowclass methods listed here: https://www.fantasygrounds.com/refdoc/windowinstance.xcp The getParent(), getChild(), etc. methods you list are for database nodes, not for window GUI hierarchy. More info on what is available for GUI variables in the "script block scope" section here: https://www.fantasygrounds.com/modguide/scripting.xcp

You can use dot notation for traversing the GUI hierarchy, but this is specific to the GUI controls and classes, not the database. For example window.name will get the control called "name" in the current window. For specifically <subwindow> elements more info can be found here: https://www.fantasygrounds.com/refdoc/subwindow.xcp

It can take a while to get used to the exact GUI hierarchy, using window.subdwindow or window.parentcontrol or some such to go up and down the GUI hierarchy.

irpagan
June 3rd, 2015, 17:31
Ach! subwindow is a bad term, it is actually a separate window.

So ... there is no way to climb back to the calling window? If the calling window is still open then Interface.findWindow() seems like it may be my only option ... if it is in fact an option, although I'm not quite sure how to reference the window I'm looking for; other than I know it's quirkslist.

Regards,
-d0gb0y

Trenloe
June 3rd, 2015, 17:51
So ... there is no way to climb back to the calling window? If the calling window is still open then Interface.findWindow() seems like it may be my only option ... if it is in fact an option, although I'm not quite sure how to reference the window I'm looking for; other than I know it's quirkslist.
Yeah, sorry I didn't mention Interface.findWindow (https://www.fantasygrounds.com/refdoc/Interface.xcp#findWindow) I generally try to avoid that as the parent window can be closed when you try to access it, you need the base class and datasource (not necessarily an issue, but more stuff to track) and you could have multiple child windows looking for the parent window. It could work for you, but if you're relying on the child window having to pass data back to the parent window then this can sometimes fail as the user might have closed the parent window.

irpagan
June 3rd, 2015, 18:02
Thanks, I don't need to pass per se - merely pull and that briefly.

The problem for me is when the DB sync's or doesn't, and I can't adjust that refresh as far as I know. I've seen it take as much as several minutes with the window open before the campaign data actually syncs up. Varies from almost instant to ... too long for my taste. Those times are rough, and probably shouldn't be considered valid ... it's me having the db.xml open in another editor and refreshing it and watching after the change takes place as to how long before it actually appears the DB.

Anyway I will try Interface.findWindow() I've tried it once or twice before when doing something else and didn't have much luck maybe third time will be the charm.

Appreciate the assist.
-d0gb0y

Trenloe
June 3rd, 2015, 18:07
The problem for me is when the DB sync's or doesn't, and I can't adjust that refresh as far as I know. I've seen it take as much as several minutes with the window open before the campaign data actually syncs up. Varies from almost instant to ... too long for my taste. Those times are rough, and probably shouldn't be considered valid ... it's me having the db.xml open in another editor and refreshing it and watching after the change takes place as to how long before it actually appears the DB.
The database should synch up straight away. The only things I can think of is if the control where the data is being entered/modified is set to only update when the control focus is lost (e.g. tabbing out of the control or clicking somewhere else) or if the control isn't directly sourced to a database entry and the DB entry relies on some code to do the update and that isn't running properly.

For delayed update waiting until the control loses focus check <delaykeyupdate /> property in the "Definition" section here: https://www.fantasygrounds.com/refdoc/stringcontrol.xcp

irpagan
June 3rd, 2015, 18:17
I'll check into that, and I'll double check the template -- I don't believe I used <delaykeyupdate /> here, I did for skills that is a whole separate tab, window.

Regards,
-d0gb0y

Trenloe
June 3rd, 2015, 18:29
Those times are rough, and probably shouldn't be considered valid ... it's me having the db.xml open in another editor and refreshing it and watching after the change takes place as to how long before it actually appears the DB.
Just noticed this... The db.xml file being written is not when the database in memory gets updated. The FG database in memory is updated in realtime and this is what FG operates against. The db.xml file is saved every 5 minutes (it's an autosave purely for data recovery if the computer crashes) or when FG is exited.

irpagan
June 3rd, 2015, 19:00
I was going to just post on this, I had just timed it out as 3:30. I must have been in between a save cycle. At least its not something whack with my PC and it is by design which means I have to work with it. So then the only possibility is Interface.findWindow().

irpagan
June 3rd, 2015, 19:01
Wait ... I hit send to fast ... is there a different set of functions for use against the DB in memory versus the DB physical?

Regards,
-d0gb0y

Trenloe
June 3rd, 2015, 19:48
Wait ... I hit send to fast ... is there a different set of functions for use against the DB in memory versus the DB physical?
You've misunderstood what I've been saying, sorry for not being clearer.

The db.xml file is only read by Fantasy Grounds when it starts up. This data is used to populate the database in memory when FG starts. From then onwards the db.xml file is not used for any database activity - everything is stored in and read read from memory. Any database access is done against the db in memory. The db.xml file is not an active database, it is just the save point that is used when FG starts again.

To re-iterate - all database activity is done in realtime in memory. The updates to the db.xml file have nothing to do with when data is stored in the live database.

Moon Wizard
June 3rd, 2015, 19:55
There's also a /save command that you can type in the chat entry window to force an immediate save to disk of the current in-memory database.

As Trenloe mentioned, the database is only "read" from disk when a campaign is first loaded, and all subsequent database activity is in memory.

Regards,
JPG

irpagan
June 3rd, 2015, 22:48
Apologies, the misunderstanding is mine I jump to fast sometimes.

It has to be something I'm doing or so I figure. I just don't know what I am doing incorrectly ... I can see it works in 3.5 and I see it works in a couple of rulesets created by others. However; for me currently it only works once the db.xml does a sync.

I am not in disagreement with anything either of you are saying, it totally makes sense what you say - like I said I can do;

getDatabaseNode().getType() and get back node, or a getChildren() and get

s'=== nodeSource.getChildren(); === '
| { s'description' = databasenode = {charsheet.id-00002.quirkslist.id-00001.description },
s'quirkshortcut' = databasenode = { charsheet.id-00002.quirkslist.id-00001.quirkshortcut },
s'locked' = databasenode = { charsheet.id-00002.quirkslist.id-00001.locked },
s'value' = databasenode = { charsheet.id-00002.quirkslist.id-00001.value },
s'name' = databasenode = { charsheet.id-00002.quirkslist.id-00001.name } }

Which I would normally take to mean those are things I can get to and access, but I can get no farther, no getChild("name").getValue(), I get a nil index error when I try. Script Error: [string "quirk_header"]:1: attempt to call field 'getChild' (a nil value).

I take that error to mean either the field doesn't exist which it does as I can see in the getChildren() or it is nil which if getChild() references the dataset in memory this shouldn't be the case correct? or am I missing the mark. Not trying to be obtuse here trying to understand what works where and when.

The interface way well ... that is its own set of issues for me

Interface.findWindow("charsheet", getDatabaseNode()) returns a nil for me, which I would expect being as getDatabaseNode() returns s'=== nodeSource.getNodeName(); === ' | s'charsheet.id-00002.quirkslist.id-00002'

Drilling backwards using getParent().getParent() gets me to charsheet but I can't seem to get to quirkslist.

Frustrating.

I'll keep studying other examples and see if I can figure out what it is I am doing incorrectly.

Regards,
-d0gb0y

Trenloe
June 3rd, 2015, 23:16
Without seeing an example of your exact database structure (XML) and control/code I can't begin to make any firm suggestions. Other than play around with the relative node identifiers - see "Node Identifiers" here: https://www.fantasygrounds.com/modguide/database.xcp You might be able to use something like databasenode.getChild("...quirkslist") to traverse the database up two levels from databasenode then look for "quirkslist".

irpagan
June 3rd, 2015, 23:47
Thanks for the suggestion, I will give it a try. I appreciate y'alls patience.

regards,
-d0gb0y

irpagan
June 4th, 2015, 03:38
Alright, I feel pretty stupid. I had a variable misspelled in the xml so it wasn't linking like it should have -- all quiet on the western front now. Thank you again for being patient.

-d0gb0y