- refactored some methods from App class and moved them to plotcanvas (plotcanvaslegacy) class

- added an label with icon in the status bar, clicking it will toggle (show status) of the X-Y axis on cavnas
- optimized the UI, added to status bar an icon to toggle the axis
This commit is contained in:
Marius Stanciu
2020-05-29 18:39:19 +03:00
committed by Marius
parent 15ec620cae
commit ffa063286f
18 changed files with 356 additions and 281 deletions

View File

@@ -2554,7 +2554,7 @@ class DialogBoxRadio(QtWidgets.QDialog):
:param title: string with the window title
:param label: string with the message inside the dialog box
"""
super(DialogBoxRadio, self).__init__()
super(DialogBoxRadio, self).__init__(parent=parent)
if initial_text is None:
self.location = str((0, 0))
else:
@@ -2797,9 +2797,12 @@ class MyCompleter(QCompleter):
insertText = QtCore.pyqtSignal(str)
def __init__(self, parent=None):
QCompleter.__init__(self)
QCompleter.__init__(self, parent=parent)
self.setCompletionMode(QCompleter.PopupCompletion)
self.highlighted.connect(self.setHighlighted)
self.lastSelected = ''
# self.popup().installEventFilter(self)
# def eventFilter(self, obj, event):
@@ -2955,9 +2958,9 @@ class FCFileSaveDialog(QtWidgets.QFileDialog):
super(FCFileSaveDialog, self).__init__(*args)
@staticmethod
def get_saved_filename(parent=None, caption='', directory='', filter='', initialFilter=''):
def get_saved_filename(parent=None, caption='', directory='', ext_filter='', initialFilter=''):
filename, _filter = QtWidgets.QFileDialog.getSaveFileName(parent=parent, caption=caption,
directory=directory, filter=filter,
directory=directory, filter=ext_filter,
initialFilter=initialFilter)
filename = str(filename)
@@ -2973,6 +2976,17 @@ class FCFileSaveDialog(QtWidgets.QFileDialog):
return filename, _filter
class FCDock(QtWidgets.QDockWidget):
def __init__(self, *args, **kwargs):
super(FCDock, self).__init__(*args)
self.close_callback = kwargs["close_callback"] if "close_callback" in kwargs else None
def closeEvent(self, event: QtGui.QCloseEvent) -> None:
self.close_callback()
super().closeEvent(event)
class FlatCAMActivityView(QtWidgets.QWidget):
"""
This class create and control the activity icon displayed in the App status bar

View File

