- all kwy shortcuts work across the entire application; started to move all the shortcuts definitions in FlatCAMGUI.keyPressEvent()

This commit is contained in:
Marius Stanciu 2019-02-06 14:44:16 +02:00 committed by Marius
parent 28f11ef55f
commit 67d089832e
3 changed files with 469 additions and 252 deletions

View File

@ -10,6 +10,7 @@ from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtCore import Qt, QSettings from PyQt5.QtCore import Qt, QSettings
from GUIElements import * from GUIElements import *
import platform import platform
import webbrowser
class FlatCAMGUI(QtWidgets.QMainWindow): class FlatCAMGUI(QtWidgets.QMainWindow):
@ -1498,31 +1499,244 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
self.snap_magnet.setDisabled(True) self.snap_magnet.setDisabled(True)
def keyPressEvent(self, event): def keyPressEvent(self, event):
modifiers = QtWidgets.QApplication.keyboardModifiers()
active = self.app.collection.get_active()
selected = self.app.collection.get_selected()
if event.key() == QtCore.Qt.Key_1: # events out of the self.app.collection view (it's about Project Tab) are of type int
self.app.on_select_tab('project') if type(event) is int:
key = event
# events from the GUI are of type QKeyEvent
else:
key = event.key()
if event.key() == QtCore.Qt.Key_2: if modifiers == QtCore.Qt.ControlModifier:
self.app.on_select_tab('selected') if key == QtCore.Qt.Key_A:
self.app.on_selectall()
if event.key() == QtCore.Qt.Key_3: if key == QtCore.Qt.Key_C:
self.app.on_select_tab('tool') self.app.on_copy_object()
if event.key() == QtCore.Qt.Key_G: if key == QtCore.Qt.Key_E:
self.grid_snap_btn.trigger() self.app.on_fileopenexcellon()
if event.key == QtCore.Qt.Key_Q: if key == QtCore.Qt.Key_G:
self.app.on_toggle_units_click() self.app.on_fileopengerber()
if event.key() == QtCore.Qt.Key_S: if key == QtCore.Qt.Key_N:
self.app.on_toggle_shell() self.app.on_file_new_click()
# Show shortcut list if key == QtCore.Qt.Key_M:
if event.key() == QtCore.Qt.Key_Ampersand: self.app.measurement_tool.run()
self.app.on_shortcut_list() if key == QtCore.Qt.Key_O:
self.app.on_file_openproject()
if event.key() == QtCore.Qt.Key_QuoteLeft: if key == QtCore.Qt.Key_S:
self.app.on_shortcut_list() self.app.on_file_saveproject()
# Toggle Plot Area
if key == QtCore.Qt.Key_F10:
self.app.on_toggle_plotarea()
return
elif modifiers == QtCore.Qt.ShiftModifier:
# Copy Object Name
# Copy Object Name
if key == QtCore.Qt.Key_C:
self.app.on_copy_name()
# Toggle axis
if key == QtCore.Qt.Key_G:
if self.toggle_axis is False:
self.app.plotcanvas.v_line.set_data(color=(0.70, 0.3, 0.3, 1.0))
self.app.plotcanvas.h_line.set_data(color=(0.70, 0.3, 0.3, 1.0))
self.app.plotcanvas.redraw()
self.app.toggle_axis = True
else:
self.app.plotcanvas.v_line.set_data(color=(0.0, 0.0, 0.0, 0.0))
self.app.plotcanvas.h_line.set_data(color=(0.0, 0.0, 0.0, 0.0))
self.appplotcanvas.redraw()
self.app.toggle_axis = False
# Open Preferences Window
if key == QtCore.Qt.Key_P:
self.app.on_preferences()
return
# Rotate Object by 90 degree CCW
if key == QtCore.Qt.Key_R:
self.app.on_rotate(silent=True, preset=-90)
return
# Run a Script
if key == QtCore.Qt.Key_S:
self.app.on_filerunscript()
return
# Toggle Workspace
if key == QtCore.Qt.Key_W:
self.app.on_workspace_menu()
return
# Skew on X axis
if key == QtCore.Qt.Key_X:
self.app.on_skewx()
return
# Skew on Y axis
if key == QtCore.Qt.Key_Y:
self.app.on_skewy()
return
elif modifiers == QtCore.Qt.AltModifier:
# Eanble all plots
if key == Qt.Key_1:
self.app.enable_all_plots()
# Disable all plots
if key == Qt.Key_2:
self.app.disable_all_plots()
# Disable all other plots
if key == Qt.Key_3:
self.app.disable_other_plots()
# 2-Sided PCB Tool
if key == QtCore.Qt.Key_D:
self.app.dblsidedtool.run()
return
# Non-Copper Clear Tool
if key == QtCore.Qt.Key_N:
self.app.ncclear_tool.run()
return
# Transformation Tool
if key == QtCore.Qt.Key_R:
self.app.transform_tool.run()
return
# Cutout Tool
if key == QtCore.Qt.Key_U:
self.app.cutout_tool.run()
return
else:
# Open Manual
if key == QtCore.Qt.Key_F1:
webbrowser.open(self.app.manual_url)
# Open Video Help
if key == QtCore.Qt.Key_F2:
webbrowser.open(self.app.video_url)
# Switch to Project Tab
if key == QtCore.Qt.Key_1:
self.app.on_select_tab('project')
# Switch to Selected Tab
if key == QtCore.Qt.Key_2:
self.app.on_select_tab('selected')
# Switch to Tool Tab
if key == QtCore.Qt.Key_3:
self.app.on_select_tab('tool')
# Delete
if key == QtCore.Qt.Key_Delete and active:
# Delete via the application to
# ensure cleanup of the GUI
active.app.on_delete()
# Space = Toggle Active/Inactive
if key == QtCore.Qt.Key_Space:
for select in selected:
select.ui.plot_cb.toggle()
self.app.delete_selection_shape()
# Copy Object Name
if key == QtCore.Qt.Key_E:
self.app.object2editor()
# Grid toggle
if key == QtCore.Qt.Key_G:
self.app.ui.grid_snap_btn.trigger()
# Jump to coords
if key == QtCore.Qt.Key_J:
self.app.on_jump_to()
# New Excellon
if key == QtCore.Qt.Key_L:
self.app.new_excellon_object()
# Move tool toggle
if key == QtCore.Qt.Key_M:
self.app.move_tool.toggle()
# New Geometry
if key == QtCore.Qt.Key_N:
self.app.on_new_geometry()
# Set Origin
if key == QtCore.Qt.Key_O:
self.app.on_set_origin()
return
# Set Origin
if key == QtCore.Qt.Key_P:
self.app.properties_tool.run()
return
# Change Units
if key == QtCore.Qt.Key_Q:
if self.app.options["units"] == 'MM':
self.app.general_options_form.general_app_group.units_radio.set_value("IN")
else:
self.app.general_options_form.general_app_group.units_radio.set_value("MM")
self.app.on_toggle_units()
# Rotate Object by 90 degree CW
if key == QtCore.Qt.Key_R:
self.app.on_rotate(silent=True, preset=90)
# Shell toggle
if key == QtCore.Qt.Key_S:
self.app.on_toggle_shell()
# Transform Tool
if key == QtCore.Qt.Key_T:
self.app.transform_tool.run()
# Zoom Fit
if key == QtCore.Qt.Key_V:
self.app.on_zoom_fit(None)
# Mirror on X the selected object(s)
if key == QtCore.Qt.Key_X:
self.app.on_flipx()
# Mirror on Y the selected object(s)
if key == QtCore.Qt.Key_Y:
self.app.on_flipy()
# Zoom In
if key == QtCore.Qt.Key_Equal:
self.app.plotcanvas.zoom(1 / self.app.defaults['zoom_ratio'], self.app.mouse)
# Zoom Out
if key == QtCore.Qt.Key_Minus:
self.app.plotcanvas.zoom(self.app.defaults['zoom_ratio'], self.app.mouse)
# Show shortcut list
if key == QtCore.Qt.Key_Ampersand:
self.app.on_shortcut_list()
if key == QtCore.Qt.Key_QuoteLeft:
self.app.on_shortcut_list()
return
def dragEnterEvent(self, event): def dragEnterEvent(self, event):
if event.mimeData().hasUrls: if event.mimeData().hasUrls:

