Clickontextlistwithsideeffects

OK this is a crazy idea. I have a little app that looks at a folder and generates a list of all files therein with a particular extension. It displays that list in a text list object. If I click on the name of a file in that list, another text list will show me what’s in the file, all nicely broken out into columns. It looks a little like this:

just fort kicks, there is another list at the right edge that displays the field names from the text list just to its left so i can click through the list at the top and see how my vendor is making me miserable by changing the field names every single day. I want to write a new procedure that tabulates the field names in each file along with the filename so i can draft a sternly worded memorandum to said vendor to institute a little consistently in their deliveries (while I figure out a way to have my application figure out how to deal with the issue programmatically)

So far, so good. In Panorama 6, I would have had all the code to populate the various text list objects in a procedure, nicely labeled for reuse in other areas… but since we’re on X now, I’ve defined my fileglobals in a procedure but packed most of the code into the individual text lists as expressions with side effects. For example, the main table is made by putting this in the formula box:

catcherror(“nothing selected yet)”, ignore("", assign(fileload(fg_folder+fg_chosenfile),“fg_filecontents”))+arraydelete(""+fg_filecontents[search(fg_filecontents,“Column”)+7,-1],2,3,cr())
)

Yeah, i thought it was pretty clever too! Here (finally) is my question. Now, I want to loop array through all the files in that list, and I will do it in a procedure. But all my clever code blocks are in objects now. I could copy them from the objects and into a procedure, but that is soooo last season. What I want to to is use a procedure to simulate clicking through each item in the top list, and aggregate the results of the formula in the rightmost list into a variable.

Is there any way to simulate user clicks in the text object programmatically and then just append the data from the appropriate variable to my little looparray stack?

I made this procedure- it runs and the result shows all the right filenames but none of the data that the rightmostlist WOULD have generated (had the top list actually been clicked) is there :frowning: It’s just the data from the first file repeated over and over (which is what i expected would happen)

I am looking for an object command that will do this but i am not seeing one…

I hope that made at least a speck of sense!

csw

So was it tl:dr or did I miss something super obvious?

Its a long post but reading the code bits isn’t strictly necessary…

The short version is “can i run a procedure to simulate a user click in a text list object?”

I think the answer is that you can’t. The problem is that Panorama has so many features, you’re never sure it’s not something you didn’t know about, or forgot.

I don’t get to say this too often, but “Dave, you’re wrong!” My procedure in the 2nd image block would have worked had I thought to include a “showvariables” statement.

I added this with the appropriate variable name and then watched in wonder as Panorama stepped through all the files and made the list I was expecting! This is what I meant about those niche features saving the day!

Consider this one solved!

I don’t understand how showvariables has anything to do with your original question, but I’m glad you figured out a solution.

However, I believe the answer to what I see as your original question is yes - you can do that.

