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

 
 

bug #60832: WindowButtonUpFcn is not always called

Submitter:  None
Submitted:  Sun 27 Jun 2021 03:51:46 AM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Duplicate Assigned to:  None
Originator Name:  Paul Mennen Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 6.1.0
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 27 Jun 2021 07:13:33 AM UTC, comment #1: 

Please be a bit more patient with good old Savannah and do not double post.

Closing as duplicate of bug #60831.

Kai Torben Ohlhus <siko1056>
Group Member
Sun 27 Jun 2021 03:51:46 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;


(It's probably obvious, but note that to start this program simply type the name of the program without any arguments. This goes for the second example as well)

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.

It seems my email didn't show up under "Originator Email", so if that is still the case, here it is: -email is unavailable-

Thanks
~Paul

Anonymous

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Digest:
   bug dependencies.

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-06-27 siko1056 StatusNone Duplicate
        Open/ClosedOpen Closed
        Dependencies- Depends on bugs #60831

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code