bugGNU Octave - Bugs: bug #50295, Calling feval() from within the Qt...

 
 

bug #50295: Calling feval() from within the Qt GUI requires to press enter otherwise the prompt is busy

Submitter:  Roland Baudin <roland65>
Submitted:  Mon 13 Feb 2017 04:24:12 PM UTC
   
 
Category:  GUI Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Works For Me Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.2.0 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 13 Jun 2018 02:01:22 PM UTC, comment #13: 

@jwe: about comment #5. Matlab deletes the current prompt, displays the string and then redraws the prompt. After one click it looks like


>> foo = @(h, e) disp ('foo');
>> h = figure ();
>> set (h, 'buttondownfcn', foo);
foo
>>


Then if I click again it looks like


>> foo = @(h, e) disp ('foo');
>> h = figure ();
>> set (h, 'buttondownfcn', foo);
foo
foo
>>


For completeness, with a "numbered" prompt it would look like this in Octave


octave:1> foo = @(h, e) disp ('foo');
octave:2> h = figure ();
octave:3> set (h, 'buttondownfcn', foo);
foo
foo
octave:4>


So from that point of view, the answer to your question "but how much output?" is: delete the prompt, display output, redraw the prompt for each output. This would also avoid the first output to be displayed after the prompt as it is currently the case in octave:


octave:1> foo = @(h, e) disp ('foo');
octave:2> h = figure ();
octave:3> set (h, 'buttondownfcn', @foo);
error: @foo: no function and no method found
octave:3> set (h, 'buttondownfcn', foo);
octave:4> foo
foo


Pantxo Diribarne <pantxo>
Group Member
Sun 19 Feb 2017 05:24:43 PM UTC, comment #12: 

Ok, you can close the bug.
You're right, this was not the correct way to implement a graphic function.

Roland Baudin <roland65>
Sun 19 Feb 2017 05:19:57 PM UTC, comment #11: 

We have already shown here that this is not a general problem. When the function called is "disp", the function actually does complete correctly.

I think this bug should be closed as everything is working correctly. I think you should explore another way to get the box to be drawn on the figure window because that specific code path does not seem to be working, probably because you have the GUI thread calling the interpreter which is trying to call back into the GUI thread. Do you agree?

Mike Miller <mtmiller>
Group Member
Sat 18 Feb 2017 08:08:07 AM UTC, comment #10: 


>>Pressing Enter in the command window is required to somehow get the tooltip to appear on the figure window


Yes, it's exactly the problem. For some reason, calling a .m from the gui requires the user to type enter otherwise the function does not complete correctly and the prompt is stuck. The example with the disp() function was just to try to simplify the problem.




Roland Baudin <roland65>
Fri 17 Feb 2017 05:38:53 PM UTC, comment #9: 

I'm sorry I don't really understand what the data cursor on a plot has to do with what is printed to the command window or whether the user has to press Enter.

As I understand it the data cursor is a tooltip that appears on a figure window when the figure area is clicked. I don't see how that requires any kind of display or interaction on the command window. If it's just for debugging while implementing this function, then I don't see any problem with the current behavior.

If pressing Enter in the command window is required to somehow get the tooltip to appear on the figure window, then that looks like a different problem from just getting the prompt to be redrawn. You may have run into a different problem and assumed that it's for the same reasons as what you describe here, while the example shown here doesn't seem to be a bug at all.

It seems more likely to me that it's because you are calling an m file function that sends a signal to the Qt figure thread to draw a text box. Instead maybe the data cursor should be done entirely in libgui without making such a callback to the interpreter.

Mike Miller <mtmiller>
Group Member
Fri 17 Feb 2017 08:14:34 AM UTC, comment #8: 

To Mike: the problem for me is point 2. As I said in the previous comment, I intended to add a callback to the datacursor of Pantxo Diribarne, but this doesn't work as expected because the user has to press enter any time he clicks on the menu item, otherwise the data cursor does not appear.

Perhaps, my approach is not the correct one, so if there is some alternative, please tell me...

Roland Baudin <roland65>
Fri 17 Feb 2017 08:11:39 AM UTC, comment #7: 

To jwe: yes, same behaviour with your example. OK, I understand this is the correct and expected way.

In fact, my problem is the following. I thought it was simple to add a callback to a function to the figure window menu (the function I was interested in is the datacursor() function written by Pantxo Diribarne, see http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-td4681801.html).

So I added the menu callback but it doesn't work properly because the user has to press enter in the command window after he has clicked somewhere on the figure to put the datacursor.

