Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Simple GUI interface enhancements #851

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

Merged
merged 12 commits into from
Jul 1, 2012
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Several fixes to WX. Modifier keys implemented for qt, wx and gtk bac…
…kends.
  • Loading branch information
pelson authored and pelson committed Jun 24, 2012
commit df0a11269f7b92173c20f8de4a95f9d4c4891a4c
4 changes: 0 additions & 4 deletions 4 lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2767,8 +2767,6 @@ def drag_zoom(self, event):

self.draw_rubberband(event, x, y, lastx, lasty)



def release_zoom(self, event):
'the release mouse button callback in zoom to rect mode'
for zoom_id in self._ids_zoom:
Expand Down Expand Up @@ -2894,8 +2892,6 @@ def draw(self):
loc.refresh()
self.canvas.draw()



def _update_view(self):
'''update the viewlim and position from the view and
position stack for each axes
Expand Down
11 changes: 7 additions & 4 deletions 11 lib/matplotlib/backends/backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,17 @@ def enter_notify_event(self, widget, event):
def _get_key(self, event):
if event.keyval in self.keyvald:
key = self.keyvald[event.keyval]
elif event.keyval <256:
elif event.keyval < 256:
key = chr(event.keyval)
else:
key = None

ctrl = event.state & gdk.CONTROL_MASK
shift = event.state & gdk.SHIFT_MASK
return key
for key_mask, prefix in ([gdk.CONTROL_MASK, 'ctrl'],
[gdk.MOD1_MASK, 'alt'], ):
if event.state & key_mask:
key = '{}+{}'.format(prefix, key)

return key


def configure_event(self, widget, event):
Expand Down
32 changes: 29 additions & 3 deletions 32 lib/matplotlib/backends/backend_qt4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import division, print_function
import math
import os
import signal
import sys

import matplotlib
Expand Down Expand Up @@ -60,8 +61,10 @@ def _create_qApp():

class Show(ShowBase):
def mainloop(self):
QtGui.qApp.exec_()
# allow KeyboardInterrupt exceptions to close the plot window.
signal.signal(signal.SIGINT, signal.SIG_DFL)

QtGui.qApp.exec_()
show = Show()


Expand Down Expand Up @@ -268,13 +271,36 @@ def minumumSizeHint( self ):
def _get_key( self, event ):
if event.isAutoRepeat():
return None

if event.key() < 256:
key = str(event.text())
key = unicode(event.text())

# if the control key is being pressed, we don't get the correct
# characters, so interpret them directly from the event.key().
# Unfortunately, this means that we cannot handle key's case
# since event.key() is not case sensitve, whereas event.text() is,
# Finally, since it is not possible to get the CapsLock state
# we cannot accurately compute the case of a pressed key when
# ctrl+shift+p is pressed.
if int(event.modifiers()) & QtCore.Qt.ControlModifier and event.key() < 256:
# we always get an uppercase charater
key = chr(event.key())
# if shift is not being pressed, lowercase it (as mentioned,
# this does not take into account the CapsLock state)
if not int(event.modifiers()) & QtCore.Qt.ShiftModifier:
key = key.lower()

elif event.key() in self.keyvald:
key = self.keyvald[ event.key() ]
key = self.keyvald[event.key()]
else:
key = None

if key is not None:
for modifier, Qt_key, prefix in [(QtCore.Qt.ControlModifier, QtCore.Qt.Key_Control, 'ctrl'),
(QtCore.Qt.AltModifier, QtCore.Qt.Key_Alt, 'alt')]:
if event.key() != Qt_key and int(event.modifiers()) & modifier == modifier:
key = '{}+{}'.format(prefix, key)

return key

def new_timer(self, *args, **kwargs):
Expand Down
81 changes: 30 additions & 51 deletions 81 lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,13 +1242,18 @@ def _get_key(self, evt):
keyval = evt.m_keyCode
if keyval in self.keyvald:
key = self.keyvald[keyval]
elif keyval <256:
elif keyval < 256:
key = chr(keyval)
# wx always returns an uppercase, so make it lowercase if the shift
# key is not depressed (NOTE: this will not handle Caps Lock)
if not evt.ShiftDown():
key = key.lower()
else:
key = None

# why is wx upcasing this?
if key is not None: key = key.lower()
for meth, prefix in ([evt.ControlDown, 'ctrl'], [evt.AltDown, 'alt'], ):
if meth():
key = '{}+{}'.format(prefix, key)

return key

Expand Down Expand Up @@ -1476,6 +1481,7 @@ def __init__(self, num, fig):
self.SetStatusBar(statbar)
self.canvas = self.get_canvas(fig)
self.canvas.SetInitialSize(wx.Size(fig.bbox.width, fig.bbox.height))
self.canvas.SetFocus()
self.sizer =wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND)
# By adding toolbar in sizer, we are able to put it at the bottom
Expand Down Expand Up @@ -1742,8 +1748,6 @@ def updateButtonText(self, lst):
self.SetLabel("Axes: %s" % axis_txt[:-1])




cursord = {
cursors.MOVE : wx.CURSOR_HAND,
cursors.HAND : wx.CURSOR_HAND,
Expand Down Expand Up @@ -1787,57 +1791,33 @@ def _init_toolbar(self):
DEBUG_MSG("_init_toolbar", 1, self)

self._parent = self.canvas.GetParent()
_NTB2_HOME =wx.NewId()
self._NTB2_BACK =wx.NewId()
self._NTB2_FORWARD =wx.NewId()
self._NTB2_PAN =wx.NewId()
self._NTB2_ZOOM =wx.NewId()
_NTB2_SAVE = wx.NewId()
_NTB2_SUBPLOT =wx.NewId()

self.SetToolBitmapSize(wx.Size(24,24))

self.AddSimpleTool(_NTB2_HOME, _load_bitmap('home.png'),
'Home', 'Reset original view')
self.AddSimpleTool(self._NTB2_BACK, _load_bitmap('back.png'),
'Back', 'Back navigation view')
self.AddSimpleTool(self._NTB2_FORWARD, _load_bitmap('forward.png'),
'Forward', 'Forward navigation view')
# todo: get new bitmap
self.AddCheckTool(self._NTB2_PAN, _load_bitmap('move.png'),
shortHelp='Pan',
longHelp='Pan with left, zoom with right')
self.AddCheckTool(self._NTB2_ZOOM, _load_bitmap('zoom_to_rect.png'),
shortHelp='Zoom', longHelp='Zoom to rectangle')

self.AddSeparator()
self.AddSimpleTool(_NTB2_SUBPLOT, _load_bitmap('subplots.png'),
'Configure subplots', 'Configure subplot parameters')

self.AddSimpleTool(_NTB2_SAVE, _load_bitmap('filesave.png'),
'Save', 'Save plot contents to file')

bind(self, wx.EVT_TOOL, self.home, id=_NTB2_HOME)
bind(self, wx.EVT_TOOL, self.forward, id=self._NTB2_FORWARD)
bind(self, wx.EVT_TOOL, self.back, id=self._NTB2_BACK)
bind(self, wx.EVT_TOOL, self.zoom, id=self._NTB2_ZOOM)
bind(self, wx.EVT_TOOL, self.pan, id=self._NTB2_PAN)
bind(self, wx.EVT_TOOL, self.configure_subplot, id=_NTB2_SUBPLOT)
bind(self, wx.EVT_TOOL, self.save, id=_NTB2_SAVE)
self.wx_ids = {}
for text, tooltip_text, image_file, callback in self.toolitems:
if text is None:
self.AddSeparator()
continue
self.wx_ids[text] = wx.NewId()
if text in ['Pan', 'Zoom']:
self.AddCheckTool(self.wx_ids[text], _load_bitmap(image_file + '.png'),
shortHelp=text, longHelp=tooltip_text)
else:
self.AddSimpleTool(self.wx_ids[text], _load_bitmap(image_file + '.png'),
text, tooltip_text)
bind(self, wx.EVT_TOOL, getattr(self, callback), id=self.wx_ids[text])

self.Realize()


def zoom(self, *args):
self.ToggleTool(self._NTB2_PAN, False)
self.ToggleTool(self.wx_ids['Pan'], False)
NavigationToolbar2.zoom(self, *args)

def pan(self, *args):
self.ToggleTool(self._NTB2_ZOOM, False)
self.ToggleTool(self.wx_ids['Zoom'], False)
NavigationToolbar2.pan(self, *args)


def configure_subplot(self, evt):
def configure_subplots(self, evt):
frame = wx.Frame(None, -1, "Configure subplots")

toolfig = Figure((6,3))
Expand All @@ -1855,7 +1835,7 @@ def configure_subplot(self, evt):
tool = SubplotTool(self.canvas.figure, toolfig)
frame.Show()

def save(self, evt):
def save_figure(self, *args):
# Fetch the required filename and file type.
filetypes, exts, filter_index = self.canvas._get_imagesave_wildcards()
default_file = "image." + self.canvas.get_default_filetype()
Expand All @@ -1881,7 +1861,7 @@ def save(self, evt):
os.path.join(dirname, filename), format=format)
except Exception as e:
error_msg_wx(str(e))

def set_cursor(self, cursor):
cursor =wx.StockCursor(cursord[cursor])
self.canvas.SetCursor( cursor )
Expand Down Expand Up @@ -1948,8 +1928,8 @@ def set_message(self, s):
def set_history_buttons(self):
can_backward = (self._views._pos > 0)
can_forward = (self._views._pos < len(self._views._elements) - 1)
self.EnableTool(self._NTB2_BACK, can_backward)
self.EnableTool(self._NTB2_FORWARD, can_forward)
self.EnableTool(self.wx_ids['Back'], can_backward)
self.EnableTool(self.wx_ids['Forward'], can_forward)


class NavigationToolbarWx(wx.ToolBar):
Expand Down Expand Up @@ -2149,13 +2129,12 @@ def _onMouseWheel(self, evt):
direction = -1
self.button_fn(direction)

_onSave = NavigationToolbar2Wx.save
_onSave = NavigationToolbar2Wx.save_figure

def _onClose(self, evt):
self.GetParent().Destroy()



class StatusBarWx(wx.StatusBar):
"""
A status bar is added to _FigureFrame to allow measurements and the
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.