- optimized the toggle axis command

- added posibility of using a big mouse cursor or a small mouse cursor. The big mouse cursor is made from 2 infinite lines. This was implemented for both graphic engines
- added ability to change the cursor size when the small mouse cursor is selected in Preferences -> General
This commit is contained in:
Marius Stanciu
2019-09-27 04:42:28 +03:00
committed by Marius
parent 9c8c36adbb
commit 46e7be20e2
11 changed files with 177 additions and 34 deletions

View File

@@ -67,6 +67,14 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
self.draw_workspace()
self.line_parent = None
self.line_color = (0.3, 0.0, 0.0, 1.0)
self.cursor_v_line = InfiniteLine(pos=None, color=self.line_color, vertical=True,
parent=self.line_parent)
self.cursor_h_line = InfiniteLine(pos=None, color=self.line_color, vertical=False,
parent=self.line_parent)
# if self.app.defaults['global_workspace'] is True:
# if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() == 'MM':
# self.wkspace_t = Line(pos=)
@@ -80,6 +88,8 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
# TODO: Should be setting to show/hide CNC job annotations (global or per object)
self.text_collection.enabled = True
self.c = None
# Keep VisPy canvas happy by letting it be "frozen" again.
self.freeze()
@@ -185,10 +195,30 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
# return sc
return ShapeCollection(parent=self.view.scene, pool=self.fcapp.pool, **kwargs)
def new_cursor(self):
c = Cursor(pos=np.empty((0, 2)), parent=self.view.scene)
c.antialias = 0
return c
def new_cursor(self, big=None):
if big is True:
self.c = CursorBig()
self.c.mouse_state_updated.connect(self.on_mouse_state)
self.c.mouse_position_updated.connect(self.on_mouse_position)
else:
self.c = Cursor(pos=np.empty((0, 2)), parent=self.view.scene)
self.c.antialias = 0
return self.c
def on_mouse_state(self, state):
if state:
self.cursor_h_line.parent = self.view.scene
self.cursor_v_line.parent = self.view.scene
else:
self.cursor_h_line.parent = None
self.cursor_v_line.parent = None
def on_mouse_position(self, pos):
# self.line_color = color
self.cursor_h_line.set_data(pos=pos[1], color=self.line_color)
self.cursor_v_line.set_data(pos=pos[0], color=self.line_color)
self.view.scene.update()
def new_text_group(self, collection=None):
if collection:
@@ -247,3 +277,38 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
def on_pool_recreated(self, pool):
self.shape_collection.pool = pool
class CursorBig(QtCore.QObject):
"""
This is a fake cursor to ensure compatibility with the OpenGL engine (VisPy).
This way I don't have to chane (disable) things related to the cursor all over when
using the low performance Matplotlib 2D graphic engine.
"""
mouse_state_updated = QtCore.pyqtSignal(bool)
mouse_position_updated = QtCore.pyqtSignal(list)
def __init__(self):
super().__init__()
self._enabled = None
@property
def enabled(self):
return True if self._enabled else False
@enabled.setter
def enabled(self, value):
self._enabled = value
self.mouse_state_updated.emit(value)
def set_data(self, pos, **kwargs):
"""Internal event handler to draw the cursor when the mouse moves."""
if 'edge_color' in kwargs:
color = kwargs['edge_color']
else:
color = (0.0, 0.0, 0.0, 1.0)
position = [pos[0][0], pos[0][1]]
self.mouse_position_updated.emit(position)

View File

