libcvautomation/libcvautomation__funcs_8py_source.html

840 lines
92 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>libcvautomation: libcvautomation_funcs.py Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script><script src="http://www.mathjax.org/mathjax/MathJax.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">libcvautomation
&#160;<span id="projectnumber">2.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File&#160;List</span></a></li>
<li><a href="globals.html"><span>File&#160;Members</span></a></li>
</ul>
</div>
</div>
<div class="header">
<div class="headertitle">
<div class="title">libcvautomation_funcs.py</div> </div>
</div><!--header-->
<div class="contents">
<a href="libcvautomation__funcs_8py.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a><a class="code" href="namespacelibcvautomation__funcs.html">00001</a> <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00002"></a>00002 <span class="stringliteral">libcvautomation_funcs.py</span>
<a name="l00003"></a>00003 <span class="stringliteral"></span>
<a name="l00004"></a>00004 <span class="stringliteral">This is a high-level wrapper intended to give you easy access to</span>
<a name="l00005"></a>00005 <span class="stringliteral">libcvautomation, while staying flexible and powerful.</span>
<a name="l00006"></a>00006 <span class="stringliteral">This wrapper was designed to be like the Bash wrapper of the</span>
<a name="l00007"></a>00007 <span class="stringliteral">same name, but allows access to the advanced features of Python - </span>
<a name="l00008"></a>00008 <span class="stringliteral">for example, error handling.</span>
<a name="l00009"></a>00009 <span class="stringliteral">Also, it becomes easy to integrate other systems like dogtail</span>
<a name="l00010"></a>00010 <span class="stringliteral">into the same application test if you want to combine features.</span>
<a name="l00011"></a>00011 <span class="stringliteral"></span>
<a name="l00012"></a>00012 <span class="stringliteral">To use:</span>
<a name="l00013"></a>00013 <span class="stringliteral">import libcvautomation_funcs</span>
<a name="l00014"></a>00014 <span class="stringliteral"></span>
<a name="l00015"></a>00015 <span class="stringliteral">If there are any questions, comments, concerns, or suggestions,</span>
<a name="l00016"></a>00016 <span class="stringliteral">notify the developer at &lt;bspeice@uncc.edu&gt;&quot;&quot;&quot;</span>
<a name="l00017"></a>00017
<a name="l00018"></a>00018 <span class="comment">## \file libcvautomation_funcs.py</span>
<a name="l00019"></a>00019 <span class="comment"># \brief Libcvautomation wrapper for python</span>
<a name="l00020"></a>00020 <span class="comment"># \details This source file is designed to give high-level access to libcvautomation using Python. It was modeled after the Bash wrapper, but allows for access to all the extra features of Python.&lt;br&gt;To use:</span>
<a name="l00021"></a>00021 <span class="comment"># \code import libcvautomation_funcs \endcode</span>
<a name="l00022"></a>00022 <span class="comment"># \author Bradlee Speice</span>
<a name="l00023"></a>00023
<a name="l00024"></a>00024 <span class="comment">## \package libcvautomation_funcs</span>
<a name="l00025"></a>00025 <span class="comment"># \brief Namespace to contain all of the features needed to use the libcvautomation_funcs wrapper</span>
<a name="l00026"></a>00026
<a name="l00027"></a>00027 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00028"></a>00028 <span class="comment"># Import the libcvautomation library - this should have already been installed</span>
<a name="l00029"></a>00029 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00030"></a>00030 <span class="keyword">import</span> libcvautomation
<a name="l00031"></a>00031
<a name="l00032"></a>00032 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00033"></a>00033 <span class="comment"># Set up the logging options</span>
<a name="l00034"></a>00034 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00035"></a>00035
<a name="l00036"></a>00036 _use_frame_trace=<span class="keywordtype">None</span>
<a name="l00037"></a>00037
<a name="l00038"></a>00038 <span class="keywordflow">try</span>:
<a name="l00039"></a>00039 <span class="keyword">import</span> inspect <span class="comment">#For getting the function that called us</span>
<a name="l00040"></a>00040 _use_frame_trace = <span class="keyword">True</span>
<a name="l00041"></a>00041 <span class="keywordflow">except</span>:
<a name="l00042"></a>00042 _use_frame_trace = <span class="keyword">False</span>
<a name="l00043"></a>00043
<a name="l00044"></a>00044 <span class="keyword">import</span> time
<a name="l00045"></a>00045
<a name="l00046"></a>00046 <span class="keyword">def </span>_get_caller():
<a name="l00047"></a>00047 <span class="keywordflow">if</span> _use_frame_trace:
<a name="l00048"></a>00048 caller_name = inspect.stack()[2][3] <span class="comment">#This requires a bit of explanation -</span>
<a name="l00049"></a>00049 <span class="comment"># The way inspect.stack works, we can actually use &#39;absolute&#39;</span>
<a name="l00050"></a>00050 <span class="comment"># positioning in the stack. The [2] indicates the frame</span>
<a name="l00051"></a>00051 <span class="comment"># two levels above us, not specifically the second frame.</span>
<a name="l00052"></a>00052 <span class="comment"># The [3] is the name of said function.</span>
<a name="l00053"></a>00053 <span class="keywordflow">return</span> caller_name
<a name="l00054"></a>00054 <span class="keywordflow">else</span>:
<a name="l00055"></a>00055 <span class="keywordflow">return</span> <span class="stringliteral">&#39;[frame trace disabled]&#39;</span>
<a name="l00056"></a>00056
<a name="l00057"></a>00057 <span class="keyword">def </span>_get_name():
<a name="l00058"></a>00058 <span class="keywordflow">if</span> _use_frame_trace:
<a name="l00059"></a>00059 caller_name = inspect.stack()[1][3] <span class="comment">#This requires a bit of explanation -</span>
<a name="l00060"></a>00060 <span class="comment"># The way inspect.stack works, we can actually use &#39;absolute&#39;</span>
<a name="l00061"></a>00061 <span class="comment"># positioning in the stack. The [1] indicates the frame</span>
<a name="l00062"></a>00062 <span class="comment"># immediately above us, not specifically the first frame.</span>
<a name="l00063"></a>00063 <span class="comment"># The [3] is the name of said function.</span>
<a name="l00064"></a>00064 <span class="keywordflow">return</span> caller_name
<a name="l00065"></a>00065 <span class="keywordflow">else</span>:
<a name="l00066"></a>00066 <span class="keywordflow">return</span> <span class="stringliteral">&#39;[frame trace disabled]&#39;</span>
<a name="l00067"></a>00067
<a name="l00068"></a>00068
<a name="l00069"></a>00069 outfile = <span class="stringliteral">&#39;/dev/null&#39;</span>
<a name="l00070"></a>00070 <span class="keyword">def </span>_log_output( message ):
<a name="l00071"></a>00071 <span class="keyword">global</span> outfile <span class="comment">#Make sure we use the global outfile,</span>
<a name="l00072"></a>00072 <span class="comment">#that people can change it if need be</span>
<a name="l00073"></a>00073
<a name="l00074"></a>00074 <span class="comment">#with open(outfile, &#39;a&#39;) as outfile_handle</span>
<a name="l00075"></a>00075 outfile_handle = open(outfile, <span class="stringliteral">&#39;a&#39;</span>)
<a name="l00076"></a>00076 <span class="comment">#Logfile format:</span>
<a name="l00077"></a>00077 <span class="comment"># &lt;hour&gt;:&lt;minute&gt;:&lt;second&gt; &lt;function_name&gt;: &lt;message&gt;</span>
<a name="l00078"></a>00078 outfile_handle.write(time.strftime(<span class="stringliteral">&#39;%I:%M:%S &#39;</span>))
<a name="l00079"></a>00079 outfile_handle.write(_get_caller() + <span class="stringliteral">&#39; &#39;</span>)
<a name="l00080"></a>00080 outfile_handle.write(message)
<a name="l00081"></a>00081 outfile_handle.write(<span class="stringliteral">&#39;\n&#39;</span>)
<a name="l00082"></a>00082
<a name="l00083"></a>00083
<a name="l00084"></a>00084 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00085"></a>00085 <span class="comment"># Set up the Xlib handler functions</span>
<a name="l00086"></a>00086 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00087"></a>00087
<a name="l00088"></a>00088 X11_display=<span class="keywordtype">None</span> <span class="comment">#NULL</span>
<a name="l00089"></a>00089
<a name="l00090"></a>00090 <span class="keyword">def </span>_check_display():
<a name="l00091"></a>00091 <span class="keyword">global</span> X11_display
<a name="l00092"></a>00092
<a name="l00093"></a>00093 <span class="keywordflow">if</span> X11_display <span class="keywordflow">is</span> <span class="keywordtype">None</span>:
<a name="l00094"></a>00094 _log_output( <span class="stringliteral">&#39;Trying to call &#39;</span> + _get_caller() + <span class="stringliteral">&#39; with no open display!&#39;</span> )
<a name="l00095"></a>00095 <span class="keywordflow">return</span> <span class="keyword">False</span>
<a name="l00096"></a>00096 <span class="keywordflow">else</span>:
<a name="l00097"></a>00097 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00098"></a>00098
<a name="l00099"></a>00099 <span class="keyword">def </span>_get_display(): <span class="comment">#Intended to be unsafe (and a bit faster)-</span>
<a name="l00100"></a>00100 <span class="comment">#all wrapper functions should use check_display() explicitly</span>
<a name="l00101"></a>00101 <span class="keyword">global</span> X11_display
<a name="l00102"></a>00102 <span class="keywordflow">return</span> X11_display
<a name="l00103"></a>00103
<a name="l00104"></a>00104 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00105"></a>00105 <span class="comment"># The following two functions are intended to be used on the front-end</span>
<a name="l00106"></a>00106 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00107"></a>00107
<a name="l00108"></a>00108 <span class="comment">## \brief Open a display for use in the libcvautomation_funcs</span>
<a name="l00109"></a>00109 <span class="comment"># \details This opens a display that will be used for every other function in libcvautomation_funcs.py. If you need to open a different display, use \ref libcvautomation_funcs::close_display() and then open the new display that you want.</span>
<a name="l00110"></a>00110 <span class="comment"># \param display_name The name of the display to open. The default is to open the first available display, which may not specifically be \c :0.</span>
<a name="l00111"></a>00111 <span class="comment"># \warning You \em must use this function to open a display before any other functions can be used.</span>
<a name="l00112"></a>00112 <span class="comment"># \returns Return \c True if the display was successfully opened, \c False otherwise</span>
<a name="l00113"></a><a class="code" href="namespacelibcvautomation__funcs.html#a46446dc9fde2c1f2cc5ac630b51760ce">00113</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a46446dc9fde2c1f2cc5ac630b51760ce" title="Open a display for use in the libcvautomation_funcs.">open_display</a>( display_name=&#39;&#39; ):
<a name="l00114"></a>00114 <span class="keyword">global</span> X11_display
<a name="l00115"></a>00115 X11_display = libcvautomation.cvaOpenDisplay( display_name )
<a name="l00116"></a>00116 <span class="keywordflow">if</span> X11_display <span class="keywordflow">is</span> <span class="keywordtype">None</span>:
<a name="l00117"></a>00117 <span class="keywordflow">return</span> <span class="keyword">False</span>
<a name="l00118"></a>00118 <span class="keywordflow">else</span>:
<a name="l00119"></a>00119 _log_output(<span class="stringliteral">&#39;Opened display with name: &#39;</span> + display_name )
<a name="l00120"></a>00120 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00121"></a>00121
<a name="l00122"></a>00122 <span class="comment">## \brief Close a display currently in use by libcvautomation_funcs</span>
<a name="l00123"></a>00123 <span class="comment"># \details This closes the currently open display. All functions used after this will fail unless you open another display. Use \ref libcvautomation_funcs::open_display() to open the new display.</span>
<a name="l00124"></a>00124 <span class="comment"># \returns None</span>
<a name="l00125"></a><a class="code" href="namespacelibcvautomation__funcs.html#a1592c65a7ffc29016fd3ef1bb6178966">00125</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a1592c65a7ffc29016fd3ef1bb6178966" title="Close a display currently in use by libcvautomation_funcs.">close_display</a>():
<a name="l00126"></a>00126 <span class="keyword">global</span> X11_display
<a name="l00127"></a>00127 <span class="keywordflow">if</span> X11_display <span class="keywordflow">is</span> <span class="keywordtype">None</span>:
<a name="l00128"></a>00128 _log_output(<span class="stringliteral">&#39;Trying to close a display that has already been closed.&#39;</span> )
<a name="l00129"></a>00129 <span class="keywordflow">else</span>:
<a name="l00130"></a>00130 libcvautomation.cvaCloseDisplay( X11_display )
<a name="l00131"></a>00131 X11_display=<span class="keywordtype">None</span>
<a name="l00132"></a>00132
<a name="l00133"></a>00133
<a name="l00134"></a>00134 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00135"></a>00135 <span class="comment"># Set up the default values for libcv</span>
<a name="l00136"></a>00136 <span class="comment"># This way, we can edit the defaults for all functions very easily</span>
<a name="l00137"></a>00137 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00138"></a>00138
<a name="l00139"></a>00139 _search_method_default=0
<a name="l00140"></a>00140 _tolerance_default=2250000 <span class="comment">#Acceptable values are INT_MIN to INT_MAX</span>
<a name="l00141"></a>00141 _timeout_default=5
<a name="l00142"></a>00142 _mouse_button_default=1 <span class="comment">#Left click</span>
<a name="l00143"></a>00143 _libcvautomation_error_location = libcvautomation.cvaPoint
<a name="l00144"></a>00144 _libcvautomation_error_location.x = _libcvautomation_error_location.y = -1
<a name="l00145"></a>00145
<a name="l00146"></a>00146 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00147"></a>00147 <span class="comment"># Set up the exceptions we will be using later</span>
<a name="l00148"></a>00148 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00149"></a><a class="code" href="classlibcvautomation__funcs_1_1LibcvImageNotFound.html">00149</a> <span class="keyword">class </span><a class="code" href="classlibcvautomation__funcs_1_1LibcvImageNotFound.html">LibcvImageNotFound</a>(Exception):
<a name="l00150"></a>00150 <span class="keyword">def </span>__init__(self, value):
<a name="l00151"></a>00151 self.<a class="code" href="classlibcvautomation__funcs_1_1LibcvImageNotFound.html#ae2cb1c89c66bafa943908df8d488ff32">value</a> = value
<a name="l00152"></a>00152 <span class="keyword">def </span>__str__(self):
<a name="l00153"></a>00153 <span class="keywordflow">return</span> repr(<span class="stringliteral">&quot;Image not found: &quot;</span> + self.<a class="code" href="classlibcvautomation__funcs_1_1LibcvImageNotFound.html#ae2cb1c89c66bafa943908df8d488ff32">value</a>)
<a name="l00154"></a>00154
<a name="l00155"></a><a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">00155</a> <span class="keyword">class </span><a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>(Exception):
<a name="l00156"></a>00156 <span class="keyword">def </span>__init__(self, value):
<a name="l00157"></a>00157 self.<a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html#a9bf9490b48ae21c38f9a7c6f851fee6f">value</a> = value
<a name="l00158"></a>00158 <span class="keyword">def </span>__str__(self):
<a name="l00159"></a>00159 <span class="keywordflow">return</span> repr(<span class="stringliteral">&quot;Tried to use function &quot;</span> + self.<a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html#a9bf9490b48ae21c38f9a7c6f851fee6f">value</a> + <span class="stringliteral">&quot; without opening a display.&quot;</span>)
<a name="l00160"></a>00160
<a name="l00161"></a>00161 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00162"></a>00162 <span class="comment"># Begin the actual wrapper functions</span>
<a name="l00163"></a>00163 <span class="comment">#-------------------------------------------------------------------------------</span>
<a name="l00164"></a>00164
<a name="l00165"></a>00165 <span class="comment">## \brief Press a mouse button down</span>
<a name="l00166"></a>00166 <span class="comment"># \param mouse_button The number of the mouse button to press</span>
<a name="l00167"></a>00167 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00168"></a><a class="code" href="namespacelibcvautomation__funcs.html#a44d208a38c591e8b9eb5aff0051f4414">00168</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a44d208a38c591e8b9eb5aff0051f4414" title="Press a mouse button down.">mouse_down</a>( mouse_button = _mouse_button_default ):
<a name="l00169"></a>00169 <span class="keywordflow">if</span> _check_display():
<a name="l00170"></a>00170 _log_output( <span class="stringliteral">&#39;Mouse button down: &#39;</span> + mouse_button )
<a name="l00171"></a>00171 libcvautomation.xte_mouseDown( _get_display(), mouse_button )
<a name="l00172"></a>00172 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00173"></a>00173 <span class="keywordflow">else</span>:
<a name="l00174"></a>00174 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00175"></a>00175
<a name="l00176"></a>00176 <span class="comment">## \brief Release a mouse button</span>
<a name="l00177"></a>00177 <span class="comment"># \param mouse_button The number of the mouse button to release</span>
<a name="l00178"></a>00178 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00179"></a><a class="code" href="namespacelibcvautomation__funcs.html#a4046c72b33ac57e1d39431c9cc888d44">00179</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a4046c72b33ac57e1d39431c9cc888d44" title="Release a mouse button.">mouse_up</a>( mouse_button = _mouse_button_default ):
<a name="l00180"></a>00180 <span class="keywordflow">if</span> _check_display():
<a name="l00181"></a>00181 _log_output( <span class="stringliteral">&#39;Mouse button up: &#39;</span> + mouse_button )
<a name="l00182"></a>00182 libcvautomation.xte_mouseUp(_get_display(), mouse_button )
<a name="l00183"></a>00183
<a name="l00184"></a>00184 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00185"></a>00185 <span class="keywordflow">else</span>:
<a name="l00186"></a>00186 <span class="comment">#Display not open</span>
<a name="l00187"></a>00187 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00188"></a>00188
<a name="l00189"></a>00189 <span class="comment">## \brief Press and release a mouse button</span>
<a name="l00190"></a>00190 <span class="comment"># \param mouse_button The number of the mouse button to click</span>
<a name="l00191"></a>00191 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00192"></a><a class="code" href="namespacelibcvautomation__funcs.html#af4d9b2f324c23336b83399f7fd71852e">00192</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#af4d9b2f324c23336b83399f7fd71852e" title="Press and release a mouse button.">mouse_click</a>( mouse_button = _mouse_button_default ):
<a name="l00193"></a>00193 <span class="keywordflow">if</span> _check_display():
<a name="l00194"></a>00194 _log_output( <span class="stringliteral">&#39;Mouse button click: &#39;</span> + mouse_button )
<a name="l00195"></a>00195 libcvautomation.xte_clickMouse(_get_display(), mouse_button )
<a name="l00196"></a>00196 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00197"></a>00197 <span class="keywordflow">else</span>:
<a name="l00198"></a>00198 <span class="comment">#Display not open</span>
<a name="l00199"></a>00199 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00200"></a>00200
<a name="l00201"></a>00201 <span class="comment">## \brief Click a mouse button at an absolute location</span>
<a name="l00202"></a>00202 <span class="comment"># \details Move the mouse to a location given by an x and y coordinate before clicking</span>
<a name="l00203"></a>00203 <span class="comment"># \param x_coord The X-coordinate to move the mouse to</span>
<a name="l00204"></a>00204 <span class="comment"># \param y_coord The Y-coordinate to move the mouse to</span>
<a name="l00205"></a>00205 <span class="comment"># \param mouse_button The mouse button to click after moving</span>
<a name="l00206"></a>00206 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00207"></a><a class="code" href="namespacelibcvautomation__funcs.html#ab98166fb3931d7cd7fbbad6a0986d46b">00207</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#ab98166fb3931d7cd7fbbad6a0986d46b" title="Click a mouse button at an absolute location.">mouse_click_xy</a>( x_coord, y_coord, mouse_button = _mouse_button_default ):
<a name="l00208"></a>00208 <span class="keywordflow">if</span> _check_display():
<a name="l00209"></a>00209 _log_output( <span class="stringliteral">&#39;Mouse button xy click: x=&#39;</span> + str(x_coord) + <span class="stringliteral">&#39; y=&#39;</span> + str(y_coord) + <span class="stringliteral">&#39; mouse_button=&#39;</span> + mouse_button )
<a name="l00210"></a>00210 current_location = libcvautomation.xte_mouseLocation(_get_display() )
<a name="l00211"></a>00211 x_increment = x_coord - current_location.x
<a name="l00212"></a>00212 y_increment = y_coord - current_location.y
<a name="l00213"></a>00213
<a name="l00214"></a>00214 libcvautomation.xte_hoverMouseRXY(_get_display(), x_increment, y_increment )
<a name="l00215"></a>00215 libcvautomation.xte_clickMouse(_get_display(), mouse_button )
<a name="l00216"></a>00216
<a name="l00217"></a>00217 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00218"></a>00218 <span class="keywordflow">else</span>:
<a name="l00219"></a>00219 <span class="comment">#Display not open</span>
<a name="l00220"></a>00220 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00221"></a>00221
<a name="l00222"></a>00222 <span class="comment">## \brief Click a mouse button at a relative location</span>
<a name="l00223"></a>00223 <span class="comment"># \details Move the mouse horizontally and vertically by an increment, and then click the mouse</span>
<a name="l00224"></a>00224 <span class="comment"># \param x_inc The increment to move the mouse horizontally</span>
<a name="l00225"></a>00225 <span class="comment"># \note A positive increment moves the mouse right, a negative increment moves the mouse left</span>
<a name="l00226"></a>00226 <span class="comment"># \param y_inc The increment to move the mouse vertically</span>
<a name="l00227"></a>00227 <span class="comment"># \note A positive increment moves the mouse down, a negative increment moves the mouse up</span>
<a name="l00228"></a>00228 <span class="comment"># \param mouse_button The mouse button to click after moving</span>
<a name="l00229"></a>00229 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00230"></a><a class="code" href="namespacelibcvautomation__funcs.html#a633ee669989a44fa6f23fdbd9881a39e">00230</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a633ee669989a44fa6f23fdbd9881a39e" title="Click a mouse button at a relative location.">mouse_click_rxy</a>( x_inc, y_inc, mouse_button = _mouse_button_default ):
<a name="l00231"></a>00231 <span class="keywordflow">if</span> _check_display():
<a name="l00232"></a>00232 _log_output( <span class="stringliteral">&#39;Mouse button rxy click: x=&#39;</span> + str(x_inc) + <span class="stringliteral">&#39; y=&#39;</span> + str(y_inc) + <span class="stringliteral">&#39; mouse_button=&#39;</span> + mouse_button )
<a name="l00233"></a>00233 libcvautomation.xte_hoverMouseRXY(_get_display(), x_inc, y_inc )
<a name="l00234"></a>00234 libcvautomation.xte_clickMouse(_get_display(), mouse_button )
<a name="l00235"></a>00235
<a name="l00236"></a>00236 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00237"></a>00237 <span class="keywordflow">else</span>:
<a name="l00238"></a>00238 <span class="comment">#Display not open</span>
<a name="l00239"></a>00239 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00240"></a>00240
<a name="l00241"></a>00241 <span class="comment">## \brief Click a mouse button on an image inside the root X11 window</span>
<a name="l00242"></a>00242 <span class="comment"># \details For each image in \c image_names, search for it inside the root X11 window. Return once a match has been found, or the timeout value has been exceeded</span>
<a name="l00243"></a>00243 <span class="comment"># \param image_names List of image names to search for</span>
<a name="l00244"></a>00244 <span class="comment"># \param search_method The search method to use when finding each \c image. See \ref libcvautomation_search_methods for more information on how to use the search methods.</span>
<a name="l00245"></a>00245 <span class="comment"># \param tolerance The tolerance to use when finding each \c image. See \ref libcvautomation_search_methods for more information on how to use tolerance.</span>
<a name="l00246"></a>00246 <span class="comment"># \param timeout Wait for \c timeout seconds before giving up the search for \c image_names in the root X11 window.</span>
<a name="l00247"></a>00247 <span class="comment"># \note \c use_wait must be set to \c True for this parameter to have any effect</span>
<a name="l00248"></a>00248 <span class="comment"># \param mouse_button The mouse button to click after finding an image</span>
<a name="l00249"></a>00249 <span class="comment"># \param use_wait Set to \c True to make this function wait \c timeout seconds before giving up finding an image.</span>
<a name="l00250"></a>00250 <span class="comment"># \note If set to \c False, this function will go through the list of \c image_names once before giving up.</span>
<a name="l00251"></a>00251 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution or there were no images found, and \c True otherwise</span>
<a name="l00252"></a><a class="code" href="namespacelibcvautomation__funcs.html#a1a05342b0159044fae6bdb9969d488d6">00252</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a1a05342b0159044fae6bdb9969d488d6" title="Click a mouse button on an image inside the root X11 window.">mouse_click_image</a>( image_names, search_method = _search_method_default,
<a name="l00253"></a>00253 tolerance = _tolerance_default, timeout = _timeout_default,
<a name="l00254"></a>00254 mouse_button = _mouse_button_default, use_wait = <span class="keyword">True</span>):
<a name="l00255"></a>00255 <span class="keywordflow">if</span> _check_display():
<a name="l00256"></a>00256 _log_output( <span class="stringliteral">&#39;Mouse button click on image: Images=&#39;</span> + image_names +
<a name="l00257"></a>00257 <span class="stringliteral">&#39; search_method=&#39;</span> + search_method + <span class="stringliteral">&#39; tolerance=&#39;</span> + tolerance +
<a name="l00258"></a>00258 <span class="stringliteral">&#39; timeout=&#39;</span> + _timeout_default + <span class="stringliteral">&#39; mouse_button=&#39;</span> +
<a name="l00259"></a>00259 <span class="stringliteral">&#39; use_wait=&#39;</span> + use_wait + <span class="stringliteral">&#39; use_center=&#39;</span> + use_center)
<a name="l00260"></a>00260
<a name="l00261"></a>00261 <span class="keywordflow">if</span> use_wait:
<a name="l00262"></a>00262 <span class="comment">#Loop through all images &#39;timeout&#39; times, and click on the first match</span>
<a name="l00263"></a>00263 loop_check = 0
<a name="l00264"></a>00264 <span class="keywordflow">while</span> loop_check &lt; timeout:
<a name="l00265"></a>00265 <span class="keywordflow">for</span> image <span class="keywordflow">in</span> image_names:
<a name="l00266"></a>00266 <span class="keywordflow">if</span> use_center:
<a name="l00267"></a>00267 image_location = libcvautomation.xte_clickMouseImage_location_center(_get_display(),
<a name="l00268"></a>00268 image, mouse_button, search_method, tolerance )
<a name="l00269"></a>00269 <span class="keywordflow">else</span>:
<a name="l00270"></a>00270 image_location = libcvautomation.xte_clickMouseImage_location(_get_display(),
<a name="l00271"></a>00271 image, mouse_button, search_method, tolerance )
<a name="l00272"></a>00272
<a name="l00273"></a>00273 <span class="keywordflow">if</span> image_location != _libcvautomation_error_location:
<a name="l00274"></a>00274 <span class="comment">#We&#39;ve found our image, break out of the for loop and while loop</span>
<a name="l00275"></a>00275 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00276"></a>00276
<a name="l00277"></a>00277 loop_check += 1
<a name="l00278"></a>00278 <span class="keywordflow">else</span>:
<a name="l00279"></a>00279 <span class="comment">#Just cycle through the images once</span>
<a name="l00280"></a>00280 <span class="keywordflow">for</span> image <span class="keywordflow">in</span> image_names:
<a name="l00281"></a>00281 <span class="keywordflow">if</span> use_center:
<a name="l00282"></a>00282 image_location = libcvautomation.xte_clickMouseImage_location_center(_get_display(),
<a name="l00283"></a>00283 image, mouse_button, search_method, tolerance )
<a name="l00284"></a>00284 <span class="keywordflow">else</span>:
<a name="l00285"></a>00285 image_location = libcvautomation.xte_clickMouseImage_location(_get_display(),
<a name="l00286"></a>00286 image, mouse_button, search_method, tolerance )
<a name="l00287"></a>00287
<a name="l00288"></a>00288 <span class="keywordflow">if</span> image_location != _libcvautomation_error_location:
<a name="l00289"></a>00289 <span class="comment">#We&#39;ve found our image, break out of the for loop</span>
<a name="l00290"></a>00290 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00291"></a>00291
<a name="l00292"></a>00292 <span class="comment">#No image was found</span>
<a name="l00293"></a>00293 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvImageNotFound.html">LibcvImageNotFound</a>( image_names )
<a name="l00294"></a>00294 <span class="keywordflow">else</span>:
<a name="l00295"></a>00295 <span class="comment">#Display not open</span>
<a name="l00296"></a>00296 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00297"></a>00297
<a name="l00298"></a>00298
<a name="l00299"></a>00299 <span class="comment">## \brief Press and release a mouse button twice</span>
<a name="l00300"></a>00300 <span class="comment"># \param mouse_button The number of the mouse button to click twice</span>
<a name="l00301"></a>00301 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00302"></a><a class="code" href="namespacelibcvautomation__funcs.html#a65604797ddffcbbfc2efcb470a54a353">00302</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a65604797ddffcbbfc2efcb470a54a353" title="Press and release a mouse button twice.">mouse_doubleclick</a>( mouse_button = _mouse_button_default ):
<a name="l00303"></a>00303 <span class="keywordflow">if</span> _check_display():
<a name="l00304"></a>00304 _log_output( <span class="stringliteral">&#39;Mouse button doubleclick: &#39;</span> + mouse_button )
<a name="l00305"></a>00305 libcvautomation.xte_clickMouse(_get_display(), mouse_button )
<a name="l00306"></a>00306
<a name="l00307"></a>00307 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00308"></a>00308 <span class="keywordflow">else</span>:
<a name="l00309"></a>00309 <span class="comment">#Display not open</span>
<a name="l00310"></a>00310 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00311"></a>00311
<a name="l00312"></a>00312
<a name="l00313"></a>00313 <span class="comment">## \brief Click a mouse button twice at an absolute location</span>
<a name="l00314"></a>00314 <span class="comment"># \details Move the mouse to a location given by an x and y coordinate before clicking twice</span>
<a name="l00315"></a>00315 <span class="comment"># \param x_coord The X-coordinate to move the mouse to</span>
<a name="l00316"></a>00316 <span class="comment"># \param y_coord The Y-coordinate to move the mouse to</span>
<a name="l00317"></a>00317 <span class="comment"># \param mouse_button The mouse button to click after moving</span>
<a name="l00318"></a>00318 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00319"></a><a class="code" href="namespacelibcvautomation__funcs.html#aa15713c985a8799f4866bd13acfa2e17">00319</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#aa15713c985a8799f4866bd13acfa2e17" title="Click a mouse button twice at an absolute location.">mouse_doubleclick_xy</a>( x_coord, y_coord, mouse_button = _mouse_button_default ):
<a name="l00320"></a>00320 <span class="keywordflow">if</span> _check_display():
<a name="l00321"></a>00321 _log_output( <span class="stringliteral">&#39;Mouse button xy doubleclick: x=&#39;</span> + str(x_coord) + <span class="stringliteral">&#39; y=&#39;</span> + str(y_coord) + <span class="stringliteral">&#39; mouse_button=&#39;</span> + mouse_button )
<a name="l00322"></a>00322 current_location = libcvautomation.xte_mouseLocation(_get_display() )
<a name="l00323"></a>00323 x_increment = x_coord - current_location.x
<a name="l00324"></a>00324 y_increment = y_coord - current_location.y
<a name="l00325"></a>00325
<a name="l00326"></a>00326 libcvautomation.xte_hoverMouseRXY(_get_display(), x_increment, y_increment )
<a name="l00327"></a>00327 libcvautomation.xte_clickMouse(_get_display(), mouse_button )
<a name="l00328"></a>00328 libcvautomation.xte_clickMouse(_get_display(), mouse_button )
<a name="l00329"></a>00329
<a name="l00330"></a>00330 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00331"></a>00331 <span class="keywordflow">else</span>:
<a name="l00332"></a>00332 <span class="comment">#Display not open</span>
<a name="l00333"></a>00333 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00334"></a>00334
<a name="l00335"></a>00335 <span class="comment">## \brief Click a mouse button twice at a relative location</span>
<a name="l00336"></a>00336 <span class="comment"># \details Move the mouse horizontally and vertically by an increment, and then click the mouse twice</span>
<a name="l00337"></a>00337 <span class="comment"># \param x_inc The increment to move the mouse horizontally</span>
<a name="l00338"></a>00338 <span class="comment"># \note A positive increment moves the mouse right, a negative increment moves the mouse left</span>
<a name="l00339"></a>00339 <span class="comment"># \param y_inc The increment to move the mouse vertically</span>
<a name="l00340"></a>00340 <span class="comment"># \note A positive increment moves the mouse down, a negative increment moves the mouse up</span>
<a name="l00341"></a>00341 <span class="comment"># \param mouse_button The mouse button to click after moving</span>
<a name="l00342"></a>00342 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00343"></a><a class="code" href="namespacelibcvautomation__funcs.html#abca5903b1e4208d1c019272f2e05ebdc">00343</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#abca5903b1e4208d1c019272f2e05ebdc" title="Click a mouse button twice at a relative location.">mouse_doubleclick_rxy</a>( x_inc, y_inc, mouse_button = _mouse_button_default ):
<a name="l00344"></a>00344 <span class="keywordflow">if</span> _check_display():
<a name="l00345"></a>00345 _log_output( <span class="stringliteral">&#39;Mouse button relative xy doubleclick: x=&#39;</span> + str(x_inc) + <span class="stringliteral">&#39; y=&#39;</span> + str(y_inc) + <span class="stringliteral">&#39; mouse_button=&#39;</span> + mouse_button )
<a name="l00346"></a>00346 libcvautomation.xte_hoverMouseRXY(_get_display(), x_inc, y_inc )
<a name="l00347"></a>00347 libcvautomation.xte_clickMouse(_get_display(), mouse_button )
<a name="l00348"></a>00348 libcvautomation.xte_clickMouse(_get_display(), mouse_button )
<a name="l00349"></a>00349
<a name="l00350"></a>00350 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00351"></a>00351 <span class="keywordflow">else</span>:
<a name="l00352"></a>00352 <span class="comment">#Display not open</span>
<a name="l00353"></a>00353 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00354"></a>00354
<a name="l00355"></a>00355 <span class="comment">## \brief Click a mouse button twice on an image inside the root X11 window</span>
<a name="l00356"></a>00356 <span class="comment"># \details For each image in \c image_names, search for it inside the root X11 window. Return once a match has been found, or the timeout value has been exceeded</span>
<a name="l00357"></a>00357 <span class="comment"># \param image_names List of image names to search for</span>
<a name="l00358"></a>00358 <span class="comment"># \param search_method The search method to use when finding each \c image. See \ref libcvautomation_search_methods for more information on how to use the search methods.</span>
<a name="l00359"></a>00359 <span class="comment"># \param tolerance The tolerance to use when finding each \c image. See \ref libcvautomation_search_methods for more information on how to use tolerance.</span>
<a name="l00360"></a>00360 <span class="comment"># \param timeout Wait for \c timeout seconds before giving up the search for \c image_names in the root X11 window.</span>
<a name="l00361"></a>00361 <span class="comment"># \note \c use_wait must be set to \c True for this parameter to have any effect</span>
<a name="l00362"></a>00362 <span class="comment"># \param mouse_button The mouse button to click after finding an image</span>
<a name="l00363"></a>00363 <span class="comment"># \param use_wait Set to \c True to make this function wait \c timeout seconds before giving up finding an image.</span>
<a name="l00364"></a>00364 <span class="comment"># \param use_center Set to \c True to make this function return the center coordinate of the matched image. Setting to \c False will use the top-left corner.</span>
<a name="l00365"></a>00365 <span class="comment"># \note If set to \c False, this function will go through the list of \c image_names once before giving up.</span>
<a name="l00366"></a>00366 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution or no images were found, and \c True otherwise</span>
<a name="l00367"></a><a class="code" href="namespacelibcvautomation__funcs.html#ad54f021aae633baac7ae0d3394c54262">00367</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#ad54f021aae633baac7ae0d3394c54262" title="Click a mouse button twice on an image inside the root X11 window.">mouse_doubleclick_image</a>( image_names, search_method = _search_method_default,
<a name="l00368"></a>00368 tolerance = _tolerance_default, timeout = _timeout_default,
<a name="l00369"></a>00369 mouse_button = _mouse_button_default, use_wait = <span class="keyword">True</span>,
<a name="l00370"></a>00370 use_center = <span class="keyword">True</span> ):
<a name="l00371"></a>00371 <span class="keywordflow">if</span> _check_display():
<a name="l00372"></a>00372 _log_output( <span class="stringliteral">&#39;Mouse button doubleclick on image: Images=&#39;</span> + image_names +
<a name="l00373"></a>00373 <span class="stringliteral">&#39; search_method=&#39;</span> + search_method + <span class="stringliteral">&#39; tolerance=&#39;</span> + tolerance +
<a name="l00374"></a>00374 <span class="stringliteral">&#39; timeout=&#39;</span> + _timeout_default + <span class="stringliteral">&#39; mouse_button=&#39;</span> +
<a name="l00375"></a>00375 <span class="stringliteral">&#39; use_wait=&#39;</span> + use_wait + <span class="stringliteral">&#39; use_center=&#39;</span> + use_center)
<a name="l00376"></a>00376
<a name="l00377"></a>00377 <span class="keywordflow">if</span> use_wait:
<a name="l00378"></a>00378 <span class="comment">#Loop through all images &#39;timeout&#39; times, and click on the first match</span>
<a name="l00379"></a>00379 loop_check = 0
<a name="l00380"></a>00380 <span class="keywordflow">while</span> loop_check &lt; timeout:
<a name="l00381"></a>00381 <span class="keywordflow">for</span> image <span class="keywordflow">in</span> image_names:
<a name="l00382"></a>00382 <span class="keywordflow">if</span> use_center:
<a name="l00383"></a>00383 image_location = libcvautomation.xte_clickMouseImage_location_center(_get_display(),
<a name="l00384"></a>00384 image, mouse_button, search_method, tolerance )
<a name="l00385"></a>00385 <span class="keywordflow">else</span>:
<a name="l00386"></a>00386 image_location = libcvautomation.xte_clickMouseImage_location(_get_display(),
<a name="l00387"></a>00387 image, mouse_button, search_method, tolerance )
<a name="l00388"></a>00388
<a name="l00389"></a>00389 <span class="keywordflow">if</span> image_location != _libcvautomation_error_location:
<a name="l00390"></a>00390 <span class="comment">#Make sure to click twice once we&#39;ve found the image</span>
<a name="l00391"></a>00391 <span class="comment">#Technically assumes that the system mouse timeout is less than</span>
<a name="l00392"></a>00392 <span class="comment">#the time it takes to do two boolean compares - I think this is pretty safe</span>
<a name="l00393"></a>00393 libcvautomation.xte_clickMouse(_get_display(), mouse_button )
<a name="l00394"></a>00394 <span class="comment">#We&#39;ve found our image, break out of the for loop and while loop</span>
<a name="l00395"></a>00395 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00396"></a>00396
<a name="l00397"></a>00397 loop_check += 1
<a name="l00398"></a>00398 <span class="keywordflow">else</span>:
<a name="l00399"></a>00399 <span class="comment">#Just cycle through the images once</span>
<a name="l00400"></a>00400 <span class="keywordflow">for</span> image <span class="keywordflow">in</span> image_names:
<a name="l00401"></a>00401 <span class="keywordflow">if</span> use_center:
<a name="l00402"></a>00402 image_location = libcvautomation.xte_clickMouseImage_location_center(_get_display(),
<a name="l00403"></a>00403 image, mouse_button, search_method, tolerance )
<a name="l00404"></a>00404 <span class="keywordflow">else</span>:
<a name="l00405"></a>00405 image_location = libcvautomation.xte_clickMouseImage_location(_get_display(),
<a name="l00406"></a>00406 image, mouse_button, search_method, tolerance )
<a name="l00407"></a>00407
<a name="l00408"></a>00408 <span class="keywordflow">if</span> image_location != _libcvautomation_error_location:
<a name="l00409"></a>00409 <span class="comment">#We&#39;ve found our image, break out of the for loop</span>
<a name="l00410"></a>00410 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00411"></a>00411 <span class="comment">#No image found</span>
<a name="l00412"></a>00412 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvImageNotFound.html">LibcvImageNotFound</a>( image_names )
<a name="l00413"></a>00413 <span class="keywordflow">else</span>:
<a name="l00414"></a>00414 <span class="comment">#Display not open</span>
<a name="l00415"></a>00415 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00416"></a>00416
<a name="l00417"></a>00417 <span class="comment">## \brief Move the mouse to a given coordinate, and leave it there</span>
<a name="l00418"></a>00418 <span class="comment"># \param x_coord The X-coordinate to move the mouse to</span>
<a name="l00419"></a>00419 <span class="comment"># \param y_coord The Y-coordinate to move the mouse to</span>
<a name="l00420"></a>00420 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00421"></a><a class="code" href="namespacelibcvautomation__funcs.html#a6585a90832b64e0b75669d458576a98f">00421</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a6585a90832b64e0b75669d458576a98f" title="Move the mouse to a given coordinate, and leave it there.">mouse_hover_xy</a>( x_coord, y_coord ):
<a name="l00422"></a>00422 <span class="keywordflow">if</span> _check_display():
<a name="l00423"></a>00423 _log_output( <span class="stringliteral">&#39;Mouse button hover xy: x=&#39;</span> + str(x_coord) + <span class="stringliteral">&#39; y=&#39;</span> + str(y_coord) + <span class="stringliteral">&#39; mouse_button=&#39;</span> + mouse_button )
<a name="l00424"></a>00424 current_location = libcvautomation.xte_mouseLocation(_get_display() )
<a name="l00425"></a>00425 x_increment = x_coord - current_location.x
<a name="l00426"></a>00426 y_increment = y_coord - current_location.y
<a name="l00427"></a>00427
<a name="l00428"></a>00428 libcvautomation.xte_hoverMouseRXY(_get_display(), x_increment, y_increment )
<a name="l00429"></a>00429
<a name="l00430"></a>00430 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00431"></a>00431 <span class="keywordflow">else</span>:
<a name="l00432"></a>00432 <span class="comment">#Display not open</span>
<a name="l00433"></a>00433 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00434"></a>00434
<a name="l00435"></a>00435 <span class="comment">## \brief Move the mouse by a given increment, and leave it there</span>
<a name="l00436"></a>00436 <span class="comment"># \param x_inc The increment to move the mouse horizontally</span>
<a name="l00437"></a>00437 <span class="comment"># \note A positive increment moves the mouse right, a negative increment moves the mouse left</span>
<a name="l00438"></a>00438 <span class="comment"># \param y_inc The increment to move the mouse vertically</span>
<a name="l00439"></a>00439 <span class="comment"># \note A positive increment moves the mouse down, a negative increment moves the mouse up</span>
<a name="l00440"></a>00440 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00441"></a><a class="code" href="namespacelibcvautomation__funcs.html#a28bf60ba05cbec59985f9655d70ee583">00441</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a28bf60ba05cbec59985f9655d70ee583" title="Move the mouse by a given increment, and leave it there.">mouse_hover_rxy</a>( x_inc, y_inc ):
<a name="l00442"></a>00442 <span class="keywordflow">if</span> _check_display():
<a name="l00443"></a>00443 _log_output( <span class="stringliteral">&#39;Mouse button hover relative xy: x=&#39;</span> + str(x_inc) + <span class="stringliteral">&#39; y=&#39;</span> + str(y_inc) )
<a name="l00444"></a>00444 libcvautomation.xte_hoverMouseRXY(_get_display(), x_inc, y_inc )
<a name="l00445"></a>00445
<a name="l00446"></a>00446 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00447"></a>00447 <span class="keywordflow">else</span>:
<a name="l00448"></a>00448 <span class="comment">#Display not open</span>
<a name="l00449"></a>00449 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00450"></a>00450
<a name="l00451"></a>00451 <span class="comment">## \brief Move the mouse to an image inside the root X11 window</span>
<a name="l00452"></a>00452 <span class="comment"># \details For each image in \c image_names, search for it inside the root X11 window. Return once a match has been found, or the timeout value has been exceeded</span>
<a name="l00453"></a>00453 <span class="comment"># \param image_names List of image names to search for</span>
<a name="l00454"></a>00454 <span class="comment"># \param search_method The search method to use when finding each \c image. See \ref libcvautomation_search_methods for more information on how to use the search methods.</span>
<a name="l00455"></a>00455 <span class="comment"># \param tolerance The tolerance to use when finding each \c image. See \ref libcvautomation_search_methods for more information on how to use tolerance.</span>
<a name="l00456"></a>00456 <span class="comment"># \param timeout Wait for \c timeout seconds before giving up the search for \c image_names in the root X11 window.</span>
<a name="l00457"></a>00457 <span class="comment"># \note \c use_wait must be set to \c True for this parameter to have any effect</span>
<a name="l00458"></a>00458 <span class="comment"># \param use_wait Set to \c True to make this function wait \c timeout seconds before giving up finding an image.</span>
<a name="l00459"></a>00459 <span class="comment"># \note If set to \c False, this function will go through the list of \c image_names once before giving up.</span>
<a name="l00460"></a>00460 <span class="comment"># \param use_center Set to \c True to make this function return the center coordinate of the matched image. Setting to \c False will use the top-left corner.</span>
<a name="l00461"></a>00461 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution or no images were found, and \c True otherwise</span>
<a name="l00462"></a><a class="code" href="namespacelibcvautomation__funcs.html#ac952f6f97c0bc2acdf1ad5b4d1d5acc1">00462</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#ac952f6f97c0bc2acdf1ad5b4d1d5acc1" title="Move the mouse to an image inside the root X11 window.">mouse_hover_image</a>( image_names, search_method = _search_method_default,
<a name="l00463"></a>00463 tolerance = _tolerance_default, timeout = _timeout_default,
<a name="l00464"></a>00464 use_wait = <span class="keyword">True</span>, use_center = <span class="keyword">True</span> ):
<a name="l00465"></a>00465 <span class="keywordflow">if</span> _check_display():
<a name="l00466"></a>00466 _log_output( <span class="stringliteral">&#39;Mouse button click on image: Images=&#39;</span> + image_names +
<a name="l00467"></a>00467 <span class="stringliteral">&#39; search_method=&#39;</span> + search_method + <span class="stringliteral">&#39; tolerance=&#39;</span> + tolerance +
<a name="l00468"></a>00468 <span class="stringliteral">&#39; timeout=&#39;</span> + _timeout_default + <span class="stringliteral">&#39; use_wait=&#39;</span> + use_wait +
<a name="l00469"></a>00469 <span class="stringliteral">&#39; use_center=&#39;</span> + use_center)
<a name="l00470"></a>00470
<a name="l00471"></a>00471 <span class="keywordflow">if</span> use_wait:
<a name="l00472"></a>00472 <span class="comment">#Loop through all images &#39;timeout&#39; times, and click on the first match</span>
<a name="l00473"></a>00473 loop_check = 0
<a name="l00474"></a>00474 <span class="keywordflow">while</span> loop_check &lt; timeout:
<a name="l00475"></a>00475 <span class="keywordflow">for</span> image <span class="keywordflow">in</span> image_names:
<a name="l00476"></a>00476 <span class="keywordflow">if</span> use_center:
<a name="l00477"></a>00477 image_location = libcvautomation.xte_hoverMouseImage_location_center(_get_display(),
<a name="l00478"></a>00478 image, mouse_button, search_method, tolerance )
<a name="l00479"></a>00479 <span class="keywordflow">else</span>:
<a name="l00480"></a>00480 image_location = libcvautomation.xte_hoverMouseImage_location(_get_display(),
<a name="l00481"></a>00481 image, mouse_button, search_method, tolerance )
<a name="l00482"></a>00482
<a name="l00483"></a>00483 <span class="keywordflow">if</span> image_location != _libcvautomation_error_location:
<a name="l00484"></a>00484 <span class="comment">#We&#39;ve found our image, break out of the for loop and while loop</span>
<a name="l00485"></a>00485 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00486"></a>00486
<a name="l00487"></a>00487 loop_check += 1
<a name="l00488"></a>00488 <span class="keywordflow">else</span>:
<a name="l00489"></a>00489 <span class="comment">#Just cycle through the images once</span>
<a name="l00490"></a>00490 <span class="keywordflow">for</span> image <span class="keywordflow">in</span> image_names:
<a name="l00491"></a>00491 <span class="keywordflow">if</span> use_center:
<a name="l00492"></a>00492 image_location = libcvautomation.xte_hoverMouseImage_location_center(_get_display(),
<a name="l00493"></a>00493 image, mouse_button, search_method, tolerance )
<a name="l00494"></a>00494 <span class="keywordflow">else</span>:
<a name="l00495"></a>00495 image_location = libcvautomation.xte_hoverMouseImage_location(_get_display(),
<a name="l00496"></a>00496 image, mouse_button, search_method, tolerance )
<a name="l00497"></a>00497
<a name="l00498"></a>00498 <span class="keywordflow">if</span> image_location != _libcvautomation_error_location:
<a name="l00499"></a>00499 <span class="comment">#We&#39;ve found our image, break out of the for loop</span>
<a name="l00500"></a>00500 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00501"></a>00501
<a name="l00502"></a>00502 <span class="comment">#No images were found</span>
<a name="l00503"></a>00503 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvImageNotFound.html">LibcvImageNotFound</a>( image_names )
<a name="l00504"></a>00504 <span class="keywordflow">else</span>:
<a name="l00505"></a>00505 <span class="comment">#Display not open or no image found</span>
<a name="l00506"></a>00506 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00507"></a>00507
<a name="l00508"></a>00508 <span class="comment">## \brief Jiggle the mouse in place</span>
<a name="l00509"></a>00509 <span class="comment"># \details Move the mouse right and down 1 pixel, and back. Useful for activating menu entries, etc.</span>
<a name="l00510"></a>00510 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00511"></a><a class="code" href="namespacelibcvautomation__funcs.html#a7c2ecbf863dcd5e4af933f38752e81e5">00511</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a7c2ecbf863dcd5e4af933f38752e81e5" title="Jiggle the mouse in place.">mouse_jiggle</a>():
<a name="l00512"></a>00512 <span class="stringliteral">&quot;&quot;&quot;Jiggle the mouse in place&quot;&quot;&quot;</span>
<a name="l00513"></a>00513 <span class="keywordflow">if</span> _check_display():
<a name="l00514"></a>00514 _log_output( <span class="stringliteral">&#39;Mouse button jiggle&#39;</span> )
<a name="l00515"></a>00515 libcvautomation.xte_mouseJiggle(_get_display() )
<a name="l00516"></a>00516 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00517"></a>00517 <span class="keywordflow">else</span>:
<a name="l00518"></a>00518 <span class="comment">#Display not open</span>
<a name="l00519"></a>00519 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00520"></a>00520
<a name="l00521"></a>00521 <span class="comment">## \brief Scroll the mouse wheel up</span>
<a name="l00522"></a>00522 <span class="comment"># \details This is the same as pressing mouse button 4</span>
<a name="l00523"></a>00523 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00524"></a><a class="code" href="namespacelibcvautomation__funcs.html#a47b44363958312c387e135e9ae484dc0">00524</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a47b44363958312c387e135e9ae484dc0" title="Scroll the mouse wheel up.">mouse_scroll_up</a>():
<a name="l00525"></a>00525 <span class="keywordflow">if</span> _check_display():
<a name="l00526"></a>00526 _log_output( <span class="stringliteral">&#39;Mouse scroll up&#39;</span> )
<a name="l00527"></a>00527 libcvautomation.xte_mouseScrollUp(_get_display() )
<a name="l00528"></a>00528 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00529"></a>00529 <span class="keywordflow">else</span>:
<a name="l00530"></a>00530 <span class="comment">#Display not open</span>
<a name="l00531"></a>00531 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00532"></a>00532
<a name="l00533"></a>00533 <span class="comment">## \brief Scroll the mouse wheel down</span>
<a name="l00534"></a>00534 <span class="comment"># \details This is the same as pressing mouse button 5</span>
<a name="l00535"></a>00535 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00536"></a><a class="code" href="namespacelibcvautomation__funcs.html#aef8e77ffd828b6803a918cc061d0b92b">00536</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#aef8e77ffd828b6803a918cc061d0b92b" title="Scroll the mouse wheel down.">mouse_scroll_down</a>():
<a name="l00537"></a>00537 <span class="keywordflow">if</span> _check_display():
<a name="l00538"></a>00538 _log_output( <span class="stringliteral">&#39;Mouse scroll down&#39;</span> )
<a name="l00539"></a>00539 libcvautomation.xte_mouseScrollDown(_get_display() )
<a name="l00540"></a>00540 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00541"></a>00541 <span class="keywordflow">else</span>:
<a name="l00542"></a>00542 <span class="comment">#Display not open</span>
<a name="l00543"></a>00543 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00544"></a>00544
<a name="l00545"></a>00545 <span class="comment">## \brief Drag and drop one image to another</span>
<a name="l00546"></a>00546 <span class="comment"># \param drag_image The image to drag from</span>
<a name="l00547"></a>00547 <span class="comment"># \param drag_to The image giving the location to drag to</span>
<a name="l00548"></a>00548 <span class="comment"># \param use_center Drag and drop the image using the center of the image as the location where the mouse will click and drag to</span>
<a name="l00549"></a>00549 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution or an image was not found, and \c True otherwise</span>
<a name="l00550"></a><a class="code" href="namespacelibcvautomation__funcs.html#af3b5f4b294fd2f429e70de18848e1ea8">00550</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#af3b5f4b294fd2f429e70de18848e1ea8" title="Drag and drop one image to another.">mouse_drag_n_drop</a>( drag_image, drag_to, use_center = True ):
<a name="l00551"></a>00551 <span class="keywordflow">if</span> _check_display():
<a name="l00552"></a>00552 _log_output( <span class="stringliteral">&#39;Mouse drag and drop: dragging from=&#39;</span> + drag_image +
<a name="l00553"></a>00553 <span class="stringliteral">&#39; dragging to=&#39;</span> + drag_to )
<a name="l00554"></a>00554 successful_hover = <a class="code" href="namespacelibcvautomation__funcs.html#ac952f6f97c0bc2acdf1ad5b4d1d5acc1" title="Move the mouse to an image inside the root X11 window.">mouse_hover_image</a>( drag_image, use_center=use_center )
<a name="l00555"></a>00555 <span class="keywordflow">if</span> successful_hover:
<a name="l00556"></a>00556 <a class="code" href="namespacelibcvautomation__funcs.html#a44d208a38c591e8b9eb5aff0051f4414" title="Press a mouse button down.">mouse_down</a>( mouse_button=1 )
<a name="l00557"></a>00557 successful_hover = <a class="code" href="namespacelibcvautomation__funcs.html#ac952f6f97c0bc2acdf1ad5b4d1d5acc1" title="Move the mouse to an image inside the root X11 window.">mouse_hover_image</a>( drag_to )
<a name="l00558"></a>00558 <a class="code" href="namespacelibcvautomation__funcs.html#a4046c72b33ac57e1d39431c9cc888d44" title="Release a mouse button.">mouse_up</a>( mouse_button=1 )
<a name="l00559"></a>00559 <span class="keywordflow">else</span>:
<a name="l00560"></a>00560 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvImageNotFound.html">LibcvImageNotFound</a>( drag_image )
<a name="l00561"></a>00561
<a name="l00562"></a>00562 <span class="comment">#Return True if both hovers are successful, raise an exception otherwise</span>
<a name="l00563"></a>00563 <span class="keywordflow">if</span> successful_hover:
<a name="l00564"></a>00564 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00565"></a>00565 <span class="keywordflow">else</span>:
<a name="l00566"></a>00566 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvImageNotFound.html">LibcvImageNotFound</a>( drag_to )
<a name="l00567"></a>00567 <span class="keywordflow">else</span>:
<a name="l00568"></a>00568 <span class="comment">#Display not open</span>
<a name="l00569"></a>00569 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00570"></a>00570
<a name="l00571"></a>00571 <span class="comment">## \brief Get the current location of the mouse</span>
<a name="l00572"></a>00572 <span class="comment"># \details This function will return the current location of the mouse as two variables - i.e. `x, y = mouse_location()`. This is a Python-specific function.</span>
<a name="l00573"></a>00573 <span class="comment"># \returns Two variables for the \c x and \c y locations</span>
<a name="l00574"></a><a class="code" href="namespacelibcvautomation__funcs.html#a9ac61209cab08f17b30fcc33b7b7438f">00574</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a9ac61209cab08f17b30fcc33b7b7438f" title="Get the current location of the mouse.">mouse_location</a>():
<a name="l00575"></a>00575 <span class="keywordflow">if</span> _check_display():
<a name="l00576"></a>00576 current_location = libcvautomation.xte_mouseLocation( _get_display() )
<a name="l00577"></a>00577 _log_output( <span class="stringliteral">&#39;Mouse location: x=&#39;</span> + str(current_location.x) + <span class="stringliteral">&#39; y=&#39;</span> + str(current_location.y) )
<a name="l00578"></a>00578 <span class="keywordflow">return</span> current_location.x, current_location.y
<a name="l00579"></a>00579 <span class="keywordflow">else</span>:
<a name="l00580"></a>00580 <span class="comment">#Display not open</span>
<a name="l00581"></a>00581 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00582"></a>00582
<a name="l00583"></a>00583 <span class="comment">## \brief Enter a string of text on the keyboard</span>
<a name="l00584"></a>00584 <span class="comment"># \details This function will simulate pressing the keys exactly as they are entered - unlike libcvautomation_funcs::key_down, libcvautomation_funcs::key_up, and libcvautomation_funcs::key_click, this function will display exactly what you entered: A string of \c &#39;!&#39; will produce a \c ! as a keypress.</span>
<a name="l00585"></a>00585 <span class="comment"># \param string The string of text to enter on the keyboard</span>
<a name="l00586"></a>00586 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00587"></a><a class="code" href="namespacelibcvautomation__funcs.html#a12177cc9e099247f535f9c87409d4259">00587</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a12177cc9e099247f535f9c87409d4259" title="Enter a string of text on the keyboard.">key_string</a>( string ):
<a name="l00588"></a>00588 <span class="keywordflow">if</span> _check_display():
<a name="l00589"></a>00589 _log_output( <span class="stringliteral">&#39;Key string enter: string=&#39;</span> + string )
<a name="l00590"></a>00590 libcvautomation.xte_clickKeyStr(_get_display(), string )
<a name="l00591"></a>00591 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00592"></a>00592 <span class="keywordflow">else</span>:
<a name="l00593"></a>00593 <span class="comment">#Display not open</span>
<a name="l00594"></a>00594 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00595"></a>00595
<a name="l00596"></a>00596 <span class="comment">## \brief Press a key down on the keyboard, and leave it down</span>
<a name="l00597"></a>00597 <span class="comment"># \param key_name The name of the key to press down. Unlike libcvautomation_funcs::key_string, this command will press a single key corresponding to the string you give it - for example, \c &#39;a&#39;, \c &#39;b&#39;, or something fancy like \c &#39;space&#39;.</span>
<a name="l00598"></a>00598 <span class="comment"># \note See \ref xtest_key_strings for a full list of accepted key strings.</span>
<a name="l00599"></a>00599 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00600"></a><a class="code" href="namespacelibcvautomation__funcs.html#a75c43acfa38dea829ce26494c7d0bf3f">00600</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a75c43acfa38dea829ce26494c7d0bf3f" title="Press a key down on the keyboard, and leave it down.">key_down</a>( key_name ):
<a name="l00601"></a>00601 <span class="keywordflow">if</span> _check_display():
<a name="l00602"></a>00602 _log_output( <span class="stringliteral">&#39;Key button down: key_name=&#39;</span> + key_name )
<a name="l00603"></a>00603 libcvautomation.xte_keyDown(_get_display(), key_name )
<a name="l00604"></a>00604 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00605"></a>00605 <span class="keywordflow">else</span>:
<a name="l00606"></a>00606 <span class="comment">#Display not open</span>
<a name="l00607"></a>00607 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00608"></a>00608
<a name="l00609"></a>00609 <span class="comment">## \brief Release a key on the keyboard</span>
<a name="l00610"></a>00610 <span class="comment"># \param key_name The name of the key to release. Unlike libcvautomation_funcs::key_string, this command will press a single key corresponding to the string you give it - for example, \c &#39;a&#39;, \c &#39;b&#39;, or something fancy like \c &#39;space&#39;.</span>
<a name="l00611"></a>00611 <span class="comment"># \note See \ref xtest_key_strings for a full list of accepted key strings.</span>
<a name="l00612"></a>00612 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00613"></a><a class="code" href="namespacelibcvautomation__funcs.html#ab12bbd622fcf5e9bb7ae31e86731d9a3">00613</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#ab12bbd622fcf5e9bb7ae31e86731d9a3" title="Release a key on the keyboard.">key_up</a>( key_name ):
<a name="l00614"></a>00614 <span class="keywordflow">if</span> _check_display():
<a name="l00615"></a>00615 _log_output( <span class="stringliteral">&#39;Key button up: key_name=&#39;</span> + key_name )
<a name="l00616"></a>00616 libcvautomation.xte_keyUp(_get_display(), key_name )
<a name="l00617"></a>00617 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00618"></a>00618 <span class="keywordflow">else</span>:
<a name="l00619"></a>00619 <span class="comment">#Display not open</span>
<a name="l00620"></a>00620 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00621"></a>00621
<a name="l00622"></a>00622 <span class="comment">## \brief Press and release a key on the keyboard</span>
<a name="l00623"></a>00623 <span class="comment"># \param key_name The name of the key to click. Unlike libcvautomation_funcs::key_string, this command will press a single key corresponding to the string you give it - for example, \c &#39;a&#39;, \c &#39;b&#39;, or something fancy like \c &#39;space&#39;.</span>
<a name="l00624"></a>00624 <span class="comment"># \note See \ref xtest_key_strings for a full list of accepted key strings.</span>
<a name="l00625"></a>00625 <span class="comment"># \returns Return \c False if the X11 display was not opened before execution, and \c True otherwise</span>
<a name="l00626"></a><a class="code" href="namespacelibcvautomation__funcs.html#a8f69f7246688b01ac3cfb8dd8d70c955">00626</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a8f69f7246688b01ac3cfb8dd8d70c955" title="Press and release a key on the keyboard.">key_click</a>( key_name ):
<a name="l00627"></a>00627 <span class="keywordflow">if</span> _check_display():
<a name="l00628"></a>00628 _log_output( <span class="stringliteral">&#39;Key button click: key_name=&#39;</span> + key_name )
<a name="l00629"></a>00629 libcvautomation.xte_keyDown(_get_display(), key_name )
<a name="l00630"></a>00630 <span class="keywordflow">return</span> <span class="keyword">True</span>
<a name="l00631"></a>00631 <span class="keywordflow">else</span>:
<a name="l00632"></a>00632 <span class="comment">#Display not open</span>
<a name="l00633"></a>00633 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00634"></a>00634
<a name="l00635"></a>00635 <span class="comment">## \brief Get the location of an image on the screen</span>
<a name="l00636"></a>00636 <span class="comment"># \param image_names List of image names to search for in the root X11 window</span>
<a name="l00637"></a>00637 <span class="comment"># \param search_method The search method to use when matching images. See \ref libcvautomation_search_methods for more information on using the \c search_method parameter</span>
<a name="l00638"></a>00638 <span class="comment"># \param tolerance The tolerance to use when matching images. See \ref libcvautomation_search_methods for more informatino on using the \c tolerance parameter</span>
<a name="l00639"></a>00639 <span class="comment"># \param use_center Set to \c True to return the center coordinate of an image. Set to \c False to use the top-left corner of an image</span>
<a name="l00640"></a>00640 <span class="comment"># \warning Unlike libcvautomation_funcs::wait_for(), this method will not wait for an image to show up before looking for it.</span>
<a name="l00641"></a>00641 <span class="comment"># \returns A dictionary pairing each image name with a cvaPoint class indicating the location it was found at (a point of (-1, -1) indicates the image was not found), or an empty dictionary if the X11 display was not opened before execution.</span>
<a name="l00642"></a><a class="code" href="namespacelibcvautomation__funcs.html#a66cb6c90b7dc78917f1cea203e089a5f">00642</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a66cb6c90b7dc78917f1cea203e089a5f" title="Get the location of an image on the screen.">image_location</a>( image_names, search_method = _search_method_default,
<a name="l00643"></a>00643 tolerance = _tolerance_default, use_center = <span class="keyword">True</span> ):
<a name="l00644"></a>00644 <span class="keywordflow">if</span> _check_display():
<a name="l00645"></a>00645 location_array = {}
<a name="l00646"></a>00646 _log_output( <span class="stringliteral">&#39;Locate image (image_location): image_names=&#39;</span> + image_names )
<a name="l00647"></a>00647 <span class="keywordflow">if</span> use_center:
<a name="l00648"></a>00648 <span class="keywordflow">for</span> image <span class="keywordflow">in</span> image_names:
<a name="l00649"></a>00649 image_location = libcvautomation.matchSubImage_X11_center(_get_display(), image,
<a name="l00650"></a>00650 search_method, tolerance )
<a name="l00651"></a>00651 location_array += [image, image_location]
<a name="l00652"></a>00652 <span class="keywordflow">else</span>:
<a name="l00653"></a>00653 <span class="keywordflow">for</span> image <span class="keywordflow">in</span> image_names:
<a name="l00654"></a>00654 image_location = libcvautomation.matchSubImage_X11(_get_display(), image,
<a name="l00655"></a>00655 search_method, tolerance )
<a name="l00656"></a>00656 location_array += [image, image_location]
<a name="l00657"></a>00657
<a name="l00658"></a>00658 <span class="keywordflow">return</span> location_array
<a name="l00659"></a>00659 <span class="keywordflow">else</span>:
<a name="l00660"></a>00660 <span class="comment">#Display not open</span>
<a name="l00661"></a>00661 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00662"></a>00662
<a name="l00663"></a>00663 <span class="comment">## \brief Get the location of an image on the screen, waiting for it to show up</span>
<a name="l00664"></a>00664 <span class="comment"># \param image_names List of image names to search for in the root X11 window</span>
<a name="l00665"></a>00665 <span class="comment"># \param search_method The search method to use when matching images. See \ref libcvautomation_search_methods for more information on using the \c search_method parameter</span>
<a name="l00666"></a>00666 <span class="comment"># \param tolerance The tolerance to use when matching images. See \ref libcvautomation_search_methods for more informatino on using the \c tolerance parameter</span>
<a name="l00667"></a>00667 <span class="comment"># \param timeout The time (in seconds) to wait when searching for an image on the root X11 window</span>
<a name="l00668"></a>00668 <span class="comment"># \param use_center Set to \c True to return the center coordinate of an image. Set to \c False to use the top-left corner of an image</span>
<a name="l00669"></a>00669 <span class="comment"># \returns A dictionary pairing each image name with a cvaPoint class indicating the location it was found at (a point of (-1, -1) indicates the image was not found), or an empty dictionary if the X11 display was not opened before execution.</span>
<a name="l00670"></a><a class="code" href="namespacelibcvautomation__funcs.html#a13cc6e8f778af64c445b78f53c7a3ab7">00670</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a13cc6e8f778af64c445b78f53c7a3ab7" title="Get the location of an image on the screen, waiting for it to show up.">wait_for</a>( image_names, search_method = _search_method_default,
<a name="l00671"></a>00671 tolerance = _tolerance_default, timeout = _timeout_default,
<a name="l00672"></a>00672 use_center = <span class="keyword">True</span> ):
<a name="l00673"></a>00673 <span class="keywordflow">if</span> _check_display():
<a name="l00674"></a>00674 location_array = {}
<a name="l00675"></a>00675 _log_output( <span class="stringliteral">&#39;Locate image (wait_for): image_names=&#39;</span> + image_names )
<a name="l00676"></a>00676 <span class="keywordflow">if</span> use_center:
<a name="l00677"></a>00677 <span class="keywordflow">for</span> image <span class="keywordflow">in</span> image_names:
<a name="l00678"></a>00678 image_location = libcvautomation.waitForImage_location(_get_display(), image,
<a name="l00679"></a>00679 search_method, tolerance, timeout )
<a name="l00680"></a>00680 location_array += [image, image_location]
<a name="l00681"></a>00681 <span class="keywordflow">else</span>:
<a name="l00682"></a>00682 <span class="keywordflow">for</span> image <span class="keywordflow">in</span> image_names:
<a name="l00683"></a>00683 image_location = libcvautomation.waitForImage_location_center(_get_display(), image,
<a name="l00684"></a>00684 search_method, tolerance, timeout )
<a name="l00685"></a>00685 location_array += [image, image_location]
<a name="l00686"></a>00686
<a name="l00687"></a>00687 <span class="keywordflow">return</span> location_array
<a name="l00688"></a>00688 <span class="keywordflow">else</span>:
<a name="l00689"></a>00689 <span class="comment">#Display not open</span>
<a name="l00690"></a>00690 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
<a name="l00691"></a>00691
<a name="l00692"></a>00692 <span class="comment">## \brief Execute a libcvautomation command based on a string</span>
<a name="l00693"></a>00693 <span class="comment"># \details This is a handler for the xte_commandString() function. </span>
<a name="l00694"></a>00694 <span class="comment"># \note Not all commands need all the parameters specified. See \ref xtest_command_strings for more information on how to use this function.</span>
<a name="l00695"></a>00695 <span class="comment"># \param string The command string to execute</span>
<a name="l00696"></a>00696 <span class="comment"># \param mouse_button The mouse button to click, if applicable</span>
<a name="l00697"></a>00697 <span class="comment"># \param search_method The search method to use, if applicable. See \ref libcvautomation_search_methods for more information on how to use the \c search_method parameter</span>
<a name="l00698"></a>00698 <span class="comment"># \param tolerance The tolerance to use, if applicable. See \ref libcvautomation_search_methods for more information on how to use the \c tolerance parameter</span>
<a name="l00699"></a>00699 <span class="comment"># \param timeout The timeout (in seconds) to use, if applicable</span>
<a name="l00700"></a>00700 <span class="comment"># \returns A cvaPoint class with the following points:&lt;br&gt;(0, 0) or up indicates a success.&lt;br&gt;(-1, -1) indicates either the command was not successful, or that the command was not recognized.&lt;br&gt;(-2, -2) indicates that the command did not need to return anything - For example, commands like \ref mousejiggle don&#39;t normally return a value.</span>
<a name="l00701"></a><a class="code" href="namespacelibcvautomation__funcs.html#a35d44bdc0e8c0e1e049d701e7c3e64ca">00701</a> <span class="keyword">def </span><a class="code" href="namespacelibcvautomation__funcs.html#a35d44bdc0e8c0e1e049d701e7c3e64ca" title="Execute a libcvautomation command based on a string.">command_string</a>( string, mouse_button = _mouse_button_default, search_method = _search_method_default,
<a name="l00702"></a>00702 tolerance = _tolerance_default, timeout = _timeout_default):
<a name="l00703"></a>00703
<a name="l00704"></a>00704 <span class="comment">#The return for this function bears a bit of talking about:</span>
<a name="l00705"></a>00705 <span class="comment"># A return of (0, 0) or up is a success</span>
<a name="l00706"></a>00706 <span class="comment"># A return of (-1, -1) is an error that either the command wasn&#39;t successful, or the command wasn&#39;t recognized</span>
<a name="l00707"></a>00707 <span class="comment"># A return of (-2, -2) indicates that the command didn&#39;t need to return anything -</span>
<a name="l00708"></a>00708 <span class="comment"># This helps differentiate between errors and functions like key_click that</span>
<a name="l00709"></a>00709 <span class="comment"># don&#39;t really use a point</span>
<a name="l00710"></a>00710
<a name="l00711"></a>00711 <span class="keywordflow">if</span> _check_display():
<a name="l00712"></a>00712 _log_output( <span class="stringliteral">&#39;Command string: string=&#39;</span> + string + <span class="stringliteral">&#39; search_method=&#39;</span> + str(search_method) +
<a name="l00713"></a>00713 <span class="stringliteral">&#39; tolerance=&#39;</span> + str(tolerance) + <span class="stringliteral">&#39; timeout=&#39;</span> + str(timeout) )
<a name="l00714"></a>00714 result_point = libcvautomation.xte_commandString(_get_display(), string,
<a name="l00715"></a>00715 mouse_button, search_method,
<a name="l00716"></a>00716 tolerance, timeout )
<a name="l00717"></a>00717
<a name="l00718"></a>00718 <span class="keywordflow">if</span> result_point == _libcvautomation_error_location:
<a name="l00719"></a>00719 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvImageNotFound.html">LibcvImageNotFound</a>( string )
<a name="l00720"></a>00720 <span class="keywordflow">else</span>:
<a name="l00721"></a>00721 <span class="keywordflow">return</span> result_point
<a name="l00722"></a>00722
<a name="l00723"></a>00723 <span class="keywordflow">else</span>:
<a name="l00724"></a>00724 <span class="comment">#Display not open</span>
<a name="l00725"></a>00725 <span class="keywordflow">raise</span> <a class="code" href="classlibcvautomation__funcs_1_1LibcvDisplayNotOpen.html">LibcvDisplayNotOpen</a>( _get_name() )
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Defines</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<hr class="footer"/><address class="footer"><small>
Generated on Thu Oct 11 2012 17:42:49 for libcvautomation by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>
</body>
</html>