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

Callback issues #386

Open
williamnavaraj opened this issue Dec 28, 2022 · 0 comments
Open

Callback issues #386

williamnavaraj opened this issue Dec 28, 2022 · 0 comments

Comments

@williamnavaraj
Copy link

williamnavaraj commented Dec 28, 2022

Describe the bug
Removing ipydatagrid on_cell_change callback (with remove==True flag) and adding it back seems to not work correctly.
To Reproduce
Steps to reproduce the behavior:
Run the below code. (I used VSCode notebook)

import pandas as pd
from ipydatagrid import DataGrid
def on_cell_changed(cell):
    
    message="Cell at primary key {row} and column '{column}'({column_index}) changed to {value}".format(
            row=cell["row"],
            column=cell["column"],
            column_index=cell["column_index"],
            value=cell["value"]

        )

    print(message)#,flush=True)
    #Tkinter box for better visualization of what is going on
    import tkinter.messagebox
    tkinter.messagebox.Message(title='On cell changed', message= message,).show()

df = pd.DataFrame(
    {
        "column0":  ["", "", ""]
    }
)

datagrid=DataGrid(
    df,editable=True
, layout={"height": "100px"})
display(datagrid)

datagrid.on_cell_change(on_cell_changed)
datagrid.set_cell_value("column0",0,"a")
datagrid.set_cell_value("column0",1,"b")
datagrid.set_cell_value("column0",2,"c") #Upto this works fine
datagrid.on_cell_change(on_cell_changed,True) #This is supposed to remove the callback
datagrid.set_cell_value("column0",0,"e")
datagrid.set_cell_value("column0",1,"f")
datagrid.set_cell_value("column0",2,"g")
#If I uncomment the below line the output for callbacks for the value changes of all 6 cases above displays
#datagrid.on_cell_change(on_cell_changed) 

The code above provides the Minimum example to replicate the code. I am running this in a jupyter notebook cell in VSCode 1.74.1.

Expected behavior

Cell at primary key 0 and column 'column0'(0) changed to a
Cell at primary key 1 and column 'column0'(0) changed to b
Cell at primary key 2 and column 'column0'(0) changed to c

Actual output

Cell at primary key 0 and column 'column0'(0) changed to a
Cell at primary key 1 and column 'column0'(0) changed to b
Cell at primary key 2 and column 'column0'(0) changed to c
Cell at primary key 0 and column 'column0'(0) changed to e Cell at primary key 0 and column 'column0'(0) changed to e Cell at primary key 1 and column 'column0'(0) changed to f Cell at primary key 0 and column 'column0'(0) changed to e Cell at primary key 1 and column 'column0'(0) changed to f Cell at primary key 2 and column 'column0'(0) changed to g

The tkinter message box shows all 6 cases are occurring again.

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

1 participant