| 
122 | 122 |             fprintf('Press q to terminate the optimization...\n');  | 
123 | 123 | 
 
  | 
124 | 124 |             % set Callback  | 
125 |  | -              | 
 | 125 | +            qCallbackSet = false;  | 
126 | 126 |             if ~isdeployed % only if _not_ running as standalone                                 | 
127 | 127 |                 switch obj.env  | 
128 | 128 |                     case 'MATLAB'  | 
129 |  | -                        % get handle to Matlab command window  | 
130 |  | -                        mde         = com.mathworks.mde.desk.MLDesktop.getInstance;  | 
131 |  | -                        cw          = mde.getClient('Command Window');  | 
132 |  | -                        xCmdWndView = cw.getComponent(0).getViewport.getComponent(0);  | 
133 |  | -                        h_cw        = handle(xCmdWndView,'CallbackProperties');  | 
 | 129 | +                        try  | 
 | 130 | +                            % get handle to Matlab command window  | 
 | 131 | +                            mde         = com.mathworks.mde.desk.MLDesktop.getInstance;  | 
 | 132 | +                            cw          = mde.getClient('Command Window');  | 
 | 133 | +                            xCmdWndView = cw.getComponent(0).getViewport.getComponent(0);  | 
 | 134 | +                            h_cw        = handle(xCmdWndView,'CallbackProperties');  | 
134 | 135 | 
 
  | 
135 |  | -                        % set Key Pressed Callback of Matlab command window  | 
136 |  | -                        set(h_cw, 'KeyPressedCallback', @(h,event) obj.abortCallbackKey(h,event));  | 
 | 136 | +                            % set Key Pressed Callback of Matlab command window  | 
 | 137 | +                            set(h_cw, 'KeyPressedCallback', @(h,event) obj.abortCallbackKey(h,event));  | 
 | 138 | +                            fprintf('Press q to terminate the optimization...\n');  | 
 | 139 | +                            qCallbackSet = true;  | 
 | 140 | +                        catch  | 
 | 141 | +                            fprintf('Manual optimization termination with q disabled.\n');  | 
 | 142 | +                        end  | 
137 | 143 |                 end                  | 
138 | 144 |             end  | 
139 | 145 | 
 
  | 
 | 
144 | 150 |             [obj.wResult, obj.resultInfo] = ipopt(w0,funcs,ipoptStruct);  | 
145 | 151 | 
 
  | 
146 | 152 |             % unset Key Pressed Callback of Matlab command window  | 
147 |  | -            if ~isdeployed && strcmp(obj.env,'MATLAB')  | 
 | 153 | +            if qCallbackSet  | 
148 | 154 |                 set(h_cw, 'KeyPressedCallback',' ');  | 
149 | 155 |             end  | 
150 | 156 | 
 
  | 
 | 
0 commit comments