| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Fenrir TTY screen reader |
| 5 |
# By Chrys, Storm Dragon, and contributors. |
| 6 |
|
| 7 |
import re |
| 8 |
|
| 9 |
from fenrirscreenreader.core import debug |
| 10 |
|
| 11 |
|
| 12 |
class TableManager: |
| 13 |
def __init__(self): |
| 14 |
self.headLine = "" |
| 15 |
self.defaultSeparators = ["+", ";", "|", " "] |
| 16 |
self.noOfHeadLineColumns = 0 |
| 17 |
self.headColumnSep = "" |
| 18 |
self.rowColumnSep = "" |
| 19 |
self.headerRow = [] |
| 20 |
self.tableMode = False |
| 21 |
self.currentColumn = 0 |
| 22 |
self.currentRow = 0 |
| 23 |
|
| 24 |
def initialize(self, environment): |
| 25 |
self.env = environment |
| 26 |
|
| 27 |
def shutdown(self): |
| 28 |
pass |
| 29 |
|
| 30 |
def is_table_mode(self): |
| 31 |
return self.tableMode |
| 32 |
|
| 33 |
def set_table_mode(self, active): |
| 34 |
self.tableMode = active |
| 35 |
if not active: |
| 36 |
self.clear_header_row() |
| 37 |
else: |
| 38 |
# Initialize current position when entering table mode |
| 39 |
self.sync_table_position_from_cursor() |
| 40 |
|
| 41 |
def set_header_row_from_cursor(self): |
| 42 |
"""Set header row from current cursor position""" |
| 43 |
if not self.env["runtime"]["CursorManager"].is_review_mode(): |
| 44 |
return False |
| 45 |
|
| 46 |
cursor_pos = self.env["runtime"]["CursorManager"].get_review_or_text_cursor() |
| 47 |
if not cursor_pos: |
| 48 |
return False |
| 49 |
|
| 50 |
# Get the line text at cursor position |
| 51 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(cursor_pos["y"]) |
| 52 |
if not line_text: |
| 53 |
return False |
| 54 |
|
| 55 |
# Parse the line into columns |
| 56 |
self.headerRow = self.parse_line_into_columns(line_text) |
| 57 |
return len(self.headerRow) > 0 |
| 58 |
|
| 59 |
def clear_header_row(self): |
| 60 |
"""Clear the stored header row""" |
| 61 |
self.headerRow = [] |
| 62 |
|
| 63 |
def has_header_row(self): |
| 64 |
"""Check if header row is set""" |
| 65 |
return len(self.headerRow) > 0 |
| 66 |
|
| 67 |
def get_column_header(self, column_index): |
| 68 |
"""Get header for a specific column (0-based)""" |
| 69 |
if column_index < 0: |
| 70 |
return f"Column {column_index + 1}" |
| 71 |
|
| 72 |
if len(self.headerRow) == 0: |
| 73 |
return f"Column {column_index + 1}" |
| 74 |
|
| 75 |
if column_index >= len(self.headerRow): |
| 76 |
return f"Column {column_index + 1}" |
| 77 |
|
| 78 |
header = self.headerRow[column_index].strip() |
| 79 |
if not header: # If header is empty |
| 80 |
return f"Column {column_index + 1}" |
| 81 |
|
| 82 |
return header |
| 83 |
|
| 84 |
def get_column_count(self): |
| 85 |
"""Get number of columns based on header row""" |
| 86 |
return len(self.headerRow) |
| 87 |
|
| 88 |
def parse_line_into_columns(self, line_text): |
| 89 |
"""Parse a line into columns using various separators""" |
| 90 |
if not line_text: |
| 91 |
return [] |
| 92 |
|
| 93 |
# Try different separators in order of preference |
| 94 |
separators = [',', '|', ';', '\t'] |
| 95 |
|
| 96 |
for sep in separators: |
| 97 |
if sep in line_text: |
| 98 |
columns = line_text.split(sep) |
| 99 |
if len(columns) > 1: |
| 100 |
return columns |
| 101 |
|
| 102 |
# If no clear separator, try to detect aligned columns |
| 103 |
return self.detect_aligned_columns(line_text) |
| 104 |
|
| 105 |
def detect_aligned_columns(self, line_text): |
| 106 |
"""Detect columns in space-aligned text""" |
| 107 |
if not line_text: |
| 108 |
return [] |
| 109 |
|
| 110 |
# Split on multiple spaces (2 or more) |
| 111 |
parts = re.split(r' +', line_text) |
| 112 |
if len(parts) > 1: |
| 113 |
return parts |
| 114 |
|
| 115 |
# Fallback: treat as single column |
| 116 |
return [line_text] |
| 117 |
|
| 118 |
def get_cell_content(self, line_text, column_index): |
| 119 |
"""Get content of a specific cell in a line""" |
| 120 |
columns = self.parse_line_into_columns(line_text) |
| 121 |
if column_index < 0 or column_index >= len(columns): |
| 122 |
return "" |
| 123 |
return columns[column_index].strip() |
| 124 |
|
| 125 |
def get_table_cell_info(self, cursor_pos): |
| 126 |
"""Get table cell information for speech output""" |
| 127 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(cursor_pos["y"]) |
| 128 |
if not line_text: |
| 129 |
return None |
| 130 |
|
| 131 |
columns = self.parse_line_into_columns(line_text) |
| 132 |
if not columns: |
| 133 |
return None |
| 134 |
|
| 135 |
# Find which column we're in based on cursor x position |
| 136 |
column_index = self.get_column_index_from_x_position(line_text, cursor_pos["x"]) |
| 137 |
|
| 138 |
if column_index < 0 or column_index >= len(columns): |
| 139 |
return None |
| 140 |
|
| 141 |
# Use header if available, otherwise generic column name |
| 142 |
if self.has_header_row(): |
| 143 |
column_header = self.get_column_header(column_index) |
| 144 |
else: |
| 145 |
column_header = f"Column {column_index + 1}" |
| 146 |
|
| 147 |
return { |
| 148 |
'column_index': column_index, |
| 149 |
'column_header': column_header, |
| 150 |
'cell_content': columns[column_index].strip(), |
| 151 |
'total_columns': len(columns), |
| 152 |
'row_number': cursor_pos["y"] + 1 |
| 153 |
} |
| 154 |
|
| 155 |
def get_column_index_from_x_position(self, line_text, x_pos): |
| 156 |
"""Determine which column an x position falls into""" |
| 157 |
columns = self.parse_line_into_columns(line_text) |
| 158 |
if not columns: |
| 159 |
return 0 |
| 160 |
|
| 161 |
# Handle CSV/delimited text |
| 162 |
if ',' in line_text or '|' in line_text or ';' in line_text or '\t' in line_text: |
| 163 |
current_pos = 0 |
| 164 |
for i, column in enumerate(columns): |
| 165 |
column_end = current_pos + len(column) |
| 166 |
if current_pos <= x_pos <= column_end: |
| 167 |
return i |
| 168 |
current_pos = column_end + 1 # +1 for separator |
| 169 |
else: |
| 170 |
# Handle space-aligned text - find the column by position ranges |
| 171 |
current_pos = 0 |
| 172 |
for i, column in enumerate(columns): |
| 173 |
# Find where this column starts in the original text |
| 174 |
if i == 0: |
| 175 |
column_start = 0 |
| 176 |
else: |
| 177 |
# Find the column by searching from current position |
| 178 |
column_start = line_text.find(column.strip(), current_pos) |
| 179 |
if column_start == -1: |
| 180 |
column_start = current_pos |
| 181 |
|
| 182 |
column_end = column_start + len(column.strip()) |
| 183 |
if column_start <= x_pos <= column_end: |
| 184 |
return i |
| 185 |
current_pos = column_end |
| 186 |
|
| 187 |
# If past the end, return last column |
| 188 |
return len(columns) - 1 |
| 189 |
|
| 190 |
def sync_table_position_from_cursor(self): |
| 191 |
"""Sync internal table position from current cursor position""" |
| 192 |
if not self.env["runtime"]["CursorManager"].is_review_mode(): |
| 193 |
return |
| 194 |
|
| 195 |
cursor_pos = self.env["runtime"]["CursorManager"].get_review_or_text_cursor() |
| 196 |
if cursor_pos: |
| 197 |
old_column = self.currentColumn |
| 198 |
self.currentRow = cursor_pos["y"] |
| 199 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(cursor_pos["y"]) |
| 200 |
if line_text: |
| 201 |
self.currentColumn = self.get_column_index_from_x_position(line_text, cursor_pos["x"]) |
| 202 |
else: |
| 203 |
self.currentColumn = 0 |
| 204 |
|
| 205 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 206 |
f"TableManager sync: old_column={old_column}, new_column={self.currentColumn}, cursor_x={cursor_pos['x']}, cursor_y={cursor_pos['y']}", |
| 207 |
debug.DebugLevel.INFO |
| 208 |
) |
| 209 |
|
| 210 |
def move_to_next_column(self): |
| 211 |
"""Move to next column in table""" |
| 212 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 213 |
f"TableManager move_to_next_column: currentColumn={self.currentColumn}", |
| 214 |
debug.DebugLevel.INFO |
| 215 |
) |
| 216 |
|
| 217 |
if not self.env["runtime"]["CursorManager"].is_review_mode(): |
| 218 |
return None |
| 219 |
|
| 220 |
cursor_pos = self.env["runtime"]["CursorManager"].get_review_or_text_cursor() |
| 221 |
if not cursor_pos: |
| 222 |
return None |
| 223 |
|
| 224 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(cursor_pos["y"]) |
| 225 |
if not line_text: |
| 226 |
return None |
| 227 |
|
| 228 |
columns = self.parse_line_into_columns(line_text) |
| 229 |
if not columns: |
| 230 |
return None |
| 231 |
|
| 232 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 233 |
f"TableManager: line_text='{line_text}', columns={columns}, currentColumn={self.currentColumn}", |
| 234 |
debug.DebugLevel.INFO |
| 235 |
) |
| 236 |
|
| 237 |
# Don't sync from cursor position - maintain our own tracking |
| 238 |
# Check if we're already at the last column |
| 239 |
if self.currentColumn >= len(columns) - 1: |
| 240 |
# At end of line - return special indicator but keep position |
| 241 |
return {"at_end": True, "current_info": self.get_table_cell_info_by_indices(cursor_pos["y"], self.currentColumn)} |
| 242 |
|
| 243 |
# Move to next column |
| 244 |
self.currentColumn += 1 |
| 245 |
|
| 246 |
self.env["runtime"]["DebugManager"].write_debug_out( |
| 247 |
f"TableManager: moved to column {self.currentColumn}", |
| 248 |
debug.DebugLevel.INFO |
| 249 |
) |
| 250 |
|
| 251 |
# Return info for the new column without moving cursor position |
| 252 |
return self.get_table_cell_info_by_indices(cursor_pos["y"], self.currentColumn) |
| 253 |
|
| 254 |
def move_to_prev_column(self): |
| 255 |
"""Move to previous column in table""" |
| 256 |
if not self.env["runtime"]["CursorManager"].is_review_mode(): |
| 257 |
return None |
| 258 |
|
| 259 |
cursor_pos = self.env["runtime"]["CursorManager"].get_review_or_text_cursor() |
| 260 |
if not cursor_pos: |
| 261 |
return None |
| 262 |
|
| 263 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(cursor_pos["y"]) |
| 264 |
if not line_text: |
| 265 |
return None |
| 266 |
|
| 267 |
columns = self.parse_line_into_columns(line_text) |
| 268 |
if not columns: |
| 269 |
return None |
| 270 |
|
| 271 |
# Don't sync from cursor position - maintain our own tracking |
| 272 |
# Check if we're already at the first column |
| 273 |
if self.currentColumn <= 0: |
| 274 |
# At beginning of line - return special indicator but keep position |
| 275 |
return {"at_start": True, "current_info": self.get_table_cell_info_by_indices(cursor_pos["y"], self.currentColumn)} |
| 276 |
|
| 277 |
# Move to previous column |
| 278 |
self.currentColumn -= 1 |
| 279 |
|
| 280 |
# Return info for the new column without moving cursor position |
| 281 |
return self.get_table_cell_info_by_indices(cursor_pos["y"], self.currentColumn) |
| 282 |
|
| 283 |
def get_current_table_cell_info(self): |
| 284 |
"""Get current table cell info using internal position tracking""" |
| 285 |
if not self.env["runtime"]["CursorManager"].is_review_mode(): |
| 286 |
return None |
| 287 |
|
| 288 |
cursor_pos = self.env["runtime"]["CursorManager"].get_review_or_text_cursor() |
| 289 |
if not cursor_pos: |
| 290 |
return None |
| 291 |
|
| 292 |
return self.get_table_cell_info_by_indices(cursor_pos["y"], self.currentColumn) |
| 293 |
|
| 294 |
def get_table_cell_info_by_indices(self, row, column_index): |
| 295 |
"""Get table cell info for specific row and column indices""" |
| 296 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(row) |
| 297 |
if not line_text: |
| 298 |
return None |
| 299 |
|
| 300 |
columns = self.parse_line_into_columns(line_text) |
| 301 |
if not columns or column_index < 0 or column_index >= len(columns): |
| 302 |
return None |
| 303 |
|
| 304 |
# Always get column header (fallback to generic if needed) |
| 305 |
column_header = self.get_column_header(column_index) |
| 306 |
|
| 307 |
cell_content = columns[column_index].strip() |
| 308 |
if not cell_content: # Handle empty cells |
| 309 |
cell_content = "blank" |
| 310 |
|
| 311 |
return { |
| 312 |
'column_index': column_index, |
| 313 |
'column_header': column_header, |
| 314 |
'cell_content': cell_content, |
| 315 |
'total_columns': len(columns), |
| 316 |
'row_number': row + 1 |
| 317 |
} |
| 318 |
|
| 319 |
def get_column_start_position(self, line_text, column_index): |
| 320 |
"""Get the starting x position of a specific column""" |
| 321 |
columns = self.parse_line_into_columns(line_text) |
| 322 |
if not columns or column_index < 0 or column_index >= len(columns): |
| 323 |
return 0 |
| 324 |
|
| 325 |
# For CSV/delimited text - find the actual position in the original line |
| 326 |
if ',' in line_text or '|' in line_text or ';' in line_text or '\t' in line_text: |
| 327 |
# Determine the separator being used |
| 328 |
separator = ',' |
| 329 |
if '|' in line_text and line_text.count('|') > line_text.count(','): |
| 330 |
separator = '|' |
| 331 |
elif ';' in line_text and line_text.count(';') > line_text.count(','): |
| 332 |
separator = ';' |
| 333 |
elif '\t' in line_text: |
| 334 |
separator = '\t' |
| 335 |
|
| 336 |
# Find the position by splitting and calculating |
| 337 |
if column_index == 0: |
| 338 |
return 0 |
| 339 |
|
| 340 |
# Count characters up to the target column |
| 341 |
parts = line_text.split(separator) |
| 342 |
position = 0 |
| 343 |
for i in range(column_index): |
| 344 |
if i < len(parts): |
| 345 |
position += len(parts[i]) + 1 # +1 for separator |
| 346 |
return position |
| 347 |
else: |
| 348 |
# For space-aligned text, find the actual position of the column |
| 349 |
if column_index == 0: |
| 350 |
return 0 |
| 351 |
|
| 352 |
# Find the column text in the line |
| 353 |
target_text = columns[column_index].strip() |
| 354 |
search_start = 0 |
| 355 |
for i in range(column_index): |
| 356 |
prev_text = columns[i].strip() |
| 357 |
found_pos = line_text.find(prev_text, search_start) |
| 358 |
if found_pos != -1: |
| 359 |
search_start = found_pos + len(prev_text) |
| 360 |
|
| 361 |
column_pos = line_text.find(target_text, search_start) |
| 362 |
return column_pos if column_pos != -1 else search_start |
| 363 |
|
| 364 |
def is_cursor_within_current_cell(self, cursor_x, cursor_y): |
| 365 |
"""Check if the given cursor position is within the current table cell""" |
| 366 |
if not self.is_table_mode(): |
| 367 |
return False |
| 368 |
|
| 369 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(cursor_y) |
| 370 |
if not line_text: |
| 371 |
return False |
| 372 |
|
| 373 |
columns = self.parse_line_into_columns(line_text) |
| 374 |
if not columns or self.currentColumn < 0 or self.currentColumn >= len(columns): |
| 375 |
return False |
| 376 |
|
| 377 |
# Get the bounds of the current column |
| 378 |
column_start = self.get_column_start_position(line_text, self.currentColumn) |
| 379 |
column_text = columns[self.currentColumn] |
| 380 |
column_end = column_start + len(column_text) |
| 381 |
|
| 382 |
# Check if cursor is within the column bounds |
| 383 |
return column_start <= cursor_x < column_end |
| 384 |
|
| 385 |
def move_to_first_cell(self): |
| 386 |
"""Move to first cell in current row""" |
| 387 |
if not self.env["runtime"]["CursorManager"].is_review_mode(): |
| 388 |
return None |
| 389 |
|
| 390 |
cursor_pos = self.env["runtime"]["CursorManager"].get_review_or_text_cursor() |
| 391 |
if not cursor_pos: |
| 392 |
return None |
| 393 |
|
| 394 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(cursor_pos["y"]) |
| 395 |
if not line_text: |
| 396 |
return None |
| 397 |
|
| 398 |
columns = self.parse_line_into_columns(line_text) |
| 399 |
if not columns: |
| 400 |
return None |
| 401 |
|
| 402 |
# Set current column to first column |
| 403 |
self.currentColumn = 0 |
| 404 |
|
| 405 |
# Return info for the first column |
| 406 |
return self.get_table_cell_info_by_indices(cursor_pos["y"], 0) |
| 407 |
|
| 408 |
def move_to_last_cell(self): |
| 409 |
"""Move to last cell in current row""" |
| 410 |
if not self.env["runtime"]["CursorManager"].is_review_mode(): |
| 411 |
return None |
| 412 |
|
| 413 |
cursor_pos = self.env["runtime"]["CursorManager"].get_review_or_text_cursor() |
| 414 |
if not cursor_pos: |
| 415 |
return None |
| 416 |
|
| 417 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(cursor_pos["y"]) |
| 418 |
if not line_text: |
| 419 |
return None |
| 420 |
|
| 421 |
columns = self.parse_line_into_columns(line_text) |
| 422 |
if not columns: |
| 423 |
return None |
| 424 |
|
| 425 |
# Set current column to last column |
| 426 |
self.currentColumn = len(columns) - 1 |
| 427 |
|
| 428 |
# Return info for the last column |
| 429 |
return self.get_table_cell_info_by_indices(cursor_pos["y"], self.currentColumn) |
| 430 |
|
| 431 |
def move_to_first_char_in_cell(self): |
| 432 |
"""Move to first character in current cell""" |
| 433 |
if not self.env["runtime"]["CursorManager"].is_review_mode(): |
| 434 |
return None |
| 435 |
|
| 436 |
cursor_pos = self.env["runtime"]["CursorManager"].get_review_or_text_cursor() |
| 437 |
if not cursor_pos: |
| 438 |
return None |
| 439 |
|
| 440 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(cursor_pos["y"]) |
| 441 |
if not line_text: |
| 442 |
return None |
| 443 |
|
| 444 |
columns = self.parse_line_into_columns(line_text) |
| 445 |
if not columns or self.currentColumn < 0 or self.currentColumn >= len(columns): |
| 446 |
return None |
| 447 |
|
| 448 |
# Get column start position |
| 449 |
column_start = self.get_column_start_position(line_text, self.currentColumn) |
| 450 |
|
| 451 |
# Find first non-space character in the column |
| 452 |
column_text = columns[self.currentColumn] |
| 453 |
first_char_offset = len(column_text) - len(column_text.lstrip()) |
| 454 |
|
| 455 |
# Set cursor position to first character in cell |
| 456 |
new_x = column_start + first_char_offset |
| 457 |
self.env["runtime"]["CursorManager"].set_review_cursor_position(new_x, cursor_pos["y"]) |
| 458 |
|
| 459 |
# Get the character at the new position |
| 460 |
from fenrirscreenreader.utils import char_utils |
| 461 |
( |
| 462 |
self.env["screen"]["newCursorReview"]["x"], |
| 463 |
self.env["screen"]["newCursorReview"]["y"], |
| 464 |
curr_char, |
| 465 |
) = char_utils.get_current_char( |
| 466 |
new_x, |
| 467 |
cursor_pos["y"], |
| 468 |
self.env["screen"]["new_content_text"], |
| 469 |
) |
| 470 |
|
| 471 |
return { |
| 472 |
'cell_content': column_text.strip(), |
| 473 |
'column_header': self.get_column_header(self.currentColumn), |
| 474 |
'character': curr_char, |
| 475 |
'position': 'first' |
| 476 |
} |
| 477 |
|
| 478 |
def move_to_last_char_in_cell(self): |
| 479 |
"""Move to last character in current cell""" |
| 480 |
if not self.env["runtime"]["CursorManager"].is_review_mode(): |
| 481 |
return None |
| 482 |
|
| 483 |
cursor_pos = self.env["runtime"]["CursorManager"].get_review_or_text_cursor() |
| 484 |
if not cursor_pos: |
| 485 |
return None |
| 486 |
|
| 487 |
line_text = self.env["runtime"]["ScreenManager"].get_line_text(cursor_pos["y"]) |
| 488 |
if not line_text: |
| 489 |
return None |
| 490 |
|
| 491 |
columns = self.parse_line_into_columns(line_text) |
| 492 |
if not columns or self.currentColumn < 0 or self.currentColumn >= len(columns): |
| 493 |
return None |
| 494 |
|
| 495 |
# Get column start position |
| 496 |
column_start = self.get_column_start_position(line_text, self.currentColumn) |
| 497 |
column_text = columns[self.currentColumn] |
| 498 |
|
| 499 |
# Find last non-space character in the column |
| 500 |
trimmed_text = column_text.rstrip() |
| 501 |
if not trimmed_text: |
| 502 |
# If empty cell, go to column start |
| 503 |
new_x = column_start |
| 504 |
else: |
| 505 |
# Find the position of the last character |
| 506 |
new_x = column_start + len(trimmed_text) - 1 |
| 507 |
|
| 508 |
# Set cursor position to last character in cell |
| 509 |
self.env["runtime"]["CursorManager"].set_review_cursor_position(new_x, cursor_pos["y"]) |
| 510 |
|
| 511 |
# Get the character at the new position |
| 512 |
from fenrirscreenreader.utils import char_utils |
| 513 |
( |
| 514 |
self.env["screen"]["newCursorReview"]["x"], |
| 515 |
self.env["screen"]["newCursorReview"]["y"], |
| 516 |
curr_char, |
| 517 |
) = char_utils.get_current_char( |
| 518 |
new_x, |
| 519 |
cursor_pos["y"], |
| 520 |
self.env["screen"]["new_content_text"], |
| 521 |
) |
| 522 |
|
| 523 |
return { |
| 524 |
'cell_content': column_text.strip(), |
| 525 |
'column_header': self.get_column_header(self.currentColumn), |
| 526 |
'character': curr_char, |
| 527 |
'position': 'last' |
| 528 |
} |
| 529 |
|
| 530 |
def reset_table_mode(self): |
| 531 |
self.set_head_line() |
| 532 |
|
| 533 |
def set_head_column_sep(self, columnSep=""): |
| 534 |
self.headColumnSep = columnSep |
| 535 |
if columnSep == "": |
| 536 |
self.noOfHeadLineColumns = 0 |
| 537 |
else: |
| 538 |
self.coun_no_of_head_columns() |
| 539 |
|
| 540 |
def coun_no_of_head_columns(self): |
| 541 |
if self.headLine and self.headColumnSep: |
| 542 |
self.noOfHeadLineColumns = len(self.headLine.split(self.headColumnSep)) |
| 543 |
|
| 544 |
def search_for_head_column_sep(self, headLine): |
| 545 |
"""Find the most likely column separator in a header line""" |
| 546 |
separators = [',', '|', ';', '\t'] |
| 547 |
|
| 548 |
for sep in separators: |
| 549 |
if sep in headLine: |
| 550 |
return sep |
| 551 |
|
| 552 |
# Check for multiple spaces (aligned columns) |
| 553 |
if ' ' in headLine: |
| 554 |
return ' ' |
| 555 |
|
| 556 |
return "" |
| 557 |
|
| 558 |
def set_row_column_sep(self, columnSep=""): |
| 559 |
self.rowColumnSep = columnSep |
| 560 |
|
| 561 |
def set_head_line(self, headLine=""): |
| 562 |
self.set_head_column_sep() |
| 563 |
self.set_row_column_sep() |
| 564 |
if headLine != "": |
| 565 |
sep = self.search_for_head_column_sep(headLine) |
| 566 |
if sep != "": |
| 567 |
self.headLine = headLine |
| 568 |
self.set_head_column_sep(sep) |