Просмотр исходного кода

- Excellon Editor: fixed mouse right click was always doing popup context menu
- GUIElements.FCEntry2(): added a try-except clause

Marius Stanciu 6 лет назад
Родитель
Сommit
72724eafae
4 измененных файлов с 48 добавлено и 42 удалено
  1. 2 0
      README.md
  2. 39 35
      flatcamEditors/FlatCAMExcEditor.py
  3. 2 6
      flatcamEditors/FlatCAMGrbEditor.py
  4. 5 1
      flatcamGUI/GUIElements.py

+ 2 - 0
README.md

@@ -20,6 +20,8 @@ CAD program, and create G-Code for Isolation routing.
 - updated the translations
 - updated the translations
 - fixed bugs in Excellon Editor
 - fixed bugs in Excellon Editor
 - Excellon Editor:  made Add Pad tool to work until right click
 - Excellon Editor:  made Add Pad tool to work until right click
+- Excellon Editor: fixed mouse right click was always doing popup context menu
+- GUIElements.FCEntry2(): added a try-except clause
 
 
 30.04.2019
 30.04.2019
 
 

+ 39 - 35
flatcamEditors/FlatCAMExcEditor.py

@@ -2123,28 +2123,29 @@ class FlatCAMExcEditor(QtCore.QObject):
     def on_canvas_click(self, event):
     def on_canvas_click(self, event):
         """
         """
         event.x and .y have canvas coordinates
         event.x and .y have canvas coordinates
-        event.xdaya and .ydata have plot coordinates
+        event.xdata and .ydata have plot coordinates
 
 
-        :param event: Event object dispatched by Matplotlib
+        :param event: Event object dispatched by VisPy
         :return: None
         :return: None
         """
         """
 
 
+        self.pos = self.canvas.vispy_canvas.translate_coords(event.pos)
+
+        if self.app.grid_status():
+            self.pos  = self.app.geo_editor.snap(self.pos[0], self.pos[1])
+            self.app.app_cursor.enabled = True
+            # Update cursor
+            self.app.app_cursor.set_data(np.asarray([(self.pos[0], self.pos[1])]), symbol='++', edge_color='black',
+                                         size=20)
+        else:
+            self.pos = (self.pos[0], self.pos[1])
+            self.app.app_cursor.enabled = False
+
         if event.button is 1:
         if event.button is 1:
             self.app.ui.rel_position_label.setText("<b>Dx</b>: %.4f&nbsp;&nbsp;  <b>Dy</b>: "
             self.app.ui.rel_position_label.setText("<b>Dx</b>: %.4f&nbsp;&nbsp;  <b>Dy</b>: "
                                                    "%.4f&nbsp;&nbsp;&nbsp;&nbsp;" % (0, 0))
                                                    "%.4f&nbsp;&nbsp;&nbsp;&nbsp;" % (0, 0))
             self.pos = self.canvas.vispy_canvas.translate_coords(event.pos)
             self.pos = self.canvas.vispy_canvas.translate_coords(event.pos)
 
 
-            # Snap coordinates
-            if self.app.grid_status():
-                self.pos = self.app.geo_editor.snap(self.pos[0], self.pos[1])
-                self.app.app_cursor.enabled = True
-                # Update cursor
-                self.app.app_cursor.set_data(np.asarray([(self.pos[0], self.pos[1])]), symbol='++', edge_color='black',
-                                             size=20)
-            else:
-                self.pos = (self.pos[0], self.pos[1])
-                self.app.app_cursor.enabled = False
-
             # Selection with left mouse button
             # Selection with left mouse button
             if self.active_tool is not None and event.button is 1:
             if self.active_tool is not None and event.button is 1:
                 # Dispatch event to active_tool
                 # Dispatch event to active_tool
@@ -2305,11 +2306,8 @@ class FlatCAMExcEditor(QtCore.QObject):
                 if self.app.selection_type is not None:
                 if self.app.selection_type is not None:
                     self.draw_selection_area_handler(self.pos, pos, self.app.selection_type)
                     self.draw_selection_area_handler(self.pos, pos, self.app.selection_type)
                     self.app.selection_type = None
                     self.app.selection_type = None
+
                 elif isinstance(self.active_tool, FCDrillSelect):
                 elif isinstance(self.active_tool, FCDrillSelect):
-                    # Dispatch event to active_tool
-                    # msg = self.active_tool.click(self.app.geo_editor.snap(event.xdata, event.ydata))
-                    # msg = self.active_tool.click_release((self.pos[0], self.pos[1]))
-                    # self.app.inform.emit(msg)
                     self.active_tool.click_release((self.pos[0], self.pos[1]))
                     self.active_tool.click_release((self.pos[0], self.pos[1]))
 
 
                     # if there are selected objects then plot them
                     # if there are selected objects then plot them
@@ -2379,16 +2377,12 @@ class FlatCAMExcEditor(QtCore.QObject):
         self.x = event.xdata
         self.x = event.xdata
         self.y = event.ydata
         self.y = event.ydata
 
 
-        # Prevent updates on pan
-        # if len(event.buttons) > 0:
-        #     return
+        self.app.ui.popMenu.mouse_is_panning = False
 
 
         # if the RMB is clicked and mouse is moving over plot then 'panning_action' is True
         # if the RMB is clicked and mouse is moving over plot then 'panning_action' is True
