临时禁用后重新启动 matlab window 按钮运动
restart matlab window button motion after a temporary disabling
我正在设计一个 Matlab GUI。在此 GUI 中,windowButtonMotion 不断地接受输入。但是,我需要将其停止一会儿,并向用户询问来自另一个图形的视觉输入。该图在输入后关闭,程序应该以相同的方式工作。
当新图形弹出时,我用这段代码禁用了 WBM:
set(fighandle, 'WindowButtonMotionFcn', '');
问题是,输入完成后如何重新启动 WBM。
我不使用像这样的函数调用来调用 WBM:
set(fighandle, 'WindowButtonMotionFcn', @fun);
相反,我在GUI中的windowButtonMotion_Fcn
回调下编写了代码。
最简单的做法是在更改回调之前存储回调,然后您可以将其重置为相同的东西。无论你的回调是什么,这都会起作用。
% Store the original
originalCallback = get(fighandle, 'WindowButtonMotionFcn');
% Disable the callback
set(fighandle, 'WindowButtonMotionFcn', '')
% Do stuff
% Now reset it
set(fighandle, 'WindowButtonMotionFcn', originalCallback)
如果这些没有发生在同一个函数中,您可以将之前的回调存储在图形的应用程序数据中。
% Get original callback and store within the appdata of the figure
setappdata(fighandle, 'motioncallback', get(fighandle, 'WindowButtonMotionFcn'));
% Disable the callback
set(fighandle, 'WindowButtonMotionFcn', '')
% Then from another function re-enable it
set(fighandle, 'WindowButtonMotionFcn', getappdata(fighandle, 'motioncallback'))
你的另一个选择是将你的第二个图形实际打开为模态图形,然后鼠标与背景图形的交互将被忽略。那么你就不必篡改 WindowButtonMotionFcn
.
fig2 = figure('WindowStyle', 'modal');
另一个答案很好,但我找到了另一种方法,效果很好,而且对我的情况来说更简单一些:
基本上,我只是将我不想与之交互的图形设置为暂时不可见,使用:
set(fig_handle, 'visible', 'off')
在我的情况下,在设置图形时需要几秒钟的时间来完成所有设置和计算,如果有人碰巧将鼠标移到图形上,因为这一切都在设置中,windowbuttonmotionfcn 将给出一个错误,所以我只是将图形设置为不可见,直到完成所有设置,然后执行以下操作:
set(fig_handle, 'visible', 'on')
这可能是也可能不是您希望在您的情况下发生的情况。
我正在设计一个 Matlab GUI。在此 GUI 中,windowButtonMotion 不断地接受输入。但是,我需要将其停止一会儿,并向用户询问来自另一个图形的视觉输入。该图在输入后关闭,程序应该以相同的方式工作。
当新图形弹出时,我用这段代码禁用了 WBM:
set(fighandle, 'WindowButtonMotionFcn', '');
问题是,输入完成后如何重新启动 WBM。
我不使用像这样的函数调用来调用 WBM:
set(fighandle, 'WindowButtonMotionFcn', @fun);
相反,我在GUI中的windowButtonMotion_Fcn
回调下编写了代码。
最简单的做法是在更改回调之前存储回调,然后您可以将其重置为相同的东西。无论你的回调是什么,这都会起作用。
% Store the original
originalCallback = get(fighandle, 'WindowButtonMotionFcn');
% Disable the callback
set(fighandle, 'WindowButtonMotionFcn', '')
% Do stuff
% Now reset it
set(fighandle, 'WindowButtonMotionFcn', originalCallback)
如果这些没有发生在同一个函数中,您可以将之前的回调存储在图形的应用程序数据中。
% Get original callback and store within the appdata of the figure
setappdata(fighandle, 'motioncallback', get(fighandle, 'WindowButtonMotionFcn'));
% Disable the callback
set(fighandle, 'WindowButtonMotionFcn', '')
% Then from another function re-enable it
set(fighandle, 'WindowButtonMotionFcn', getappdata(fighandle, 'motioncallback'))
你的另一个选择是将你的第二个图形实际打开为模态图形,然后鼠标与背景图形的交互将被忽略。那么你就不必篡改 WindowButtonMotionFcn
.
fig2 = figure('WindowStyle', 'modal');
另一个答案很好,但我找到了另一种方法,效果很好,而且对我的情况来说更简单一些:
基本上,我只是将我不想与之交互的图形设置为暂时不可见,使用:
set(fig_handle, 'visible', 'off')
在我的情况下,在设置图形时需要几秒钟的时间来完成所有设置和计算,如果有人碰巧将鼠标移到图形上,因为这一切都在设置中,windowbuttonmotionfcn 将给出一个错误,所以我只是将图形设置为不可见,直到完成所有设置,然后执行以下操作:
set(fig_handle, 'visible', 'on')
这可能是也可能不是您希望在您的情况下发生的情况。