Skip to content

Commit af57305

Browse files
author
stephanie
committed
merge fix_filter, fix_toolbar
2 parents 04032c3 + 918e077 commit af57305

File tree

3 files changed

+158
-49
lines changed

3 files changed

+158
-49
lines changed

odmtools/gui/mnuPlotToolbar.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212

1313

1414

15+
1516
# tools = LoggerTool()
1617
# logger = tools.setupLogger(__name__, __name__ + '.log', 'w', logging.DEBUG)
1718
logger =logging.getLogger('main')
1819

20+
import matplotlib.dates as mdates
21+
from matplotlib.lines import Line2D
22+
from matplotlib.text import Text
23+
from matplotlib import dates
24+
1925

2026
def bind(actor,event,action,id=None):
2127
if id is not None:
@@ -74,6 +80,20 @@ def _init_toolbar(self):
7480
text, tooltip_text)
7581
bind(self, wx.EVT_TOOL, getattr(self, callback), id=self.wx_ids[text])
7682

83+
84+
#init hover tooltip
85+
86+
# create a long tooltip with newline to get around wx bug (in v2.6.3.3)
87+
# where newlines aren't recognized on subsequent self.tooltip.SetTip() calls
88+
self.tooltip = ToolTip(tip='tip with a long %s line and a newline\n')
89+
self.canvas.SetToolTip(self.tooltip)
90+
# self.tooltip.Enable(False)
91+
self.tooltip.SetDelay(0)
92+
93+
self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick)
94+
95+
96+
7797
self.Realize()
7898

7999

@@ -141,11 +161,17 @@ def editSeries(self, xys, edit):
141161
# enable select button
142162
self.xys = xys
143163
self.editCurve = edit
164+
self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick)
144165
self.select_tool.Enable(True)
145166
self.zoom_to_data.Enable(True)
146167
self.Realize()
147168

148169
def stopEdit(self):
170+
try:
171+
self.canvas.mpl_disconnect(self.pointPick)
172+
self.pointPick = None
173+
except AttributeError as e:
174+
logger.error(e)
149175

150176
self.canvas.mpl_disconnect(self.lassoAction)
151177
self.xys = None
@@ -252,6 +278,63 @@ def on_toggle_zoom_data_tool(self, event):
252278
self.canvas.draw()
253279

254280