You can extract code and formulas from objects no problem, just use the objectinfo( function. Extracted code can be run with the execute statement, an extracted formula can be run the same way or with the formulavalue function.

In my last code block, above, the object code is only run if the showvariables is included…

csw

I’m sure some may think that I’m being pedantic here, but I would say that showvariables is causing the obect’s formula to be evaluated, not it’s code. In this case, the formula has a “side-effect” because it contains the assign( function. The object’s code is in a different panel, and can only be run by clicking on the object (or by extracting it and using execute as I mentioned in a previous post).

The showvariables statement will scan the form and evaluate any object formula that contains one of the listed variables. Normally the only result of evaluating a formula is that the object is re-displayed, but it is possible to write formulas with side effects, as you have done here. You could also use the call( function to actually execute procedure code when the formula is evaluated.

Though you can use a formula with side effects in Panorama, my advice would be to try to avoid this when possible. For one thing, it makes it very difficult to come back later and understand the code. Or, you might later change the formula and not realize that some code elsewhere was relying on side effects, so you could break that other code accidentally. A year from now, if you have to make a change to this code, you’ll probably have a hard time figuring out what you did. And if anyone else ever has to maintain this code…

If I was writing this code, I’d probably move the formula into a procedure with a label, and use the callwithin( function to call it from the object. The subroutine would have only one line, a functionvalue statement (ok, it would probably also need a return statement). Instead of the assign( function, I would use the cache( function – that way the formula would not have any side effects. And then in any other code that needed to use this formula, you could simply use callwithin( instead of relying on a side effect.

In fact – are your sure your revised code works? You are using the fg_filecontents variable before the showvariables statement. I would think it would need to be moved above before the assignment to lv_stackedlist. I think you are getting incorrect values and perhaps didn’t look at the results closely enough.

Really, I think rewriting your code like this would be much clearer, even though it is not referencing the formula in the object.

let lv_stackedlist = ""
looparray fg_filelist, cr(), l_currentlist
    let fg_filecontents = fileload(fg_folder+l_currentlist)
    lv_stackedlist = lv+stackedlist+cr()+l_currentlist+"**->"+nthline(fg_filecontents,8)
endloop
clipboard = lv_stackedlist

In fact really the fg_filecontents assignment isn’t needed, you could just put the fileload( into the assignment to lv_stackedlist, since you only use the contents in one place.


Note: Instead of making screenshots of your code, I would suggest that it is easier to use the Source>Copy Indented Code command to copy the code into the clipboard, then paste it here. That will automatically format it as code, and also make it easier for others to copy/paste the code for suggestions, instead of having to completely retyp it.

I noticed that too, (about the placement of showvariables) It definitely works the way i want but i haven’t checked to be sure that it’s not skipping the first or last file. I agree that this style of programming can lead to code spaghettification, but this is (after TEN YEARS) my first serious foray into doing something complicated and useful in PX (Now that I am being paid to do it heheh) I’m kinda just trying to see what’s possible.

No joke, when you say “I’d avoid programming this way” I have learned to believe you (I’m looking at YOU, mister WindowProc)

Anyway, the showvariables is DEFINITELY working. When I comment it out, this is the result (part of it, anyway)

20220324_DAY_08_VFX.ALE**->Color	Name	Scene	Tape	Shoot day	Shoot Date	FPS	Duration	Camera #	Roll card #	Soundroll	Drive	Creation Date	End	Audio SR	Tracks	Video	Start	Comments	Comment	Source File	Manufacturer	Source resolutioa	Source bit deptha	Descript	Unc	Source file patha	Display name	Sync audio	Sync audio offsea	Production name	Keywords	Iso	White point (kela	White balance tia	Camera id	Camera fps	Camera type	Camera serial #	Shutter	Camera aperture	Lens type	Focal point (mm)a	Nd filter	Filter	Distance	Par notes	Camera position	Camera roll angla	Camera tilt angla	Camera tc type	Video codec	Format	Color Space	Shutter type	Mon color space	Cdl sat	Cdl sop	Gamma notes	Aspect ratio nota	Sound TC	TRK1	TRK2	TRK3	TRK4	TRK8	
20220427_DAY_31_VFX.ALE**->Color	Name	Scene	Tape	Shoot day	Shoot Date	FPS	Duration	Camera #	Roll card #	Soundroll	Drive	Creation Date	End	Audio SR	Tracks	Video	Start	Comments	Comment	Source File	Manufacturer	Source resolutioa	Source bit deptha	Descript	Unc	Source file patha	Display name	Sync audio	Sync audio offsea	Production name	Keywords	Iso	White point (kela	White balance tia	Camera id	Camera fps	Camera type	Camera serial #	Shutter	Camera aperture	Lens type	Focal point (mm)a	Nd filter	Filter	Distance	Par notes	Camera position	Camera roll angla	Camera tilt angla	Camera tc type	Video codec	Format	Color Space	Shutter type	Mon color space	Cdl sat	Cdl sop	Gamma notes	Aspect ratio nota	Sound TC	TRK1	TRK2	TRK3	TRK4	TRK8	

and WITH showvariables I get this:

20220324_DAY_08_VFX.ALE**->Color	Name	Scene	Tape	Shoot day	Shoot Date	FPS	Duration	Camera #	Roll card #	Soundroll	Drive	Creation Date	End	Audio SR	Tracks	Video	Start	Comments	Comment	Source File	Manufacturer	Source resolutioa	Source bit deptha	Descript	Unc	Source file patha	Display name	Sync audio	Sync audio offsea	Production name	Keywords	Iso	White point (kela	White balance tia	Camera id	Camera fps	Camera type	Camera serial #	Shutter	Camera aperture	Lens type	Focal point (mm)a	Nd filter	Filter	Distance	Par notes	Camera position	Camera roll angla	Camera tilt angla	Camera tc type	Video codec	Format	Color Space	Shutter type	Mon color space	Cdl sat	Cdl sop	Gamma notes	Aspect ratio nota	Sound TC	TRK1	TRK2	TRK3	TRK4	TRK8	
20220427_DAY_31_VFX.ALE**->Color	Name	Scene	Tape	Shoot day	Shoot Date	FPS	Unit name	Duration	Camera #	Roll card #	Soundroll	Drive	Creation Date	End	Audio SR	Tracks	Video	Start	Comments	Comment	Source File	Manufacturer	Source resolutioa	Source bit deptha	Descript	Unc	Source file patha	Display name	Sync audio	Sync audio offsea	Production name	Keywords	Iso	White point (kela	White balance tia	Camera id	Camera fps	Camera type	Camera serial #	Shutter	Camera aperture	Lens type	Focal point (mm)a	Nd filter	Filter	Distance	Par notes	Camera position	Camera roll angla	Camera tilt angla	Camera tc type	Video codec	Format	Color Space	Shutter type	Mon color space	Cdl sat	Cdl sop	Gamma notes	Aspect ratio nota	Sound TC	TRK1	TRK2	TRK3	TRK4	TRK8	

Note that the field list is the same for both files in the first paste and the fields are different in the 2nd paste. (the 2nd file in the 2nd take has a field called “Unit Name”, for example.

And, when the procedure runs, i get an extremely satisfying few seconds of onscreen list scrolling :slight_smile:

csw

Yes, I’m sure that they are different, and without the showvariables they would be the same. But I would double check to make sure that different actually means correct. My guess is that they are off by one, and the first one may be somewhat random depending on what had been done before. Not really a guess – you are using the value in the fg_filecontents variable without having explicitly initialized it. So the first time thru the loop, you’ll get whatever happened to be lying around in that variable. The second time thru the loop, you’ll get what should have been on the first line, the third time you’ll get what should have been on the second line, etc.

I certainly don’t want to discourage that!

Oh, yes, you were right about that- I moved the showvariables up a line or two. Since the looparray goes through all the values in the same array that populated the text object, it doesn’t really matter what was selected in the text object at the time- all the values get looped through, so all the files get read and now that the showvariables is moved, the result is attached to the right file name.

I was so excited by the fact that the showvariables was eliciting the side effect (after writing that loooong original post) I had to answer my own question before scrutinizing the result…

The fact that I got to say “Dave, you’re wrong” had nothing at all to do with it! /humor

csw

And, not to be pedantic, Dave wasn’t really wrong, because I said ‘code’, not ‘formula’. Close call!

csw