1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#!/usr/bin/env python3
# Qtvcp versa probe
#
# Copyright (c) 2018 Chris Morley <chrisinnanaimo@hotmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# a probe screen based on Versa probe screen
import sys
import os
from PyQt5 import QtWidgets, uic
from qtvcp.widgets.widget_baseclass import _HalWidgetBase
from qtvcp.core import Status, Action, Info
from qtvcp import logger
# Instantiate the libraries with global reference
# STATUS gives us status messages from linuxcnc
# LOG is for running code logging
STATUS = Status()
ACTION = Action()
INFO = Info()
LOG = logger.getLogger(__name__)
current_dir = os.path.dirname(__file__)
SUBPROGRAM = os.path.abspath(os.path.join(current_dir, 'versa_probe_subprog.py'))
HELP = os.path.join(INFO.LIB_PATH,'widgets_ui', 'versa_usage.html')
class RunFromLineDialog(QtWidgets.QDialog, _HalWidgetBase):
def __init__(self, parent=None):
super(RunFromLineDialog, self).__init__(parent)
# Load the widgets UI file:
self.filename = os.path.join(INFO.LIB_PATH,'widgets_ui', 'runFromLine_dialog.ui')
try:
self.instance = uic.loadUi(self.filename, self)
except AttributeError as e:
LOG.critical(e)
def _hal_init(self):
def homed_on_test():
return (self.probe_enable and STATUS.machine_is_on()
and (STATUS.is_all_homed() or INFO.NO_HOME_REQUIRED))
STATUS.connect('state-off', lambda w: self.setEnabled(False))
STATUS.connect('state-estop', lambda w: self.setEnabled(False))
STATUS.connect('interp-idle', lambda w: self.setEnabled(homed_on_test()))
STATUS.connect('all-homed', lambda w: self.setEnabled(homed_on_test()))
def accept(self):
if self.radioButton_cw.isChecked():
direction = 'M3'
else:
direction = 'M4'
speed = self.spinBox_rpm.value()
ACTION.CALL_MDI('s{} {}'.format(speed,direction))
super(RunFromLineDialog, self).accept()
########################################
# required boiler code
########################################
def __getitem__(self, item):
return getattr(self, item)
def __setitem__(self, item, value):
return setattr(self, item, value)
####################################
# Testing
####################################
if __name__ == "__main__":
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
app = QtWidgets.QApplication(sys.argv)
w = RunFromLineDialog()
w.show()
sys.exit( app.exec_() )
|