ragardner / tksheet

Python tkinter table widget for displaying tabular data
https://pypi.org/project/tksheet/
MIT License
408 stars 50 forks source link

Dropdown menu fails to open if some rows are hidden #203

Closed egoldinInt closed 1 year ago

egoldinInt commented 1 year ago

Set up

I have a dataset consisting of 49 rows and 2 columns. The first column has a dropdown menu in rows: [10, 14, 20, 25, 26, 27, 29, 30, 32, 33, 37, 38, 40, 42, 45, 48]. Dropdowns are set by:

def _set_dropdowns(self):
        for row, data in enumerate(self.data):
            options = self._params[data[0]]['options']
            if len(options) > 0:
                self.create_dropdown(r=row,
                                     c=1,
                                     values=options,
                                     validate_input=False,
                                     selection_function=self.check_default)

Issue description

When rows {6, 7, 8, 9, 10, 12, 14, 15, 17, 19, 20, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 41, 43, 45, 46, 47, 48} are hidden by hide_advanced:

def hide_advanced(self):
        rows = set(self.data.index([k, v]) for k, v in self.data if k in self._settings.advanced_params
                   and v == self.default_values.get(k)) # hide rows where Parameter is advanced and value is default

        self.hide_rows(rows)
        self.redraw()

The remaining rows with dropdowns are fail to be open due to:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "C:\Users\egoldin\AppData\Roaming\Python\Python310\site-packages\tksheet\_tksheet_main_table.py", line 3211, in b1_release
    self.open_cell(event)
  File "C:\Users\egoldin\AppData\Roaming\Python\Python310\site-packages\tksheet\_tksheet_main_table.py", line 6093, in open_cell
    self.open_dropdown_window(r, c, event=event)
  File "C:\Users\egoldin\AppData\Roaming\Python\Python310\site-packages\tksheet\_tksheet_main_table.py", line 7062, in open_dropdown_window
    win_h, anchor = self.get_dropdown_height_anchor(datarn, datacn)
  File "C:\Users\egoldin\AppData\Roaming\Python\Python310\site-packages\tksheet\_tksheet_main_table.py", line 7035, in get_dropdown_height_anchor
    space_bot = self.get_space_bot(datarn, text_editor_h)
  File "C:\Users\egoldin\AppData\Roaming\Python\Python310\site-packages\tksheet\_tksheet_main_table.py", line 7010, in get_space_bot
    win_h = int(self.canvasy(0) + self.winfo_height() - self.row_positions[r + 1])
IndexError: list index out of range
ragardner commented 1 year ago

Thank you very much for your report, it is indeed a bug and I will get back to you when a new version with a fix is released, it shouldn't be too long

ragardner commented 1 year ago

It should be fixed in version 6.2.9, thanks again for reporting this and let me know if you have any further issues