@@ -159,6 +159,9 @@ class PlotCanvasLegacy(QtCore.QObject):
self.axes.axhline(color=(0.70, 0.3, 0.3), linewidth=2)
self.axes.axvline(color=(0.70, 0.3, 0.3), linewidth=2)
self.ch_line = None
self.cv_line = None
# The canvas is the top level container (FigureCanvasQTAgg)
self.canvas = FigureCanvas(self.figure)
@@ -207,6 +210,7 @@ class PlotCanvasLegacy(QtCore.QObject):
self.pan_axes = []
self.panning = False
self.mouse = [0, 0]
self.big_cursor = False
# signal is the mouse is dragging
self.is_dragging = False
@@ -254,17 +258,19 @@ class PlotCanvasLegacy(QtCore.QObject):
pass
# log.debug("Cache updated the screen!")
def new_cursor(self, axes=None):
def new_cursor(self, axes=None, big=None):
# if axes is None:
# c = MplCursor(axes=self.axes, color='black', linewidth=1)
# else:
# c = MplCursor(axes=axes, color='black', linewidth=1)
if big is True:
self.big_cursor = True
self.ch_line = self.axes.axhline(color=(0.0, 0.0, 0.0), linewidth=1)
self.cv_line = self.axes.axvline(color=(0.0, 0.0, 0.0), linewidth=1)
c = FakeCursor()
try:
c.mouse_state_updated.connect(self.clear_cursor)
except Exception as e:
print(str(e))
c.mouse_state_updated.connect(self.clear_cursor)
return c
def draw_cursor(self, x_pos, y_pos):
@@ -277,18 +283,26 @@ class PlotCanvasLegacy(QtCore.QObject):
"""
# there is no point in drawing mouse cursor when panning as it jumps in a confusing way
if self.app.app_cursor.enabled is True and self.panning is False:
try:
x, y = self.app.geo_editor.snap(x_pos, y_pos)
if self.big_cursor is False:
try:
x, y = self.app.geo_editor.snap(x_pos, y_pos)
# Pointer (snapped)
elements = self.axes.plot(x, y, 'k+', ms=33, mew=1, animated=True)
for el in elements:
self.axes.draw_artist(el)
except Exception as e:
# this happen at app initialization since self.app.geo_editor does not exist yet
# I could reshuffle the object instantiating order but what's the point? I could crash something else
# and that's pythonic, too
pass
# Pointer (snapped)
# The size of the cursor is multiplied by 1.65 because that value made the cursor similar with the
# one in the OpenGL(3D) graphic engine
pointer_size = int(float(self.app.defaults["global_cursor_size"] ) * 1.65)
elements = self.axes.plot(x, y, 'k+', ms=pointer_size, mew=1, animated=True)
for el in elements:
self.axes.draw_artist(el)
except Exception as e:
# this happen at app initialization since self.app.geo_editor does not exist yet
# I could reshuffle the object instantiating order but what's the point? I could crash something else
# and that's pythonic, too
pass
else:
self.ch_line.set_ydata(y_pos)
self.cv_line.set_xdata(x_pos)
self.canvas.draw_idle()
self.canvas.blit(self.axes.bbox)
@@ -742,7 +756,6 @@ class FakeCursor(QtCore.QObject):
def set_data(self, pos, **kwargs):
"""Internal event handler to draw the cursor when the mouse moves."""
pass
class ShapeCollectionLegacy:

View File

@@ -754,6 +754,29 @@ class GeneralGUISetGroupUI(OptionsGroupUI):
"when hovering with mouse over items throughout the App.")
)
# Mouse Cursor Shape
self.cursor_lbl = QtWidgets.QLabel('%s:' % _('Mouse Cursor'))
self.cursor_lbl.setToolTip(
_("Choose a mouse cursor shape.\n"
"- Small -> with a customizable size.\n"
"- Big -> Infinite lines")
)
self.cursor_radio = RadioSet([
{"label": _("Small"), "value": "small"},
{"label": _("Big"), "value": "big"}
], orientation='horizontal', stretch=False)
self.cursor_size_lbl = QtWidgets.QLabel('%s:' % _('Mouse Cursor Size'))
self.cursor_size_lbl.setToolTip(
_("Set the size of the mouse cursor, in pixels.")
)
self.cursor_size_entry = FCSpinner()
self.cursor_size_entry.set_range(10, 70)
self.cursor_size_entry.setWrapping(True)
# Add (label - input field) pair to the QFormLayout
self.form_box.addRow(self.spacelabel, self.spacelabel)
@@ -775,6 +798,8 @@ class GeneralGUISetGroupUI(OptionsGroupUI):
self.form_box.addRow(self.project_autohide_label, self.project_autohide_cb)
self.form_box.addRow(QtWidgets.QLabel(''))
self.form_box.addRow(self.toggle_tooltips_label, self.toggle_tooltips_cb)
self.form_box.addRow(self.cursor_lbl, self.cursor_radio)
self.form_box.addRow(self.cursor_size_lbl, self.cursor_size_entry)
# Add the QFormLayout that holds the Application general defaults
# to the main layout of this TAB