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

Observe triggers too many times #103

Open
krey opened this issue Apr 5, 2019 · 1 comment
Open

Observe triggers too many times #103

krey opened this issue Apr 5, 2019 · 1 comment

Comments

@krey
Copy link

krey commented Apr 5, 2019

Version: 5065a59

import ipywidgets as widgets
import ipysheet

sheet = ipysheet.Sheet(rows=1, columns=1)
sheet.cells = ipysheet.Cell(value=[""], row_start=0, row_end=0, column_start=0, column_end=0, squeeze_column=False),

output = widgets.Output()

def observer(change):
    with output:
        print("{0} -> {1}".format(change.old, change.new))
        
sheet.cells[0].observe(observer, names='value')
sheet.cells[0].value = ['a']
sheet.cells[0].value = ['b']
sheet.cells[0].value = ['c']

output

output contains

[''] -> ['a']
['a'] -> ['b']
['b'] -> ['c']
['c'] -> ['a']
['a'] -> ['c']

Related: #85

@krey
Copy link
Author

krey commented Apr 8, 2019

Another example:

In[0]:

import ipywidgets as widgets
import ipysheet

sheet = ipysheet.Sheet(rows=1, columns=2)

sheet.cells = (
    ipysheet.Cell(value=[""], row_start=0, row_end=0, column_start=0, column_end=0, squeeze_column=False),
    ipysheet.Cell(value=[""], row_start=0, row_end=0, column_start=1, column_end=1, squeeze_column=False)
)

output = widgets.Output()

def observer(change):
    with output:
        print("{0} -> {1}".format(change.old, change.new))

sheet.cells[0].value = ["A"]
sheet.cells[1].value = ["B"]

sheet.cells[0].observe(observer, names='value')
sheet.cells[1].observe(observer, names='value')
    
output

In[1]:

sheet.cells[0].value = ["C"]
sheet.cells[1].value = ["D"]

Run In[0] and then In[1]. output will then contain

['A'] -> ['C']
['B'] -> ['D']
['D'] -> ['B']
['B'] -> ['D']

Interestingly, if you replace In[1] with

sheet.cells[1].value = ["D"]
sheet.cells[0].value = ["C"]

then it works fine. output contains

['B'] -> ['D']
['A'] -> ['C']

Doesn't seem to happen if the cells are in two different sheets.

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