gpt4 book ai didi

Python: enter file path in open file dialog window opened by another software(在其他软件打开的文件对话框窗口中输入文件路径)

转载 作者:bug小助手 更新时间:2023-10-25 15:07:14 24 4
gpt4 key购买 nike



Open File Dialog to interact withI have a Python code that shall interact with a Filedialog Window opened by another software.

我有一个可以与另一个软件打开的文件对话框窗口交互的Python代码。


I need to insert Filename and Filepath in the File Dialog boxes.

我需要在文件对话框中插入文件名和文件路径。


The Python code identifies the window, and write correctly the file name in the file name box.

Python代码标识窗口,并在文件名框中正确写入文件名。


The software can also identify the item containing the address.
I've use this code for this task (function List() below)

该软件还可以识别包含该地址的物品。我已经为这个任务使用了这个代码(下面的函数list())


def List(): #List of all element in file dialog box


app = Application().connect(title="Open")
dlg = app.window(title="Open")


all_elements = dlg.children()


for element in all_elements:
print(f"Class Name: {element.class_name()}")
print(f"Control ID: {element.control_id()}")
print(f"Control Text: {element.window_text()}")
print("=" * 40)

In my case item is a ToolbarWindows32, Control id : 1001
The main problem is that i can't write inside it.
I can solve by using pyautogui, by entering in the box with the horkey CTRL +L, but I would prefer not to emulate the keys

在我的例子中,项是一个工具栏Windows32,控件id:1001,主要问题是我不能在它里面写东西。我可以通过使用PYOTOGUIUS来解决,通过使用Horkey Ctrl+L在框中输入,但我不喜欢模仿键


Here below the code I'm working on:`

下面是我正在编写的代码:`


from pywinauto import Application

window_name="Open"
#window_name="Apri"
app = Application().connect(title=window_name) #Change wit
dlg = app.window(title=window_name)

file_name="Adam2.txt"
file_path = "C:\Test"

#Set the file name in File name box
edit_control_filename = dlg.children(class_name="Edit")
edit_control_filename = edit_control_filename[0]
edit_control_filename.type_keys(file_name)

#Set the file path in File path box
edit_controls = [control for control in dlg.children(class_name="ToolbarWindow32") if control.control_id() == 1001]
edit_control_filepath = edit_controls[0]

edit_control_filepath.set_focus()
edit_control_filepath.click_input()

`

`


更多回答
优秀答案推荐

edit_control_filename.set_edit_text(file_name)

doesn't emulate key actions. Also you can enter the full path to File name: (Nome file:) edit box at once. It should work, and you don't need to enter path separately.

不会模仿关键动作。您还可以一次输入文件名的完整路径:(Nome文件:)编辑框。它应该可以工作,并且您不需要单独输入路径。


更多回答

Hi Vasily. Thank you for your answer. Unfortunately it doesn't work... First of all becuase what I'm trying to edit is the filepath, By default that field is not editable, because has a "breadcumb" structure. To get it editable I should select it all. The only way I found is to use the hotkey CTRL +L. But I guess I could avoid this and try to select all by using pywinauto only

嗨,瓦西里。谢谢你的回答。不幸的是它不起作用..。首先,因为我要编辑的是文件路径,默认情况下,该字段是不可编辑的,因为它有一个“面包盒”结构。要使其可编辑,我应该将其全部选中。我找到的唯一方法是使用热键CTRL+L,但我想我可以避免这一点,并尝试仅使用pywinauto来选择全部

Oh, well, this is a bit more tricky and needs some time to figure out. :) Maybe method .invoke() would help for some elements.

哦,好吧,这有点棘手,需要一些时间来弄清楚。:)也许方法.Invoke()会对某些元素有所帮助。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com