Matlab GUI temporarily disable uitable CellSelectionCallback

6 visualizaciones (últimos 30 días)
Aleksejs Fomins
Aleksejs Fomins el 4 de Mayo de 2018
Respondida: Chris el 12 de Feb. de 2019
I have a GUI that has a table. The table has a CellSelectionCallback function to respond to user selecting certain cells. There are also several functions that work with that table, when corresponding buttons are pressed
  • A function to delete rows
  • A function to add rows
  • A function to programmatically select certain entries in the table. This last one is more or less a hack using java handles. Its main problem is that it can only select one entry at a time due to the provided interface
What I want is to completely disable CellSelectionCallback while each of the above functions execute. In Python, for example, it is achieved by adding and removing listeners. I have found a solution following this logic here (see 2nd answer)
namely,
set(mtable, 'CellSelectionCallback', []);
... Do stuff ...
pause(1)
set(mtable, 'CellSelectionCallback', @mtable_CellSelectionCallback);
However, it does not seem to work. In particular, when I select uitable entries with mouse after having disabled and enabled callback in this way, I get a really weird error in the callback function which otherwise seems to work flawlessly
Error using uiwait (line 81)
Error while evaluating Table CellSelectionCallback.
Not enough input arguments.
Error in mtable_CellSelectionCallback (line 4)
gridData = get(handles.mtable, 'Data');
any ideas are welcome

Respuestas (1)

Chris
Chris el 12 de Feb. de 2019
Hello, I can't imagine you are still looking for an aswer but since no one has answered this and someone may want some sort of solution I figured I'd comment:
So I did almost the same thing as you and it worked (using 2018a), with the difference being how I redefined my callback:
var = mtable.CellSelectionCallback;
mtable.CellSelectionCallback = [];
... Do Stuff ....
mtable.CellSelectionCallback = var;
I used dot notation, as opposed to the set function, which I imagine shouldn't matter? The key difference (probably) being that I saved the original function handle and re-assigned it at the end.
I am currently working on a GUI so I just threw the script in there, so I'll explain a little about how I implemented it in case that difference is the source of our differing results:
I made a 'CellEditCallback' so I could 'toggle' the state of the 'CellSelectionCallback' (no CellSelectionCallback vs having a CellSelectionCallback) depending on the value I entered into a cell.
I made a property of the class I was working in to hold 'var'. (obj.var)
When I called the CellEditCallback function by entering '3' (arbitrary value chosen) I assigned the value of the CellSelectionCallback function handle to obj.var, and then mtable.CellSelectionCallback = [];
At this point my CellSelectionCallback function was no longer called when selecting different cells within the table.
When I called the CellEditCallback function by entering '2' (arbitrary value chosen) into a cell in the table I reassigned the CellSelectionCallback function handle to the table: mtable.CellSelectionCallback = obj.var.
At this point my cell selection function was working like it did in the beginning before i set it to empty.
Hope this helps someone.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by