Page 1 of 2

Associate or tie together two groups of information

Posted: 14 Aug 2014 14:44
by klownboy
Hi, I've come across this scenario a number of times so I figured it was about time to ask after having search to no avail. Is there a way in XY scripting to associate or tie together 2 groups of information. As in the following case, I have a group of "View" numbers obtained with get("view") and I want to associate that with the proper text that I will use later. It's being used only for the users information in the inputselect header not in the listdata.

Code: Select all

    $cur_view = get("View");
	 if($cur_view < "4") {$cur_view = " Not a thumbnail or tile view";}
	 if($cur_view == "4") {$cur_view = "Small Thumbnails [$T_sm]";}
	 if($cur_view == "5") {$cur_view = "Medium Thumbnails [$T_med]";}
	 if($cur_view == "6") {$cur_view = "Large Thumbnails [$T_lg]";}
	 if($cur_view == "8") {$cur_view = "Small Tiles [48x48]";}
	 if($cur_view == "9") {$cur_view = "Large Tiles [64x64]";}
Is there cleaner, less verbose way to tie together data in one group to data in another, item 1 in the group "A" ($cur_view number group ) with item 1 in group "B" (view description group), (e.g., "6" with "Large Thumbnails [$T_lg]", etc? Can I accomplish group comparisons "|" pipe separators or some other method?
Thanks,
Ken

Re: Associate or tie together two groups of information

Posted: 14 Aug 2014 14:51
by TheQwerty
Use GetToken!

Code: Select all

$views = <<<VIEWS
Details
Details with Thumbnails
List
Small Icons
Thumbnails #1
Thumbnails #2
Thumbnails #3
Large Icons
Small Tiles
Large Tiles
VIEWS;
  Echo 'The current view is: ' . GetToken($views, Get('View')+1, "<crlf>");
EDIT: Though honestly, you're probably better off making $views into a lookup table rather than relying on it being in the correct order:

Code: Select all

$views = <<<VIEWS
0|Details
1|Details with Thumbnails
2|List
3|Small Icons
4|Thumbnails #1
5|Thumbnails #2
6|Thumbnails #3
7|Large Icons
8|Small Tiles
9|Large Tiles
VIEWS;

 // Filter the list of views by the current view index.
 $view = FormatList($views, 'f', "<crlf>", Get('View') . '|*');

 // Strip off the index value.
 $view = GetToken($view, 2, '|', 't', 2);

 Echo "The current view is: $view";

EDIT 2: And if you want to be even more awesome add the CIDs to your lookup table so you can retrieve the translated captions (where you could thus include accelerators or the user's shortcut keys).

Code: Select all

// List of Views
// Format is: ViewIndex|CommandID|Description
$views = <<<VIEWS
0|302|Details
1|303|Details with Thumbnails
2|304|List
3|305|Small Icons
4|306|Thumbnails #1
5|307|Thumbnails #2
6|308|Thumbnails #3
7|309|Large Icons
8|313|Small Tiles
9|314|Large Tiles
VIEWS;

 // Get current view line.
 $view = FormatList($views, 'f', "<crlf>", Get('View') . '|*');
  
 // Get our description of view.
 $ourCaption = GetToken($view, 3, '|', 't', 2);

 // Get the translated menu caption of the view. 
 $cid = GetToken($view, 2, '|', 't');
 $translatedCaption = Get('MenuCaption', $cid, 2); // 2 = strip accelerators

 Echo "We call the current view: $ourCaption<crlf>But you might call it: $translatedCaption";

Re: Associate or tie together two groups of information

Posted: 14 Aug 2014 16:14
by klownboy
I've been stepping through all 3 of your examples. Your last one is really great. I may have to go back and revamp parts of my script to take advantage of pulling out the menu caption. I like the way you filtered using "formatlist" in two of your examples. I was actually trying to use gettokenindex for each of the "groupings" but obviously that would be totally relying on position in the group. I tend to forget about using heredoc and it can be very handy. More great example to keep in my script techniques book. :) Thanks so much,
Ken

Edit: I wanted to note that I was also obtaining the users specified thumbnail sizes from XYplorer.ini using using getkey, for example...

Code: Select all

    $T_sm = getkey("Width", "Thumbs") . "x" . getkey("Height", "Thumbs");
    $T_med = getkey("Width1", "Thumbs") . "x" . getkey("Height1", "Thumbs");
    $T_lg = getkey("Width2", "Thumbs") . "x" . getkey("Height2", "Thumbs");
But, I suppose I could also get that from the menucaption as in your example especially if I'm using the other information anyway and since the menu does reflect any user changes to the default sizes.

Code: Select all

    $T_size = trim(gettoken($translatedCaption, "2", "(", "t"), ")", "R");
    echo "Thumbnail size is:  $T_size";  ///will give me 240x180 etc.
I compare what we have for a thumbnail size to what exists for a particular folder in all the thumbnail "dat2" files and this info is in the format of "240x180" etc.
Thanks again

Re: Associate or tie together two groups of information

Posted: 14 Aug 2014 19:51
by bdeshi
Regarding OT OP, I often use replacelist().

Code: Select all

    $cur_view = get("View");
    $cur_view = replacelist($cur_view, "0|1|2|3|4|5|6|8|9", "Not a thumbnail view|Not a thumbnail view|Not a thumbnail view|Not a thumbnail view|Small Thumbnails [$T_sm]|Medium Thumbnails [$T_med]|Large Thumbnails [$T_lg]|Small Tiles [48x48]|Large Tiles [64x64]","|");
Look ugly though.

Re: Associate or tie together two groups of information

Posted: 14 Aug 2014 21:01
by klownboy
Thanks Sammay for the additional method. Using replacelist may be ugly as you called it, but it is less lines of code.

Re: Associate or tie together two groups of information

Posted: 15 Aug 2014 07:26
by Filehero
TheQwerty wrote:Use GetToken!

EDIT: Though honestly, you're probably better off making $views into a lookup table rather than relying on it being in the correct order:

Code: Select all

$views = <<<VIEWS
0|Details
1|Details with Thumbnails
2|List
3|Small Icons
4|Thumbnails #1
5|Thumbnails #2
6|Thumbnails #3
7|Large Icons
8|Small Tiles
9|Large Tiles
VIEWS;
Simple HashMaps - there they are! :D :appl: :beer:

Thanks, TheQuerty.


Cheers,
Filehero

Re: Associate or tie together two groups of information

Posted: 15 Aug 2014 12:21
by klownboy
Hi TheQwerty, I've been experiencing problem with the use of the code from your previous post in that sometimes (3 times since yesterday including once this morning after a cold bootup) the values for the thumbsizes (e.g., (240x180)) do not appear after the menu caption (e.g., Thumbnail #3) in my script.
TheQwerty wrote:$translatedCaption = Get('MenuCaption', $cid, 2); // 2 = strip accelerators
Obviously the same is happening with the other Thumbnail sizes. Note: the sizes are always present in the actual view menu, they're just not showing with get menucaption. It's very inconsistent to a point where if I can't figure it out, I may have to return to using getkey to obtain the users thumbnail sizes. Maybe this is a question for Don or is possibly a bug, in that, when I go into configuration doing absolutely nothing and come out the the sizes then appear using SC get menucaption. It seems as if XY needs to be refreshed in some way for them to show up using "get menucaption" where as it doesn't to display in the menu. Any ideas on why that may be happening?
Thanks,
Ken

Re: Associate or tie together two groups of information

Posted: 15 Aug 2014 14:48
by bdeshi
Additionally, if the thumb sizes are changed in config, get(MenuCaption, 306|307|308) show the previous sizes of each until View->Views submenu or List all commands is displayed at least once.

Re: Associate or tie together two groups of information

Posted: 15 Aug 2014 15:05
by klownboy
Thanks Sammay. I hadn't tested that, but I figured that would probably be the case. I'm not overly concerned about the script and someone changing the values though only because I don't think it's something people would do that often. I haven't changed the thumb sizes from the defaults at all though so I'm still curious why "get MenuCaption" wouldn't reflect what I've had since 2012. Doesn't that seem odd to you? XY's displaying the thumb sizes properly in the menu yet it's not displaying them at all in get MenuCaption when I haven't changed thumb sizes ever. Correct me if I'm wrong, but it shouldn't take a view menu display to have them display properly using get MenuCaption (when I've never changed them). :eh:

Re: Associate or tie together two groups of information

Posted: 15 Aug 2014 16:06
by bdeshi
Right. Some size should come up with get, correct one or not.


EDIT: Well, turns out you have to open Views or List All.... to make get(…) register the sizes, even if they're not changed from default.
Checked with ::fresh;

Maybe XY doesn't make those updated menu captions (maybe all dynamic captions) available to scripting unless they're reloaded in GUI beforehand.

Re: Associate or tie together two groups of information

Posted: 15 Aug 2014 18:30
by klownboy
OK thanks Sammay, I understand what you're saying concerning the registering of the size when you use the view menu, but it does seem a bit strange that XY would have to do that over and over on startups when no changes to the sizes have been made. I assume that I'll be safe, or should I say, safer to pull the sizes from XYplorer.ini file using getkey as I showed in an earlier post. It happens so fast it probably makes no difference speed wise. I just don't want to set the script up to fail if the sizes haven't been registered via the menu yet.

Re: Associate or tie together two groups of information

Posted: 15 Aug 2014 18:56
by bdeshi
That menu caption refreshing behavior smells of bugs. :|
On the other hand, parsing the sizes from ini will not represent most current sizes, if the settings were changed and not saved yet.
Therefore you might call the savesettings command before looking at the ini.

Re: Associate or tie together two groups of information

Posted: 15 Aug 2014 19:11
by klownboy
SammaySarkar wrote:That menu caption refreshing behavior smells of bugs.
I agree ...I smell something funny and it's not my cat. Honestly I don't really want to get into saving user settings if I don't have to (especially without the user knowing it) since I really don't think the changing of thumb sizes is something one does on a regular basis if at all.

By the way I'm nearly done updating the Thumbnail Maintenance script once again. It will have a dialog where the user can select which thumbnail sizes he wants to generate/rebuild/refresh. The inputselect box will also indicate which thumbnail sizes are already in the database for a particular folder. I've provided this option for the rebuild of one folder (i.e., the current folder), but I have no plans on doing it for the other option, that is the current folder and all its subs...to me that would be just too much user intervention required for this type of thing.

Re: Associate or tie together two groups of information

Posted: 15 Aug 2014 19:18
by SkyFrontier
SammaySarkar wrote: ...Therefore you might call the savesettings command before looking at the ini.
User prompts are welcome in cases like this and might provide the perfect balance.

Re: Associate or tie together two groups of information

Posted: 15 Aug 2014 20:54
by bdeshi
klownboy wrote:It will have a dialog where the user can select which thumbnail sizes he wants to generate/rebuild/refresh.
That's a big help! :D
"but I have no plans on doing it for the other option" — that's it, you leave me no choice but to hack your code! :whistle: