vitzthumb
vitzthumb

Reputation: 23

Win32com interfacing with Reflection Desktop

I run a number of python scripts and programs to aggregate and edit data in Attachmate Extra. My company was on an old version of Attachmate Extra until recently. I'm testing the new version (Reflection Desktop v. 16.2) and my scripts no longer work. I built them with the aid of the helpful advice on this link. I would like to be able to control (scrape, write, etc) screens on the new version.

Here's where I currently am. Running this code creates the a new window:

system = win32com.client.Dispatch("ReflectionIBM.Session")
system.Visible = True

...but then from there I cannot do any of the commands I previously used. Running this, for example

system.MoveCursor(11, 65)

creates a new tab in the emulator that doesn't connect to a session. I've looked all around the Reflection documentation for an answer. This page led me to believe the old session method is no longer necessary but I'm not sure. I think I'm wrapping the correct object, and the documentation says that legacy commands still work, but I haven't figured out how to link them.

For reference, here are the lines I was using previously to connect to Attachmate:

system = win32com.client.Dispatch("EXTRA.System")
sess0 = system.ActiveSession
Screen = sess0.Screen

Any help is appreciated. I've been scouring the win32com browser for a list commands and looking through the registry to find available classes but I don't know what to look for. Thank you!

EDIT:

I previously used a couple of functions to read, write, and move the cursor around within Attachmate. Example:

def write(screen,row,col,text):
    screen.row = row
    screen.col = col
    screen.SendKeys(text)

write(screen, 10, 65, "test")

Is there a way to get this working again in Reflection?

Upvotes: 2

Views: 2216

Answers (2)

Prasun Bhattacharyya
Prasun Bhattacharyya

Reputation: 72

Have launched python package py_reflection in this regards,

How to start:

Install the package via pip:

py -m pip install py_reflection

Run the package (Run the commands below in terminal):

python
>>>from py_reflection import app
>>>app.run()

Api Endpoint and their description: ** All of the endpoints have a common parameter view_idx(integer, optional). Use this parameter to toggle between session in emulator.

/send_keys: Use this endpoint to press keys in the emulator. Parameters to pass: text(string), x(integer), y(integer)

/get_text: Use this endpoint to get text from a specific coordinate. Parameters to pass: x(integer), y(integer)

/press_key: Use this endpoint to press special control keys: Parameters to pass: control_key(string all in caps). Available control keys: 'F1','F2','F3','F4','F5','F6','F7','F8','F9','F10','F11','F12','F13','F14','F15','F16','F17','F18','F19','TAB','DELETE','LEFT','DOWN','UP','RIGHT','PAGEUP','PAGEDOWN','CLEAR','END','ENTER'

/get_text_coordinates: Use this endpoint to get coordinates of text present in emulator screen. Parameters to pass: text(string), total_row_count(integer, optional), total_column_count(integer, optional)

/check_text_present: Use this endpoint to check if given text present in emulator screen. Parameters to pass: text(string), total_row_count(integer, optional), total_column_count(integer, optional)

/move_cursor: Use this endpoint to move cursor to specified coordinate. Parameters to pass: x(integer), y(integer)

/get_view_count: Use this endpoint to get number of sessions opened in emulator.

More info at pypi.org

Upvotes: 1

chris
chris

Reputation: 132

I still do not know why this works the way it does. In VBA the GetObject method works on "Reflection Workspace" but in python that did not produce any usable attributes that I could find. For python, to get the active session object I had to use EXTRA.System:

from win32com.client.gencache import EnsureDispatch
screen = EnsureDispatch("EXTRA.System").ActiveSession.Screen

From there the code seems generally the same as VBA with

screen.GetString(row, col, len)
screen.PutString(data, row, col)
screen.SendKeys('<PF1>')

for interacting with the host.

After more documentation reading and more trial and error I solved it. "EXTRA.System" is kept for legacy reasons so technically will still work. However, to connect to an active session of Reflection this worked:

system = win32com.client.GetObject('Reflection Workspace')

then to get the active view:

screen = system.GetObject("Frame").SelectedView.Control.Screen

or a specific numbered view:

screen = system.GetObject("Frame").view(1).Control.Screen

The code for interacting with Reflection also has changed and now looks like:

screen.GetText(row, col, len)
screen.PutText2(data, row, col)
screen.SendControlKey(ControlKeyCode)

The documentation for ControlKeyCode does not seem to provide the codes for the control keys. However, you can find the definitions in the Visual Basic Object Browser that comes with Reflection. In Reflection, on the macros tab, click Visual Basic, then press F2 and search for ControlKeyCode. A list of them should show up. For example, mine shows ControlKey_F1=10.

screen.SendKeys("N")

can still be used to send individual key strokes such as the N key but SendControlKey seems to have replaced the command keys such as Enter, Page Up, and the Function keys.

Upvotes: 1

Related Questions