ITK-dev-shared-components 0.0.5__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {ITK_dev_shared_components-0.0.5/ITK_dev_shared_components.egg-info → itk_dev_shared_components-1.0.0}/PKG-INFO +7 -2
  2. itk_dev_shared_components-1.0.0/itk_dev_shared_components/graph/authentication.py +63 -0
  3. itk_dev_shared_components-1.0.0/itk_dev_shared_components/graph/mail.py +317 -0
  4. itk_dev_shared_components-1.0.0/itk_dev_shared_components/sap/__init__.py +0 -0
  5. itk_dev_shared_components-1.0.0/itk_dev_shared_components/sap/gridview_util.py +168 -0
  6. {ITK_dev_shared_components-0.0.5/ITK_dev_shared_components/SAP → itk_dev_shared_components-1.0.0/itk_dev_shared_components/sap}/multi_session.py +41 -25
  7. {ITK_dev_shared_components-0.0.5/ITK_dev_shared_components/SAP → itk_dev_shared_components-1.0.0/itk_dev_shared_components/sap}/opret_kundekontakt.py +14 -22
  8. itk_dev_shared_components-1.0.0/itk_dev_shared_components/sap/sap_login.py +186 -0
  9. {ITK_dev_shared_components-0.0.5/ITK_dev_shared_components/SAP → itk_dev_shared_components-1.0.0/itk_dev_shared_components/sap}/sap_util.py +1 -11
  10. itk_dev_shared_components-1.0.0/itk_dev_shared_components/sap/tree_util.py +71 -0
  11. {ITK_dev_shared_components-0.0.5 → itk_dev_shared_components-1.0.0/itk_dev_shared_components.egg-info}/PKG-INFO +7 -2
  12. itk_dev_shared_components-1.0.0/itk_dev_shared_components.egg-info/SOURCES.txt +19 -0
  13. itk_dev_shared_components-1.0.0/itk_dev_shared_components.egg-info/requires.txt +5 -0
  14. itk_dev_shared_components-1.0.0/itk_dev_shared_components.egg-info/top_level.txt +1 -0
  15. {ITK_dev_shared_components-0.0.5 → itk_dev_shared_components-1.0.0}/pyproject.toml +6 -3
  16. ITK_dev_shared_components-0.0.5/ITK_dev_shared_components/SAP/gridview_util.py +0 -126
  17. ITK_dev_shared_components-0.0.5/ITK_dev_shared_components/SAP/sap_login.py +0 -93
  18. ITK_dev_shared_components-0.0.5/ITK_dev_shared_components/SAP/tree_util.py +0 -71
  19. ITK_dev_shared_components-0.0.5/ITK_dev_shared_components.egg-info/SOURCES.txt +0 -16
  20. ITK_dev_shared_components-0.0.5/ITK_dev_shared_components.egg-info/requires.txt +0 -2
  21. ITK_dev_shared_components-0.0.5/ITK_dev_shared_components.egg-info/top_level.txt +0 -1
  22. {ITK_dev_shared_components-0.0.5 → itk_dev_shared_components-1.0.0}/LICENSE +0 -0
  23. {ITK_dev_shared_components-0.0.5 → itk_dev_shared_components-1.0.0}/README.md +0 -0
  24. {ITK_dev_shared_components-0.0.5/ITK_dev_shared_components/SAP → itk_dev_shared_components-1.0.0/itk_dev_shared_components}/__init__.py +0 -0
  25. {ITK_dev_shared_components-0.0.5/ITK_dev_shared_components → itk_dev_shared_components-1.0.0/itk_dev_shared_components/graph}/__init__.py +0 -0
  26. {ITK_dev_shared_components-0.0.5/ITK_dev_shared_components.egg-info → itk_dev_shared_components-1.0.0/itk_dev_shared_components.egg-info}/dependency_links.txt +0 -0
  27. {ITK_dev_shared_components-0.0.5 → itk_dev_shared_components-1.0.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
- Name: ITK-dev-shared-components
3
- Version: 0.0.5
2
+ Name: itk_dev_shared_components
3
+ Version: 1.0.0
4
4
  Summary: Shared components to use in RPA projects
5
5
  Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
6
6
  Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
@@ -11,6 +11,11 @@ Classifier: Operating System :: Microsoft :: Windows
11
11
  Requires-Python: >=3.7
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
+ Requires-Dist: pywin32>=306
15
+ Requires-Dist: selenium>=4.10.0
16
+ Requires-Dist: msal>=1.24.1
17
+ Requires-Dist: requests>=2.31.0
18
+ Requires-Dist: beautifulsoup4>=4.12.2
14
19
 
15
20
  # itk-dev-shared-components
16
21
 
@@ -0,0 +1,63 @@
1
+ """This module is responsible for authenticating a Microsoft Graph
2
+ connection."""
3
+
4
+ import msal
5
+
6
+ # pylint: disable-next=too-few-public-methods
7
+ class GraphAccess:
8
+ """An object that handles access to the Graph api.
9
+ This object should not be created directly but instead
10
+ using one of the authorize methods in the graph.authentication module.
11
+ """
12
+ def __init__(self, app: msal.PublicClientApplication, scopes: list[str]) -> str:
13
+ self.app = app
14
+ self.scopes = scopes
15
+
16
+ def get_access_token(self):
17
+ """Get the access token to Graph.
18
+ This function automatically reuses an existing token
19
+ or refreshes an expired one.
20
+
21
+ Raises:
22
+ RuntimeError: If the access token couldn't be acquired.
23
+
24
+ Returns:
25
+ str: The Graph access token.
26
+ """
27
+ account = self.app.get_accounts()[0]
28
+ token = self.app.acquire_token_silent(self.scopes, account)
29
+
30
+ if "access_token" in token:
31
+ return token['access_token']
32
+
33
+ if 'error_description' in token:
34
+ raise RuntimeError(f"Token could not be acquired. {token['error_description']}")
35
+
36
+ raise RuntimeError("Something went wrong. No error description was returned from Graph.")
37
+
38
+
39
+ def authorize_by_username_password(username: str, password: str, *, client_id: str, tenant_id: str) -> GraphAccess:
40
+ """Get a bearer token for the given user.
41
+ This is used in most other Graph API calls.
42
+
43
+ Args:
44
+ username: The username of the user (email address).
45
+ password: The password of the user.
46
+ client_id: The Graph API client id in 8-4-4-12 format.
47
+ tenant_id: The Graph API tenant id in 8-4-4-12 format.
48
+
49
+ Returns:
50
+ GraphAccess: The GraphAccess object used to authorize Graph access.
51
+ """
52
+ authority = f"https://login.microsoftonline.com/{tenant_id}"
53
+ scopes = ["https://graph.microsoft.com/.default"]
54
+
55
+ app = msal.PublicClientApplication(client_id, authority=authority)
56
+ app.acquire_token_by_username_password(username, password, scopes)
57
+
58
+ graph_access = GraphAccess(app, scopes)
59
+
60
+ # Test connection
61
+ graph_access.get_access_token()
62
+
63
+ return graph_access
@@ -0,0 +1,317 @@
1
+ """This module is responsible for accessing emails using the Microsoft Graph API."""
2
+
3
+ from dataclasses import dataclass, field
4
+ import io
5
+
6
+ import requests
7
+ from bs4 import BeautifulSoup
8
+
9
+ from itk_dev_shared_components.graph.authentication import GraphAccess
10
+
11
+
12
+ @dataclass
13
+ # pylint: disable-next=too-many-instance-attributes
14
+ class Email:
15
+ """A class representing an email."""
16
+ user: str
17
+ id: str = field(repr=False)
18
+ received_time: str
19
+ sender: str
20
+ receivers: list[str]
21
+ subject: str
22
+ body: str = field(repr=False)
23
+ body_type: str
24
+ has_attachments: bool
25
+
26
+ def get_text(self) -> str:
27
+ """Get the body as plain text.
28
+ If the body is html it's converted to plaintext.
29
+ If the body is text it's returned as is.
30
+
31
+ Returns:
32
+ str: The body as plain text.
33
+ """
34
+ if self.body_type == 'html':
35
+ soup = BeautifulSoup(self.body, "html.parser")
36
+ return soup.get_text().strip()
37
+
38
+ return self.body
39
+
40
+
41
+ @dataclass
42
+ class Attachment:
43
+ """A dataclass representing an email Attachment.
44
+ It contains the graph id, name and size of the attachment.
45
+ To get the actual data call graph.mail.get_attachment_data.
46
+ """
47
+ email: Email = field(repr=False)
48
+ id: str = field(repr=False)
49
+ name: str
50
+ size: int
51
+
52
+
53
+ def get_emails_from_folder(user: str, folder_path: str, graph_access: GraphAccess) -> tuple[Email]:
54
+ """Get all emails from the specified user and folder.
55
+ You need to authorize against Graph to get the GraphAccess before using this function
56
+ see the graph.authentication module.
57
+
58
+ Args:
59
+ user: The user who owns the folder.
60
+ folder_path: The absolute path of the folder e.g. 'Inbox/Economy/May'
61
+ graph_access: The GraphAccess object used to authenticate.
62
+
63
+ Returns:
64
+ tuple[Email]: The emails from the given folder.
65
+ """
66
+ folder_id = get_folder_id_from_path(user, folder_path, graph_access)
67
+
68
+ endpoint = f"https://graph.microsoft.com/v1.0/users/{user}/mailFolders/{folder_id}/messages?$top=1000"
69
+
70
+ response = _get_request(endpoint, graph_access)
71
+ emails_raw = response.json()['value']
72
+
73
+ return _unpack_email_response(user, emails_raw)
74
+
75
+
76
+ def get_email_as_mime(email: Email, graph_access: GraphAccess) -> io.BytesIO:
77
+ """Get an email as a file-like object in MIME format.
78
+
79
+ Args:
80
+ email: The email to get as MIME.
81
+ graph_access: The GraphAccess object used to authenticate.
82
+
83
+ Returns:
84
+ io.BytesIO: A file-like object of the MIME file.
85
+ """
86
+ endpoint = f"https://graph.microsoft.com/v1.0/users/{email.user}/messages/{email.id}/$value"
87
+ response = _get_request(endpoint, graph_access)
88
+ data = response.content
89
+ return io.BytesIO(data)
90
+
91
+
92
+ def get_folder_id_from_path(user: str, folder_path: str, graph_access: GraphAccess) -> str:
93
+ """Get the Graph id of a folder based on the path of the folder.
94
+ You need to authorize against Graph to get the GraphAccess before using this function
95
+ see the graph.authentication module.
96
+
97
+ Args:
98
+ user: The user who owns the folder.
99
+ folder_path: The absolute path of the folder e.g. 'Inbox/Economy/May'
100
+ graph_access: The GraphAccess object used to authenticate.
101
+
102
+ Raises:
103
+ ValueError: If a folder in the path can't be found.
104
+
105
+ Returns:
106
+ str: The UUID of the folder in Graph.
107
+ """
108
+ folders = folder_path.split("/")
109
+ main_folder = folders[0]
110
+ child_folders = folders[1:]
111
+
112
+ folder_id = None
113
+
114
+ # Get main folder
115
+ endpoint = f"https://graph.microsoft.com/v1.0/users/{user}/mailFolders"
116
+ response = _get_request(endpoint, graph_access).json()
117
+ folder_id = _find_folder(response, main_folder)
118
+ if folder_id is None:
119
+ raise ValueError(f"Top level folder '{main_folder}' was not found for user '{user}'.")
120
+
121
+ # Get child folders
122
+ for child_folder in child_folders:
123
+ endpoint = f"https://graph.microsoft.com/v1.0/users/{user}/mailFolders/{folder_id}/childFolders"
124
+ response = _get_request(endpoint, graph_access).json()
125
+ folder_id = _find_folder(response, child_folder)
126
+ if folder_id is None:
127
+ raise ValueError(f"Child folder '{child_folder}' not found under '{main_folder}' for user '{user}'.")
128
+
129
+ return folder_id
130
+
131
+
132
+ def list_email_attachments(email: Email, graph_access: GraphAccess) -> tuple[Attachment]:
133
+ """List all attachments of the given email. This function only gets the id, name and size
134
+ of the attachment. Use get_attachment_data to get the actual data of an attachment.
135
+
136
+ Args:
137
+ email: The email which attachments to list.
138
+ graph_access: The GraphAccess object used to authenticate.
139
+
140
+ Returns:
141
+ tuple[Attachment]: A tuple of Attachment objects describing the attachments.
142
+ """
143
+ endpoint = f"https://graph.microsoft.com/v1.0/users/{email.user}/messages/{email.id}/attachments?$select=name,size,id"
144
+ response = _get_request(endpoint, graph_access).json()
145
+
146
+ attachments = []
147
+ for att in response['value']:
148
+ attachments.append(Attachment(email, att['id'], att['name'], att['size']))
149
+
150
+ return tuple(attachments)
151
+
152
+
153
+ def get_attachment_data(attachment: Attachment, graph_access: GraphAccess) -> io.BytesIO:
154
+ """Get a file-like object representing the attachment.
155
+
156
+ Args:
157
+ attachment: The attachment to get.
158
+ graph_access: The GraphAccess object used to authenticate.
159
+
160
+ Returns:
161
+ io.BytesIO: A file-like object representing the attachment.
162
+ """
163
+ email = attachment.email
164
+ endpoint = f"https://graph.microsoft.com/v1.0/users/{email.user}/messages/{email.id}/attachments/{attachment.id}/$value"
165
+ response = _get_request(endpoint, graph_access)
166
+ data_bytes = response.content
167
+ return io.BytesIO(data_bytes)
168
+
169
+
170
+ def move_email(email: Email, folder_path: str, graph_access: GraphAccess, *, well_known_folder: bool=False) -> None:
171
+ """Move an email to another folder under the same user.
172
+ If well_known_folder is true, the folder path is assumed to be a well defined folder.
173
+ See https://learn.microsoft.com/en-us/graph/api/resources/mailfolder?view=graph-rest-1.0
174
+ for a list of well defined folder names.
175
+
176
+ Args:
177
+ email: The email to move.
178
+ folder_path: The absolute path to the new folder. E.g. 'Inbox/Economy/May'
179
+ graph_access: The GraphAccess object used to authenticate.
180
+ well_known_folder: Whether the path is a 'well known folder'. Defaults to False.
181
+ """
182
+ if well_known_folder:
183
+ folder_id = folder_path
184
+ else:
185
+ folder_id = get_folder_id_from_path(email.user, folder_path, graph_access)
186
+
187
+ endpoint = f"https://graph.microsoft.com/v1.0/users/{email.user}/messages/{email.id}/move"
188
+
189
+ token = graph_access.get_access_token()
190
+ headers = {
191
+ 'Authorization': f"Bearer {token}",
192
+ 'Content-Type': "application/json"
193
+ }
194
+
195
+ body = {
196
+ 'destinationId': folder_id
197
+ }
198
+
199
+ response = requests.post(
200
+ url=endpoint,
201
+ headers=headers,
202
+ json=body,
203
+ timeout=30
204
+ )
205
+ response.raise_for_status()
206
+
207
+ new_id = response.json()['id']
208
+ email.id = new_id
209
+
210
+
211
+ def delete_email(email: Email, graph_access: GraphAccess, *, permanent: bool=False) -> None:
212
+ """Delete an email from the mailbox.
213
+ If permanent is true the email is completely removed from the user's mailbox.
214
+ If permanent is false the email is instead moved to the Deleted Items folder.
215
+
216
+ Args:
217
+ email: The email to delete.
218
+ graph_access: The GraphAccess object used to authenticate.
219
+ permanent: Whether to permanently remove the email or not. Defaults to False.
220
+ """
221
+ if permanent:
222
+ endpoint = f"https://graph.microsoft.com/v1.0/users/{email.user}/messages/{email.id}"
223
+
224
+ token = graph_access.get_access_token()
225
+ headers = {'Authorization': f"Bearer {token}"}
226
+
227
+ response = requests.delete(
228
+ url=endpoint,
229
+ headers=headers,
230
+ timeout=30
231
+ )
232
+ response.raise_for_status()
233
+ else:
234
+ move_email(email, "deleteditems", graph_access, well_known_folder=True)
235
+
236
+
237
+ def _find_folder(response: dict, target_folder: str) -> str:
238
+ """Find the target folder in
239
+
240
+ Args:
241
+ response: The json dict of the HTTP response.
242
+ target_folder: The folder to find.
243
+
244
+ Returns:
245
+ str: The id of the target folder.
246
+ """
247
+ for g_folder in response['value']:
248
+ if g_folder['displayName'] == target_folder:
249
+ return g_folder['id']
250
+ return None
251
+
252
+
253
+ def _unpack_email_response(user: str, emails_raw: list[dict[str, str]]) -> tuple[Email]:
254
+ """Unpack a json HTTP response and create a list of Email objects.
255
+
256
+ Args:
257
+ user: The user who owns the email folder.
258
+ json: The json dictionary created by response.json().
259
+
260
+ Returns:
261
+ tuple[Email]: A tuple of Email objects.
262
+ """
263
+ emails = []
264
+
265
+ for email in emails_raw:
266
+ mail_id = email['id']
267
+ received_time = email['receivedDateTime']
268
+ sender = email['from']['emailAddress']['address']
269
+ receivers = [r['emailAddress']['address'] for r in email['toRecipients']]
270
+ subject = email['subject']
271
+ body = email['body']['content']
272
+ body_type = email['body']['contentType']
273
+ has_attachments = email['hasAttachments']
274
+
275
+ emails.append(
276
+ Email(
277
+ user,
278
+ mail_id,
279
+ received_time,
280
+ sender,
281
+ receivers,
282
+ subject,
283
+ body,
284
+ body_type,
285
+ has_attachments
286
+ )
287
+ )
288
+
289
+ return tuple(emails)
290
+
291
+
292
+ def _get_request(endpoint: str, graph_access: GraphAccess) -> requests.models.Response:
293
+ """Sends a get request to the given Graph endpoint using the GraphAccess
294
+ and returns the json object of the response.
295
+
296
+ Args:
297
+ endpoint: The URL of the Graph endpoint.
298
+ graph_access: The GraphAccess object used to authenticate.
299
+ timeout: Timeout in seconds of the HTTP request. Defaults to 10.
300
+
301
+ Returns:
302
+ Response: The response object of the GET request.
303
+
304
+ Raises:
305
+ HTTPError: Any errors raised while performing GET request.
306
+ """
307
+ token = graph_access.get_access_token()
308
+ headers = {'Authorization': f"Bearer {token}"}
309
+
310
+ response = requests.get(
311
+ endpoint,
312
+ headers=headers,
313
+ timeout=30
314
+ )
315
+ response.raise_for_status()
316
+
317
+ return response
@@ -0,0 +1,168 @@
1
+ """This module provides static functions to perform common tasks with SAP GuiGridView COM objects."""
2
+
3
+ def scroll_entire_table(grid_view, return_to_top=False) -> None:
4
+ """This function scrolls through the entire table to load all cells.
5
+
6
+ Args:
7
+ grid_view: A SAP GuiGridView object.
8
+ return_to_top: Whether to return the table to the first row after scrolling. Defaults to False.
9
+ """
10
+ if grid_view.RowCount == 0 or grid_view.VisibleRowCount == 0:
11
+ return
12
+
13
+ for i in range(0, grid_view.RowCount, grid_view.VisibleRowCount):
14
+ grid_view.FirstVisibleRow = i
15
+
16
+ if return_to_top:
17
+ grid_view.FirstVisibleRow = 0
18
+
19
+
20
+ def get_all_rows(grid_view, pre_load=True) -> tuple[tuple[str]]:
21
+ """Get all values from a table and return them in a 2D tuple.
22
+
23
+ Args:
24
+ grid_view: A SAP GuiGridView object.
25
+ pre_load: Whether to first scroll through the table to load all values.
26
+ If a row hasn't been loaded before reading, the row data will be empty.
27
+
28
+ Returns:
29
+ tuple[tuple[str]]: A 2D tuple of all cell values in the gridview.
30
+ """
31
+
32
+ if pre_load:
33
+ scroll_entire_table(grid_view, True)
34
+
35
+ columns = grid_view.ColumnOrder
36
+ row_count = grid_view.RowCount
37
+
38
+ output = []
39
+
40
+ for r in range(row_count):
41
+ row_data = []
42
+ for c in columns:
43
+ v = grid_view.GetCellValue(r, c)
44
+ row_data.append(v)
45
+
46
+ output.append(tuple(row_data))
47
+
48
+ return tuple(output)
49
+
50
+
51
+ def get_row(grid_view, row:int, scroll_to_row=False) -> tuple[str]:
52
+ """Returns the data of a single row.
53
+
54
+ Args:
55
+ grid_view: A SAP GuiGridView object.
56
+ row: The zero-based index of the row.
57
+ scroll_to_row: Whether to scroll to the row before reading the data.
58
+ This ensures the data of the row has been loaded before reading.
59
+
60
+ Returns:
61
+ tuple[str]: A tuple of the row's data.
62
+ """
63
+
64
+ if scroll_to_row:
65
+ grid_view.FirstVisibleRow = row
66
+
67
+ row_data = []
68
+ for c in grid_view.ColumnOrder:
69
+ v = grid_view.GetCellValue(row, c)
70
+ row_data.append(v)
71
+ return tuple(row_data)
72
+
73
+
74
+ def iterate_rows(grid_view) -> tuple[str]:
75
+ """This generator yields each row of the table in order.
76
+ This is preferable to loading all rows as this will only load a row when it's needed.
77
+ As a side effect this function scrolls the yielded row into view, so the
78
+ table doesn't need to be pre-loaded before calling this function.
79
+
80
+ Args:
81
+ grid_view: A SAP GuiGridView object.
82
+
83
+ Yields:
84
+ tuple[str]: A tuple of the next row's data.
85
+ """
86
+
87
+ row = 0
88
+ while row < grid_view.RowCount:
89
+ # Only scroll when row isn't visible
90
+ if not grid_view.FirstVisibleRow <= row <= grid_view.FirstVisibleRow + grid_view.VisibleRowCount-1:
91
+ grid_view.FirstVisibleRow = row
92
+
93
+ yield get_row(grid_view, row)
94
+ row += 1
95
+
96
+
97
+ def get_column_titles(grid_view) -> tuple[str]:
98
+ """Get the column titles of the table instead of the column ids.
99
+ To get the column ids use grid_view.ColumnOrder.
100
+
101
+ Args:
102
+ grid_view: A SAP GuiGridView object.
103
+
104
+ Returns:
105
+ tuple[str]: A tuple of the gridview's column titles.
106
+ """
107
+
108
+ return tuple(grid_view.GetColumnTitles(c)[0] for c in grid_view.ColumnOrder)
109
+
110
+
111
+ def find_row_index_by_value(grid_view, column:str, value:str) -> int:
112
+ """Find the index of the first row where the given column's value
113
+ matches the given value. Returns -1 if no row is found.
114
+
115
+ Args:
116
+ grid_view: A SAP GuiGridView object.
117
+ column: The id of the column.
118
+ value: The value to search for.
119
+
120
+ Raises:
121
+ ValueError: If the gridview doesn't contain a column with the given id.
122
+
123
+ Returns:
124
+ int: The index of the first row which column value matches the given value.
125
+ """
126
+
127
+ if column not in grid_view.ColumnOrder:
128
+ raise ValueError(f"Column '{column}' not in grid_view")
129
+
130
+ for row in range(grid_view.RowCount):
131
+ # Only scroll when row isn't visible
132
+ if not grid_view.FirstVisibleRow <= row <= grid_view.FirstVisibleRow + grid_view.VisibleRowCount-1:
133
+ grid_view.FirstVisibleRow = row
134
+
135
+ if grid_view.GetCellValue(row, column) == value:
136
+ return row
137
+
138
+ return -1
139
+
140
+ def find_all_row_indices_by_value(grid_view, column:str, value:str) -> list[int]:
141
+ """Find all indices of the rows where the given column's value
142
+ match the given value. Returns an empty list if no row is found.
143
+
144
+ Args:
145
+ grid_view (_type_): A SAP GuiGridView object.
146
+ column (str): The name of the column whose value to check.
147
+ value (str): The value to search for.
148
+
149
+ Raises:
150
+ ValueError: If the column name doesn't exist in the grid view.
151
+
152
+ Returns:
153
+ list[int]: A list of row indices where the value matches.
154
+ """
155
+ if column not in grid_view.ColumnOrder:
156
+ raise ValueError(f"Column '{column}' not in grid_view")
157
+
158
+ rows = []
159
+
160
+ for row in range(grid_view.RowCount):
161
+ # Only scroll when row isn't visible
162
+ if not grid_view.FirstVisibleRow <= row <= grid_view.FirstVisibleRow + grid_view.VisibleRowCount-1:
163
+ grid_view.FirstVisibleRow = row
164
+
165
+ if grid_view.GetCellValue(row, column) == value:
166
+ rows.append(row)
167
+
168
+ return rows