@@ -58,17 +58,6 @@ class MainGUI(QtWidgets.QMainWindow):
# ############ BUILDING THE GUI IS EXECUTED HERE ########################
# #######################################################################
# #######################################################################
# ####################### TCL Shell DOCK ################################
# #######################################################################
self.shell_dock = QtWidgets.QDockWidget("FlatCAM TCL Shell")
self.shell_dock.setObjectName('Shell_DockWidget')
self.shell_dock.setAllowedAreas(QtCore.Qt.AllDockWidgetAreas)
self.shell_dock.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
QtWidgets.QDockWidget.DockWidgetFloatable |
QtWidgets.QDockWidget.DockWidgetClosable)
self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.shell_dock)
# #######################################################################
# ###################### Menu BUILDING ##################################
# #######################################################################
@@ -200,9 +189,9 @@ class MainGUI(QtWidgets.QMainWindow):
self.menufilerunscript = QtWidgets.QAction(
QtGui.QIcon(self.app.resource_location + '/script16.png'), '%s\tShift+S' % _('Run Script ...'), self)
self.menufilerunscript.setToolTip(
_("Will run the opened Tcl Script thus\n"
"enabling the automation of certain\n"
"functions of FlatCAM.")
_("Will run the opened Tcl Script thus\n"
"enabling the automation of certain\n"
"functions of FlatCAM.")
)
self.menufile_scripting.addAction(self.menufilenewscript)
self.menufile_scripting.addAction(self.menufileopenscript)
@@ -265,9 +254,9 @@ class MainGUI(QtWidgets.QMainWindow):
self.menufileexportexcellon = QtWidgets.QAction(
QtGui.QIcon(self.app.resource_location + '/drill32.png'), _('Export &Excellon ...'), self)
self.menufileexportexcellon.setToolTip(
_("Will export an Excellon Object as Excellon file,\n"
"the coordinates format, the file units and zeros\n"
"are set in Preferences -> Excellon Export.")
_("Will export an Excellon Object as Excellon file,\n"
"the coordinates format, the file units and zeros\n"
"are set in Preferences -> Excellon Export.")
)
self.menufileexport.addAction(self.menufileexportexcellon)
@@ -344,16 +333,16 @@ class MainGUI(QtWidgets.QMainWindow):
self.menuedit_convertjoin = self.menuedit_convert.addAction(
QtGui.QIcon(self.app.resource_location + '/join16.png'), _('&Join Geo/Gerber/Exc -> Geo'))
self.menuedit_convertjoin.setToolTip(
_("Merge a selection of objects, which can be of type:\n"
"- Gerber\n"
"- Excellon\n"
"- Geometry\n"
"into a new combo Geometry object.")
_("Merge a selection of objects, which can be of type:\n"
"- Gerber\n"
"- Excellon\n"
"- Geometry\n"
"into a new combo Geometry object.")
)
self.menuedit_convertjoinexc = self.menuedit_convert.addAction(
QtGui.QIcon(self.app.resource_location + '/join16.png'), _('Join Excellon(s) -> Excellon'))
self.menuedit_convertjoinexc.setToolTip(
_("Merge a selection of Excellon objects into a new combo Excellon object.")
_("Merge a selection of Excellon objects into a new combo Excellon object.")
)
self.menuedit_convertjoingrb = self.menuedit_convert.addAction(
QtGui.QIcon(self.app.resource_location + '/join16.png'), _('Join Gerber(s) -> Gerber'))
@@ -365,14 +354,14 @@ class MainGUI(QtWidgets.QMainWindow):
self.menuedit_convert_sg2mg = self.menuedit_convert.addAction(
QtGui.QIcon(self.app.resource_location + '/convert24.png'), _('Convert Single to MultiGeo'))
self.menuedit_convert_sg2mg.setToolTip(
_("Will convert a Geometry object from single_geometry type\n"
"to a multi_geometry type.")
_("Will convert a Geometry object from single_geometry type\n"
"to a multi_geometry type.")
)
self.menuedit_convert_mg2sg = self.menuedit_convert.addAction(
QtGui.QIcon(self.app.resource_location + '/convert24.png'), _('Convert Multi to SingleGeo'))
self.menuedit_convert_mg2sg.setToolTip(
_("Will convert a Geometry object from multi_geometry type\n"
"to a single_geometry type.")
_("Will convert a Geometry object from multi_geometry type\n"
"to a single_geometry type.")
)
# Separator
self.menuedit_convert.addSeparator()
@@ -825,10 +814,10 @@ class MainGUI(QtWidgets.QMainWindow):
self.grb_edit_toolbar.setObjectName('GrbEditor_TB')
self.addToolBar(self.grb_edit_toolbar)
self.snap_toolbar = QtWidgets.QToolBar(_('Grid Toolbar'))
self.snap_toolbar.setObjectName('Snap_TB')
# self.addToolBar(self.snap_toolbar)
self.snap_toolbar.setStyleSheet(
self.status_toolbar = QtWidgets.QToolBar(_('Grid Toolbar'))
self.status_toolbar.setObjectName('Snap_TB')
# self.addToolBar(self.status_toolbar)
self.status_toolbar.setStyleSheet(
"""
QToolBar { padding: 0; }
QToolBar QToolButton { padding: -2; margin: -2; }
@@ -1088,42 +1077,61 @@ class MainGUI(QtWidgets.QMainWindow):
# ########################################################################
# Snap GRID toolbar is always active to facilitate usage of measurements done on GRID
self.grid_snap_btn = self.snap_toolbar.addAction(
self.grid_snap_btn = self.status_toolbar.addAction(
QtGui.QIcon(self.app.resource_location + '/grid32.png'), _('Snap to grid'))
self.grid_gap_x_entry = FCEntry2()
self.grid_gap_x_entry.setMaximumWidth(70)
self.grid_gap_x_entry.setToolTip(_("Grid X snapping distance"))
self.snap_toolbar.addWidget(self.grid_gap_x_entry)
self.status_toolbar.addWidget(self.grid_gap_x_entry)
self.snap_toolbar.addWidget(QtWidgets.QLabel(" "))
self.status_toolbar.addWidget(QtWidgets.QLabel(" "))
self.grid_gap_link_cb = FCCheckBox()
self.grid_gap_link_cb.setToolTip(_("When active, value on Grid_X\n"
"is copied to the Grid_Y value."))
self.snap_toolbar.addWidget(self.grid_gap_link_cb)
self.snap_toolbar.addWidget(QtWidgets.QLabel(" "))
self.status_toolbar.addWidget(self.grid_gap_link_cb)
self.status_toolbar.addWidget(QtWidgets.QLabel(" "))
self.grid_gap_y_entry = FCEntry2()
self.grid_gap_y_entry.setMaximumWidth(70)
self.grid_gap_y_entry.setToolTip(_("Grid Y snapping distance"))
self.snap_toolbar.addWidget(self.grid_gap_y_entry)
self.status_toolbar.addWidget(self.grid_gap_y_entry)
self.status_toolbar.addWidget(QtWidgets.QLabel(" "))
self.axis_status_label = FCLabel()
self.axis_status_label.setToolTip(_("Toggle the display of axis on canvas"))
self.axis_status_label.setPixmap(QtGui.QPixmap(self.app.resource_location + '/axis16.png'))
self.status_toolbar.addWidget(self.axis_status_label)
self.status_toolbar.addWidget(QtWidgets.QLabel(" "))
self.shell_status_label = FCLabel()
self.shell_status_label.setToolTip(_("Command Line"))
self.shell_status_label.setPixmap(QtGui.QPixmap(self.app.resource_location + '/shell20.png'))
self.snap_toolbar.addWidget(self.shell_status_label)
self.status_toolbar.addWidget(self.shell_status_label)
self.ois_grid = OptionalInputSection(self.grid_gap_link_cb, [self.grid_gap_y_entry], logic=False)
self.corner_snap_btn = self.snap_toolbar.addAction(
self.corner_snap_btn = self.status_toolbar.addAction(
QtGui.QIcon(self.app.resource_location + '/corner32.png'), _('Snap to corner'))
self.snap_max_dist_entry = FCEntry()
self.snap_max_dist_entry.setMaximumWidth(70)
self.snap_max_dist_entry.setToolTip(_("Max. magnet distance"))
self.snap_magnet = self.snap_toolbar.addWidget(self.snap_max_dist_entry)
self.snap_magnet = self.status_toolbar.addWidget(self.snap_max_dist_entry)
self.corner_snap_btn.setVisible(False)
self.snap_magnet.setVisible(False)
# #######################################################################
# ####################### TCL Shell DOCK ################################
# #######################################################################
self.shell_dock = FCDock("FlatCAM TCL Shell", close_callback=self.toggle_shell_ui)
self.shell_dock.setObjectName('Shell_DockWidget')
self.shell_dock.setAllowedAreas(QtCore.Qt.AllDockWidgetAreas)
self.shell_dock.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
QtWidgets.QDockWidget.DockWidgetFloatable |
QtWidgets.QDockWidget.DockWidgetClosable)
self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.shell_dock)
# ########################################################################
# ########################## Notebook # ##################################
# ########################################################################
@@ -1493,8 +1501,7 @@ class MainGUI(QtWidgets.QMainWindow):
QtGui.QIcon(self.app.resource_location + '/resize16.png'), _("Resize Drill"))
self.popMenu.addSeparator()
self.popmenu_copy = self.popMenu.addAction(
QtGui.QIcon(self.app.resource_location + '/copy32.png'), _("Copy"))
self.popmenu_copy = self.popMenu.addAction(QtGui.QIcon(self.app.resource_location + '/copy32.png'), _("Copy"))
self.popmenu_delete = self.popMenu.addAction(
QtGui.QIcon(self.app.resource_location + '/delete32.png'), _("Delete"))
self.popmenu_edit = self.popMenu.addAction(
@@ -1517,19 +1524,19 @@ class MainGUI(QtWidgets.QMainWindow):
self.infobar.addWidget(self.fcinfo, stretch=1)
# self.rel_position_label = QtWidgets.QLabel(
# "<b>Dx</b>: 0.0000&nbsp;&nbsp; <b>Dy</b>: 0.0000&nbsp;&nbsp;&nbsp;&nbsp;")
# "<b>Dx</b>: 0.0000&nbsp;&nbsp; <b>Dy</b>: 0.0000&nbsp;&nbsp;&nbsp;&nbsp;")
# self.rel_position_label.setMinimumWidth(110)
# self.rel_position_label.setToolTip(_("Relative measurement.\nReference is last click position"))
# self.infobar.addWidget(self.rel_position_label)
#
self.position_label = QtWidgets.QLabel(
"&nbsp;<b>X</b>: 0.0000&nbsp;&nbsp; <b>Y</b>: 0.0000&nbsp;")
self.position_label = QtWidgets.QLabel("&nbsp;<b>X</b>: 0.0000&nbsp;&nbsp; <b>Y</b>: 0.0000&nbsp;")
self.position_label.setMinimumWidth(110)
self.position_label.setToolTip(_("Absolute measurement.\nReference is (X=0, Y= 0) position"))
self.position_label.setToolTip(_("Absolute measurement.\n"
"Reference is (X=0, Y= 0) position"))
self.infobar.addWidget(self.position_label)
self.snap_toolbar.setMaximumHeight(24)
self.infobar.addWidget(self.snap_toolbar)
self.status_toolbar.setMaximumHeight(24)
self.infobar.addWidget(self.status_toolbar)
self.hud_label = FCLabel("H")
self.hud_label.setToolTip(_("HUD (Heads up display)"))
@@ -1537,10 +1544,14 @@ class MainGUI(QtWidgets.QMainWindow):
self.infobar.addWidget(self.hud_label)
self.wplace_label = FCLabel("A4")
self.wplace_label.setToolTip(_("Draw a delimiting rectangle on canvas.\n"
"The purpose is to illustrate the limits for our work.")
)
self.wplace_label.setMargin(2)
self.infobar.addWidget(self.wplace_label)
self.units_label = QtWidgets.QLabel("[mm]")
self.units_label.setToolTip(_("Application units"))
self.units_label.setMargin(2)
self.infobar.addWidget(self.units_label)
@@ -1659,8 +1670,8 @@ class MainGUI(QtWidgets.QMainWindow):
self.clear_btn.clicked.connect(self.on_gui_clear)
self.wplace_label.clicked.connect(self.app.on_workspace_toggle)
self.hud_label.clicked.connect(self.app.on_toggle_hud)
self.shell_status_label.clicked.connect(self.toggle_shell_ui)
# to be used in the future
# self.plot_tab_area.tab_attached.connect(lambda x: print(x))
# self.plot_tab_area.tab_detached.connect(lambda x: print(x))
@@ -1760,12 +1771,12 @@ class MainGUI(QtWidgets.QMainWindow):
self.grb_edit_toolbar.setVisible(False)
# if tb & 128:
# self.ui.snap_toolbar.setVisible(True)
# self.ui.status_toolbar.setVisible(True)
# else:
# self.ui.snap_toolbar.setVisible(False)
# self.ui.status_toolbar.setVisible(False)
# Grid Toolbar is always active now
self.snap_toolbar.setVisible(True)
self.status_toolbar.setVisible(True)
if tb & 256:
self.toolbarshell.setVisible(True)
@@ -2241,11 +2252,11 @@ class MainGUI(QtWidgets.QMainWindow):
# Toggle axis
if key == QtCore.Qt.Key_G:
self.app.on_toggle_axis()
self.app.plotcanvas.on_toggle_axis()
# Toggle HUD (Heads-Up Display)
if key == QtCore.Qt.Key_H:
self.app.on_toggle_hud()
self.app.plotcanvas.on_toggle_hud()
# Locate in Object
if key == QtCore.Qt.Key_J:
self.app.on_locate(obj=self.app.collection.get_active())
@@ -2324,7 +2335,7 @@ class MainGUI(QtWidgets.QMainWindow):
# Toggle Grid lines
if key == QtCore.Qt.Key_G:
self.app.on_toggle_grid_lines()
self.app.plotcanvas.on_toggle_grid_lines()
return
# Punch Gerber Tool
@@ -2494,7 +2505,7 @@ class MainGUI(QtWidgets.QMainWindow):
if active_index == 0:
self.app.collection.set_active(names_list[-1])
else:
self.app.collection.set_active(names_list[active_index-1])
self.app.collection.set_active(names_list[active_index - 1])
# Select the object in the Tree below the current one
if key == QtCore.Qt.Key_Down:
@@ -2509,7 +2520,7 @@ class MainGUI(QtWidgets.QMainWindow):
if active_index == len(names_list) - 1:
self.app.collection.set_active(names_list[0])
else:
self.app.collection.set_active(names_list[active_index+1])
self.app.collection.set_active(names_list[active_index + 1])
# New Geometry
if key == QtCore.Qt.Key_B:
@@ -3583,7 +3594,7 @@ class MainGUI(QtWidgets.QMainWindow):
# hide all Toolbars
for tb in self.findChildren(QtWidgets.QToolBar):
tb.setVisible(False)
self.snap_toolbar.setVisible(True) # This Toolbar is always visible so restore it
self.status_toolbar.setVisible(True) # This Toolbar is always visible so restore it
self.splitter.setSizes([0, 1])
self.toggle_fscreen = True
@@ -3695,7 +3706,7 @@ class ShortcutsTab(QtWidgets.QWidget):
self.sh_tab_layout.addLayout(self.sh_hlay)
self.app_sh_msg = (
'''<b>%s</b><br>
'''<b>%s</b><br>
<table border="0" cellpadding="0" cellspacing="0" style="width:283px">
<tbody>
<tr height="20">
@@ -4064,53 +4075,53 @@ class ShortcutsTab(QtWidgets.QWidget):
</tbody>
</table>
''' %
(
_("General Shortcut list"),
_("SHOW SHORTCUT LIST"), _("Switch to Project Tab"), _("Switch to Selected Tab"),
_("Switch to Tool Tab"),
_("New Gerber"), _("Edit Object (if selected)"), _("Grid On/Off"), _("Jump to Coordinates"),
_("New Excellon"), _("Move Obj"), _("New Geometry"), _("Set Origin"), _("Change Units"),
_("Open Properties Tool"), _("Rotate by 90 degree CW"), _("Shell Toggle"),
_("Add a Tool (when in Geometry Selected Tab or in Tools NCC or Tools Paint)"), _("Zoom Fit"),
_("Flip on X_axis"), _("Flip on Y_axis"), _("Zoom Out"), _("Zoom In"),
(
_("General Shortcut list"),
_("SHOW SHORTCUT LIST"), _("Switch to Project Tab"), _("Switch to Selected Tab"),
_("Switch to Tool Tab"),
_("New Gerber"), _("Edit Object (if selected)"), _("Grid On/Off"), _("Jump to Coordinates"),
_("New Excellon"), _("Move Obj"), _("New Geometry"), _("Set Origin"), _("Change Units"),
_("Open Properties Tool"), _("Rotate by 90 degree CW"), _("Shell Toggle"),
_("Add a Tool (when in Geometry Selected Tab or in Tools NCC or Tools Paint)"), _("Zoom Fit"),
_("Flip on X_axis"), _("Flip on Y_axis"), _("Zoom Out"), _("Zoom In"),
# CTRL section
_("Select All"), _("Copy Obj"), _("Open Tools Database"),
_("Open Excellon File"), _("Open Gerber File"), _("Distance Tool"), _("New Project"),
_("Open Project"), _("Print (PDF)"), _("PDF Import Tool"), _("Save Project"), _("Toggle Plot Area"),
# CTRL section
_("Select All"), _("Copy Obj"), _("Open Tools Database"),
_("Open Excellon File"), _("Open Gerber File"), _("Distance Tool"), _("New Project"),
_("Open Project"), _("Print (PDF)"), _("PDF Import Tool"), _("Save Project"), _("Toggle Plot Area"),
# SHIFT section
_("Copy Obj_Name"),
_("Toggle Code Editor"), _("Toggle the axis"), _("Locate in Object"), _("Distance Minimum Tool"),
_("Open Preferences Window"),
_("Rotate by 90 degree CCW"), _("Run a Script"), _("Toggle the workspace"), _("Skew on X axis"),
_("Skew on Y axis"),
# SHIFT section
_("Copy Obj_Name"),
_("Toggle Code Editor"), _("Toggle the axis"), _("Locate in Object"), _("Distance Minimum Tool"),
_("Open Preferences Window"),
_("Rotate by 90 degree CCW"), _("Run a Script"), _("Toggle the workspace"), _("Skew on X axis"),
_("Skew on Y axis"),
# ALT section
_("Align Objects Tool"), _("Calculators Tool"), _("2-Sided PCB Tool"), _("Extract Drills Tool"),
_("Fiducials Tool"), _("Toggle Grid Lines"),
_("Punch Gerber Tool"), _("Isolation Tool"), _("Copper Thieving Tool"),
_("Solder Paste Dispensing Tool"),
_("Film PCB Tool"), _("Corner Markers Tool"), _("Non-Copper Clearing Tool"), _("Optimal Tool"),
_("Paint Area Tool"), _("QRCode Tool"), _("Rules Check Tool"),
_("View File Source"), _("Transformations Tool"),
_("Subtract Tool"), _("Cutout PCB Tool"), _("Panelize PCB"),
_("Enable all Plots"), _("Disable all Plots"), _("Disable Non-selected Plots"),
_("Toggle Full Screen"),
# ALT section
_("Align Objects Tool"), _("Calculators Tool"), _("2-Sided PCB Tool"), _("Extract Drills Tool"),
_("Fiducials Tool"), _("Toggle Grid Lines"),
_("Punch Gerber Tool"), _("Isolation Tool"), _("Copper Thieving Tool"),
_("Solder Paste Dispensing Tool"),
_("Film PCB Tool"), _("Corner Markers Tool"), _("Non-Copper Clearing Tool"), _("Optimal Tool"),
_("Paint Area Tool"), _("QRCode Tool"), _("Rules Check Tool"),
_("View File Source"), _("Transformations Tool"),
_("Subtract Tool"), _("Cutout PCB Tool"), _("Panelize PCB"),
_("Enable all Plots"), _("Disable all Plots"), _("Disable Non-selected Plots"),
_("Toggle Full Screen"),
# CTRL + ALT section
_("Abort current task (gracefully)"),
# CTRL + ALT section
_("Abort current task (gracefully)"),
# CTRL + SHIFT section
_("Save Project As"),
_("Paste Special. Will convert a Windows path style to the one required in Tcl Shell"),
# CTRL + SHIFT section
_("Save Project As"),
_("Paste Special. Will convert a Windows path style to the one required in Tcl Shell"),
# F keys section
_("Open Online Manual"),
_("Open Online Tutorials"), _("Refresh Plots"), _("Delete Object"), _("Alternate: Delete Tool"),
_("(left to Key_1)Toggle Notebook Area (Left Side)"), _("En(Dis)able Obj Plot"),
_("Deselects all objects")
)
# F keys section
_("Open Online Manual"),
_("Open Online Tutorials"), _("Refresh Plots"), _("Delete Object"), _("Alternate: Delete Tool"),
_("(left to Key_1)Toggle Notebook Area (Left Side)"), _("En(Dis)able Obj Plot"),
_("Deselects all objects")
)
)
self.sh_app = QtWidgets.QTextEdit()

View File

@@ -12,9 +12,17 @@ from AppGUI.VisPyCanvas import VisPyCanvas, Color
from AppGUI.VisPyVisuals import ShapeGroup, ShapeCollection, TextCollection, TextGroup, Cursor
from vispy.scene.visuals import InfiniteLine, Line, Rectangle, Text
import gettext
import AppTranslation as fcTranslate
import builtins
import numpy as np
from vispy.geometry import Rect
fcTranslate.apply_language('strings')
if '_' not in builtins.__dict__:
_ = gettext.gettext
log = logging.getLogger('base')
@@ -133,11 +141,6 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
self.h_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 0.8), vertical=False,
parent=self.view.scene)
# draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area
# all CNC have a limited workspace
if self.fcapp.defaults['global_workspace'] is True:
self.draw_workspace(workspace_size=self.fcapp.defaults["global_workspaceT"])
self.line_parent = None
if self.fcapp.defaults["global_cursor_color_enabled"]:
c_color = Color(self.fcapp.defaults["global_cursor_color"]).rgba
@@ -150,9 +153,6 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
self.cursor_h_line = InfiniteLine(pos=None, color=c_color, vertical=False,
parent=self.line_parent)
# HUD Display
self.hud_enabled = False
# font size
qsettings = QtCore.QSettings("Open Source", "FlatCAM")
if qsettings.contains("hud_font_size"):
@@ -181,10 +181,27 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
border_color=self.rect_hud_color, color=self.rect_hud_color, parent=None)
self.rect_hud.set_gl_state(depth_test=False)
# draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area
# all CNC have a limited workspace
if self.fcapp.defaults['global_workspace'] is True:
self.draw_workspace(workspace_size=self.fcapp.defaults["global_workspaceT"])
# HUD Display
self.hud_enabled = False
# enable the HUD if it is activated in FlatCAM Preferences
if self.fcapp.defaults['global_hud'] is True:
self.on_toggle_hud(state=True)
# Axis Display
self.axis_enabled = True
# enable Axis
self.on_toggle_axis(state=True)
# enable Grid lines
self.grid_lines_enabled = True
self.shape_collections = []
self.shape_collection = self.new_shape_collection()
@@ -201,27 +218,75 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
self.graph_event_connect('mouse_wheel', self.on_mouse_scroll)
def on_toggle_hud(self, state):
def on_toggle_axis(self, signal=None, state=None):
if state is None:
state = not self.axis_enabled
if state:
self.axis_enabled = True
self.v_line.parent = self.view.scene
self.h_line.parent = self.view.scene
self.fcapp.ui.axis_status_label.setStyleSheet("""
QLabel
{
color: black;
background-color: peachpuff;
}
""")
self.fcapp.inform[str, bool].emit(_("Axis enabled."), False)
else:
self.axis_enabled = False
self.v_line.parent = None
self.h_line.parent = None
self.fcapp.ui.axis_status_label.setStyleSheet("")
self.fcapp.inform[str, bool].emit(_("Axis disabled."), False)
def on_toggle_hud(self, signal=None, state=None):
if state is None:
state = not self.hud_enabled
if state:
self.hud_enabled = True
self.rect_hud.parent = self.view
self.text_hud.parent = self.view
self.fcapp.defaults['global_hud'] = True
self.fcapp.ui.hud_label.setStyleSheet("""
QLabel
{
color: black;
background-color: lightblue;
}
""")
QLabel
{
color: black;
background-color: lightblue;
}
""")
self.fcapp.inform[str, bool].emit(_("HUD enabled."), False)
else:
self.hud_enabled = False
self.rect_hud.parent = None
self.text_hud.parent = None
self.fcapp.defaults['global_hud'] = False
self.fcapp.ui.hud_label.setStyleSheet("")
self.fcapp.inform[str, bool].emit(_("HUD disabled."), False)
def on_toggle_grid_lines(self):
state = not self.grid_lines_enabled
if state:
self.grid_lines_enabled = True
self.grid.parent = self.view.scene
self.fcapp.inform[str, bool].emit(_("Grid enabled."), False)
else:
self.grid_lines_enabled = False
self.grid.parent = None
self.fcapp.inform[str, bool].emit(_("Grid disabled."), False)
# HACK: enabling/disabling the cursor seams to somehow update the shapes on screen
# - perhaps is a bug in VisPy implementation
if self.fcapp.grid_status():
self.fcapp.app_cursor.enabled = False
self.fcapp.app_cursor.enabled = True
else:
self.fcapp.app_cursor.enabled = True
self.fcapp.app_cursor.enabled = False
def draw_workspace(self, workspace_size):
"""

View File

@@ -38,7 +38,6 @@ fcTranslate.apply_language('strings')
if '_' not in builtins.__dict__:
_ = gettext.gettext
log = logging.getLogger('base')
@@ -310,6 +309,9 @@ class PlotCanvasLegacy(QtCore.QObject):
self.hud_enabled = False
self.text_hud = self.Thud(plotcanvas=self)
# enable Grid lines
self.grid_lines_enabled = True
# draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area
# all CNC have a limited workspace
if self.app.defaults['global_workspace'] is True:
@@ -318,25 +320,62 @@ class PlotCanvasLegacy(QtCore.QObject):
if self.app.defaults['global_hud'] is True:
self.on_toggle_hud(state=True)
def on_toggle_hud(self, state):
# Axis Display
self.axis_enabled = True
# enable Axis
self.on_toggle_axis(state=True)
def on_toggle_axis(self, signal=None, state=None):
if state is None:
state = not self.axis_enabled
if state:
self.axis_enabled = True
if self.h_line not in self.axes.lines and self.v_line not in self.axes.lines:
self.h_line = self.axes.axhline(color=(0.70, 0.3, 0.3), linewidth=2)
self.v_line = self.axes.axvline(color=(0.70, 0.3, 0.3), linewidth=2)
self.app.ui.axis_status_label.setStyleSheet("""
QLabel
{
color: black;
background-color: peachpuff;
}
""")
self.app.inform[str, bool].emit(_("Axis enabled."), False)
else:
self.axis_enabled = False
if self.h_line in self.axes.lines and self.v_line in self.axes.lines:
self.axes.lines.remove(self.h_line)
self.axes.lines.remove(self.v_line)
self.app.ui.axis_status_label.setStyleSheet("")
self.app.inform[str, bool].emit(_("Axis disabled."), False)
self.canvas.draw()
def on_toggle_hud(self, signal=None, state=None):
if state is None:
state = not self.hud_enabled
if state:
self.hud_enabled = True
self.text_hud.add_artist()
self.app.defaults['global_hud'] = True
self.fcapp.ui.hud_label.setStyleSheet("""
QLabel
{
color: black;
background-color: lightblue;
}
""")
self.app.ui.hud_label.setStyleSheet("""
QLabel
{
color: black;
background-color: lightblue;
}
""")
self.app.inform[str, bool].emit(_("HUD enabled."), False)
else:
self.hud_enabled = False
self.text_hud.remove_artist()
self.app.defaults['global_hud'] = False
self.fcapp.ui.hud_label.setStyleSheet("")
self.app.ui.hud_label.setStyleSheet("")
self.app.inform[str, bool].emit(_("HUD disabled."), False)
self.canvas.draw()
@@ -399,6 +438,26 @@ class PlotCanvasLegacy(QtCore.QObject):
if self.hud_holder in self.p.axes.artists:
self.p.axes.artists.remove(self.hud_holder)
def on_toggle_grid_lines(self):
state = not self.grid_lines_enabled
if state:
self.grid_lines_enabled = True
self.axes.grid(True)
try:
self.canvas.draw()
except IndexError:
pass
self.app.inform[str, bool].emit(_("Grid enabled."), False)
else:
self.grid_lines_enabled = False
self.axes.grid(False)
try:
self.canvas.draw()
except IndexError:
pass
self.app.inform[str, bool].emit(_("Grid disabled."), False)
def draw_workspace(self, workspace_size):
"""
Draw a rectangular shape on canvas to specify our valid workspace.

View File

@@ -1122,7 +1122,7 @@ class PreferencesUIManager:
if self.ui.grb_edit_toolbar.isVisible():
tb_status += 64
if self.ui.snap_toolbar.isVisible():
if self.ui.status_toolbar.isVisible():
tb_status += 128
if self.ui.toolbarshell.isVisible():