Import LinuxCNC source tree
This commit is contained in:
249
share/qtvcp/screens/x1mill/x1mill_handler.py
Normal file
249
share/qtvcp/screens/x1mill/x1mill_handler.py
Normal file
@@ -0,0 +1,249 @@
|
||||
############################
|
||||
# **** IMPORT SECTION **** #
|
||||
############################
|
||||
import sys
|
||||
import os
|
||||
import linuxcnc
|
||||
|
||||
from qtpy import QtCore, QtWidgets
|
||||
|
||||
from qtvcp.widgets.mdi_line import MDILine as MDI_WIDGET
|
||||
from qtvcp.widgets.gcode_editor import GcodeEditor as GCODE
|
||||
from qtvcp.lib.keybindings import Keylookup
|
||||
from qtvcp.lib.toolbar_actions import ToolBarActions
|
||||
from qtvcp.widgets.stylesheeteditor import StyleSheetEditor as SSE
|
||||
from qtvcp.core import Status, Action, Info
|
||||
|
||||
# Set up logging
|
||||
from qtvcp import logger
|
||||
LOG = logger.getLogger(__name__)
|
||||
|
||||
# Set the log level for this module
|
||||
#LOG.setLevel(logger.INFO) # One of DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
|
||||
###########################################
|
||||
# **** instantiate libraries section **** #
|
||||
###########################################
|
||||
|
||||
KEYBIND = Keylookup()
|
||||
STATUS = Status()
|
||||
ACTION = Action()
|
||||
INFO = Info()
|
||||
###################################
|
||||
# **** HANDLER CLASS SECTION **** #
|
||||
###################################
|
||||
|
||||
class HandlerClass:
|
||||
|
||||
########################
|
||||
# **** INITIALIZE **** #
|
||||
########################
|
||||
# widgets allows access to widgets from the qtvcp files
|
||||
# at this point the widgets and hal pins are not instantiated
|
||||
def __init__(self, halcomp,widgets,paths):
|
||||
self.hal = halcomp
|
||||
self.w = widgets
|
||||
self.PATHS = paths
|
||||
self.STYLEEDITOR = SSE(widgets,paths)
|
||||
self.picked_line = None
|
||||
STATUS.connect('general',self.return_value)
|
||||
STATUS.connect('graphics-line-selected', self.set_picked_line)
|
||||
|
||||
##########################################
|
||||
# Special Functions called from QTSCREEN
|
||||
##########################################
|
||||
|
||||
# at this point:
|
||||
# the widgets are instantiated.
|
||||
# the HAL pins are built but HAL is not set ready
|
||||
def initialized__(self):
|
||||
KEYBIND.add_call('Key_F12','on_keycall_F12')
|
||||
|
||||
def processed_key_event__(self,receiver,event,is_pressed,key,code,shift,cntrl):
|
||||
# when typing in MDI, we don't want keybinding to call functions
|
||||
# so we catch and process the events directly.
|
||||
# We do want ESC, F1 and F2 to call keybinding functions though
|
||||
if code not in(QtCore.Qt.Key_Escape,QtCore.Qt.Key_F1 ,QtCore.Qt.Key_F2,
|
||||
QtCore.Qt.Key_F3,QtCore.Qt.Key_F5,QtCore.Qt.Key_F5):
|
||||
|
||||
# search for the top widget of whatever widget received the event
|
||||
# then check if it's one we want the keypress events to go to
|
||||
flag = False
|
||||
receiver2 = receiver
|
||||
while receiver2 is not None and not flag:
|
||||
if isinstance(receiver2, QtWidgets.QDialog):
|
||||
flag = True
|
||||
break
|
||||
if isinstance(receiver2, MDI_WIDGET):
|
||||
flag = True
|
||||
break
|
||||
if isinstance(receiver2, GCODE):
|
||||
flag = False
|
||||
break
|
||||
receiver2 = receiver2.parent()
|
||||
|
||||
if flag:
|
||||
if isinstance(receiver2, GCODE):
|
||||
# if in manual do our keybindings - otherwise
|
||||
# send events to gcode widget
|
||||
if STATUS.is_man_mode() == False:
|
||||
if is_pressed:
|
||||
receiver.keyPressEvent(event)
|
||||
event.accept()
|
||||
return True
|
||||
elif is_pressed:
|
||||
receiver.keyPressEvent(event)
|
||||
event.accept()
|
||||
return True
|
||||
else:
|
||||
event.accept()
|
||||
return True
|
||||
|
||||
if event.isAutoRepeat():return True
|
||||
|
||||
# ok if we got here then try keybindings function calls
|
||||
# KEYBINDING will call functions from handler file as
|
||||
# registered by KEYBIND.add_call(KEY,FUNCTION) above
|
||||
return KEYBIND.manage_function_calls(self,event,is_pressed,key,shift,cntrl)
|
||||
|
||||
########################
|
||||
# callbacks from STATUS #
|
||||
########################
|
||||
# process the STATUS return message for run-from-line
|
||||
def return_value(self, obj, message):
|
||||
num = message['RETURN']
|
||||
code = bool(message['ID'] == '_RunFromLine_')
|
||||
name = bool(message['NAME'] == 'CALCULATOR')
|
||||
if num is not None and code and name:
|
||||
ACTION.RUN(int(num))
|
||||
|
||||
def set_picked_line(self, obj, line):
|
||||
self.picked_line = line
|
||||
|
||||
#######################
|
||||
# callbacks from form #
|
||||
#######################
|
||||
def full_screen(self, state):
|
||||
if state:
|
||||
self.w.stackedWidget_0.setCurrentIndex(1)
|
||||
self.w.widgetswitcher.show_id_widget(1)
|
||||
else:
|
||||
self.w.stackedWidget_0.setCurrentIndex(0)
|
||||
self.w.widgetswitcher.show_id_widget(0)
|
||||
|
||||
def slow_jog_slider_changed(self, rate):
|
||||
if self.w.pbtn_jog_rate_slow.isChecked():
|
||||
ACTION.SET_JOG_RATE(rate)
|
||||
def fast_jog_slider_changed(self, rate):
|
||||
if self.w.pbtn_jog_rate_fast.isChecked():
|
||||
ACTION.SET_JOG_RATE(rate)
|
||||
|
||||
def set_slow_rate(self, state):
|
||||
if state:
|
||||
ACTION.SET_JOG_RATE(self.w.scrb_jog_linear_slow.value())
|
||||
def set_fast_rate(self, state):
|
||||
if state:
|
||||
ACTION.SET_JOG_RATE(self.w.scrb_jog_linear_fast.value())
|
||||
|
||||
def run_from_line_clicked(self):
|
||||
mess = {'NAME':'CALCULATOR','ID':'_RunFromLine_',
|
||||
'PRELOAD':self.picked_line,
|
||||
'TITLE':'Run From Line Dialog'}
|
||||
ACTION.CALL_DIALOG('dialog-request', mess)
|
||||
|
||||
#####################
|
||||
# general functions #
|
||||
#####################
|
||||
|
||||
# keyboard jogging from key binding calls
|
||||
# double the rate if fast is true
|
||||
def kb_jog(self, state, joint, direction, fast = False, linear = True):
|
||||
if not STATUS.is_man_mode() or not STATUS.machine_is_on():
|
||||
return
|
||||
if linear:
|
||||
distance = STATUS.get_jog_increment()
|
||||
rate = STATUS.get_jograte()/60
|
||||
else:
|
||||
distance = STATUS.get_jog_increment_angular()
|
||||
rate = STATUS.get_jograte_angular()/60
|
||||
if state:
|
||||
if fast:
|
||||
rate = rate * 2
|
||||
ACTION.JOG(joint, direction, rate, distance)
|
||||
else:
|
||||
ACTION.JOG(joint, 0, 0, 0)
|
||||
|
||||
#####################
|
||||
# KEY BINDING CALLS #
|
||||
#####################
|
||||
|
||||
# Machine control
|
||||
def on_keycall_ESTOP(self,event,state,shift,cntrl):
|
||||
if state:
|
||||
ACTION.SET_ESTOP_STATE(STATUS.estop_is_clear())
|
||||
def on_keycall_POWER(self,event,state,shift,cntrl):
|
||||
if state:
|
||||
ACTION.SET_MACHINE_STATE(not STATUS.machine_is_on())
|
||||
def on_keycall_HOME(self,event,state,shift,cntrl):
|
||||
if state:
|
||||
if STATUS.is_all_homed():
|
||||
ACTION.SET_MACHINE_UNHOMED(-1)
|
||||
else:
|
||||
ACTION.SET_MACHINE_HOMING(-1)
|
||||
def on_keycall_ABORT(self,event,state,shift,cntrl):
|
||||
if state:
|
||||
if STATUS.stat.interp_state == linuxcnc.INTERP_IDLE:
|
||||
self.w.close()
|
||||
else:
|
||||
ACTION.ABORT()
|
||||
|
||||
# Linear Jogging
|
||||
def on_keycall_XPOS(self,event,state,shift,cntrl):
|
||||
self.kb_jog(state, 0, 1, shift)
|
||||
|
||||
def on_keycall_XNEG(self,event,state,shift,cntrl):
|
||||
self.kb_jog(state, 0, -1, shift)
|
||||
|
||||
def on_keycall_YPOS(self,event,state,shift,cntrl):
|
||||
self.kb_jog(state, 1, 1, shift)
|
||||
|
||||
def on_keycall_YNEG(self,event,state,shift,cntrl):
|
||||
self.kb_jog(state, 1, -1, shift)
|
||||
|
||||
def on_keycall_ZPOS(self,event,state,shift,cntrl):
|
||||
self.kb_jog(state, 2, 1, shift)
|
||||
|
||||
def on_keycall_ZNEG(self,event,state,shift,cntrl):
|
||||
self.kb_jog(state, 2, -1, shift)
|
||||
|
||||
def on_keycall_APOS(self,event,state,shift,cntrl):
|
||||
pass
|
||||
#self.kb_jog(state, 3, 1, shift, False)
|
||||
|
||||
def on_keycall_ANEG(self,event,state,shift,cntrl):
|
||||
pass
|
||||
#self.kb_jog(state, 3, -1, shift, linear=False)
|
||||
|
||||
def on_keycall_F12(self,event,state,shift,cntrl):
|
||||
if state:
|
||||
self.STYLEEDITOR.load_dialog()
|
||||
|
||||
###########################
|
||||
# **** closing event **** #
|
||||
###########################
|
||||
|
||||
##############################
|
||||
# required class boiler code #
|
||||
##############################
|
||||
|
||||
def __getitem__(self, item):
|
||||
return getattr(self, item)
|
||||
def __setitem__(self, item, value):
|
||||
return setattr(self, item, value)
|
||||
|
||||
################################
|
||||
# required handler boiler code #
|
||||
################################
|
||||
|
||||
def get_handlers(halcomp,widgets,paths):
|
||||
return [HandlerClass(halcomp,widgets,paths)]
|
||||
Reference in New Issue
Block a user