-        if event.button == 2:
-            self.app.panning_action = True
+        if event.button == 2 and event.is_dragging == 1:
+            self.app.ui.popMenu.mouse_is_panning = True
             return
             return
-        else:
-            self.app.panning_action = False
 
 
         try:
         try:
             x = float(event.xdata)
             x = float(event.xdata)
@@ -2400,7 +2394,13 @@ class FlatCAMExcEditor(QtCore.QObject):
             return
             return
 
 
         ### Snap coordinates
         ### Snap coordinates
-        x, y = self.app.geo_editor.app.geo_editor.snap(x, y)
+        if self.app.grid_status():
+            x, y = self.app.geo_editor.snap(x, y)
+            self.app.app_cursor.enabled = True
+            # Update cursor
+            self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
+        else:
+            self.app.app_cursor.enabled = False
 
 
         self.snap_x = x
         self.snap_x = x
         self.snap_y = y
         self.snap_y = y
@@ -2422,23 +2422,27 @@ class FlatCAMExcEditor(QtCore.QObject):
         geo = self.active_tool.utility_geometry(data=(x, y))
         geo = self.active_tool.utility_geometry(data=(x, y))
 
 
         if isinstance(geo, DrawToolShape) and geo.geo is not None:
         if isinstance(geo, DrawToolShape) and geo.geo is not None:
-
             # Remove any previous utility shape
             # Remove any previous utility shape
             self.tool_shape.clear(update=True)
             self.tool_shape.clear(update=True)
             self.draw_utility_geometry(geo=geo)
             self.draw_utility_geometry(geo=geo)
 
 
         ### Selection area on canvas section ###
         ### Selection area on canvas section ###
-        dx = pos[0] - self.pos[0]
         if event.is_dragging == 1 and event.button == 1:
         if event.is_dragging == 1 and event.button == 1:
-            self.app.delete_selection_shape()
-            if dx < 0:
-                self.app.draw_moving_selection_shape((self.pos[0], self.pos[1]), (x,y),
-                     color=self.app.defaults["global_alt_sel_line"],
-                     face_color=self.app.defaults['global_alt_sel_fill'])
-                self.app.selection_type = False
+            # I make an exception for FCDrillAdd and FCDrillArray because clicking and dragging while making regions
+            # can create strange issues
+            if isinstance(self.active_tool, FCDrillAdd) or isinstance(self.active_tool, FCDrillArray):
+                pass
             else:
             else:
-                self.app.draw_moving_selection_shape((self.pos[0], self.pos[1]), (x,y))
-                self.app.selection_type = True
+                dx = pos[0] - self.pos[0]
+                self.app.delete_selection_shape()
+                if dx < 0:
+                    self.app.draw_moving_selection_shape((self.pos[0], self.pos[1]), (x,y),
+                         color=self.app.defaults["global_alt_sel_line"],
+                         face_color=self.app.defaults['global_alt_sel_fill'])
+                    self.app.selection_type = False
+                else:
+                    self.app.draw_moving_selection_shape((self.pos[0], self.pos[1]), (x,y))
+                    self.app.selection_type = True
         else:
         else:
             self.app.selection_type = None
             self.app.selection_type = None
 
 

+ 2 - 6
flatcamEditors/FlatCAMGrbEditor.py

@@ -3233,9 +3233,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
     def on_canvas_click(self, event):
     def on_canvas_click(self, event):
         """
         """
         event.x and .y have canvas coordinates
         event.x and .y have canvas coordinates
-        event.xdaya and .ydata have plot coordinates
+        event.xdata and .ydata have plot coordinates
 
 
-        :param event: Event object dispatched by Matplotlib
+        :param event: Event object dispatched by VisPy
         :return: None
         :return: None
         """
         """
 
 
@@ -3359,10 +3359,6 @@ class FlatCAMGrbEditor(QtCore.QObject):
                     self.app.selection_type = None
                     self.app.selection_type = None
 
 
                 elif isinstance(self.active_tool, FCApertureSelect):
                 elif isinstance(self.active_tool, FCApertureSelect):
-                    # Dispatch event to active_tool
-                    # msg = self.active_tool.click(self.app.geo_editor.snap(event.xdata, event.ydata))
-                    # msg = self.active_tool.click_release((self.pos[0], self.pos[1]))
-                    # self.app.inform.emit(msg)
                     self.active_tool.click_release((self.pos[0], self.pos[1]))
                     self.active_tool.click_release((self.pos[0], self.pos[1]))
 
 
                     # if there are selected objects then plot them
                     # if there are selected objects then plot them

+ 5 - 1
flatcamGUI/GUIElements.py

@@ -367,7 +367,11 @@ class FCEntry2(FCEntry):
         self.readyToEdit = True
         self.readyToEdit = True
 
 
     def set_value(self, val):
     def set_value(self, val):
-        self.setText('%.4f' % float(val))
+        try:
+            fval = float(val)
+        except ValueError:
+            return
+        self.setText('%.4f' % fval)
 
 
 
 
 class EvalEntry(QtWidgets.QLineEdit):
 class EvalEntry(QtWidgets.QLineEdit):