From d90e86da391961fc6280571526677a5d130f910a Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Tue, 31 Aug 2021 02:25:43 +0300 Subject: [PATCH] - made sure that the location labels in the InfoBar have only the decimals required when the Grid snapping is ON --- CHANGELOG.md | 4 ++++ appCommon/Common.py | 9 ++++---- appEditors/AppExcEditor.py | 11 +++++---- appEditors/AppGeoEditor.py | 13 ++++++----- appEditors/AppGerberEditor.py | 26 +++++++++++---------- appGUI/MainGUI.py | 39 ++++++++++++++++++++++++++++++-- appGUI/PlotCanvas.py | 14 ++++++++---- appPlugins/ToolCopperThieving.py | 9 ++++---- appPlugins/ToolDistance.py | 11 +++++---- appPlugins/ToolFollow.py | 9 ++++---- appPlugins/ToolIsolation.py | 9 ++++---- appPlugins/ToolNCC.py | 9 ++++---- appPlugins/ToolPaint.py | 9 ++++---- app_Main.py | 34 ++++++++++++++++------------ 14 files changed, 133 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68b8ed2b..2496af5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ CHANGELOG for FlatCAM beta ================================================= +31.08.2021 + +- made sure that the location labels in the InfoBar have only the decimals required when the Grid snapping is ON + 30.08.2021 - fixed the reconnection of the mouse events when canceling setting the origin diff --git a/appCommon/Common.py b/appCommon/Common.py index d9a8d257..a5098b2c 100644 --- a/appCommon/Common.py +++ b/appCommon/Common.py @@ -597,10 +597,11 @@ class ExclusionAreas(QtCore.QObject): self.app.dx = curr_pos[0] - float(self.cursor_pos[0]) self.app.dy = curr_pos[1] - float(self.cursor_pos[1]) - self.app.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (curr_pos[0], curr_pos[1])) - self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.app.dx, self.app.dy)) + # self.app.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (curr_pos[0], curr_pos[1])) + # self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.app.dx, self.app.dy)) + self.app.ui.update_location_labels(self.dx, self.dy, curr_pos[0], curr_pos[1]) units = self.app.defaults["units"].lower() # self.app.plotcanvas.text_hud.text = \ diff --git a/appEditors/AppExcEditor.py b/appEditors/AppExcEditor.py index f5668def..87c823f4 100644 --- a/appEditors/AppExcEditor.py +++ b/appEditors/AppExcEditor.py @@ -3423,11 +3423,12 @@ class AppExcEditor(QtCore.QObject): self.app.dy = y - self.pos[1] # # update the position label in the infobar since the APP mouse event handlers are disconnected - self.app.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (x, y)) - # # update the reference position label in the infobar since the APP mouse event handlers are disconnected - self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.app.dx, self.app.dy)) + # self.app.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (x, y)) + # # # update the reference position label in the infobar since the APP mouse event handlers are disconnected + # self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.app.dx, self.app.dy)) + self.app.ui.update_location_labels(self.app.dx, self.app.dy, x, y) units = self.app.defaults["units"].lower() # self.app.plotcanvas.text_hud.text = \ diff --git a/appEditors/AppGeoEditor.py b/appEditors/AppGeoEditor.py index b6003eb7..6031973a 100644 --- a/appEditors/AppGeoEditor.py +++ b/appEditors/AppGeoEditor.py @@ -4787,12 +4787,13 @@ class AppGeoEditor(QtCore.QObject): self.app.dy = y - self.pos[1] # # update the position label in the infobar since the APP mouse event handlers are disconnected - self.app.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (x, y)) - # - # # update the reference position label in the infobar since the APP mouse event handlers are disconnected - self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.app.dx, self.app.dy)) + # self.app.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (x, y)) + # # + # # # update the reference position label in the infobar since the APP mouse event handlers are disconnected + # self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.app.dx, self.app.dy)) + self.app.ui.update_location_labels(self.app.dx, self.app.dy, x, y) units = self.app.defaults["units"].lower() # self.app.plotcanvas.text_hud.text = \ diff --git a/appEditors/AppGerberEditor.py b/appEditors/AppGerberEditor.py index 31282988..ff96fd70 100644 --- a/appEditors/AppGerberEditor.py +++ b/appEditors/AppGerberEditor.py @@ -2916,12 +2916,13 @@ class ImportEditorGrb(QtCore.QObject, DrawTool): self.app.dy = y - self.pos[1] # # update the position label in the infobar since the APP mouse event handlers are disconnected - self.app.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (x, y)) - - # update the reference position label in the infobar since the APP mouse event handlers are disconnected - self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.app.dx, self.app.dy)) + # self.app.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (x, y)) + # + # # update the reference position label in the infobar since the APP mouse event handlers are disconnected + # self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.app.dx, self.app.dy)) + self.app.ui.update_location_labels(self.app.dx, self.app.dy, x, y) # Selection area on canvas section # ## if self.event_is_dragging == 1 and event.button == 1: @@ -5406,12 +5407,13 @@ class AppGerberEditor(QtCore.QObject): self.app.dy = y - self.pos[1] # # update the position label in the infobar since the APP mouse event handlers are disconnected - self.app.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (x, y)) - - # update the reference position label in the infobar since the APP mouse event handlers are disconnected - self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.app.dx, self.app.dy)) + # self.app.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (x, y)) + # + # # update the reference position label in the infobar since the APP mouse event handlers are disconnected + # self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.app.dx, self.app.dy)) + self.app.ui.update_location_labels(self.app.dx, self.app.dy, x, y) units = self.app.defaults["units"].lower() # self.app.plotcanvas.text_hud.text = \ diff --git a/appGUI/MainGUI.py b/appGUI/MainGUI.py index 41facbfa..f83f4794 100644 --- a/appGUI/MainGUI.py +++ b/appGUI/MainGUI.py @@ -1370,7 +1370,7 @@ class MainGUI(QtWidgets.QMainWindow): # ####################### Delta Coordinates TOOLBAR ##################### # ####################################################################### self.rel_position_label = FCLabel( - "Dx: 0.0000   Dy: 0.0000    ") + "Dx: 0.0   Dy: 0.0    ") self.rel_position_label.setMinimumWidth(110) self.rel_position_label.setToolTip(_("Relative measurement.\nReference is last click position")) self.delta_coords_toolbar.addWidget(self.rel_position_label) @@ -1378,7 +1378,7 @@ class MainGUI(QtWidgets.QMainWindow): # ####################################################################### # ####################### Coordinates TOOLBAR ########################### # ####################################################################### - self.position_label = FCLabel(" X: 0.0000   Y: 0.0000 ") + self.position_label = FCLabel(" X: 0.0   Y: 0.0 ") self.position_label.setMinimumWidth(110) self.position_label.setToolTip(_("Absolute measurement.\n" "Reference is (X=0, Y= 0) position")) @@ -2010,6 +2010,41 @@ class MainGUI(QtWidgets.QMainWindow): # ratio = new_pixel_ratio / old_pixel_ratio # self.app.plotcanvas.dpi = self.app.plotcanvas.dpi * ratio + def update_location_labels(self, dx, dy, x, y): + """ + Update the text of the location labels from InfoBar + + :param x: X location + :type x: float + :param y: Y location + :type y: float + :param dx: Delta X location + :type dx: float + :param dy: Delta Y location + :type dy: float + :return: + :rtype: None + """ + + # Set the position label + if x is None or y is None: + self.position_label.setText("") + else: + x_dec = str(self.app.dec_format(x, self.app.decimals)) if x else '0.0' + y_dec = str(self.app.dec_format(y, self.app.decimals)) if y else '0.0' + self.position_label.setText(" X: %s   " + "Y: %s " % (x_dec, y_dec)) + + # Set the Delta position label + if dx is None or dy is None: + self.rel_position_label.setText("") + else: + dx_dec = str(self.app.dec_format(dx, self.app.decimals)) if dx else '0.0' + dy_dec = str(self.app.dec_format(dy, self.app.decimals)) if dy else '0.0' + + self.rel_position_label.setText("Dx: %s   Dy: " + "%s    " % (dx_dec, dy_dec)) + def on_tab_detached(self, tab_detached, tab_detached_name): if tab_detached_name == 'FlatCAM Plot Area': pass diff --git a/appGUI/PlotCanvas.py b/appGUI/PlotCanvas.py index 340460b1..0339211c 100644 --- a/appGUI/PlotCanvas.py +++ b/appGUI/PlotCanvas.py @@ -300,12 +300,18 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): def on_update_text_hud(self, dx=None, dy=None, x=None, y=None): """ + Update the text of the location labels from HUD - :param dx: - :param dy: - :param x: - :param y: + :param x: X location + :type x: float + :param y: Y location + :type y: float + :param dx: Delta X location + :type dx: float + :param dy: Delta Y location + :type dy: float :return: + :rtype: None """ # units units = self.fcapp.defaults["units"].lower() diff --git a/appPlugins/ToolCopperThieving.py b/appPlugins/ToolCopperThieving.py index c7939e47..ae9fd4a5 100644 --- a/appPlugins/ToolCopperThieving.py +++ b/appPlugins/ToolCopperThieving.py @@ -512,10 +512,11 @@ class ToolCopperThieving(AppTool): self.app.dy = curr_pos[1] - float(self.cursor_pos[1]) # # update the positions on status bar - self.app.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (curr_pos[0], curr_pos[1])) - self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.app.dx, self.app.dy)) + # self.app.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (curr_pos[0], curr_pos[1])) + # self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.app.dx, self.app.dy)) + self.app.ui.update_location_labels(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) units = self.app.defaults["units"].lower() # self.app.plotcanvas.text_hud.text = \ diff --git a/appPlugins/ToolDistance.py b/appPlugins/ToolDistance.py index a6ff3564..58f0c996 100644 --- a/appPlugins/ToolDistance.py +++ b/appPlugins/ToolDistance.py @@ -481,11 +481,12 @@ class Distance(AppTool): else: pos = (pos_canvas[0], pos_canvas[1]) - self.app.ui.position_label.setText( - "    X: {}   Y: {}".format( - '%.*f' % (self.decimals, pos[0]), '%.*f' % (self.decimals, pos[1]) - ) - ) + # self.app.ui.position_label.setText( + # "    X: {}   Y: {}".format( + # '%.*f' % (self.decimals, pos[0]), '%.*f' % (self.decimals, pos[1]) + # ) + # ) + self.app.ui.update_location_labels(dx=None, dy=None, x=pos[0], y=pos[1]) units = self.app.defaults["units"].lower() # self.app.plotcanvas.text_hud.text = \ diff --git a/appPlugins/ToolFollow.py b/appPlugins/ToolFollow.py index 3e0b7805..ff3b4d41 100644 --- a/appPlugins/ToolFollow.py +++ b/appPlugins/ToolFollow.py @@ -578,10 +578,11 @@ class ToolFollow(AppTool, Gerber): self.app.dy = curr_pos[1] - float(self.cursor_pos[1]) # # update the positions on status bar - self.app.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (curr_pos[0], curr_pos[1])) - self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.app.dx, self.app.dy)) + # self.app.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (curr_pos[0], curr_pos[1])) + # self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.app.dx, self.app.dy)) + self.app.ui.update_location_labels(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) units = self.app.defaults["units"].lower() # self.app.plotcanvas.text_hud.text = \ diff --git a/appPlugins/ToolIsolation.py b/appPlugins/ToolIsolation.py index aa2d786c..3c1a7cae 100644 --- a/appPlugins/ToolIsolation.py +++ b/appPlugins/ToolIsolation.py @@ -2650,10 +2650,11 @@ class ToolIsolation(AppTool, Gerber): self.app.dy = curr_pos[1] - float(self.cursor_pos[1]) # # update the positions on status bar - self.app.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (curr_pos[0], curr_pos[1])) - self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.app.dx, self.app.dy)) + # self.app.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (curr_pos[0], curr_pos[1])) + # self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.app.dx, self.app.dy)) + self.app.ui.update_location_labels(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) units = self.app.defaults["units"].lower() # self.app.plotcanvas.text_hud.text = \ diff --git a/appPlugins/ToolNCC.py b/appPlugins/ToolNCC.py index cbdd49f3..3459637f 100644 --- a/appPlugins/ToolNCC.py +++ b/appPlugins/ToolNCC.py @@ -1834,10 +1834,11 @@ class NonCopperClear(AppTool, Gerber): self.app.dy = curr_pos[1] - float(self.cursor_pos[1]) # # update the positions on status bar - self.app.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (curr_pos[0], curr_pos[1])) - self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.app.dx, self.app.dy)) + # self.app.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (curr_pos[0], curr_pos[1])) + # self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.app.dx, self.app.dy)) + self.app.ui.update_location_labels(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) units = self.app.defaults["units"].lower() # self.app.plotcanvas.text_hud.text = \ diff --git a/appPlugins/ToolPaint.py b/appPlugins/ToolPaint.py index c7c72d83..4f9471ff 100644 --- a/appPlugins/ToolPaint.py +++ b/appPlugins/ToolPaint.py @@ -1503,10 +1503,11 @@ class ToolPaint(AppTool, Gerber): self.app.dy = curr_pos[1] - float(self.cursor_pos[1]) # # update the positions on status bar - self.app.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (curr_pos[0], curr_pos[1])) - self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.app.dx, self.app.dy)) + # self.app.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (curr_pos[0], curr_pos[1])) + # self.app.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.app.dx, self.app.dy)) + self.app.ui.update_location_labels(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) units = self.app.defaults["units"].lower() # self.app.plotcanvas.text_hud.text = \ diff --git a/app_Main.py b/app_Main.py index 8e4b0b87..c149333c 100644 --- a/app_Main.py +++ b/app_Main.py @@ -5622,11 +5622,12 @@ class App(QtCore.QObject): # Set the relative position label dx = location[0] - float(self.rel_point1[0]) dy = location[1] - float(self.rel_point1[1]) - self.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (location[0], location[1])) - # Set the position label - self.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (dx, dy)) + # self.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (location[0], location[1])) + # # Set the position label + # self.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (dx, dy)) + self.ui.update_location_labels(dx, dy, location[0], location[1]) # units = self.defaults["units"].lower() # self.plotcanvas.text_hud.text = \ @@ -5778,10 +5779,11 @@ class App(QtCore.QObject): self.dx = location[0] - float(self.rel_point1[0]) self.dy = location[1] - float(self.rel_point1[1]) # Set the position label - self.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (location[0], location[1])) - self.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.dx, self.dy)) + # self.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (location[0], location[1])) + # self.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.dx, self.dy)) + self.ui.update_location_labels(self.dx, self.dy, location[0], location[1]) # units = self.defaults["units"].lower() # self.plotcanvas.text_hud.text = \ @@ -7225,10 +7227,11 @@ class App(QtCore.QObject): self.dx = pos[0] - float(self.rel_point1[0]) self.dy = pos[1] - float(self.rel_point1[1]) - self.ui.position_label.setText(" X: %.4f   " - "Y: %.4f " % (pos[0], pos[1])) - self.ui.rel_position_label.setText("Dx: %.4f   Dy: " - "%.4f    " % (self.dx, self.dy)) + # self.ui.position_label.setText(" X: %.4f   " + # "Y: %.4f " % (pos[0], pos[1])) + # self.ui.rel_position_label.setText("Dx: %.4f   Dy: " + # "%.4f    " % (self.dx, self.dy)) + self.ui.update_location_labels(self.dx, self.dy, pos[0], pos[1]) units = self.defaults["units"].lower() # self.plotcanvas.text_hud.text = \ @@ -7290,8 +7293,9 @@ class App(QtCore.QObject): except Exception as e: self.log.error("App.on_mouse_move_over_plot() - rel_point1 is not None -> %s" % str(e)) - self.ui.position_label.setText("") - self.ui.rel_position_label.setText("") + # self.ui.position_label.setText("") + # self.ui.rel_position_label.setText("") + self.ui.update_location_labels(0.0, 0.0, 0.0, 0.0) self.mouse = None def on_mouse_click_release_over_plot(self, event):