View File

@ -12,7 +12,7 @@ import inspect # TODO: Remove
import FlatCAMApp import FlatCAMApp
from PyQt5 import QtGui, QtCore, QtWidgets from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
import webbrowser # import webbrowser
class KeySensitiveListView(QtWidgets.QTreeView): class KeySensitiveListView(QtWidgets.QTreeView):
@ -228,6 +228,8 @@ class ObjectCollection(QtCore.QAbstractItemModel):
# tasks know that they have to wait until available. # tasks know that they have to wait until available.
self.promises = set() self.promises = set()
self.app = app
### View ### View
self.view = KeySensitiveListView(app) self.view = KeySensitiveListView(app)
self.view.setModel(self) self.view.setModel(self)
@ -247,7 +249,8 @@ class ObjectCollection(QtCore.QAbstractItemModel):
## GUI Events ## GUI Events
self.view.selectionModel().selectionChanged.connect(self.on_list_selection_change) self.view.selectionModel().selectionChanged.connect(self.on_list_selection_change)
self.view.activated.connect(self.on_item_activated) self.view.activated.connect(self.on_item_activated)
self.view.keyPressed.connect(self.on_key) # self.view.keyPressed.connect(self.on_key)
self.view.keyPressed.connect(self.app.ui.keyPressEvent)
self.view.clicked.connect(self.on_mouse_down) self.view.clicked.connect(self.on_mouse_down)
self.view.customContextMenuRequested.connect(self.on_menu_request) self.view.customContextMenuRequested.connect(self.on_menu_request)
@ -260,238 +263,238 @@ class ObjectCollection(QtCore.QAbstractItemModel):
def has_promises(self): def has_promises(self):
return len(self.promises) > 0 return len(self.promises) > 0
def on_key(self, key): # def on_key(self, key):
modifiers = QtWidgets.QApplication.keyboardModifiers() # modifiers = QtWidgets.QApplication.keyboardModifiers()
active = self.get_active() # active = self.get_active()
selected = self.get_selected() # selected = self.get_selected()
#
if modifiers == QtCore.Qt.ControlModifier: # if modifiers == QtCore.Qt.ControlModifier:
if key == QtCore.Qt.Key_A: # if key == QtCore.Qt.Key_A:
self.app.on_selectall() # self.app.on_selectall()
#
if key == QtCore.Qt.Key_C: # if key == QtCore.Qt.Key_C:
self.app.on_copy_object() # self.app.on_copy_object()
#
if key == QtCore.Qt.Key_E: # if key == QtCore.Qt.Key_E:
self.app.on_fileopenexcellon() # self.app.on_fileopenexcellon()
#
if key == QtCore.Qt.Key_G: # if key == QtCore.Qt.Key_G:
self.app.on_fileopengerber() # self.app.on_fileopengerber()
#
if key == QtCore.Qt.Key_N: # if key == QtCore.Qt.Key_N:
self.app.on_file_new_click() # self.app.on_file_new_click()
#
if key == QtCore.Qt.Key_M: # if key == QtCore.Qt.Key_M:
self.app.measurement_tool.run() # self.app.measurement_tool.run()
if key == QtCore.Qt.Key_O: # if key == QtCore.Qt.Key_O:
self.app.on_file_openproject() # self.app.on_file_openproject()
#
if key == QtCore.Qt.Key_S: # if key == QtCore.Qt.Key_S:
self.app.on_file_saveproject() # self.app.on_file_saveproject()
#
# Toggle Plot Area # # Toggle Plot Area
if key == QtCore.Qt.Key_F10: # if key == QtCore.Qt.Key_F10:
self.app.on_toggle_plotarea() # self.app.on_toggle_plotarea()
#
return # return
elif modifiers == QtCore.Qt.ShiftModifier: # elif modifiers == QtCore.Qt.ShiftModifier:
#
# Copy Object Name # # Copy Object Name
# Copy Object Name # # Copy Object Name
if key == QtCore.Qt.Key_C: # if key == QtCore.Qt.Key_C:
self.app.on_copy_name() # self.app.on_copy_name()
#
# Toggle axis # # Toggle axis
if key == QtCore.Qt.Key_G: # if key == QtCore.Qt.Key_G:
if self.toggle_axis is False: # if self.toggle_axis is False:
self.app.plotcanvas.v_line.set_data(color=(0.70, 0.3, 0.3, 1.0)) # self.app.plotcanvas.v_line.set_data(color=(0.70, 0.3, 0.3, 1.0))
self.app.plotcanvas.h_line.set_data(color=(0.70, 0.3, 0.3, 1.0)) # self.app.plotcanvas.h_line.set_data(color=(0.70, 0.3, 0.3, 1.0))
self.app.plotcanvas.redraw() # self.app.plotcanvas.redraw()
self.app.toggle_axis = True # self.app.toggle_axis = True
else: # else:
self.app.plotcanvas.v_line.set_data(color=(0.0, 0.0, 0.0, 0.0)) # self.app.plotcanvas.v_line.set_data(color=(0.0, 0.0, 0.0, 0.0))
#
self.app.plotcanvas.h_line.set_data(color=(0.0, 0.0, 0.0, 0.0)) # self.app.plotcanvas.h_line.set_data(color=(0.0, 0.0, 0.0, 0.0))
self.appplotcanvas.redraw() # self.appplotcanvas.redraw()
self.app.toggle_axis = False # self.app.toggle_axis = False
#
# Open Preferences Window # # Open Preferences Window
if key == QtCore.Qt.Key_P: # if key == QtCore.Qt.Key_P:
self.app.on_preferences() # self.app.on_preferences()
return # return
#
# Rotate Object by 90 degree CCW # # Rotate Object by 90 degree CCW
if key == QtCore.Qt.Key_R: # if key == QtCore.Qt.Key_R:
self.app.on_rotate(silent=True, preset=-90) # self.app.on_rotate(silent=True, preset=-90)
return # return
#
# Run a Script # # Run a Script
if key == QtCore.Qt.Key_S: # if key == QtCore.Qt.Key_S:
self.app.on_filerunscript() # self.app.on_filerunscript()
return # return
#
# Toggle Workspace # # Toggle Workspace
if key == QtCore.Qt.Key_W: # if key == QtCore.Qt.Key_W:
self.app.on_workspace_menu() # self.app.on_workspace_menu()
return # return
#
# Skew on X axis # # Skew on X axis
if key == QtCore.Qt.Key_X: # if key == QtCore.Qt.Key_X:
self.app.on_skewx() # self.app.on_skewx()
return # return
#
# Skew on Y axis # # Skew on Y axis
if key == QtCore.Qt.Key_Y: # if key == QtCore.Qt.Key_Y:
self.app.on_skewy() # self.app.on_skewy()
return # return
#
elif modifiers == QtCore.Qt.AltModifier: # elif modifiers == QtCore.Qt.AltModifier:
# Eanble all plots # # Eanble all plots
if key == Qt.Key_1: # if key == Qt.Key_1:
self.app.enable_all_plots() # self.app.enable_all_plots()
#
# Disable all plots # # Disable all plots
if key == Qt.Key_2: # if key == Qt.Key_2:
self.app.disable_all_plots() # self.app.disable_all_plots()
#
# Disable all other plots # # Disable all other plots
if key == Qt.Key_3: # if key == Qt.Key_3:
self.app.disable_other_plots() # self.app.disable_other_plots()
#
# 2-Sided PCB Tool # # 2-Sided PCB Tool
if key == QtCore.Qt.Key_D: # if key == QtCore.Qt.Key_D:
self.app.dblsidedtool.run() # self.app.dblsidedtool.run()
return # return
#
# Non-Copper Clear Tool # # Non-Copper Clear Tool
if key == QtCore.Qt.Key_N: # if key == QtCore.Qt.Key_N:
self.app.ncclear_tool.run() # self.app.ncclear_tool.run()
return # return
#
# Transformation Tool # # Transformation Tool
if key == QtCore.Qt.Key_R: # if key == QtCore.Qt.Key_R:
self.app.transform_tool.run() # self.app.transform_tool.run()
return # return
#
# Cutout Tool # # Cutout Tool
if key == QtCore.Qt.Key_U: # if key == QtCore.Qt.Key_U:
self.app.cutout_tool.run() # self.app.cutout_tool.run()
return # return
#
else: # else:
# Open Manual # # Open Manual
if key == QtCore.Qt.Key_F1: # if key == QtCore.Qt.Key_F1:
webbrowser.open(self.app.manual_url) # webbrowser.open(self.app.manual_url)
#
# Open Video Help # # Open Video Help
if key == QtCore.Qt.Key_F2: # if key == QtCore.Qt.Key_F2:
webbrowser.open(self.app.video_url) # webbrowser.open(self.app.video_url)
#
# Switch to Project Tab # # Switch to Project Tab
if key == QtCore.Qt.Key_1: # if key == QtCore.Qt.Key_1:
self.app.on_select_tab('project') # self.app.on_select_tab('project')
#
# Switch to Selected Tab # # Switch to Selected Tab
if key == QtCore.Qt.Key_2: # if key == QtCore.Qt.Key_2:
self.app.on_select_tab('selected') # self.app.on_select_tab('selected')
#
# Switch to Tool Tab # # Switch to Tool Tab
if key == QtCore.Qt.Key_3: # if key == QtCore.Qt.Key_3:
self.app.on_select_tab('tool') # self.app.on_select_tab('tool')
#
# Delete # # Delete
if key == QtCore.Qt.Key_Delete and active: # if key == QtCore.Qt.Key_Delete and active:
# Delete via the application to # # Delete via the application to
# ensure cleanup of the GUI # # ensure cleanup of the GUI
active.app.on_delete() # active.app.on_delete()
#
# Space = Toggle Active/Inactive # # Space = Toggle Active/Inactive
if key == QtCore.Qt.Key_Space: # if key == QtCore.Qt.Key_Space:
for select in selected: # for select in selected:
select.ui.plot_cb.toggle() # select.ui.plot_cb.toggle()
self.app.delete_selection_shape() # self.app.delete_selection_shape()
#
# Copy Object Name # # Copy Object Name
if key == QtCore.Qt.Key_E: # if key == QtCore.Qt.Key_E:
self.app.object2editor() # self.app.object2editor()
#
# Grid toggle # # Grid toggle
if key == QtCore.Qt.Key_G: # if key == QtCore.Qt.Key_G:
self.app.ui.grid_snap_btn.trigger() # self.app.ui.grid_snap_btn.trigger()
#
# Jump to coords # # Jump to coords
if key == QtCore.Qt.Key_J: # if key == QtCore.Qt.Key_J:
self.app.on_jump_to() # self.app.on_jump_to()
#
# New Excellon # # New Excellon
if key == QtCore.Qt.Key_L: # if key == QtCore.Qt.Key_L:
self.app.new_excellon_object() # self.app.new_excellon_object()
#
# Move tool toggle # # Move tool toggle
if key == QtCore.Qt.Key_M: # if key == QtCore.Qt.Key_M:
self.app.move_tool.toggle() # self.app.move_tool.toggle()
#
# New Geometry # # New Geometry
if key == QtCore.Qt.Key_N: # if key == QtCore.Qt.Key_N:
self.app.on_new_geometry() # self.app.on_new_geometry()
#
# Set Origin # # Set Origin
if key == QtCore.Qt.Key_O: # if key == QtCore.Qt.Key_O:
self.app.on_set_origin() # self.app.on_set_origin()
return # return
#
# Set Origin # # Set Origin
if key == QtCore.Qt.Key_P: # if key == QtCore.Qt.Key_P:
self.app.properties_tool.run() # self.app.properties_tool.run()
return # return
#
# Change Units # # Change Units
if key == QtCore.Qt.Key_Q: # if key == QtCore.Qt.Key_Q:
if self.app.options["units"] == 'MM': # if self.app.options["units"] == 'MM':
self.app.general_options_form.general_app_group.units_radio.set_value("IN") # self.app.general_options_form.general_app_group.units_radio.set_value("IN")
else: # else:
self.app.general_options_form.general_app_group.units_radio.set_value("MM") # self.app.general_options_form.general_app_group.units_radio.set_value("MM")
self.app.on_toggle_units() # self.app.on_toggle_units()
#
# Rotate Object by 90 degree CW # # Rotate Object by 90 degree CW
if key == QtCore.Qt.Key_R: # if key == QtCore.Qt.Key_R:
self.app.on_rotate(silent=True, preset=90) # self.app.on_rotate(silent=True, preset=90)
#
# Shell toggle # # Shell toggle
if key == QtCore.Qt.Key_S: # if key == QtCore.Qt.Key_S:
self.app.on_toggle_shell() # self.app.on_toggle_shell()
#
# Transform Tool # # Transform Tool
if key == QtCore.Qt.Key_T: # if key == QtCore.Qt.Key_T:
self.app.transform_tool.run() # self.app.transform_tool.run()
#
# Zoom Fit # # Zoom Fit
if key == QtCore.Qt.Key_V: # if key == QtCore.Qt.Key_V:
self.app.on_zoom_fit(None) # self.app.on_zoom_fit(None)
#
# Mirror on X the selected object(s) # # Mirror on X the selected object(s)
if key == QtCore.Qt.Key_X: # if key == QtCore.Qt.Key_X:
self.app.on_flipx() # self.app.on_flipx()
#
# Mirror on Y the selected object(s) # # Mirror on Y the selected object(s)
if key == QtCore.Qt.Key_Y: # if key == QtCore.Qt.Key_Y:
self.app.on_flipy() # self.app.on_flipy()
#
# Zoom In # # Zoom In
if key == QtCore.Qt.Key_Equal: # if key == QtCore.Qt.Key_Equal:
self.app.plotcanvas.zoom(1 / self.app.defaults['zoom_ratio'], self.app.mouse) # self.app.plotcanvas.zoom(1 / self.app.defaults['zoom_ratio'], self.app.mouse)
#
# Zoom Out # # Zoom Out
if key == QtCore.Qt.Key_Minus: # if key == QtCore.Qt.Key_Minus:
self.app.plotcanvas.zoom(self.app.defaults['zoom_ratio'], self.app.mouse) # self.app.plotcanvas.zoom(self.app.defaults['zoom_ratio'], self.app.mouse)
#
# Show shortcut list # # Show shortcut list
if key == QtCore.Qt.Key_Ampersand: # if key == QtCore.Qt.Key_Ampersand:
self.app.on_shortcut_list() # self.app.on_shortcut_list()
#
if key == QtCore.Qt.Key_QuoteLeft: # if key == QtCore.Qt.Key_QuoteLeft:
self.app.on_shortcut_list() # self.app.on_shortcut_list()
return # return
def on_mouse_down(self, event): def on_mouse_down(self, event):
FlatCAMApp.App.log.debug("Mouse button pressed on list") FlatCAMApp.App.log.debug("Mouse button pressed on list")

View File

@ -18,8 +18,8 @@ CAD program, and create G-Code for Isolation routing.
- fixed bug in Excellon Slots milling: a value of a dict key was a string instead to be an int. A cast to integer solved it. - fixed bug in Excellon Slots milling: a value of a dict key was a string instead to be an int. A cast to integer solved it.
- fixed the name self-insert in save dialog file for GCode; added protection in case the save path is None - fixed the name self-insert in save dialog file for GCode; added protection in case the save path is None
- fixed FlatCAM crash when trying to make drills GCode out of a file that have only slots. - fixed FlatCAM crash when trying to make drills GCode out of a file that have only slots.
- made the shell toggle shortcut key work when focused on Selected Tab; toggle units shortcut also
- changed the messages for Units Conversion - changed the messages for Units Conversion
- all kwy shortcuts work across the entire application; started to move all the shortcuts definitions in FlatCAMGUI.keyPressEvent()
5.02.3019 5.02.3019