FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Rename set_time_inspector to the more sensible set_mouse_callback · robot-python/finplot@7208f3f · GitHub

Commit 7208f3f

Browse files
committed
Rename set_time_inspector to the more sensible set_mouse_callback
1 parent 3c0f3c6 commit 7208f3f

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎finplot/__init__.py‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
# module definitions, mostly colors
3535
legend_border_color = '#777'
36-
legend_fill_color = '#6668'
36+
legend_fill_color = '#666a'
3737
legend_text_color = '#ddd6'
3838
soft_colors = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']
3939
hard_colors = ['#000000', '#772211', '#000066', '#555555', '#0022cc', '#ffcc00']
@@ -1857,16 +1857,21 @@ def remove_primitive(primitive):
18571857
ax.vb.removeItem(txt)
18581858

18591859

1860-
def set_time_inspector(inspector, ax=None, when='click'):
1861-
'''Callback when clicked like so: inspector(x, y).'''
1860+
def set_mouse_callback(callback, ax=None, when='click'):
1861+
'''Callback when clicked like so: callback(x, y).'''
18621862
ax = ax if ax else last_ax
18631863
master = ax.ax_widget if hasattr(ax, 'ax_widget') else ax.vb.win
18641864
if when == 'hover':
1865-
master.proxy_hover = pg.SignalProxy(master.scene().sigMouseMoved, rateLimit=15, slot=partial(_inspect_pos, ax, inspector))
1865+
master.proxy_hover = pg.SignalProxy(master.scene().sigMouseMoved, rateLimit=15, slot=partial(_mcallback_pos, ax, callback))
18661866
elif when in ('dclick', 'double-click'):
1867-
master.proxy_dclick = pg.SignalProxy(master.scene().sigMouseClicked, slot=partial(_inspect_clicked, ax, inspector, True))
1867+
master.proxy_dclick = pg.SignalProxy(master.scene().sigMouseClicked, slot=partial(_mcallback_click, ax, callback, True))
18681868
else:
1869-
master.proxy_click = pg.SignalProxy(master.scene().sigMouseClicked, slot=partial(_inspect_clicked, ax, inspector, False))
1869+
master.proxy_click = pg.SignalProxy(master.scene().sigMouseClicked, slot=partial(_mcallback_click, ax, callback, False))
1870+
1871+
1872+
def set_time_inspector(callback, ax=None, when='click'):
1873+
print('Warning: set_time_inspector() is a misnomer from olden days. Please use set_mouse_callback() instead.')
1874+
set_mouse_callback(callback, ax, when)
18701875

18711876

18721877
def add_crosshair_info(infofunc, ax=None):
@@ -2616,14 +2621,14 @@ def _wheel_event_wrapper(self, orig_func, ev):
26162621
orig_func(self, ev)
26172622

26182623

2619-
def _inspect_clicked(ax, inspector, when_double_click, evs):
2624+
def _mcallback_click(ax, callback, when_double_click, evs):
26202625
if evs[-1].accepted or when_double_click != evs[-1].double():
26212626
return
26222627
pos = evs[-1].scenePos()
2623-
return _inspect_pos(ax, inspector, (pos,))
2628+
return _mcallback_pos(ax, callback, (pos,))
26242629

26252630

2626-
def _inspect_pos(ax, inspector, poss):
2631+
def _mcallback_pos(ax, callback, poss):
26272632
if not ax.vb.datasrc:
26282633
return
26292634
point = ax.vb.mapSceneToView(poss[-1])
@@ -2634,7 +2639,7 @@ def _inspect_pos(ax, inspector, poss):
26342639
if clamp_grid:
26352640
t = ax.vb.datasrc.x.iloc[-1 if t > 0 else 0]
26362641
try:
2637-
inspector(t, point.y())
2642+
callback(t, point.y())
26382643
except OSError as e:
26392644
pass
26402645
except Exception as e:

‎finplot/examples/snp500.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def update_crosshair_text(x, y, xtext, ytext):
5454
ytext = '%s (Close%+.2f)' % (ytext, (y - df.iloc[x].Close))
5555
return xtext, ytext
5656

57-
fplt.set_time_inspector(update_legend_text, ax=ax, when='hover')
57+
fplt.set_mouse_callback(update_legend_text, ax=ax, when='hover')
5858
fplt.add_crosshair_info(update_crosshair_text, ax=ax)
5959

6060
fplt.show()

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL