octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #60831] WindowButtonUpFcn is not always called


From: anonymous
Subject: [Octave-bug-tracker] [bug #60831] WindowButtonUpFcn is not always called
Date: Sat, 26 Jun 2021 23:30:49 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36

URL:
  <https://savannah.gnu.org/bugs/?60831>

                 Summary: WindowButtonUpFcn is not always called
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Sun 27 Jun 2021 03:30:47 AM UTC
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
             Assigned to: None
         Originator Name: Paul Mennen
        Originator Email: paul@mennen.org
             Open/Closed: Open
                 Release: 6.1.0
         Discussion Lock: Any
        Operating System: Microsoft Windows

    _______________________________________________________

Details:

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.





    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?60831>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]