The best way to execute a script?
#1
Hi, I've got a script I'm running from Script.Embuary.Helper to work out "percentage watched" for TV show and Season views based on [watched episodes / total episodes]. Currently this fires using a hidden button embedded in the <focusedlayout> with an <onfocus> condition. It works fine for normal scrolling, but when you scroll really quickly and come to a stop, it gets quite glitchy as I think there's a slight delay and so it takes a few hundred milliseconds working out the calculation for each item you've scrolled through.

Here's a video showing what I mean: https://cl.ly/887ca78f616b

Ideally I want it only to trigger after a short period of no scrolling. Because of the delay to conduct the calculation using the script, I already have a 380ms window between a ListItem displaying and the progress bar showing. But I can't really think of an elegant way to get this script to fire afer, say 150ms of no scrolling. I'm sure it's simple, but I'm a bit end-of-year frazzled and need a pair of fresh eyes!!

Thanks!

Here is the include that I currently have in all my <focusedlayout>s:

xml:

  <include name="HiddenFocusButton">
    <control type="button">
      <visible allowhiddenfocus="true">false</visible>
      <onfocus condition="System.HasAddon(script.embuary.helper) + [Container.Content(tvshows) | Container.Content(seasons)]">RunScript(script.embuary.helper,action=calc,do='"($INFO[ListItem.Property(WatchedEpisodes)] / $INFO[ListItem.Property(TotalEpisodes)]) * 100"',prop=MyResult)</onfocus>
    </control>
  </include>
Reply
#2
You could try with System.IdleTime(1), although it's a whole second...

xml:

  <include name="HiddenFocusButton">
    <control type="button">
      <visible allowhiddenfocus="true">false</visible>
      <onfocus condition="System.IdleTime(1) + System.HasAddon(script.embuary.helper) + [Container.Content(tvshows) | Container.Content(seasons)]">RunScript(script.embuary.helper,action=calc,do='"($INFO[ListItem.Property(WatchedEpisodes)] / $INFO[ListItem.Property(TotalEpisodes)]) * 100"',prop=MyResult)</onfocus>
    </control>
  </include>
If I have helped you or increased your knowledge, please click the 'thumbs up' button to give thanks :)
Reply
#3
(2019-12-31, 20:51)manfeed Wrote: You could try with System.IdleTime(1), although it's a whole second...

xml:

  <include name="HiddenFocusButton">
    <control type="button">
      <visible allowhiddenfocus="true">false</visible>
      <onfocus condition="System.IdleTime(1) + System.HasAddon(script.embuary.helper) + [Container.Content(tvshows) | Container.Content(seasons)]">RunScript(script.embuary.helper,action=calc,do='"($INFO[ListItem.Property(WatchedEpisodes)] / $INFO[ListItem.Property(TotalEpisodes)]) * 100"',prop=MyResult)</onfocus>
    </control>
  </include>

Thanks for the suggestion @manfeed - unfortunately, it doesn't seem to trigger with System.IdleTime(1).
Reply
#4
What about putting it in the call to the include? Something like...

  <include condition="System.IdleTime(1)">HiddenFocusButton</include>
If I have helped you or increased your knowledge, please click the 'thumbs up' button to give thanks :)
Reply
#5
Try using !Container.OnNext + !Container.OnPrevious instead.
Reply
#6
run the script with alarm clock instaed just the action


<onfocus>
AlarmClock(forcedelayed,[runscript.action],00:03,silent)
</onfocus>
<onunfocus>
CancelAlarm(forcedelayed,true)</onunfocus>

note that the script action is fired correct, but the result of last 'stored result' remain till refresh.

EDIT:

Maybe this works better

so to get correct result visible you should add propertys via alarm clock
instead fire the action delayed, fire set prop delayed !
to compare strings.

xml:
<onfocus>[runscript.action]</onfocus>
<onfocus>
AlarmClock(forcedelayed,setproperty(comparelabel,$INFO[ListItem.label],home) ,00:02,silent)
</onfocus>
<onunfocus>CancelAlarm(forcedelayed,true)</onunfocus>



This ways you can show correct result via visible cond for your " progress " group
(compare stored vs current item)
xml:
<visible>String.IsEqual($INFO[window(home).property(comparelabel),ListItem.label)]</visible>

EDIT 2:

saw lately ,progress info is filled by prop

so

xml:
<onfocus condition="System.HasAddon(script.embuary.helper) + [Container.Content(tvshows) | Container.Content(seasons)]">RunScript(script.embuary.helper,action=calc,do='"($INFO[ListItem.Property(WatchedEpisodes)] / $INFO[ListItem.Property(TotalEpisodes)]) * 100"',prop=MyResult)</onfocus>

<onunfocus condition="!String.IsEmpty($INFO[window(home).property(myresult)">ClearProperty(MyResult,home)</onunfocus>

and use

xml:
<visible effect="fade">"!String.IsEmpty($INFO[window(home).property(myresult)</visible>
for you progress bar.
Skins |  Titan M O D   •   S W A N (WIP)
Reply
#7
Thanks @manfeed @Hitcher and @mardukL for the suggestions. I'll be sure to try these all tomorrow and report back if I have success!!
Reply
#8
(2020-01-02, 01:59)QuizKid Wrote: Thanks @manfeed @Hitcher and @mardukL for the suggestions. I'll be sure to try these all tomorrow and report back if I have success!!

