Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with set_sheet_data #201

Closed
mithoon19 opened this issue Oct 25, 2023 · 6 comments
Closed

Issue with set_sheet_data #201

mithoon19 opened this issue Oct 25, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@mithoon19
Copy link

Hello, good day.

First of all, Thank you for your amazing work.

I have a table and I keep refreshing it with new data. I use set_sheet_data to update data in table. I use below code to update sheet.

self.sheet.set_sheet_data(data=newdata, reset_col_positions=False)

Above code works most of the time. But, sometimes, I get below error and after which new values does not reflect automatically in my table. Table data gets updated with new values but does not get displayed. New updated values are displayed only after I click some cell.

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\catuser\AppData\Local\Programs\Python\Python310\lib\tkinter_init_.py", line 1921, in call
return self.func(*args)
File "C:\Users\catuser\AppData\Local\Programs\Python\Python310\lib\tkinter_init_.py", line 839, in callit
func(*args)
File "C:\Users\catuser\OneDrive\proj\lib\site-packages\tksheet_tksheet.py", line 383, in after_redraw
self.MT.main_table_redraw_grid_and_text(redraw_header=redraw_header, redraw_row_index=redraw_row_index)
File "C:\Users\catuser\OneDrive\proj\lib\site-packages\tksheet_tksheet_main_table.py", line 5461, in main_table_redraw_grid_and_text
self.CH.redraw_grid_and_text(
File "C:\Users\catuser\OneDrive\proj\lib\site-packages\tksheet_tksheet_column_headers.py", line 1626, in redraw_grid_and_text
iid, showing = self.hidd_text[k].pop()
KeyError: 'pop from an empty set'

I tested with delete_rows and then calling set_sheet_data. But, again received error sometimes.

self.sheet.delete_rows()
self.sheet.set_sheet_data(data=newdata, reset_col_positions=False)

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\catuser\AppData\Local\Programs\Python\Python310\lib\tkinter_init_.py", line 1921, in call
return self.func(*args)
File "C:\Users\catuser\AppData\Local\Programs\Python\Python310\lib\tkinter_init_.py", line 839, in callit
func(*args)
File "C:\Users\catuser\OneDrive\proj\lib\site-packages\tksheet_tksheet.py", line 383, in after_redraw
self.MT.main_table_redraw_grid_and_text(redraw_header=redraw_header, redraw_row_index=redraw_row_index)
File "C:\Users\catuser\OneDrive\proj\lib\site-packages\tksheet_tksheet_main_table.py", line 5351, in main_table_redraw_grid_and_text
iid, showing = self.hidd_text[k].pop()
KeyError: 'pop from an empty set'ty set'

I use below code to initialize my sheet.

self.sheet = Sheet(self.table_frame,
                            show_top_left=False,
                            show_row_index=False,
                            show_x_scrollbar=False,
                            show_y_scrollbar=False,
                            empty_horizontal=0,
                            empty_vertical=0,
                            headers=['1', '2', '3', '4', '5', '6', '7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22'],
                            theme="dark",
                            width=800,
                            height=200,
                            align="c")

self.sheet.enable_bindings("single_select")
self.sheet.set_column_widths([200, 80, 80, 80, 120, 100, 100, 100, 70, 70, 70, 70, 60, 70, 70, 70, 70, 70, 70, 50, 50, 50])
self.sheet.grid(row=0, rowspan=4, column=0, padx=5, pady=(10, 0), sticky="nswe")
@ragardner ragardner added the bug Something isn't working label Oct 25, 2023
@ragardner
Copy link
Owner

ragardner commented Oct 25, 2023

Hello and thank you very much for your report, I suspect this is a bug and I'll get back to you when I have fixed it

@ragardner
Copy link
Owner

@mithoon19 I am having some trouble reproducing the error myself, is there a way you could provide me a minimal example?

I am currently using the below code on tksheet version 6.2.5

# ruff: noqa

from tksheet import *
import tkinter as tk
import random


class demo(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)
        self.frame = tk.Frame(self)
        self.frame.grid_columnconfigure(0, weight=1)
        self.frame.grid_rowconfigure(0, weight=1)

        self.sheet = Sheet(self.frame,
                            show_top_left=False,
                            show_row_index=False,
                            show_x_scrollbar=False,
                            show_y_scrollbar=False,
                            empty_horizontal=0,
                            empty_vertical=0,
                            headers=['1', '2', '3', '4', '5', '6', '7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22'],
                            theme="dark",
                            width=800,
                            height=200,
                            align="c")
        self.sheet.set_column_widths([200, 80, 80, 80, 120, 100, 100, 100, 70, 70, 70, 70, 60, 70, 70, 70, 70, 70, 70, 50, 50, 50])
        self.sheet.enable_bindings("all", "edit_index", "edit header", "ctrl_select")
        self.sheet.popup_menu_add_command(
            "test",
            self.test,
            table_menu=True,
            header_menu=True,
            empty_space_menu=True,
        )

        self.frame.grid(row=0, column=0, sticky="nswe")
        self.sheet.grid(row=0, column=0, sticky="nswe")


    def test(self, event=None):
        t = random.randint(0, 500)
        newdata = [[f"{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n" for c in range(22)] for r in range(30)]
        self.sheet.headers([f"{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n{t}\n" for c in range(22)])
        self.sheet.set_sheet_data(data=newdata, reset_col_positions=False)


app = demo()
app.mainloop()

ragardner added a commit that referenced this issue Oct 25, 2023
@mithoon19
Copy link
Author

Thank you for quick response. I unable to reproduce the error. It just happens randomly. Most of the time it works just perfect. So, I am unable to figure out what could be the issue.

@ragardner
Copy link
Owner

Ok no worries in that case, just to check before I make some changes sorry, which version of tksheet are you using?

@mithoon19
Copy link
Author

I am using Version: 6.2.5

ragardner added a commit that referenced this issue Oct 26, 2023
Address potential error with redrawing as described in issue #201

Also simplified some of the code involved with redrawing and removed unused classes as a result of changes
@ragardner
Copy link
Owner

@mithoon19 The issue should be totally fixed in version 6.2.6, release notes:

Version 6.2.6

Fixed:

  • #201
  • The ends of grid lines were incorrectly displaying connections with one another when only showing horizontal or vertical grid
  • When a cell dropdown and a row checkbox were in the same cell both would be drawn but only one would function, this has been changed to give dropdown boxes priority
  • Index text overlapping checkbox when alignment is "right"/"e"/"east" and index is not wide enough

Added:

But please let me know if you encounter any issues!

Thanks for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants