Turn gtk3 pan/zoom button into togglable buttons.#15226
Turn gtk3 pan/zoom button into togglable buttons.#15226timhoffm merged 1 commit intomatplotlib:masterfrom
Conversation
| super().pan(*args) | ||
| self._updating_button_states = True | ||
| try: | ||
| if "Pan" in self._gtk_ids: |
There was a problem hiding this comment.
Extract method similar to _update_buttons_checked() in Qt backend?
Or maybe even better make a private context so that the whole method would be:
def pan(self, *args):
with self._update_button_states('Pan'):
super().pan(*args)
There was a problem hiding this comment.
re-triggering pan just to update the button state seems... confusing. perhaps @QuLogic knows if there's a gtk3 equivalent of qt's blockSignals? (which is the way this is implemented in qt)
There was a problem hiding this comment.
Even without, you can still extract a method:
def _update_buttom_states(self, active_tool):
self._updating_button_states = True
try:
for button_id in ['Zoom', 'Pan']:
if button_id in self._gtk_ids:
self._gtk_ids[button_id].set_active(
button_id.upper() == active_tool == self._active)
finally:
self._updating_button_states = False
def pan(self, *args):
if self._updating_button_states:
return
super().pan(*args)
self._update_buttom_states(active_tool='PAN')
def zoom(self, *args):
if self._updating_button_states:
return
super().zoom(*args)
self._update_buttom_states(active_tool='ZOOM')
There was a problem hiding this comment.
actually I finally found a more reasonable solution...
16bb3fe to
376d0da
Compare
| tbutton.set_icon_widget(image) | ||
| self.insert(tbutton, -1) | ||
| tbutton.connect('clicked', getattr(self, callback)) | ||
| tbutton._signal_handler = tbutton.connect( |
There was a problem hiding this comment.
is _signal_handler an API of GTK or is it just some attibute that you invented to carry the signal handler around. If the latter, that should be documented in a commment.
There was a problem hiding this comment.
it's just our own thing; comment added.
... similar to the qt5 ones.
376d0da to
284577f
Compare
... similar to the qt5 ones.
PR Summary
PR Checklist