bugGNU Octave - Bugs: bug #54942, implement uicontrol focusing...

 
 

bug #54942: implement uicontrol focusing behavior

Submitter:  Rik <rik5>
Submitted:  Fri 02 Nov 2018 07:16:15 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 06 Nov 2018 05:15:30 PM UTC, comment #13: 

Thanks Rik for the reminder. I pushed a fix here:

http://hg.savannah.gnu.org/hgweb/octave/rev/864448a7f347

Pantxo Diribarne <pantxo>
Group Member
Tue 06 Nov 2018 04:17:36 PM UTC, comment #12: 

As part of that cset, also change msgbox.m to put the focus on the newly created button.  A sample diff is


diff -r fe29584dad35 scripts/gui/msgbox.m
--- a/scripts/gui/msgbox.m        Mon Nov 05 11:11:47 2018 -0800
+++ b/scripts/gui/msgbox.m        Tue Nov 06 08:16:41 2018 -0800
@@ -268,6 +268,7 @@ function hf = __msgbox__ (msg, tit, icon
                    "callback", @cb_callback,
                    "keypressfcn", @cb_keypress,
                    "position", [ax_sz(1)/2-40 ax_margin 80 28], "parent", hp);
+  uicontrol (hui);  # Set focus on created pushbutton

   set (hf, "windowstyle", windowstyle, "visible", "on");

 

Rik <rik5>
Group administrator
Tue 06 Nov 2018 10:59:07 AM UTC, comment #11: 

@Guillaume: Ok, I incorrectly assumed uicontrol objects got the focus at creation. This one has an easy fix and I'll provide a patch.

Pantxo Diribarne <pantxo>
Group Member
Tue 06 Nov 2018 10:53:07 AM UTC, comment #10: 

There seems to be a difference of behavior with Matlab concerning the focus: when created, a uicontrol doesn't seem to get focus automatically.

If I run the following in Matlab:


h = figure;
uicontrol(h,'callback','disp(''callback'')');


the button doesn't show any visual cue it has focus and pressing the space or return key doesn't trigger the callback. If one clicks on the button then the callback is executed and the button now has the focus (and callback is triggered if one presses the space bar). Focus is then lost if one clicks anywhere else on the figure.

Guillaume <gyom>
Mon 05 Nov 2018 07:12:49 PM UTC, comment #9: 

I added the other potential keys which could close the msgbox window in this cset: https://hg.savannah.gnu.org/hgweb/octave/rev/fe29584dad35.

Rik <rik5>
Group administrator
Mon 05 Nov 2018 05:19:15 PM UTC, comment #8: 

Testing in Matlab all the keys of the keyboard, I found that the window is closed when ev.Key is one of "enter", "return", "escape", "space".

Guillaume <gyom>
Mon 05 Nov 2018 05:05:54 PM UTC, comment #7: 

I changed the underlying msgbox.m function to have a "keypress" callback that closes the window when <RETURN> is pressed.  Since the XXXdlg functions are built on top of msgbox they now do the correct thing.

Marking bug as fixed and closing report.

Rik <rik5>
Group administrator
Mon 05 Nov 2018 11:12:27 AM UTC, comment #6: 

In Matlab, typing:


h = helpdlg ('Some help text');


opens a figure that gets the focus automatically so no need to click on it ,and typing <SPACE> or <RETURN> closes the window.

Guillaume <gyom>
Sun 04 Nov 2018 10:19:48 PM UTC, comment #5: 

So what does Matlab do for the XXXdlg functions?  Does it automatically create the callback?  Or does it leave it empty?

Sample Code to test in Matlab:


h = helpdlg ('Some help tex');
% Click on figure window to make sure it has focus
% Type <RETURN>, does window close?



Rik <rik5>
Group administrator
Sun 04 Nov 2018 07:37:15 PM UTC, comment #4: 

@Rik:

>> What is this piece of code?

This was indeed debugging leftover, thaks, I pushed the patch here:

http://hg.savannah.gnu.org/hgweb/octave/rev/80c8062e855a

>> I thought that if the button had the focus and I typed <RETURN> that the button would be activated


No, this just gives this uicontrol (widget) the keyboard focus. As a result it is this widget that will receive keyboard events and have a chance to handle them.
Now if you want the uicontrol to react on <return> entry you need to provide a corresponding "keypressfcn", e.g.


function keypress (h, ev)
  if (strcmp (ev.Key, "return"))
    close (gcbf ())
  endif
endfunction

uicontrol ("keypressfcn", @keypress);


Pantxo Diribarne <pantxo>
Group Member
Sun 04 Nov 2018 06:01:03 PM UTC, comment #3: 

The patch seems on the right track.

What is this piece of code?


diff -r e3a2ef3dced9 -r 60b0988efb93 libgui/graphics/BaseControl.cc
--- a/libgui/graphics/BaseControl.cc        Mon Feb 22 21:07:09 2016 +0100
+++ b/libgui/graphics/BaseControl.cc        Sun Nov 04 00:12:22 2018 +0100
@@ -92,6 +92,9 @@
     : Object (go, w), m_normalizedFont (false), m_keyPressHandlerDefined (false)
   {
     init (w);
+    w->setFocus ();
+    if (w->hasFocus ())
+      printf ("Toto\n");
   }


The printf looks like debugging code accidentally left in place.

Second question, maybe this is an issue in the implementation of a push button, but I thought that if the button had the focus and I typed <RETURN>, that the button would be activated.  This doesn't seem to be the case for push buttons, although it is for the buttons on a listdlg.

Sample test code:


close all
h = uicontrol ("String", "OK");
# Click on figure window
# type <RETURN>



Rik <rik5>
Group administrator
Sat 03 Nov 2018 11:19:45 PM UTC, comment #2: 

I attached a patch that fixes the issue for me. I used an additional hidden property "__focus__" to implement the interface.

(file #45357)

Pantxo Diribarne <pantxo>
Group Member
Sat 03 Nov 2018 08:53:32 AM UTC, comment #1: 

This was initially mentioned in bug #53710. Until this is implemented, would it be possible to display the warning only once, as we do elsewhere?

Guillaume <gyom>
Fri 02 Nov 2018 07:16:15 PM UTC, original submission:  

It should be possible to switch the focus to a particular uicontrol object by using the syntax


uicontrol (handle)


However, this is currently unimplemented in Octave and throws a warning.


uicontrol (hu)
warning: uicontrol: focusing not implemented yet
warning: called from
    uicontrol at line 110 column 5


Just briefly looking at the Qt docs shows that there is a setFocus member function for QWidgets.  The path to implementing this is probably straightforward, but also long.  One would need to create an interface in octave_link, call the new function from uicontrol.m, and implement the actual behavior in libgui/src/octave-link.cc.

Rik <rik5>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #45357:  control_focus.patch added by pantxo (3KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pantxo (Updated the item)
  • -email is unavailable- added by gyom (Posted a comment)
  • -email is unavailable- added by rik5 (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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-11-05 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2018-11-04 pantxo StatusPatch Reviewed Ready For Test
    2018-11-04 rik5 StatusPatch Submitted Patch Reviewed
    2018-11-03 pantxo Attached File- Added control_focus.patch, #45357
        StatusConfirmed Patch Submitted

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code