From 537b843a04990672da812647a2a056d1e3fda32a Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Fri, 27 Sep 2019 17:19:44 +0300 Subject: [PATCH] - made the mouse cursor (big, small) change in real time for both graphic engines --- FlatCAMApp.py | 8 ++++++++ README.md | 1 + flatcamGUI/PlotCanvas.py | 28 +++++++++++++++++++++++----- flatcamGUI/PlotCanvasLegacy.py | 10 +++++++++- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 1610e51a..bee19cc9 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -6428,13 +6428,21 @@ class App(QtCore.QObject): :param val: type of mouse cursor, set in Preferences ('small' or 'big') :return: None """ + self.app_cursor.enabled = False if val == 'small': self.ui.general_defaults_form.general_gui_set_group.cursor_size_entry.setDisabled(False) self.ui.general_defaults_form.general_gui_set_group.cursor_size_lbl.setDisabled(False) + self.app_cursor = self.plotcanvas.new_cursor() else: self.ui.general_defaults_form.general_gui_set_group.cursor_size_entry.setDisabled(True) self.ui.general_defaults_form.general_gui_set_group.cursor_size_lbl.setDisabled(True) + self.app_cursor = self.plotcanvas.new_cursor(big=True) + + if self.ui.grid_snap_btn.isChecked(): + self.app_cursor.enabled = True + else: + self.app_cursor.enabled = False def on_cnc_custom_parameters(self, signal_text): if signal_text == 'Parameters': diff --git a/README.md b/README.md index b42d9f07..6ad20e12 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ CAD program, and create G-Code for Isolation routing. - removed the line that remove the spaces from the path parameter in the Tcl commands that open something (Gerber, Gcode, Excellon) - fixed issue with the old SysTray icon not hidden when the application is restarted programmatically - if an object is edited but the result is not saved, the app will reload the edited object UI and set the Selected tab as active +- made the mouse cursor (big, small) change in real time for both graphic engines 27.09.2019 diff --git a/flatcamGUI/PlotCanvas.py b/flatcamGUI/PlotCanvas.py index 42d5dbcc..7911c81e 100644 --- a/flatcamGUI/PlotCanvas.py +++ b/flatcamGUI/PlotCanvas.py @@ -104,7 +104,7 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): a3l_in = np.array([(0, 0), (16.5, 0), (16.5, 11.7), (0, 11.7)]) a4p_mm = np.array([(0, 0), (210, 0), (210, 297), (0, 297)]) - a4l_mm = np.array([(0, 0), (297, 0), (297,210), (0, 210)]) + a4l_mm = np.array([(0, 0), (297, 0), (297, 210), (0, 210)]) a3p_mm = np.array([(0, 0), (297, 0), (297, 420), (0, 420)]) a3l_mm = np.array([(0, 0), (420, 0), (420, 297), (0, 297)]) @@ -130,14 +130,14 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): self.delete_workspace() self.b_line = Line(pos=a[0:2], color=(0.70, 0.3, 0.3, 1.0), - antialias= True, method='agg', parent=self.view.scene) + antialias=True, method='agg', parent=self.view.scene) self.r_line = Line(pos=a[1:3], color=(0.70, 0.3, 0.3, 1.0), - antialias= True, method='agg', parent=self.view.scene) + antialias=True, method='agg', parent=self.view.scene) self.t_line = Line(pos=a[2:4], color=(0.70, 0.3, 0.3, 1.0), - antialias= True, method='agg', parent=self.view.scene) + antialias=True, method='agg', parent=self.view.scene) self.l_line = Line(pos=np.array((a[0], a[3])), color=(0.70, 0.3, 0.3, 1.0), - antialias= True, method='agg', parent=self.view.scene) + antialias=True, method='agg', parent=self.view.scene) if self.fcapp.defaults['global_workspace'] is False: self.delete_workspace() @@ -196,13 +196,31 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): return ShapeCollection(parent=self.view.scene, pool=self.fcapp.pool, **kwargs) def new_cursor(self, big=None): + """ + Will create a mouse cursor pointer on canvas + + :param big: if True will create a mouse cursor made out of infinite lines + :return: the mouse cursor object + """ if big is True: self.c = CursorBig() + + # in case there are multiple new_cursor calls, best to disconnect first the signals + try: + self.c.mouse_state_updated.disconnect(self.on_mouse_state) + except (TypeError, AttributeError): + pass + try: + self.c.mouse_position_updated.disconnect(self.on_mouse_position) + except (TypeError, AttributeError): + pass + 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): diff --git a/flatcamGUI/PlotCanvasLegacy.py b/flatcamGUI/PlotCanvasLegacy.py index 96df7e6a..4be2fb3e 100644 --- a/flatcamGUI/PlotCanvasLegacy.py +++ b/flatcamGUI/PlotCanvasLegacy.py @@ -264,10 +264,13 @@ class PlotCanvasLegacy(QtCore.QObject): # else: # c = MplCursor(axes=axes, color='black', linewidth=1) - if big is True: + 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) + else: + self.big_cursor = False + c = FakeCursor() c.mouse_state_updated.connect(self.clear_cursor) @@ -311,6 +314,11 @@ class PlotCanvasLegacy(QtCore.QObject): if state is True: self.draw_cursor(x_pos=self.mouse[0], y_pos=self.mouse[1]) else: + if self.big_cursor is True: + self.ch_line.remove() + self.cv_line.remove() + self.canvas.draw_idle() + self.canvas.restore_region(self.background) self.canvas.blit(self.axes.bbox)