X Tutup
Skip to content

Fix a bug in TextBox where shortcut keys were not being reenabled#7585

Merged
NelleV merged 2 commits intomatplotlib:masterfrom
mikehenninger:textbox_typo_fix
Dec 18, 2016
Merged

Fix a bug in TextBox where shortcut keys were not being reenabled#7585
NelleV merged 2 commits intomatplotlib:masterfrom
mikehenninger:textbox_typo_fix

Conversation

@mikehenninger
Copy link
Copy Markdown
Contributor

in _click(), the self.capturekeystrokes flag was being set false before
calling stop_typing() when the click was outside the textbox axes.
stop_typing() expects this flag to still be set if the textbox was
capturing keystrokes, and does not reenable shortcut keys
if it is not set. The line setting self.capturekeystrokes false in _click()
is deleted, which fixes the behavior of /examples/widgets/textbox.py. There
is no test suite set up for the textbox class and I'm not prepared to start
one now, so no tests submitted for this bugfix.

This is babby's first pull request so let me know if I'm doing it wrong.

…nabled

in _click(), the self.capturekeystrokes flag was being set false before
calling stop_typing(). stop_typing() expects this flag to still be set if
the textbox was capturing keystrokes, and does not reenable shortcut keys
if it is not set. The line setting self.capturekeystrokes false in _click()
is deleted, which fixes the behavior in /examples/widgets/textbox.py. There
is no test set setup for the textbox class and I'm not prepared to start one
now, so no actual test.
if event.inaxes != self.ax:
self.capturekeystrokes = False
self.stop_typing()
self.stop_typing()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You have one too many spaces on this line which is causing syntax errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Idonteven... thanks.
I'm new to this whole contributing to public projects thing... I marked this PR as editable by the mpl powers that be, but I don't know that just means this thread or the committed code itself. Given that git is telling me that my remote is unchanged, I guess it means the former (your diff in which you show the fixed code notwithstanding), so I went ahead and pushed the typo fix myself. Is that right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yup, that's fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To be clear, marking the PR as editable allows mpl committers to push changes to your branch--but that takes more than just commenting here.

@anntzer
Copy link
Copy Markdown
Contributor

anntzer commented Dec 7, 2016

In the absence of testing (which I agree is difficult for UI work) it would be nice if you could post a minimal example that was failing before this PR and works with it -- something that the maintainers can directly copy-paste to test the patch.

@mikehenninger
Copy link
Copy Markdown
Contributor Author

mikehenninger commented Dec 8, 2016

minimal example in lieu of proper test:

code below is just /examples/widgets/textbox.py.

  1. Run script
  2. note keyboard shortcuts are working (f for fullscreen, etc.)
  3. click in textbox
  4. note keyboard shortcuts are not working, which is clearly intended
    4.5) make sure the contents of the textbox is a valid math expression*
  5. click outside the textbox's axes
  6. note keyboard shortcuts are still not working, which is the bug
    with this PR, the keyboard shortcuts work correctly in step 6

* submit(text) does no validation and will barf at eval(text) if text isn't valid expression

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.2)
t = np.arange(-2.0, 2.0, 0.001)
s = t ** 2
initial_text = "t ** 2"
l, = plt.plot(t, s, lw=2)


def submit(text):
    ydata = eval(text)
    l.set_ydata(ydata)
    ax.set_ylim(np.min(ydata), np.max(ydata))
    plt.draw()

axbox = plt.axes([0.1, 0.05, 0.8, 0.075])
text_box = TextBox(axbox, 'Evaluate', initial=initial_text)
text_box.on_submit(submit)

plt.show()

@anntzer
Copy link
Copy Markdown
Contributor

anntzer commented Dec 8, 2016

Upon further testing, it seems that the issues are different depending on whether toolmanager is enabled or not. It seems that this PR fixes the case without toolmanager, i.e. it reenables shortcuts after defocusing from the textbox.
However, with toolmanager, the issue is that the shortcut never gets disabled in the first place.

In any case this is already an improvement.

@anntzer anntzer changed the title Fix a bug in TextBox where shortcut keys were not being reenabled [MRG+1] Fix a bug in TextBox where shortcut keys were not being reenabled Dec 8, 2016
@mikehenninger
Copy link
Copy Markdown
Contributor Author

mikehenninger commented Dec 8, 2016

@anntzer Yes, there are definitely other toolmanager bugs. "shortcuts never get disabled" is the toolmanager bug for TkAgg, while for Qt5Agg, the shortcuts never get enabled... even if there is no textbox. I talk a bit about this in a comment on issue #7571

This PR was for a bug that was on top of/independent of them, which is why I bothered to make a PR even with these (far bigger) bugs outstanding.

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Dec 9, 2016
@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Dec 12, 2016

@tacaswell added this to the 2.0.1 (next bug fix release) milestone 2 days ago

Does the TextBox even exist on 2.0?

@NelleV NelleV merged commit 4932e2b into matplotlib:master Dec 18, 2016
@tacaswell
Copy link
Copy Markdown
Member

Can we hold off on backporting this to the rc?

@tacaswell
Copy link
Copy Markdown
Member

assuming I am not confused and it even can be backported.

@NelleV
Copy link
Copy Markdown
Member

NelleV commented Dec 18, 2016

My plan was holding off until I found time to check whether it had to be backported.

@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Dec 19, 2016

The only instance of TextBox I could find in v2.x was this issue title in the stats.

@QuLogic QuLogic modified the milestones: 2.1 (next point release), 2.0.1 (next bug fix release) Dec 19, 2016
@QuLogic QuLogic changed the title [MRG+1] Fix a bug in TextBox where shortcut keys were not being reenabled Fix a bug in TextBox where shortcut keys were not being reenabled Dec 19, 2016
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.

6 participants

X Tutup