2017-08-12 2 views
0

Je veux utiliser Python (3.6) et pywinauto (0.6.3) pour contrôler Google Earth (7.1.8.3036) dans la plate-forme Windows 10 pour enregistrer l'image de Google Earth dans un fichier. Je suis en mesure de démarrer Google Earth à partir de pywinauto et d'obtenir la boîte de dialogue Google Earth, mais je n'ai pas trouvé l'attribut pour 'Fichier'. J'ai essayé d'utiliser app['Google Earth'].print_control_identifiers() mais je n'ai vu aucun attribut pour 'Fichier' (trop long pour être inclus ici).Impossible de localiser l'attribut 'Fichier' de Google Earth en utilisant pywinauto

J'apprécie n'importe quelle aide ou suggestion comment faire . Une alternative simple consiste à utiliser les raccourcis clavier (Ctrl + Alt + S) dans la fenêtre active de Google Earth. J'ai essayé d'utiliser SendKeys('^%S') ou type_keys('^%S'), mais cela n'a pas fonctionné. Je ne dois pas faire quelque chose de bien.

Voici comment j'ai essayé de lancer Google Earth et savoir s'il y avait un attribut 'fichier':

app = Application(backend='uia').start('c:/Program Files (x86)/Google/Google Earth/client/googleearth.exe') 

app['Google Earth'].File.click() 

Traceback (most recent call last): File "C:\Users\Brian\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto\application.py", line 245, in __resolve_control criteria) File "C:\Users\Brian\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto\timings.py", line 447, in wait_until_passes raise err pywinauto.timings.TimeoutError

Au cours de la manipulation de l'exception ci-dessus, une autre exception est survenue:

Traceback (most recent call last): File "", line 1, in File "C:\Users\Brian\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto\application.py", line 351, in getattribute ctrls = self.__resolve_control(self.criteria) File "C:\Users\Brian\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto\application.py", line 248, in __resolve_control raise e.original_exception File "C:\Users\Brian\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto\timings.py", line 425, in wait_until_passes func_val = func(*args) File "C:\Users\Brian\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto\application.py", line 209, in __get_ctrl ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria)) File "C:\Users\Brian\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto\findwindows.py", line 84, in find_element elements = find_elements(**kwargs) File "C:\Users\Brian\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto\findwindows.py", line 300, in find_elements elements = findbestmatch.find_best_control_matches(best_match, wrapped_elems) File "C:\Users\Brian\AppData\Local\Programs\Python\Python36\lib\site-packages\pywinauto\findbestmatch.py", line 533, in find_best_control_matches raise MatchError(items = name_control_map.keys(), tofind = search_text) pywinauto.findbestmatch.MatchError: Could not find 'File' in 'dict_keys(['Tour GuidePane', 'Tour Guide', 'Pane', '', 'Custom', '0', '1', '2', 'Pane0', 'Pane1', 'Pane2', '3', 'Pane3', '4', 'Pane4', '5', 'Pane5', '6', 'Pane6', '7', 'Custom0', 'Custom1', 'Custom2', '8', 'Custom3', '9', 'Custom4', '10', 'Custom5', '11', 'Custom6', '12', 'Custom7', '13', 'Custom8', '14', 'Custom9', '15', 'Custom10', '16', 'Custom11', '17', 'Custom12', '18', 'Custom13', '19', 'Custom14', '20', 'Custom15', '21', 'Custom16', '22', 'Custom17', '23', 'Custom18', '24', 'Custom19', '25', 'Custom20', '26', 'Custom21', '27', 'Custom22', '28', 'Custom23', '29', 'Custom24', '30', 'Custom25', '31', 'Custom26', '32', 'Custom27', '33', 'Custom28', '34', 'Custom29', '35', 'Custom30', '36', 'Custom31', '37', 'Custom32', '38', 'Custom33', '39', 'Custom34', '40', 'Custom35', '41', 'Custom36', '42', 'Custom37', '43', 'Custom38', '44', 'Custom39', '45', 'Custom40', '46', 'Custom41', '47', 'Custom42', '48', 'Custom43', '49', 'Custom44', '50', 'Custom45', '51', 'Pane7', '52', 'Pane8', '53', 'Pane9', '54', 'Pane10', '55', 'Pane11', '56', 'Pane12', '57', 'Pane13', '58', 'Pane14', '59', 'Custom46', '60', 'Custom47', '61', 'Custom48', '62', 'Custom49', '63', 'Custom50', '64', 'Custom51', '65', 'Custom52', '66', 'Custom53', '67', 'Custom54', '68', 'Custom55', '69', 'Custom56', '70', 'Custom57', '71', 'Custom58', '72', 'Custom59', '73', 'Custom60', '74', 'Custom61', '75', 'Custom62', '76', 'Custom63', '77', 'TitleBar', 'System', 'SystemMenu', 'Menu', 'System0', 'System1', 'System2', 'SystemMenuItem', 'MenuItem', 'Minimize', 'MinimizeButton', 'Button', 'Maximize', 'MaximizeButton', 'Button0', 'Button1', 'Button2', 'CloseButton', 'Close', 'Button3'])'

+0

Bienvenue sur Stack Overflow Sur ce site vous êtes censé essayer d'écrire le code vous-même. Après avoir fait plus de recherches, si vous avez un problème, vous pouvez poster ** ce que vous avez essayé avec une explication claire de ce qui ne fonctionne pas ** et fournir un exemple minimal, complet et vérifiable. Je suggère de lire [Comment demander] (https://stackoverflow.com/help/how-to-ask) une bonne question et la [question parfaite] (http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question /). Assurez-vous également de prendre le [tour] (https://stackoverflow.com/tour) et lisez [this] (https://meta.stackoverflow.com/q/347937/6676466). –

+0

Vous devez d'abord développer le sous-menu "Fichier". Google Earth est une application Qt5 donc vous pouvez jeter un oeil à l'exemple de WireShark dans le repo à titre indicatif (c'est aussi Qt5). Le sous-menu peut être développé par '.invoke()' pour ce cas. –

Répondre

0

J'ai trouvé un moyen d'enregistrer une image d'un fichier KML dans Google Earth en utilisant les raccourcis clavier (Ctrl + Alt + S). Mais cela va à l'encontre du but principal de l'utilisation de pywinauto. Je suis toujours à la recherche d'une meilleure façon d'utiliser pywinauto pour contrôler Google Earth. Voici mon code python avec des commentaires:

import os, time 
from pywinauto import Application 
from pywinauto import keyboard 

kmlfile = 'rcglic1457645225.kml' 
kmlimage= kmlfile[:-3]+'jpg' 
os.startfile(kmlfile) 
time.sleep(15)  #wait for completely loading Google Earth 

app = Application(backend='uia').connect(path='googleearth.exe') #connect to the Google Earth process 
dlg = app['Google Earth'] #connect to the Google Earth dialog 
dlg['Maximize'].click()  #click on 'Maximize' button of the Google Earth window to have the best image 
time.sleep(1) 
keyboard.SendKeys('^%S') #hot keys to save the image (Ctrl+Alt+S) 
keyboard.SendKeys(kmlimage+'{ENTER}') #enter the image file name 
keyboard.SendKeys('{TAB}{ENTER}')  #use TAB to select 'Yes' and replace file if existed 
dlg['Restore'].click()  #click on 'Restore' button of the Google Earth window to go back to normal 
dlg['Close'].click()   #click on 'Close' button 
keyboard.SendKeys('{TAB}{ENTER}')  #use TAB to select 'Discard' and close the Google Earth window