Skip to content

Commit 61150f7

Browse files
author
stephanie
committed
move tooltip data into toolbar
1 parent d0025bc commit 61150f7

File tree

3 files changed

+148
-102
lines changed

3 files changed

+148
-102
lines changed

odmtools/gui/mnuPlotToolbar.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313

1414

15+
import matplotlib.dates as mdates
16+
from matplotlib.lines import Line2D
17+
from matplotlib.text import Text
18+
from matplotlib import dates
19+
1520
tools = LoggerTool()
1621
logger = tools.setupLogger(__name__, __name__ + '.log', 'w', logging.DEBUG)
1722

@@ -72,6 +77,18 @@ def _init_toolbar(self):
7277
text, tooltip_text)
7378
bind(self, wx.EVT_TOOL, getattr(self, callback), id=self.wx_ids[text])
7479

80+
81+
#init hover tooltip
82+
83+
# create a long tooltip with newline to get around wx bug (in v2.6.3.3)
84+
# where newlines aren't recognized on subsequent self.tooltip.SetTip() calls
85+
self.tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n')
86+
self.canvas.SetToolTip(self.tooltip)
87+
self.tooltip.Enable(False)
88+
self.tooltip.SetDelay(0)
89+
90+
91+
7592
self.Realize()
7693

7794

@@ -139,11 +156,17 @@ def editSeries(self, xys, edit):
139156
# enable select button
140157
self.xys = xys
141158
self.editCurve = edit
159+
self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick)
142160
self.select_tool.Enable(True)
143161
self.zoom_to_data.Enable(True)
144162
self.Realize()
145163

146164
def stopEdit(self):
165+
try:
166+
self.canvas.mpl_disconnect(self.pointPick)
167+
self.pointPick = None
168+
except AttributeError as e:
169+
logger.error(e)
147170

148171
self.canvas.mpl_disconnect(self.lassoAction)
149172
self.xys = None
@@ -248,6 +271,63 @@ def on_toggle_zoom_data_tool(self, event):
248271
self.canvas.draw()
249272

250273

274+
275+
def _onMotion(self, event):
276+
"""
277+
278+
:type event: matplotlib.backend_bases.MouseEvent
279+
:return:
280+
"""
281+
try:
282+
if event.xdata and event.ydata:
283+
xValue = dates.num2date(event.xdata).replace(tzinfo=None)
284+
#self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%Y-%m-%d %H:%M:%S"), event.ydata))
285+
#self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M:%S"), event.ydata))
286+
self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M"), event.ydata))
287+
self.toolbar.msg.SetForegroundColour((66, 66, 66))
288+
else:
289+
self.toolbar.msg.SetLabelText("")
290+
except ValueError:
291+
pass
292+
293+
def _onPick(self, event):
294+
"""
295+
296+
:param event:
297+
:return:
298+
"""
299+
300+
if isinstance(event.artist, Line2D):
301+
thisline = event.artist
302+
xdata = thisline.get_xdata()
303+
ydata = thisline.get_ydata()
304+
ind = event.ind
305+
306+
xValue = xdata[ind][0]
307+
yValue = ydata[ind][0]
308+
#tip = '(%s, %s)' % (xValue.strftime("%Y-%m-%d %H:%M:%S"), yValue)
309+
#tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M:%S"), yValue)
310+
tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M"), yValue)
311+
312+
self.tooltip.SetTip(tip)
313+
self.tooltip.Enable(True)
314+
self.tooltip.SetAutoPop(10000)
315+
316+
elif isinstance(event.artist, Text):
317+
text = event.artist
318+
#print "Picking Label: ", text.get_text()
319+
320+
def _onFigureLeave(self, event):
321+
"""Catches mouse leaving the figure
322+
323+
:param event:
324+
:return:
325+
"""
326+
327+
if self.tooltip.Window.Enabled:
328+
self.tooltip.SetTip("")
329+
330+
251331
#must add these methods for mac functionality
252332
def release_zoom(self, event):
253333
super(self.__class__, self).release_zoom(event)

odmtools/gui/mnuRibbon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from odmtools.controller.frmLinearDrift import frmLinearDrift
1616
from odmtools.controller.frmAbout import frmAbout
1717
import wizSave
18-
from odmtools.common import *
18+
from odmtools.common.icons import *
1919
import pandas as pd
2020

2121

odmtools/gui/plotTimeSeries.py

Lines changed: 67 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
from mpl_toolkits.axes_grid1 import host_subplot
1616

1717