281+
282+
def _onMotion(self, event):
283+
"""
284+
285+
:type event: matplotlib.backend_bases.MouseEvent
286+
:return:
287+
"""
288+
try:
289+
if event.xdata and event.ydata:
290+
xValue = dates.num2date(event.xdata).replace(tzinfo=None)
291+
#self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%Y-%m-%d %H:%M:%S"), event.ydata))
292+
#self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M:%S"), event.ydata))
293+
self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M"), event.ydata))
294+
self.toolbar.msg.SetForegroundColour((66, 66, 66))
295+
else:
296+
self.toolbar.msg.SetLabelText("")
297+
except ValueError:
298+
pass
299+
300+
def _onPick(self, event):
301+
"""
302+
303+
:param event:
304+
:return:
305+
"""
306+
307+
if isinstance(event.artist, Line2D):
308+
thisline = event.artist
309+
xdata = thisline.get_xdata()
310+
ydata = thisline.get_ydata()
311+
ind = event.ind
312+
313+
xValue = xdata[ind][0]
314+
yValue = ydata[ind][0]
315+
#tip = '(%s, %s)' % (xValue.strftime("%Y-%m-%d %H:%M:%S"), yValue)
316+
#tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M:%S"), yValue)
317+
tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M"), yValue)
318+
319+
self.tooltip.SetString(tip)
320+
self.tooltip.Enable(True)
321+
self.tooltip.SetAutoPop(10000)
322+
323+
elif isinstance(event.artist, Text):
324+
text = event.artist
325+
#print "Picking Label: ", text.get_text()
326+
327+
def _onFigureLeave(self, event):
328+
"""Catches mouse leaving the figure
329+
330+
:param event:
331+
:return:
332+
"""
333+
334+
if self.tooltip.Window.Enabled:
335+
self.tooltip.SetTip("")
336+
337+
255338
#must add these methods for mac functionality
256339
def release_zoom(self, event):
257340
super(self.__class__, self).release_zoom(event)
@@ -268,3 +351,58 @@ def forward(self, event):
268351
def home(self, event):
269352
super(self.__class__, self).home(event)
270353
self.canvas.draw()
354+
355+
356+
357+
358+
359+
360+
def on_scroll_zoom(self, event):
361+
axes = self.canvas.figure.axes[0]
362+
base_scale = 1.2
363+
# get the current x and y limits
364+
cur_xlim = axes.get_xlim()
365+
cur_ylim = axes.get_ylim()
366+
cur_xrange = (cur_xlim[1] - cur_xlim[0])*.5
367+
cur_yrange = (cur_ylim[1] - cur_ylim[0])*.5
368+
xdata = event.xdata # get event x location
369+
ydata = event.ydata # get event y location
370+
if event.button == 'up':
371+
# deal with zoom in
372+
scale_factor = 1/base_scale
373+
elif event.button == 'down':
374+
# deal with zoom out
375+
scale_factor = base_scale
376+
else:
377+
# deal with something that should never happen
378+
scale_factor = 1
379+
print event.button
380+
# set new limits
381+
axes.set_xlim([xdata - cur_xrange*scale_factor,
382+
xdata + cur_xrange*scale_factor])
383+
axes.set_ylim([ydata - cur_yrange*scale_factor,
384+
ydata + cur_yrange*scale_factor])
385+
self.canvas.draw() # force re-draw
386+
387+
# fig = ax.get_figure() # get the figure of interest
388+
# attach the call back
389+
390+
391+
class ToolTip(wx.ToolTip):
392+
"""
393+
a subclass of wx.Tooltip which can be disable on mac
394+
"""
395+
396+
def __init__(self, tip):
397+
self.tooltip_string = tip
398+
self.TooltipsEnabled = True
399+
wx.ToolTip.__init__(self, tip)
400+
401+
def SetString(self, tip):
402+
self.tooltip_string = tip
403+
404+
def Enable(self, x):
405+
print ("in custom tooltip set enable")
406+
if x: self.SetTip(self.tooltip_string)
407+
else: self.SetTip("")
408+

odmtools/gui/mnuRibbon.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,11 @@ def onSave(self, event):
398398

399399
def onEditFilter(self, event):
400400
data_filter = frmDataFilter(self.parent, self.parent.getRecordService())
401-
val = data_filter.ShowModal()
402401

403-
data_filter.Destroy()
402+
if data_filter.Show() == wx.OK:
403+
print "OK"
404+
data_filter.Destroy()
405+
404406
event.Skip()
405407

406408
# ###################################

odmtools/gui/plotTimeSeries.py

Lines changed: 16 additions & 47 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

@@ -279,14 +246,15 @@ def drawEditPlot(self, oneSeries):
279246

280247
convertedDates = matplotlib.dates.date2num(dates)
281248

249+
282250
# scale = 1.5
283251
# f = zoom_factory(curraxis , base_scale = scale)
252+
284253
self.xys = zip(convertedDates, oneSeries.dataTable['DataValue'])
285254
self.toolbar.editSeries(self.xys, self.editCurve)
286-
self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick)
255+
# self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick)
287256
self.editSeries = oneSeries
288257

289-
290258
def _setColor(self, color):
291259
"""Set figure and canvas colours to be the same.
292260
:rtype : object
@@ -601,6 +569,7 @@ def make_patch_spines_invisible(self, ax):
601569
for sp in ax.spines.itervalues():
602570
sp.set_visible(False)
603571

572+
604573
def _onMotion(self, event):
605574
"""
606575

0 commit comments

Comments
 (0)