Skip to content

Corrected _key_event_setup signature and added 3 new methods to Instance class #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 73 additions & 7 deletions ibm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from .exceptions import InvalidSessionName, WindowNotFound


class Instance(object):
"""A wrapper to AS400 session. Primitive methods like read, write is
provided."""
Expand Down Expand Up @@ -58,7 +57,7 @@ def _key_event_setup(self, wait):
self.ps.SendKeys("[ENTER]")
self._input_wait(wait)

def get_text(self, row, column, length=1, wait=2):
def get_text(self, row, column, length=1, wait=60):
"""Screen is divided in two axis: X and Y. For a given length, pass
x, y location to read AS400 screen. Default word length is set to 1.

Expand All @@ -69,27 +68,64 @@ def get_text(self, row, column, length=1, wait=2):

:return: stripped string from AS400 instance."""
self._key_event_setup(wait)
return self.ps.GetText(row, column, length).encode("UTF-8").strip()
return self.ps.GetText(row, column, length).encode("UTF-8")

def get_text_rect(self, startRow, startColumn, endRow, endColumn, wait=60):
"""Screen is divided in two axis: X and Y. For a given length, pass
x, y location to read AS400 screen. Default word length is set to 1.

def set_text(self, text, row, column):
:param startRow: start x axis location.
:param startColumn: start y axis location.
:param endRow: start x axis location.
:param endColumn: start y axis location.
:param wait: max wait time, before raising the error, default is 2 sec.

:return: stripped string from AS400 instance."""
self._key_event_setup(wait)
return self.ps.GetTextRect(startRow, startColumn, endRow, endColumn).encode("UTF-8")

def set_text(self, text, row, column, wait=60):
"""Set text to a specified location on AS400 screen.
:param text: string that needs to be set.
:param row: location of x axis.
:param column: location of y axis.

:return: None"""
self._key_event_setup()
self._key_event_setup(wait) #no tenia ningún parámetro
self.ps.SetText(text, row, column)

def send_keys(self, key):
def set_cursor(self, row, column, wait=60):
"""Set cursor to a specified location on AS400 screen.
:param row: location of x axis.
:param column: location of y axis.

:return: None"""
self._key_event_setup(wait) #no tenia ningún parámetro
self.ps.SetCursorPos(row, column)

def get_cursor_pos_row(self, wait=60):
"""Get cursor row on AS400 screen.

:return: Cursor row"""
self._key_event_setup(wait) #no tenia ningún parámetro
return self.ps.CursorPosRow

def get_cursor_pos_col(self, wait=60):
"""Get cursor row on AS400 screen.

:return: Cursor col"""
self._key_event_setup(wait) #no tenia ningún parámetro
return self.ps.CursorPosCol

def send_keys(self, key, wait=60):
"""Send keystrokes to AS400 screen.

:param key: Mnemonic keystrokes that need to be send to the session.
List of these keystrokes can be found at
https://ibm.co/31yC100

:return: None"""
self._key_event_setup()
self._key_event_setup(wait)
self.ps.SendKeys(key)

def wait(self, seconds):
Expand All @@ -98,6 +134,36 @@ def wait(self, seconds):
:param seconds: time in seconds to wait."""
self.ps.Wait(int(seconds * 1000))

def waitForCursor(self, row, column, seconds=60):
"""Wait for the cursor to be in a given position.
Afert the given seconds, timeout.

:param row: Row where the cursor should be.
:param column: Column where the cursor should be.
:param seconds: time in seconds to wait."""
return self.ps.WaitForCursor(row, column, int(seconds * 1000))

def waitForString(self, string, row, column, seconds=60):
"""Wait for the cursor to be in a given position.
Afert the given seconds, timeout.

:param row: Row where the cursor should be.
:param column: Column where the cursor should be.
:param seconds: time in seconds to wait."""
return self.ps.WaitForString(string, row, column, int(seconds * 1000))

def search_text(self, string='', dir=1, row=1, column=1, wait=1):
"""Searches for the first ocurrence of the string.

:param string: text to search.
:param dir: 1: forward, 2: backward.
:param row: row from where to start the search.
:param column: column from where to start the search.
:param second: wait time in second.

:return: None"""
self._key_event_setup(wait)
return self.ps.SearchText(string, dir, row, column)

class Screen:
"""Allow to create screen objects For AS400 session. Screen objects are
Expand Down