18-
from matplotlib.lines import Line2D
19-
from matplotlib.text import Text
18+
2019

2120
from matplotlib.font_manager import FontProperties
2221
from wx.lib.pubsub import pub as Publisher
@@ -59,11 +58,12 @@ def _init_ctrls(self, parent):
5958
self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
6059
self.isShowLegendEnabled = False
6160

62-
self.canvas.mpl_connect('figure_leave_event', self._onFigureLeave)
63-
Publisher.subscribe(self.updateCursor, "updateCursor")
61+
6462

6563
# Create the navigation toolbar, tied to the canvas
6664
self.toolbar = NavigationToolbar(self.canvas, allowselect=True)
65+
self.canvas.mpl_connect('figure_leave_event', self.toolbar._onFigureLeave)
66+
Publisher.subscribe(self.updateCursor, "updateCursor")
6767
self.toolbar.Realize()
6868
self.seriesPlotInfo = None
6969

@@ -76,24 +76,13 @@ def _init_ctrls(self, parent):
7676
self._setColor("WHITE")
7777

7878
left = 0.125 # the left side of the subplots of the figure
79-
#right = 0.9 # the right side of the subplots of the figure
80-
#bottom = 0.51 # the bottom of the subplots of the figure
81-
#top = 1.2 # the top of the subplots of the figure
82-
#wspace = .8 # the amount of width reserved for blank space between subplots
83-
#hspace = .8 # the amount of height reserved for white space between subplots
79+
8480
plt.subplots_adjust(
8581
left=left#, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace
8682
)
8783
plt.tight_layout()
8884

89-
#init hover tooltip
9085

91-
# create a long tooltip with newline to get around wx bug (in v2.6.3.3)
92-
# where newlines aren't recognized on subsequent self.tooltip.SetTip() calls
93-
self.tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n')
94-
self.canvas.SetToolTip(self.tooltip)
95-
self.tooltip.Enable(False)
96-
self.tooltip.SetDelay(0)
9786

9887
#init lists
9988
#self.lines = {}
@@ -103,7 +92,7 @@ def _init_ctrls(self, parent):
10392
self.editseriesID = -1
10493
self.editCurve = None
10594
self.editPoint =None
106-
self.hoverAction = None
95+
# self.hoverAction = None
10796
self.selplot= None
10897

10998
self.cursors = []
@@ -117,28 +106,6 @@ def _init_sizers(self):
117106
self._init_coll_boxSizer1_Items(self.boxSizer1)
118107
self.SetSizer(self.boxSizer1)
119108

120-
'''
121-
def changePlotSelection(self, datetime_list=[]):
122-
cc= ColorConverter()
123-
# k black, # r red
124-
# needs to have graph first
125-
selected = cc.to_rgba('r', 1)
126-
unselected = cc.to_rgba('k', 0.1)
127-
allunselected = cc.to_rgba('k', 1)
128-
if self.editPoint:
129-
colorlist=[allunselected] *len(self.editCurve.dataTable)
130-
if len(datetime_list)>0:
131-
for i in xrange(len(self.editCurve.dataTable)):
132-
if self.editCurve.dataTable[i][1] in datetime_list:
133-
colorlist[i]=selected
134-
else:
135-
colorlist[i]=unselected
136-
137-
self.editPoint.set_color(colorlist)
138-
#self.editPoint.set_color(['k' if x == 0 else 'r' for x in tflist])
139-
self.canvas.draw()
140-
141-
'''
142109
## TODO 10/15/2014 Change function so that it will accept a list of datavalues. This will remove the need to loop through the values currently plotted and we would instead plot the list of datetimes and datavalues together.
143110

144111
def changePlotSelection(self, filtered_datetime):
@@ -225,13 +192,13 @@ def stopEdit(self):
225192
self.lman = None
226193

227194
#self.canvas.mpl_disconnect(self.hoverAction)
228-
try:
229-
self.canvas.mpl_disconnect(self.pointPick)
230-
self.pointPick = None
231-
except AttributeError as e:
232-
logger.error(e)
195+
# try:
196+
# self.canvas.mpl_disconnect(self.pointPick)
197+
# self.pointPick = None
198+
# except AttributeError as e:
199+
# logger.error(e)
233200

234-
self.hoverAction = None
201+
# self.hoverAction = None
235202
self.xys = None
236203
self.alpha=1
237204

