Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Text box widget #5375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed

Conversation

HastingsGreer
Copy link
Contributor

Several users (myself included) have wanted the ability to do text input as a widget. This text box widget is implemented by capturing keystrokes and adding them to a string, with special cases for keys like "enter", "left", "right" etc.

http://stackoverflow.com/questions/25231449/do-text-number-input-fields-exist-in-matplotlib
http://stackoverflow.com/questions/25449398/matplotlib-user-enters-numeric-input-through-figure

@HastingsGreer
Copy link
Contributor Author

It looks like I messed up some formatting. This is my first pull request, is the procedure to close this, fix the formatting, then open a new pull request?

@QuLogic
Copy link
Member

QuLogic commented Oct 31, 2015

No, you created a separate branch for this PR, so you can just add on to it and push. If it becomes too long, we might request that you rebase too.

@tacaswell tacaswell added this to the proposed next point release (2.1) milestone Nov 1, 2015
@tacaswell
Copy link
Member

There is at least one other quasi-dead PR open which tries to add this. #1983

A GUI neutral text input box.

For the text box to remain responsive
you must keep a reference to it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make lines in docstrings as long as will fit in 80 columns.

@mdboom
Copy link
Member

mdboom commented Nov 2, 2015

This is cool work, and as you say, has been requested many times.

A couple of other things I'd like to see: The mouse cursor should change to an I-beam when hovering over the text widget. Clicking within the string should move the insertion cursor.

@HastingsGreer
Copy link
Contributor Author

I went through and fixed the formatting issues you pointed out. Thanks!

To my knowledge, there isn't currently a backend-agnostic way to set the cursor, so implementing the hover I-beam would require writing different code for each backend. All the other widgets light up when moused over, so I mimicked that behavior to indicate that this is a clickable element.

I will look into adding the ability to move the cursor by clicking, and moving to pixel coordinates for the cursor.
Should I add kwargs passthorugh for the text objects?

@mdboom
Copy link
Member

mdboom commented Nov 3, 2015

To my knowledge, there isn't currently a backend-agnostic way to set the cursor, so implementing the hover I-beam would require writing different code for each backend.

You can call set_cursor on a canvas, but I BEAM isn't currently one of the choices:

class Cursors(object):
    """Simple namespace for cursor reference"""
    HAND, POINTER, SELECT_REGION, MOVE = list(range(4))
cursors = Cursors()

It shouldn't be too much trouble to add that in all backends, though. They all follow the same pattern.

Should I add kwargs passthorugh for the text objects?

What do you mean, specifically?

@DanHickstein
Copy link
Contributor

I've been wanting a textbox widget for a while, and I'm excited to see that there is already a PR in place!

Any chance that this will move forward soon?

EDIT: This widget seems to work very well on OSX. The typing is a little bit laggy, and there is the above-mentioned problem that when you click on the text the cursor does not move, which may frustrate some people. But these are minor details in my opinion – the basic functionality is great!

@HastingsGreer
Copy link
Contributor Author

Yeah, it's good to hear that there's interest! I'll work on it this
weekend.

On Fri, Jan 15, 2016 at 1:36 PM, Danhickstein [email protected]
wrote:

I've been wanting a textbox widget for a while, and I'm excited to see
that there is already a PR in place!

Any chance that this will move forward soon?


Reply to this email directly or view it on GitHub
#5375 (comment)
.

@DanHickstein
Copy link
Contributor

One other small issue: the label text seems a little bit too close to the textbox, and adding spaces to the string has no effect.

An example:

import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
TextBox(plt.axes([0.5, 0.5, .2, .2]),'This is the label    ')
TextBox(plt.axes([0.5, 0.2, .2, .2]),'This is the label')
plt.show()

image

Thanks again for making this feature. I am using it make a quick-and-easy MPL-widgets based GUI and it's working nicely.

EDIT: I would suggest to include an option to set the padding between the label and the axes. Something like changing line 683 or widgets.py to:

