ragardner / tksheet

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

Can i have help changing listed behavior of tksheet ? #186

Open Mrasipila opened 1 year ago

Mrasipila commented 1 year ago

Hello, I have been going through your code for some time trying to edit it so that the sheet changes it's behavior, here are the behaviors i would like to change :

If i can have any help on the functions i should focus on to add those features, please, it would be cool.

ragardner commented 1 year ago

Hi,

The Second issue i came across was the double_clicking on a cell which has an overflowing number of characters. When i double click, the column gets resized. I have tried to disable the following bindings 'double_click_column_resize' and 'column_width_resize' but nothing changes. I still have the same issue.

You can disable cell auto resizing when editing cells completely with the argument enable_edit_cell_auto_resize = False in the Sheet() initialization

my_sheet = Sheet(parent, enable_edit_cell_auto_resize = False)

or with set_options(enable_edit_cell_auto_resize = False)

The specific part of the code that deals with resizing the cell upon opening is:

text = "" if text is None else text
if self.cell_auto_resize_enabled:
    self.set_cell_size_to_text(r, c, only_set_if_too_small=True, redraw=True, run_binding=True)

It's in the open_text_editor() function


I also would like to have an autofill feature for the drop down list. This way when I write 'OF' on an ['ON','OFF'] drop down list and then press < Tab > the 'OFF' gets selected.

I won't be working on this functionality for some time, I am not sure of the best way to implement it sorry but there would have to be communication between the dropdown window and the text editor, these two are in the open_dropdown() function


When i press < Tab > or < Enter > on an editable sheet, I can't edit the cell without an additional click to reselect the ongoing cell. I have tried to go through the tab_key(self, event=None) function of the MainTable class, replacing self.see by self.select_cell but it doesn't work.

Sorry, I'm not sure what you mean, is focus not being applied to the text editor when you press Enter on a cell?

Mrasipila commented 1 year ago

Thank you for your response. Focus is being applied but I can't write text on the cell without reclicking on the focused cell.

ragardner commented 1 year ago

I cannot think why this is happening sorry, is there any way you could provide a minimal example and which version of tksheet you're using?

Mrasipila commented 1 year ago

I have the issue with this piece of code, my version is 6.1.2.

from tksheet import Sheet
import tkinter as tk

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,
                           data = [[f"Row {r}, Column {c}\nnewline1\nnewline2" for c in range(50)] for r in range(500)])
        self.sheet.enable_bindings()
        self.show_selections = tk.Label(self)
        self.frame.grid(row = 0, column = 0, sticky = "nswe")
        self.sheet.grid(row = 0, column = 0, sticky = "nswe")
        self.show_selections.grid(row = 1, column = 0, sticky = "nswe")
        self.sheet.dropdown_column(c=1, values=["ON", "OFF"])

app = demo()
app.mainloop()

I upgraded to the latest version which is "6.1.9" and the problem has been solved. I work with PyCharm hence the fact that i didn't have installed the latest version to start with.
Thank you !

Mrasipila commented 1 year ago
from tksheet import Sheet
import tkinter as tk

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,
                           data = [[f"Row {r}, Column {c}\nnewline1\nnewline2" for c in range(50)] for r in range(500)])
        self.sheet.enable_bindings()
        self.show_selections = tk.Label(self)
        self.frame.grid(row = 0, column = 0, sticky = "nswe")
        self.sheet.grid(row = 0, column = 0, sticky = "nswe")
        self.show_selections.grid(row = 1, column = 0, sticky = "nswe")
        self.sheet.dropdown_column(c=1, values=["ON", "OFF"])
        self.sheet.dropdown_column(c=2, values=["ON", "OFF"])
        self.sheet.dropdown_column(c=3, values=["ON", "OFF"])

app = demo()
app.mainloop()

but with this example the problem seems to persist with the drop down columns. The dropdown list doesn't drop after pressing TAB and arriving on it.

ragardner commented 1 year ago

Ah, I think this is the behavior I programmed for,

Would you prefer the next dropdown box to open when pressing tab out of an existing one? I am not sure, it's not the behavior in excel and google sheets as far as I can tell, although it might be more convenient to have it this way...

You could open it by using Tab -> Return I think