From 3a647e602c9f96364ace4b49efb06d51860c59f1 Mon Sep 17 00:00:00 2001 From: Alejandro Greppi Date: Fri, 7 Jul 2023 17:04:23 -0300 Subject: [PATCH 1/3] Added attribute wait to function _key_event_setup within function Instance.get_text Added attribute wait to function _key_event_setup within function Instance.send_keys Added functions set_cursor, waitForCursor, waitForString to Instance class --- ibm/core.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/ibm/core.py b/ibm/core.py index b03e312..440808d 100644 --- a/ibm/core.py +++ b/ibm/core.py @@ -71,17 +71,26 @@ def get_text(self, row, column, length=1, wait=2): self._key_event_setup(wait) return self.ps.GetText(row, column, length).encode("UTF-8").strip() - def set_text(self, text, row, column): + 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) 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) + self.ps.SetCursorPos(row, column) + + 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 +98,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 +107,23 @@ 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)) class Screen: """Allow to create screen objects For AS400 session. Screen objects are From c16329ff2b9a65a33f1e8fa839640ef292b462c5 Mon Sep 17 00:00:00 2001 From: Alejandro Greppi Date: Thu, 31 Aug 2023 15:43:15 -0300 Subject: [PATCH 2/3] feat: se agregan los comandos search_text y get_text_rect --- ibm/core.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/ibm/core.py b/ibm/core.py index 440808d..7c4b1de 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,7 +68,21 @@ 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. + + :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. @@ -78,7 +91,7 @@ def set_text(self, text, row, column, wait=60): :param column: location of y axis. :return: None""" - self._key_event_setup(wait) + self._key_event_setup(wait) #no tenia ningún parámetro self.ps.SetText(text, row, column) def set_cursor(self, row, column, wait=60): @@ -87,7 +100,7 @@ def set_cursor(self, row, column, wait=60): :param column: location of y axis. :return: None""" - self._key_event_setup(wait) + self._key_event_setup(wait) #no tenia ningún parámetro self.ps.SetCursorPos(row, column) def send_keys(self, key, wait=60): @@ -125,6 +138,19 @@ def waitForString(self, string, row, column, seconds=60): :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 descriptive object of AS400 that describe how the screen looks like. From af58fc3c8779525d097edfbaa68c88a0bfb2d98e Mon Sep 17 00:00:00 2001 From: Alejandro Greppi Date: Wed, 25 Oct 2023 21:01:40 -0300 Subject: [PATCH 3/3] =?UTF-8?q?feature:=20se=20agregan=20los=20m=C3=A9todo?= =?UTF-8?q?s=20get=5Fcursor=5Fpos=5Frow=20y=20col?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Estos métodos devuelven la fila y columna actual del cursor --- ibm/core.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ibm/core.py b/ibm/core.py index 7c4b1de..7d4a4da 100644 --- a/ibm/core.py +++ b/ibm/core.py @@ -103,6 +103,20 @@ def set_cursor(self, row, column, wait=60): 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.