I would like to use pywinauto to control an image processing software.
First, I need to click a specific area (which is used for image dragging) to pop up a windows for path input. See the first figure.
Then, I need to input a path and click the button "Select Folder". See the second figure.
I tried:
from pywinauto import Desktop, Application, mouse, findwindows
from pywinauto.keyboard import SendKeys
app = Application(backend='uia').start(r"C:\Program Files\Duplicate Photo Cleaner\DuplicatePhotoCleaner.exe")
app.connect(path="DuplicatePhotoCleaner.exe")
app.DuplicatePhotoCleaner.print_control_identifiers()
Control Identifiers:
Dialog - 'Duplicate Photo Cleaner' (L440, T126, R1480, B915)
['Duplicate Photo Cleaner', 'Duplicate Photo CleanerDialog', 'Dialog']
child_window(title="Duplicate Photo Cleaner", control_type="Window")
|
| TitleBar - '' (L464, T129, R1472, B157)
| ['', 'TitleBar']
| |
| | Menu - 'System' (L448, T134, R470, B156)
| | ['System', 'Menu', 'SystemMenu', 'System0', 'System1']
| | child_window(title="System", auto_id="MenuBar", control_type="MenuBar")
| | |
| | | MenuItem - 'System' (L448, T134, R470, B156)
| | | ['System2', 'SystemMenuItem', 'MenuItem']
| | | child_window(title="System", control_type="MenuItem")
| |
| | Button - 'Minimize' (L1333, T127, R1380, B157)
| | ['Minimize', 'Button', 'MinimizeButton', 'Button0', 'Button1']
| | child_window(title="Minimize", control_type="Button")
| |
| | Button - 'Maximize' (L1380, T127, R1426, B157)
| | ['Button2', 'Maximize', 'MaximizeButton']
| | child_window(title="Maximize", control_type="Button")
| |
| | Button - 'Close' (L1426, T127, R1473, B157)
| | ['CloseButton', 'Button3', 'Close']
| | child_window(title="Close", control_type="Button")
Can anyone help?
Thank you very much.
Looks like the + button where you need to click to get the window (shown in second figure) is ownerdrawn.
So, there is only one way to bring up the "Add folder to search" window: use click_input method by passing coordinates.
Once the window comes up, you can use the below code to set the value:
app.DuplicatePhotoCleaner.child_window(title="Folder:", auto_id="1152", control_type="Edit").set_text('Hello world') #or
app.DuplicatePhotoCleaner['Folder:Edit'].set_text('Hello world')
Application().connect(title='Add folder to search')...
Please go though pywinauto docs for further info.
Related
I want to have automate process for this program: TimeComX Basic.
The script i wrote:
from pywinauto.application import Application as PyWinAutoApplication
from pywinauto.timings import wait_until
from pywinauto.keyboard import send_keys
import pywinauto
import os
import sys
from pywinauto import mouse
import traceback
#Hidernate pc
app2 = PyWinAutoApplication(backend="uia").connect(found_index=0,title="TimeComX Basic")
handle = pywinauto.findwindows.find_windows(title="TimeComX Basic")[0]
window = app2.window(handle=handle)
window.maximize()
window.set_focus()
app2.TimeComxBasic.print_control_identifiers()
#mouse.click(button='left', coords=(150, 960))
Note that to run this script you have to manually install and open TimeComX Basic.
The output:
Control Identifiers:
Dialog - 'TimeComX Basic' (L-11, T-11, R1931, B1019)
['TimeComX BasicDialog', 'Dialog', 'TimeComX Basic']
child_window(title="TimeComX Basic", control_type="Window")
|
| TitleBar - '' (L24, T-8, R1920, B34)
| ['TitleBar']
| |
| | Menu - 'System' (L0, T0, R22, B22)
| | ['Menu', 'System', 'SystemMenu', 'System0', 'System1']
| | child_window(title="System", auto_id="MenuBar", control_type="MenuBar")
| | |
| | | MenuItem - 'System' (L0, T0, R22, B22)
| | | ['MenuItem', 'System2', 'SystemMenuItem']
| | | child_window(title="System", control_type="MenuItem")
| |
| | Button - 'Minimize' (L1707, T0, R1778, B33)
| | ['MinimizeButton', 'Button', 'Minimize', 'Button0', 'Button1']
| | child_window(title="Minimize", control_type="Button")
| |
| | Button - 'Restore' (L1778, T0, R1848, B33)
| | ['Restore', 'Button2', 'RestoreButton']
| | child_window(title="Restore", control_type="Button")
| |
| | Button - 'Close' (L1848, T0, R1920, B33)
| | ['Close', 'Button3', 'CloseButton']
| | child_window(title="Close", control_type="Button")
As you can see it has options only for close, minimize and maximize buttons and for main menu. There is no option to "Start" button for example.
What can I do in this situation?
I'm redirecting the stdout and stderr streams from a Python script to a file. Before redirecting, I was using the tqdm progress bar in my script which continually updates the bar in the same place in the console. However, after redirecting, in the file each update is printed to a new line:
0%| | 0/1369 [00:00<?, ?it/s]
0%| | 1/1369 [00:00<08:40, 2.63it/s]
0%| | 2/1369 [00:00<08:03, 2.82it/s]
0%| | 3/1369 [00:00<07:35, 3.00it/s]
0%| | 4/1369 [00:01<07:15, 3.14it/s]
0%| | 5/1369 [00:01<07:52, 2.89it/s]
0%| | 6/1369 [00:01<07:26, 3.05it/s]
1%| | 7/1369 [00:02<07:08, 3.18it/s]
1%| | 8/1369 [00:02<06:55, 3.28it/s]
1%| | 9/1369 [00:02<06:46, 3.35it/s]
1%| | 10/1369 [00:03<06:39, 3.40it/s]
1%| | 11/1369 [00:03<06:35, 3.43it/s]
1%| | 12/1369 [00:03<06:32, 3.46it/s]
1%| | 13/1369 [00:03<06:29, 3.48it/s]
1%| | 14/1369 [00:04<06:28, 3.49it/s]
Is there a way to write tqdm output (or any other progress bar) to a file which stays on the same line?
I'm working with account-financial-reporting module (OCA).
I want to add tree structure according to Code :
if account.code = "xxx000" or "yyy000" , then change the line style to bold ,
and get the other codes in ascending order . Example:
Code | |
-------------------------
xxx000 | |
-------------------------
|xxx001 |
-------------------------
|xxx003 |
-------------------------
yyy000 | |
-------------------------
|yyy002 |
-------------------------
|yyy005 |
-------------------------
def _generate_report_content(self, workbook, report):
if not report.show_partner_details:
# Display array header for account lines
self.write_array_header()
# For each account
for account in report.account_ids.filtered(lambda a: not a.hide_line):
if not report.show_partner_details:
# Display account lines
self.write_line(account, 'account')
Any help please ?
I'm trying to load a serries of files that are dics and then load arrays from within dics to my QTreeView and then be able to edit these dics. I have a problem when it comes to connecting signal as it connects all buttons to 1 data - last created one. If I load 20 arrays from 1 dict I should be able to click on each array and print its name. Right now it just prints last added name.
Here is the code:
def add_data(self):
for subdir, dirs, files in os.walk(self.dat_folder):
for file_inx, file_name in enumerate(files):
''' loading file '''
''' creating data'''
if len(data[1]) >0:
#file_inx = file_inx + 1 # not sure if I need this tbd.
job = QStandardItem(project_name)
self.model.setItem(file_inx,0,job)
self.model.setItem(file_inx, 1, QStandardItem(project_time_day+" "+project_time_time))
for inx, layers in enumerate(data[1]):
child1 = QStandardItem(layers["Name"])
child2 = QStandardItem("Push Button or Combobox or QCheckBox")
job.insertRow(inx,[child1, child2])
b=QPushButton("TestPrint"+str(inx))
b.clicked.connect(lambda: self.printData(child1.text(),layers["Name"]))
a = self.model.index(file_inx, 0) #find parent
i = a.child(inx,7) # find parented location
self.tv_job_list.setIndexWidget(i,b) # replace child2 with QPushButton - b
def printData(self,value,name):
print value,name
Here is how the QTreeView looks like, each job can have hundreds of job_names and there can be hundreds of Job_01 etc etc... Its a big list :- )
1 file on HDD creates 1 parent that create child jobs.
Parent > JOB_01
Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
... x 1000 Childs...
Parent > JOB_01
Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
... x 1000 Childs...
Use partial :
b = QPushButton(str(inx))
b.clicked.connect(partial(self.printData,child1.text()))
I'm new to GTK, I'm trying to figure out how to accomplish something like this:
+---+------+---+
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
+---+------+---+
I want this done in an HBox. How would I accomplish this? Thanks.
It is done with "packing".
I always keep the class reference under my pillow : http://www.pygtk.org/docs/pygtk/gtk-class-reference.html
Samples in the good tutorial found here :
http://www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html
And finally, this shows up something like your drawing :
import gtk as g
win = g.Window ()
win.set_default_size(600, 400)
win.set_position(g.WIN_POS_CENTER)
win.connect ('delete_event', g.main_quit)
hBox = g.HBox()
win.add (hBox)
f1 = g.Frame()
f2 = g.Frame()
f3 = g.Frame()
hBox.pack_start(f1)
hBox.pack_start(f2)
hBox.pack_start(f3)
win.show_all ()
g.main ()
Have fun ! (and I hope my answer is helpful)
The answer is pack_start() and pack_end()
The function has a few parameters you can send to it that give you the desired effect
If you use Louis' example:
hBox.pack_start(f1, expand =False, fill=False)
hBox.pack_start( f2, expand=True, fill=True, padding=50)
hBox.pack_end(f3, expand=False, fill=False)
Hope that helps!