Debian Codegraph @

xbmc/addons/gui/skin/SkinTimers.dox

raw
1 /*!
2
3 \page Skin_Timers Skin Timers
4 \brief **Programatic time-based resources for Skins**
5
6 \tableofcontents
7
8 --------------------------------------------------------------------------------
9 \section Skin_Timers_sect1 Description
10
11 Skin timers are skin resources that are dependent on time and can be fully controlled from skins either using
12 \link page_List_of_built_in_functions **Builtin functions**\endlink or
13 \link modules__infolabels_boolean_conditions **Infolabels and Boolean conditions**\endlink. One can see them
14 as stopwatches that can be activated and deactivated automatically depending on the value of info expressions or simply activated/deactivated
15 manually from builtins.
16 The framework was created to allow skins to control the visibility of windows (and controls) depending on
17 the elapsed time of timers the skin defines. Skin timers allow multiple use cases in skins, previously only available via the execution
18 of python scripts:
19 - Closing a specific window after x seconds have elapsed
20 - Controlling the visibility of a group (or triggering an animation) depending on the elapsed time of a given timer
21 - Defining a buffer time window that is kept activated for a short period of time (e.g. keep controls visible for x seconds after a player seek)
22 - Executing timed actions (on timer stop or timer start)
23 - etc
24
25 Skin timers are defined in the `Timers.xml` file within the xml directory of the skin. The file has the following "schema":
26
27 ~~~~~~~~~~~~~{.xml}
28 <timers>
29 <timer>...</timer>
30 <timer>...</timer>
31 </timers>
32 ~~~~~~~~~~~~~
33
34 see \link Skin_Timers_sect2 the examples section\endlink and \link Skin_Timers_sect3 the list of available tags\endlink for concrete details.
35
36 \skinning_v20 Added skin timers
37
38 --------------------------------------------------------------------------------
39 \section Skin_Timers_sect2 Examples
40
41 The following example illustrates the simplest possible skin timer. This timer is completely manual (it has to be manually started and stopped):
42
43 ~~~~~~~~~~~~~{.xml}
44 <timer>
45 <name>mymanualtimer</name>
46 <description>100% manual timer</description>
47 </timer>
48 ~~~~~~~~~~~~~
49
50 This timer can be controlled from your skin by executing the \link Builtin_SkinStartTimer `Skin.TimerStart(mymanualtimer)` builtin\endlink or
51 \link Builtin_SkinStopTimer `Skin.TimerStop(mymanualtimer)` builtin\endlink. You can define the visibility of skin elements based on the internal
52 properties of the timer, such as the fact that the timer is active/running using \link Skin_TimerIsRunning `Skin.TimerIsRunning(mymanualtimer)` info\endlink
53 or depending on the elapsed time (e.g. 5 seconds) using the \link Skin_TimerElapsedSecs Integer.IsGreaterOrEqual(Skin.TimerElapsedSecs(mymanualtimer),5) info\endlink.
54
55 The following timer is a variation of the previous timer but with the added ability of being automatically stopped by the skinning engine after a maximum of elapsed
56 5 seconds without having to issue the `Skin.TimerStop(mymanualtimer)` builtin:
57
58 ~~~~~~~~~~~~~{.xml}
59 <timer>
60 <name>mymanualautocloseabletimer</name>
61 <description>100% manual autocloseable timer</description>
62 <stop>Integer.IsGreaterOrEqual(Skin.TimerElapsedSecs(mymanualautocloseabletimer),5)</stop>
63 </timer>
64 ~~~~~~~~~~~~~
65
66 This type of timer is particularly useful if you want to automatically close a specific window (or triggering a close animation) after x time has elapsed,
67 while guaranteeing the timer is also stopped. See the example below:
68
69 ~~~~~~~~~~~~~{.xml}
70 <?xml version="1.0" encoding="utf-8"?>
71 <window type="dialog" id="1109">
72 <onload>Skin.TimerStart(mymanualautocloseabletimer)</onload>
73 ...
74 <controls>
75 <control type="group">
76 <animation effect="slide" start="0,0" end="0,-80" time="300" condition="Integer.IsGreaterOrEqual(Skin.TimerElapsedSecs(mymanualautocloseabletimer),5)">Conditional</animation>
77 ...
78 </control>
79 </controls>
80 </window>
81 ~~~~~~~~~~~~~
82
83 The following timer presents a notification (for 1 sec) whenever the timer is activated or deactivated:
84
85 ~~~~~~~~~~~~~{.xml}
86 <timer>
87 <name>manualtimerwithactions</name>
88 <description>100% manual timer with actions</description>
89 <onstart>Notification(skintimer, My timer was started, 1000)</onstart>
90 <onstop>Notification(skintimer, My timer was stopped, 1000)</onstop>
91 </timer>
92 ~~~~~~~~~~~~~
93
94 The following timer is an example of a completely automatic timer. The timer is automatically activated or deactivated based on the value
95 of boolean info expressions. In this particular example, the timer is automatically started whenever the Player is playing a file (if not already running). It is stopped if
96 there is no file being played (and of course if previously running). Since the timer can be activated/deactivated multiple times, `reset="true"` ensures the timer is
97 always reset to 0 on each start operation. Whenever the timer is started or stopped, notifications are issued.
98
99 ~~~~~~~~~~~~~{.xml}
100 <timer>
101 <name>myautomatictimer</name>
102 <description>Player state checker</description>
103 <start reset="true">Player.Playing</start>
104 <stop>!Player.Playing</stop>
105 <onstart>Notification(skintimer, Player has started playing a file, 1000)</onstart>
106 <onstop>Notification(skintimer, Player is no longer playing a file, 1000)</onstop>
107 </timer>
108 ~~~~~~~~~~~~~
109
110 In certain situations you might want to reset your timer without having to stop and start. For instance, if you want to stop the timer after 5 seconds
111 but have the timer resetting to 0 seconds if the user provides some input to Kodi. For such cases the `<reset/>` condition can be used:
112
113 ~~~~~~~~~~~~~{.xml}
114 <timer>
115 <name>windowtimer</name>
116 <description>Reset on idle</description>
117 <start reset="true">Window.IsActive(mywindow)</start>
118 <reset>Window.IsActive(mywindow) + !System.IdleTime(1) + Integer.IsGreaterOrEqual(Skin.TimerElapsedSecs(windowtimer), 1)</reset>
119 <stop>!Window.IsActive(mywindow) + Integer.IsGreaterOrEqual(Skin.TimerElapsedSecs(windowtimer), 5)</stop>
120 <onstop>Dialog.Close(mywindow)</onstop>
121 </timer>
122 ~~~~~~~~~~~~~
123
124 Finer conditional granularity can also be applied to the `onstop` or `onstart` actions. This allows the skinner to create generic timers which respect a
125 limited set of conditions but trigger different actions depending on a condition applied only to the action.
126 The following timer plays the trailer of a given item when the user is in the videos window, the item has a trailer, the player is not playing and the
127 global idle time is greater than 3 seconds.
128 As you can see, the first action (notification) is triggered for any item. The actual playback, on the other hand, will only play if the focused
129 item has the label "MyAwesomeMovie".
130
131 ~~~~~~~~~~~~~{.xml}
132 <timer>
133 <name>trailer_autoplay_idle_timer</name>
134 <start reset="true">System.IdleTime(3) + Window.IsVisible(videos) + !Player.HasMedia + !String.IsEmpty(ListItem.Trailer)</start>
135 <onstart>Notification(skintimer try play, $INFO[ListItem.Trailer], 1000)</onstart>
136 <onstart condition="String.IsEqual(ListItem.Label,MyAwesomeMovie)">PlayMedia($INFO[ListItem.Trailer],1,noresume)</onstart>
137 </timer>
138 ~~~~~~~~~~~~~
139
140 --------------------------------------------------------------------------------
141 \section Skin_Timers_sect3 Available tags
142
143 Skin timers have the following available tags:
144
145 | Tag | Description |
146 |--------------:|:--------------------------------------------------------------|
147 | name | The unique name of the timer. The name is used as the id of the timer, hence needs to be unique. <b>(required)</b>
148 | description | The description of the timer, a helper string. <b>(optional)</b>
149 | start | An info bool expression that the skinning engine should use to automatically start the timer <b>(optional)</b>
150 | reset | An info bool expression that the skinning engine should use to automatically reset the timer <b>(optional)</b>
151 | stop | An info bool expression that the skinning engine should use to automatically stop the timer <b>(optional)</b>
152 | onstart | A builtin function that the skinning engine should execute when the timer is started <b>(optional)</b><b>(can be repeated)</b>. Supports an additional `"condition"` as element attribute.
153 | onstop | A builtin function that the skinning engine should execute when the timer is stopped <b>(optional)</b><b>(can be repeated)</b>. Supports an additional `"condition"` as element attribute.
154
155 @note If multiple onstart or onstop actions exist, their execution is triggered sequentially.
156 @note Both onstart and onstop actions support fine-grained conditional granularity by specifying a "condition" attribute (see the examples above).
157
158 --------------------------------------------------------------------------------
159 \section Skin_Timers_sect4 See also
160 #### Development:
161
162 - [Skinning](http://kodi.wiki/view/Skinning)
163
164 */