Not having much luck with these suggestions. From what I can tell, I think it's because the condition on the <onfocus> is only checked when the item receives focus and it's not checked again after that, so using !container.onprevious/container.onnext doesn't work as it will always be false at the time the <onfocus> condition is evaluated. 

I've added an onunfocus condition to clear the property just as good practice but this doesn't change the underlying issue that i can't figure out how to trigger the <onfocus> command on a time delay. The Alarm Clock sounded like an ingenious idea, but I'm not having any luck with it. Might be due to a formatting error on my part.

Hmmm
Reply
#9
(2020-01-02, 02:52)QuizKid Wrote:
(2020-01-02, 01:59)QuizKid Wrote: Thanks @manfeed @Hitcher and @mardukL for the suggestions. I'll be sure to try these all tomorrow and report back if I have success!!

Not having much luck with these suggestions. From what I can tell, I think it's because the condition on the <onfocus> is only checked when the item receives focus and it's not checked again after that, so using !container.onprevious/container.onnext doesn't work as it will always be false at the time the <onfocus> condition is evaluated. 

I've added an onunfocus condition to clear the property just as good practice but this doesn't change the underlying issue that i can't figure out how to trigger the <onfocus> command on a time delay. The Alarm Clock sounded like an ingenious idea, but I'm not having any luck with it. Might be due to a formatting error on my part.

Hmmm 

Ahh think I figured it out and it was deceptively simple in the end. The description in the wiki for <onfocus> is: "Specifies the action to perform when the button is focused. Should be a built in function. The action is performed after any focus animations have completed."

So I added a focus animation and that seems to delay it just as I needed!

xml:
  <include name="HiddenFocusButton">
    <control type="button">
      <animation effect="slide" end="0,0" time="380" reversible="false">Focus</animation>
      <onfocus condition="System.HasAddon(script.embuary.helper) + [Container.Content(tvshows) | Container.Content(seasons)]">RunScript(script.embuary.helper,action=calc,do='"($INFO[ListItem.Property(WatchedEpisodes)] / $INFO[ListItem.Property(TotalEpisodes)]) * 100"',prop=MyResult)</onfocus>
      <onunfocus>ClearProperty(MyResult,home)</onunfocus>
    </control>
  </include>

Thanks again for all the responses!
Reply
#10
Just one followup question... is there a way to clear a window property when you navigate in myvideonav from tvshows > seasons or seasons > episodes or even tvshows > home > movies? Right now in these scenarios it appears my <onunfocus> command isn't triggering, so the progressbar shows up from the previous item.

As it's not technically a window change, I'm not really sure how to control the transition.
Reply
#11
(2020-01-02, 03:46)QuizKid Wrote: Just one followup question... is there a way to clear a window property when you navigate in myvideonav from tvshows > seasons or seasons > episodes or even tvshows > home > movies? Right now in these scenarios it appears my <onunfocus> command isn't triggering, so the progressbar shows up from the previous item.

As it's not technically a window change, I'm not really sure how to control the transition.

For TvShows > Home > Movies, you can clear the window property with an <onload> condition in Home.xml and/or MyVideoNav.xml

However, there isn't any easy way to do it when navigating between levels in MyVideoNav (e.g. Seasons > Episodes).
Arctic Fuse - Alpha now available. Support me on Ko-fi.
Reply
#12
(2020-01-03, 13:18)jurialmunkey Wrote:
(2020-01-02, 03:46)QuizKid Wrote: Just one followup question... is there a way to clear a window property when you navigate in myvideonav from tvshows > seasons or seasons > episodes or even tvshows > home > movies? Right now in these scenarios it appears my <onunfocus> command isn't triggering, so the progressbar shows up from the previous item.

As it's not technically a window change, I'm not really sure how to control the transition.

For TvShows > Home > Movies, you can clear the window property with an <onload> condition in Home.xml and/or MyVideoNav.xml

However, there isn't any easy way to do it when navigating between levels in MyVideoNav (e.g. Seasons > Episodes). 

Thanks, I thought as much, not a massive issue, as I can just use visibility conditions to make sure the progress bar only shows in the correct scenarios and when I need that property again, it will be recalculated beforehand. Thanks for confirming though
Reply
#13
(2020-01-02, 03:46)QuizKid Wrote: Just one followup question... is there a way to clear a window property when you navigate in myvideonav from tvshows > seasons or seasons > episodes or even tvshows > home > movies? Right now in these scenarios it appears my <onunfocus> command isn't triggering, so the progressbar shows up from the previous item.

As it's not technically a window change, I'm not really sure how to control the transition.

Not sure,
did you test to use clear the property as the first onfocus action instead of use it on last position ?

if that is not workin,you could also try to add an conditional onfocus action the the view id content group itself.
Skins |  Titan M O D   •   S W A N (WIP)
Reply
#14
(2020-01-05, 01:43)mardukL Wrote:
(2020-01-02, 03:46)QuizKid Wrote: Just one followup question... is there a way to clear a window property when you navigate in myvideonav from tvshows > seasons or seasons > episodes or even tvshows > home > movies? Right now in these scenarios it appears my <onunfocus> command isn't triggering, so the progressbar shows up from the previous item.

As it's not technically a window change, I'm not really sure how to control the transition.

Not sure,
did you test to use clear the property as the first onfocus action instead of use it on last position ?

if that is not workin,you could also try to add an conditional onfocus action the the view id content group itself. 
Thanks, I'll give that a go, but I think the issue is the focus doesn't retrigger when the window changes from tv show to seasons until you change the position manually.
Reply

Logout Mark Read Team Forum Stats Members Help
The best way to execute a script?0