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

Refresh slider and rows after movetoSelection #245

Open
Alhanz opened this issue Sep 23, 2023 · 1 comment
Open

Refresh slider and rows after movetoSelection #245

Alhanz opened this issue Sep 23, 2023 · 1 comment

Comments

@Alhanz
Copy link

Alhanz commented Sep 23, 2023

Hello,
I am currently making database using TKinter and Pandasframe, but I started to face one small issue. I created window with all data ( over 10 000 , all working fine ) , but after I search for some term and I use "movetoSelection" , it moves me to matched term, but left indexes disappear ( I need to manually click slider to refresh them ) and slider is also not in correct position ( in a graphic way ) . I tried to refresh table, and other way to manipulate window after I moved to search result, but nothing worked in my favor. Not sure if it's because of 10 000 loaded records.

main issue is here, this is search input which will move me to match :
` def open_input_dialog_event(self):

    if self.loaded_df is None:
        tkinter.messagebox.showinfo("Search", "No data loaded. Please load data first.")
        return

    dialog = customtkinter.CTkInputDialog(text="Enter a search query:", title="Search")
    search_query = dialog.get_input().strip()

    if not search_query:
        tkinter.messagebox.showinfo("Search", "Please enter a search query.")
        return

    # Check if the search query is in the currently displayed data
    matched_rows = [
        row_index
        for row_index, row in enumerate(self.pt.model.df.itertuples(index=False), start=1)
        if any(search_query.lower() in str(val).lower() for val in row)
    ]

    if not matched_rows:
        tkinter.messagebox.showinfo("Search", "No matching records found.")
        return

    # Move to the first matched row (you can customize this behavior)
    self.pt.movetoSelection(row=matched_rows[0]-1)
    # Ensure the widget is updated and displayed
    self.pt.show()
    # Force a redraw/update of the widget
    self.pt.redraw()`

image

All code

@MikeStratoti
Copy link

MikeStratoti commented Sep 27, 2023

I have a similar result implementing PageUp/PageDown functionality:

        self.tableTop.bind("<Prior>",   self.handle_page_keys,  '+')       # Bind to PageUp
        self.tableTop.bind("<Next>",    self.handle_page_keys,  '+')       # Bind to PageDown
def handle_page_keys (self, event):
    """Handle PageUp/PageDown scroll for grid.  It has a problem with not updating the row (side) headers properly.  Can use up/down arrows when hitting top/bottom grid edges to redraw."""

    direction = -1 if event.keysym == 'Prior'  else 1
    table = event.widget
    table.yview_scroll (direction, tk.PAGES)
    table.rowheader.redraw()
    table.redraw()
    return 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants