@@ -39,7 +39,7 @@ def py23_encode(input_variable):
3939 elif python2_env (): return input_variable
4040 else : return input_variable .encode ('utf-8' )
4141
42- def tagui_open ():
42+ def init ():
4343# connect to tagui process by checking tagui live mode readiness
4444
4545 global process , tagui_id
@@ -69,7 +69,7 @@ def tagui_open():
6969 print ('[ERROR] - ' + str (e ))
7070 return False
7171
72- def tagui_ready ():
72+ def ready ():
7373# check whether tagui is ready to receive instructions
7474
7575 global process , tagui_id
@@ -96,7 +96,7 @@ def tagui_ready():
9696 print ('[ERROR] - ' + str (e ))
9797 return False
9898
99- def tagui_send (tagui_instruction ):
99+ def send (tagui_instruction ):
100100# send next live mode instruction to tagui for processing if tagui is ready
101101
102102 global process , tagui_id
@@ -108,7 +108,7 @@ def tagui_send(tagui_instruction):
108108 if process .poll () is not None : return False
109109
110110 # loop until tagui live mode is ready and listening for inputs
111- while not tagui_ready (): pass
111+ while not ready (): pass
112112
113113 # echo live mode instruction, first remove quotes to be echo-safe
114114 safe_tagui_instruction = tagui_instruction .replace ("'" , "" ).replace ('"' ,'' )
@@ -130,7 +130,7 @@ def tagui_send(tagui_instruction):
130130 print ('[ERROR] - ' + str (e ))
131131 return False
132132
133- def tagui_close ():
133+ def close ():
134134# disconnect from tagui process by sending done instruction
135135
136136 global process , tagui_id
@@ -140,7 +140,7 @@ def tagui_close():
140140 if process .poll () is not None : return False
141141
142142 # loop until tagui live mode is ready and listening for inputs
143- while not tagui_ready (): pass
143+ while not ready (): pass
144144
145145 # send done instruction to terminate live mode and exit tagui
146146 process .stdin .write (py23_encode ('echo "[tagui][finished listening]"\n ' ))
@@ -157,15 +157,15 @@ def tagui_close():
157157 print ('[ERROR] - ' + str (e ))
158158 return False
159159
160- def tagui_present (element_identifier ):
160+ def present (element_identifier ):
161161 if element_identifier is None or element_identifier == '' :
162162 return False
163163
164164 tagui_timeout = time .time () + 10
165165 while time .time () < tagui_timeout :
166- tagui_send ('present_result = present(\' ' + element_identifier + '\' )' )
167- tagui_send ('dump present_result.toString() to /tmp/tagui_python.txt' )
168- tagui_send ('load /tmp/tagui_python.txt to present_result' )
166+ send ('present_result = present(\' ' + element_identifier + '\' )' )
167+ send ('dump present_result.toString() to /tmp/tagui_python.txt' )
168+ send ('load /tmp/tagui_python.txt to present_result' )
169169
170170 tagui_text = open ('/tmp/tagui_python.txt' , mode = 'r' )
171171 element_present = tagui_text .read (); tagui_text .close ()
@@ -174,51 +174,22 @@ def tagui_present(element_identifier):
174174
175175 return False
176176
177- def tagui_click (element_identifier ):
177+ def click (element_identifier ):
178178 if element_identifier is None or element_identifier == '' :
179179 print ('[ERROR] - target missing for click()' )
180180 return False
181181
182- elif tagui_present (element_identifier ) == False :
182+ elif present (element_identifier ) == False :
183183 print ('[ERROR] - cannot find ' + element_identifier )
184184 return False
185185
186- elif tagui_send ('click ' + element_identifier ) == False :
186+ elif send ('click ' + element_identifier ) == False :
187187 return False
188188
189189 else :
190190 return True
191191
192- def tagui_wait (delay_in_seconds ):
192+ def wait (delay_in_seconds ):
193193 if delay_in_seconds is None : delay_in_seconds = 5.0
194194 time .sleep (float (delay_in_seconds ))
195195 return True
196-
197- # testing code for development
198-
199- tagui_flow = [
200- 'https://ca.yahoo.com' ,
201- 'type search-box as github' ,
202- 'show search-box' ,
203- 'click search-button' ,
204- 'snap page' ,
205- 'snap logo' ,
206- 'https://duckduckgo.com' ,
207- 'type search_form_input_homepage as The search engine that doesnt track you.' ,
208- ]
209-
210- tagui_open ()
211-
212- tagui_send (tagui_flow [0 ])
213- tagui_send (tagui_flow [1 ])
214- tagui_send (tagui_flow [2 ])
215- tagui_click ("search-button" )
216-
217- tagui_wait (5 )
218-
219- tagui_send (tagui_flow [4 ])
220- tagui_send (tagui_flow [5 ])
221- tagui_send (tagui_flow [6 ])
222- tagui_send (tagui_flow [7 ])
223-
224- tagui_close ()
0 commit comments