bugGNU Octave - Bugs: bug #60831, WindowButtonUpFcn is not always...

 
 

bug #60831: WindowButtonUpFcn is not always called

Submitter:  None
Submitted:  Sun 27 Jun 2021 03:30:47 AM UTC
   
 
Category:  Plotting with OpenGL Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Paul Mennen Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 28 Jun 2021 08:42:24 PM UTC, comment #1: 

Confirmed.  Changing the Operating System to Any since this occurred on a Linux machine running KDE, as well as the Microsoft Windows that you report.  I've also changed the Release to "dev" because it occurs on the development branch and will need to be fixed there.

The problem seems to be specific to uicontrol objects.  I re-wrote the first example to use a text object and it works correctly with left and right clicks.  Code is attached as repeat3.m and shown below.


function repeat3 (in)
  persistent ht;
  if (~nargin)
    ht = text (0.5, 0.5, '0', 'backgroundcolor', 'm', ...
               'buttondownfcn','repeat3(1)');
  else
    setappdata(gcf,'bdown',1);
    set(gcf,'WindowButtonUpFcn','setappdata(gcf,''bdown'',0);');
    while getappdata(gcf,'bdown')                            % loop until user lets go of mouse
       incr = 1 - 2*strcmp(get(gcf,'SelectionType'),'alt');  % left/right button goes up/down
       set(ht,'string',num2str(str2num(get(ht,'string'))+incr));
       pause(.1);
    end
  end
end



(file #51613)

Rik <rik5>
Group administrator
Sun 27 Jun 2021 03:30:47 AM UTC, original submission:  

I need to know if the user has released the mouse button. The only way I have found to do this in Octave is by using the WindowButtonUpFcn, which unfortunately is not working. Here are two examples that demonstrate the problem.

The first one (called repeat) creates a text uicontrol containing the string '0'. When you left click on the control, the number increments and continues to increment (every 100 milliseconds) as long as you hold down the mouse button. When you release the mouse button the incrementing stops ... at least that is what happens in Matlab. When you right click, the same thing happens except it decrements instead of incrementing. Again, in Matlab it stops decrementing as soon as you let go of the mouse button. However when I run this in Octave, the number continues to increment even after I release the mouse button. You can change the direction (increment vs. decrement) by left or right clicking again but it will never stop. The reason for this behavior is that apparently the WindowButtonUpFcn is not called when the user releases the mouse button. Here is the code:


function repeat(in)
  if ~nargin  % create uicontrol object
    uicontrol('style','text','string','0','buttondownfcn','repeat(1)',...
         'enable','inactive','backgroundcolor','black','foregroundcolor','white');
  else
    setappdata(gcf,'bdown',1);
    set(gcf,'WindowButtonUpFcn','setappdata(gcf,''bdown'',0);');
    while getappdata(gcf,'bdown')                            % loop until user lets go of mouse
       incr = 1 - 2*strcmp(get(gcf,'SelectionType'),'alt');  % left/right button goes up/down
       set(gcbo,'string',num2str(str2num(get(gcbo,'string'))+incr));
       pause(.1);
    end;
  end;


My second example (called movebut) shows how the WindowButtonUpFcn fails to get called in a quite different context. This program creates 3 objects (a button, an axis, and a text object). Then it allows you to move any of these objects around the screen by dragging them with the mouse. Of course when you release the mouse button, the object stops moving around and its new position is displayed in the command window ... at least that is the way it is supposed to work. It does work that way in Matlab. In Octave however, it almost works. The axis and the text object behave correctly. You can drag them to new positions and they stay there once you let go of the mouse. However the button doesn't work correctly. It moves around properly, but then when you let go of the mouse, it continues to follow the mouse, obviously because the WindowButtonUpFcn fails to get called. Actually when I try this many dozens of times I find that the WindowButtonUpFcn does occasionally get called (perhaps 1 time out of 50 or so). I can tell that it gets called, because occationally the new position is displayed in the command window. Here is the code:


function movbut(in)
  if ~nargin % create a pushbutton, an axis, and a text object
    a = uicontrol('position',[50 50 60 30],'string','ABCDE','enable','off');
    b = axes('units','pixels','position',[1 1 1 1]*200,'color',[.7 1 1]);
    c = text(0,0,'FGHIJKLM','units','pixels','position',[225 0]);
    set([a b c],'buttondownfcn','movbut(0)');
  else
    s = getappdata(gcf,'Dxy');  CP = get(gcf,'currentpoint');       % get mouse position
    switch in
    case 0, setappdata(gcf,'Dxy',{get(gcbo,'position') CP gcbo});   % buttondownfcn
            set(gcf,'WindowButtonMotionFcn','movbut(1)',...
                    'WindowButtonUpFcn',    'movbut(2)');
    case 1, p = s{1};  p(1:2)=p(1:2)+CP-s{2};  set(s{3},'position',p);  % WindowButtonMotionFcn
    case 2, set(gcf,'WindowButtonMotionFcn','','WindowButtonUpFcn',''); % WindowButtonUpFcn
            p = get(s{3},'position');  fprintf('New position: [%d %d]\n',p(1:2));
    end;
  end;


A workaround for both of these programs would be to check the mouse button status inside the loop and exit when the mouse button is not being pressed. Does anyone know a way to check the mouse status? If there is a way, I could avoid using the problematic WindowButtonUpFcn, and in fact the code would be simpler.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #51613:  repeat3.m added by rik5 (552B - text/x-matlab)

 

Depends on the following items: None found

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-11-23 jwe Item GroupMatlab Compatibility Incorrect Result
    2021-06-28 rik5 Attached File- Added repeat3.m, #51613
        CategoryNone Plotting with OpenGL
        Item GroupNone Matlab Compatibility
        StatusNone Confirmed
        Release6.1.0 dev
        Operating SystemMicrosoft Windows Any
    2021-06-27 siko1056 Dependencies- bugs #60832 is dependent

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code