self.label = ax.text(-label_pad, 0.5, label,

and including label_pad as a keyword argument to the __init__ function in the TextBox class:

def __init__(self, ax, label, initial='',label_pad=0.05,

@HastingsGreer
Copy link
Contributor Author

What should I do to fix the failed check "AppVeyor was unable to build non-mergable pull request" ?
Also, I have added the adjustable padding, and made the text box stop editing when the window is resized so that the cursor does not become misaligned.
I am working on the ability to move the cursor by clicking.
What else needs to be done for this to be pulled?

@QuLogic
Copy link
Member

QuLogic commented Jan 20, 2016

You will need to fetch master and rebase this branch to fix the merge conflicts.

@DanHickstein
Copy link
Contributor

If you are using the GitHub Desktop app, then you just hit the button "Update from matplotlib/master". I think that the only conflict is with the CHANGELOG file.

Is label_pad=0.01 enough? I thought that 0.05 seemed prettier, but it probably depends on the figure size.

@tacaswell
Copy link
Member

Pleas make sure you rebase + forcepush rather than merging master into your feature branch.

@DanHickstein
Copy link
Contributor

Oh yes, I suppose that rebasing avoids a lot of clutter in the git history.

Anyway, @QuadmasterXLII, you should go ahead and do that so that this can be merged.

@DanHickstein
Copy link
Contributor

@QuadmasterXLII - you should rebase this so that it can be merged. I've been using these textboxes all the time for the last few months and they work great. (Well, pretty well. It's annoying that you can't click on move the cursor. But nothing's perfect...)

@HastingsGreer
Copy link
Contributor Author

I did a rebase but appveyor is saying it fails. What should I do next?

@DanHickstein
Copy link
Contributor

You can click on the appveyor build that failed and see the error. Unfortunately, it's not clear to me what's going wrong. It's a build from 18 days ago, so it hasn't been updated in a while. I'm not sure how to get it to rebuild aside from making some small commit to this fork.

@HastingsGreer
Copy link
Contributor Author

I think it's ready for merger now!

@DanHickstein
Copy link
Contributor

Nice work @QuadmasterXLII!

It might also need a unit test in /lib/matplotlib/tests/test_widgets.py?

@Joshuaalbert
Copy link

Joshuaalbert commented Jul 14, 2016

You should add a set_val function, similar to the set_val function for Slider.
This can be done with

TextBox.text.text_disp('str')
TextBox.ax.get_figure().canvas.draw()

@fariza
Copy link
Member

fariza commented Aug 8, 2016

Really nice, one last thing @QuadmasterXLII can you squash the commits?

@Nodraak
Copy link
Contributor

Nodraak commented Aug 24, 2016

Hi!

I just tested this PR, it looks lovely, I don't know why this is not yet in matplotlib (yeah, nobody had taken care of this I guess :) ). I have just one small request:

When the user click outside of the text box, the on_submit callback is called. I believe this callback should be called only when the user actually validate its input with Enter or some submit button. As a workaround I have added self.capturekeystrokes = False just before this.

Anyway, thanks for this, it still get the work done !

Edit: I tested by copy/paste the code with py3, matploblib 1.5.2, debian 8 and commented out two lines because of AttributeError: 'AxesSubplot' object has no attribute 'set_facecolor'

@tacaswell
Copy link
Member

@fariza Can you be responsible for getting this merged? I am not super worried about squashing the commits, but the changes from @smithsp should probably get included (modulo the set_axis_bgcolor change).

We have not heard from @QuadmasterXLII , it might be most expedient if @fariza just took over and opened a new PR.

@Nodraak Yes, development is mostly by volunteers with day jobs, things can fall through the cracks 😞 . Could you work with @fariza and @QuadmasterXLII to get that change integrated with this PR?

@fariza
Copy link
Member

fariza commented Sep 12, 2016

Replaced by #6988

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants