diff --git a/ibm/core.py b/ibm/core.py index b03e312..7d4a4da 100644 --- a/ibm/core.py +++ b/ibm/core.py @@ -8,7 +8,6 @@ from .exceptions import InvalidSessionName, WindowNotFound - class Instance(object): """A wrapper to AS400 session. Primitive methods like read, write is provided.""" @@ -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. @@ -69,19 +68,56 @@ 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. @@ -89,7 +125,7 @@ def send_keys(self, key): https://ibm.co/31yC100 :return: None""" - self._key_event_setup() + self._key_event_setup(wait) self.ps.SendKeys(key) def wait(self, seconds): @@ -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