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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#!/usr/bin/env python3
#
# QTVcp Widget
# Copyright (c) 2018 Chris Morley
#
# 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.
###############################################################################
from PyQt5.QtWidgets import QToolButton, QMenu, QAction
from PyQt5.QtGui import QIcon
from qtvcp.widgets.widget_baseclass import _HalWidgetBase
from qtvcp.widgets.dialog_widget import EntryDialog
from qtvcp.core import Status, Action, Info
from qtvcp import logger
# Instiniate the libraries with global reference
# STATUS gives us status messages from linuxcnc
# AUX_PRGM holds helper program loader
# INI holds ini details
# ACTION gives commands to linuxcnc
# LOG is for running code logging
STATUS = Status()
INFO = Info()
ACTION = Action()
LOG = logger.getLogger(__name__)
# Force the log level for this module
#LOG.setLevel(logger.DEBUG) # One of DEBUG, INFO, WARNING, ERROR, CRITICAL
class SystemToolButton(QToolButton, _HalWidgetBase):
def __init__(self, parent=None):
super(SystemToolButton, self).__init__(parent)
self._joint = 0
self._last = 0
self._block_signal = False
self._auto_label_flag = True
SettingMenu = QMenu(self)
for system in('G54', 'G55', 'G56', 'G57', 'G58', 'G59', 'G59.1', 'G59.2', 'G59.3'):
Button = QAction(QIcon('exit24.png'), system, self)
Button.triggered.connect(self[system.replace('.','_')])
SettingMenu.addAction(Button)
self.setMenu(SettingMenu)
self.dialog = EntryDialog()
#self.setPopupMode(QToolButton.DelayedPopup)
def _hal_init(self):
if not self.text() == '':
self._auto_label_flag = False
def homed_on_test():
return (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('interp-run', lambda w: self.setEnabled(False))
STATUS.connect('all-homed', lambda w: self.setEnabled(True))
STATUS.connect('not-all-homed', lambda w, data: self.setEnabled(False))
STATUS.connect('interp-paused', lambda w: self.setEnabled(False))
STATUS.connect('user-system-changed', self._set_user_system_text)
def G54(self):
ACTION.SET_USER_SYSTEM('54')
def G55(self):
ACTION.SET_USER_SYSTEM(55)
def G56(self):
ACTION.SET_USER_SYSTEM('G56')
def G57(self):
ACTION.SET_USER_SYSTEM('G57')
def G58(self):
ACTION.SET_USER_SYSTEM('G58')
def G59(self):
ACTION.SET_USER_SYSTEM('G59')
def G59_1(self):
ACTION.SET_USER_SYSTEM('G59.1')
def G59_2(self):
ACTION.SET_USER_SYSTEM('G59.2')
def G59_3(self):
ACTION.SET_USER_SYSTEM('G59.3')
def _set_user_system_text(self, w, data):
convert = { 0:'None',1:"G54", 2:"G55", 3:"G56", 4:"G57", 5:"G58", 6:"G59", 7:"G59.1", 8:"G59.2", 9:"G59.3"}
if self._auto_label_flag:
self.setText(convert[int(data)])
def ChangeState(self, joint):
if int(joint) != self._joint:
self._block_signal = True
self.setChecked(False)
self._block_signal = False
self.hal_pin.set(False)
##############################
# required class boiler code #
##############################
def __getitem__(self, item):
return getattr(self, item)
def __setitem__(self, item, value):
return setattr(self, item, value)
# for testing without editor:
def main():
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
widget = SystemToolButton()
widget.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
|