@@ -280,10 +247,9 @@ def drawEditPlot(self, oneSeries):
280247
convertedDates = matplotlib.dates.date2num(dates)
281248
self.xys = zip(convertedDates, oneSeries.dataTable['DataValue'])
282249
self.toolbar.editSeries(self.xys, self.editCurve)
283-
self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick)
250+
# self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick)
284251
self.editSeries = oneSeries
285252

286-
287253
def _setColor(self, color):
288254
"""Set figure and canvas colours to be the same.
289255
:rtype : object
@@ -596,60 +562,60 @@ def make_patch_spines_invisible(self, ax):
596562
for sp in ax.spines.itervalues():
597563
sp.set_visible(False)
598564

599-
def _onMotion(self, event):
600-
"""
601-
602-
:type event: matplotlib.backend_bases.MouseEvent
603-
:return:
604-
"""
605-
try:
606-
if event.xdata and event.ydata:
607-
xValue = matplotlib.dates.num2date(event.xdata).replace(tzinfo=None)
608-
#self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%Y-%m-%d %H:%M:%S"), event.ydata))
609-
#self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M:%S"), event.ydata))
610-
self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M"), event.ydata))
611-
self.toolbar.msg.SetForegroundColour((66, 66, 66))
612-
else:
613-
self.toolbar.msg.SetLabelText("")
614-
except ValueError:
615-
pass
616-
617-
def _onPick(self, event):
618-
"""
619-
620-
:param event:
621-
:return:
622-
"""
623-
624-
if isinstance(event.artist, Line2D):
625-
thisline = event.artist
626-
xdata = thisline.get_xdata()
627-
ydata = thisline.get_ydata()
628-
ind = event.ind
629-
630-
xValue = xdata[ind][0]
631-
yValue = ydata[ind][0]
632-
#tip = '(%s, %s)' % (xValue.strftime("%Y-%m-%d %H:%M:%S"), yValue)
633-
#tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M:%S"), yValue)
634-
tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M"), yValue)
635-
636-
self.tooltip.SetTip(tip)
637-
self.tooltip.Enable(True)
638-
self.tooltip.SetAutoPop(10000)
639-
640-
elif isinstance(event.artist, Text):
641-
text = event.artist
642-
#print "Picking Label: ", text.get_text()
643-
644-
def _onFigureLeave(self, event):
645-
"""Catches mouse leaving the figure
646-
647-
:param event:
648-
:return:
649-
"""
650-
651-
if self.tooltip.Window.Enabled:
652-
self.tooltip.SetTip("")
565+
# def _onMotion(self, event):
566+
# """
567+
#
568+
# :type event: matplotlib.backend_bases.MouseEvent
569+
# :return:
570+
# """
571+
# try:
572+
# if event.xdata and event.ydata:
573+
# xValue = matplotlib.dates.num2date(event.xdata).replace(tzinfo=None)
574+
# #self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%Y-%m-%d %H:%M:%S"), event.ydata))
575+
# #self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M:%S"), event.ydata))
576+
# self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M"), event.ydata))
577+
# self.toolbar.msg.SetForegroundColour((66, 66, 66))
578+
# else:
579+
# self.toolbar.msg.SetLabelText("")
580+
# except ValueError:
581+
# pass
582+
#
583+
# def _onPick(self, event):
584+
# """
585+
#
586+
# :param event:
587+
# :return:
588+
# """
589+
#
590+
# if isinstance(event.artist, Line2D):
591+
# thisline = event.artist
592+
# xdata = thisline.get_xdata()
593+
# ydata = thisline.get_ydata()
594+
# ind = event.ind
595+
#
596+
# xValue = xdata[ind][0]
597+
# yValue = ydata[ind][0]
598+
# #tip = '(%s, %s)' % (xValue.strftime("%Y-%m-%d %H:%M:%S"), yValue)
599+
# #tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M:%S"), yValue)
600+
# tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M"), yValue)
601+
#
602+
# self.tooltip.SetTip(tip)
603+
# self.tooltip.Enable(True)
604+
# self.tooltip.SetAutoPop(10000)
605+
#
606+
# elif isinstance(event.artist, Text):
607+
# text = event.artist
608+
# #print "Picking Label: ", text.get_text()
609+
#
610+
# def _onFigureLeave(self, event):
611+
# """Catches mouse leaving the figure
612+
#
613+
# :param event:
614+
# :return:
615+
# """
616+
#
617+
# if self.tooltip.Window.Enabled:
618+
# self.tooltip.SetTip("")
653619

654620
class Cursor(object):
655621
def __init__(self, canvas, toolbar, ax, name):

0 commit comments

Comments
 (0)