Perhaps, there is some method to call to simulate this enter pressing ?

Roland Baudin <roland65>
Fri 17 Feb 2017 12:44:25 AM UTC, comment #6: 

Roland - which of the following are you reporting as the bug here:

1. You have to click in the figure window for the text to be printed to the command window, rather than it appearing immediately when the menu item is selected?

2. You have to press Enter in the command window for the Octave prompt to be redrawn?

These are two different behaviors, and I don't think I can reproduce the first one. I agree with jwe that the second behavior is simply how Octave works, it should not be redisplaying the prompt any time any text is printed to the command window out of band with what the user is typing.

Mike Miller <mtmiller>
Group Member
Thu 16 Feb 2017 01:33:38 PM UTC, comment #5: 

I think the behavior you are seeing is expected.  When you write to the command window, Octave doesn't redraw the prompt after your output.  Is the behavior the same for you with the following code?


function foo ()
  disp ('foo!');
endfunction
h = figure ();
set (h, 'buttondownfcn', @foo);
## Now, "foo!" should appear in the command
## window each time there is a mouse click
## in the figure window.


Maybe Octave should redraw the prompt, but I'm not sure exactly when that should happen or what should trigger it.  I know, you are probably thinking "after output is displayed in the command window", but how much output?  After each callback function is executed, or just after a series of them have been executed and there are no more pending events?  How do we know there won't be more events arriving?

John W. Eaton <jwe>
Group administrator
Thu 16 Feb 2017 10:53:04 AM UTC, comment #4: 

OK, I was probably not clear.

Here are the steps to reproduce the issue:

1. Add the code snippet I provided to Figure.cc and add the prototypes of the two functions to Figure.h (myfunction_callback to the private section and myFunction to the private slot section).

2. Rebuild Octave and run it

3. In the command window, type:
x=[0:0.1:2*pi];y=sin(x);plot(x,y);

4. In the figure window, click on the new menu item Edit / My function

5. Click somewhere in the figure

6. Then the command window displays '1' (the figure number) and the prompt does not return. You'll have to press enter get the prompt again

This is 100 % reproducible.

Roland Baudin <roland65>
Wed 15 Feb 2017 05:42:28 PM UTC, comment #3: 

Then I am not able to reproduce this. I do see a delay until pressing Enter in the command window, but only when the pager is enabled.

Mike Miller <mtmiller>
Group Member
Wed 15 Feb 2017 07:51:13 AM UTC, comment #2: 

I have 'more off' in my .octaverc file, so the problem is not there.

Roland Baudin <roland65>
Tue 14 Feb 2017 11:45:59 PM UTC, comment #1: 

Can you confirm that running "more off" in the command window results in the display happening immediately? This appears to me to be an interaction between the default pager buffering mode and the output of the disp function.

If a GUI menu item or other input method wanted to display output on the command window immediately, it might be helpful to look at how it is done in the Workspace panel.

If you can confirm that it is simply the pager mode that is affecting the result, does something need to be done about this or is it working as expected?

Mike Miller <mtmiller>
Group Member
Mon 13 Feb 2017 04:24:12 PM UTC, original submission:  

I tried to add a new menu item to the figure window of the qt graphics toolkit, to call an Octave function from the figure window.

I used the following code in libgui/graphics/Figure.cc:

void
Figure::createFigureToolBarAndMenuBar (void)
{
   <...>

  editMenu->addSeparator ();
  editMenu->addActions (m_mouseModeGroup->actions ());
  editMenu->addAction (tr ("&My function"), this, SLOT (myFunction (void)));

  < ... >
}

void
Figure::myFunction (void)
{
    octave_link::post_event (this, &Figure::myfunction_callback);
}

void
Figure::myfunction_callback (void)
{
  figure::properties& fp = properties<figure> ();
  octave_value fnum = fp.get___myhandle__ ().as_octave_value ();

  Ffeval (ovl ("disp", fnum));
  feval (ovl ("fprintf",1,"example\n"), 1);
}


This silly example should display the figure id in the command window (of course the real function will do much more).

This almost works (to test, plot anything and click on the Edit / My function menu item), but after the figure id is displayed in the command window, the prompt gets stuck and I have to type <enter> to get the prompt back again.

Same behaviour with the fprintf() function (see the commented line above)...



Roland Baudin <roland65>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by roland65 (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
    2017-02-19 mtmiller Open/ClosedOpen Closed
    2017-02-15 mtmiller StatusNeed Info Works For Me
    2017-02-14 mtmiller StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code