Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Using Find Window to limit scope for next Find Window action

If you have a question or need help, this is the place to be.
Post Reply
eventspook
Posts: 23
Joined: Tue Mar 05, 2013 2:50 pm

Using Find Window to limit scope for next Find Window action

Post by eventspook »

Not sure how to properly word this, but here goes.

I have a process which has various sub windows, each window having a RichText edit box. Example using the Find Window interface:

Code: Select all

ProcessName.exe
    - "connected to server 127.0.0.1"
        - "RichEdit20A"
        - "ListBox"
    - "connected to server 127.0.0.2"
        - "RichEdit20A"
        - "ListBox"

I need to be able to target/send text to the RichEdit20A component of the 127.0.0.1 window (using the Child Name filter), but because the window order can change, I can't use the 'th match' option. The UI rich text edit box always has the same name, so I can't target it directly.

Can I use Find Window to target the main window via the '127.0.0.1' string in the Child Name filter, then somehow use another Find Window action to search for 'RichEdit20A' within that scope?

Or do I need to do this via a Python script?
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Using Find Window to limit scope for next Find Window ac

Post by kgschlosser »

well that's going to be a very complicated one to tackle. because you want to grab data from another program and look it it to perform an action.. I am sure it can be done. but i do know it will be very complicated to do. and would break if the developer changed something in the software you are trying to get the data from. It's beyond my programming skills. but there may be someone in here that has the ability and is up for the task.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Using Find Window to limit scope for next Find Window ac

Post by kgschlosser »

ok i spoke way to soon.. I did a little poking about and found out this is actually pretty simple. I am sorry for jumping the gun like that...

we may have to fine tune this to the type of control that you are targeting.. so follow the directions below

set up the Find Window to target that specific control

and then copy and paste this code into a python script

change CONTROL_TEXT to whatever is entered in the field that you are searching for
change NEW_CONTROL_TEXT to whatever it is that you want to change it to

remove the # before the print statement to help identify the proper control

Code: Select all

CONTROL_TEXT = "Enter the text to search for here"
NEW_CONTROL_TEXT = "Enter the replacement text here"

import win32con
import win32gui

text = eg.plugins.Window.GrabText(True)
#print repr(text)

if text[0][0] == CONTROL_TEXT:
    win32gui.SendMessage(eg.result[0], win32con.WM_SETTEXT, 0, NEW_CONTROL_TEXT)

K
If you like the work I have been doing then feel free to Image
eventspook
Posts: 23
Joined: Tue Mar 05, 2013 2:50 pm

Re: Using Find Window to limit scope for next Find Window ac

Post by eventspook »

Thanks for giving this another shot. I really like your approach, however, I'm having trouble with the Windows.GrabText call:

Code: Select all

13:51:27      Python Script
13:51:27         Traceback (most recent call last):
13:51:27           Python script "12", line 4, in <module>
13:51:27             text = eg.plugins.Window.GrabText(True)
13:51:27           File "C:\Program Files (x86)\EventGhost\plugins\Window\__init__.py", line 543, in __call__
13:51:27             from win32_ctrls import win32_ctrls
13:51:27         ImportError: No module named win32_ctrls
and stripped the script down to something really basic:

Code: Select all

import win32con
import win32gui

text = eg.plugins.Window.GrabText(True)
print repr(text)
But same issue.

Find window command I used (with 1 match when testing):

Code: Select all

eg.plugins.Window.FindWindow(u'myprogram.exe', u'mIRC{*}', u'myprogram', u'Status:{*}SERVERNAME{*}', u'myprogram_Status', None, True, 0.0, 2)

I'm sure it's user error on my part, so any additional pointers would be appreciated. I'm running 0.4.1.r1722.
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Using Find Window to limit scope for next Find Window ac

Post by kgschlosser »

that's off it's saying you have an import error.

do this... copy the code below.. then pick a spot in your configuration tree and paste. this will create a new folder with a macro in it.
then open notepad and type something into it..

leave notepad open and run the macro. see if you get the same import error.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1722">
    <Folder Name="Grab Text Test" Expanded="True">
        <Macro Name="Find Window: notepad.exe">
            <Action>
                Window.FindWindow(u'notepad.exe', u'New Text Document (4).txt - Notepad', u'Notepad', u'', u'Edit', 1, False, 0.0, 0)
            </Action>
            <Action>
                Window.GrabText(True)
            </Action>
            <Action>
                EventGhost.DumpResult()
            </Action>
        </Macro>
    </Folder>
</EventGhost>
If you like the work I have been doing then feel free to Image
eventspook
Posts: 23
Joined: Tue Mar 05, 2013 2:50 pm

Re: Using Find Window to limit scope for next Find Window ac

Post by eventspook »

I had to update the Windows title in your example ({*} - Notepad, test works), but I'm still getting the same error:

Code: Select all

09:49:00      Grab Text Item(s): Return only selected item(s): True
09:49:00         Error in Action: "Grab Text Item(s): Return only selected item(s): True"
09:49:00         Traceback (most recent call last) (1722):
09:49:00           File "C:\Program Files (x86)\EventGhost\eg\Classes\ActionBase.py", line 170, in CallWrapper
09:49:00             return self(*args)
09:49:00           File "C:\Program Files (x86)\EventGhost\plugins\Window\__init__.py", line 543, in __call__
09:49:00             from win32_ctrls import win32_ctrls
09:49:00         ImportError: No module named win32_ctrls
09:49:00      Dump Result to Log
09:49:00         [20579948]
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Using Find Window to limit scope for next Find Window ac

Post by kgschlosser »

win32_ctrls is what is throwing the error.

so go into your plugins folder.. open the window folder..

in there should be a file named win32_ctrls.py

I have attached a copy just in case you do not have one.. do not know why it wouldn't be there but.. maybe it got deleted on accident..

but the win32_ctrls is used to properly identify the widget you are trying to access. so you do need it.. this should resolve your issue. then we can move on with the tests.. Now i do not understand what you mean that you had to edit something in that macro i sent ya. could you please elaborate
Attachments
win32_ctrls.py
(431 Bytes) Downloaded 119 times
If you like the work I have been doing then feel free to Image
eventspook
Posts: 23
Joined: Tue Mar 05, 2013 2:50 pm

Re: Using Find Window to limit scope for next Find Window ac

Post by eventspook »

The file is there, content is identical. I'm going to have to try this on one of my other EventGhost machines to see what's going on.

As for the edit, you are looking for "New Text Document (4).txt", which is not what you get when you first open Notepad.
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Using Find Window to limit scope for next Find Window ac

Post by kgschlosser »

thanks about catching the file thing... and i do not know why you are having a problem with the import it's very odd. maybe a permissions issue??
If you like the work I have been doing then feel free to Image
Post Reply