Skip to content

Commit 0cfe1f8

Browse files
committed
qtvcp -add new widgets axis picker and user DRO label
together used to make a user DRO label separate from the system DRO. Probably most useful for setup references
1 parent 27706fc commit 0cfe1f8

4 files changed

Lines changed: 475 additions & 0 deletions

File tree

lib/python/qtvcp/plugins/toolbutton_plugin.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from PyQt5.QtDesigner import QPyDesignerCustomWidgetPlugin
55
from qtvcp.widgets.system_tool_button import SystemToolButton
66
from qtvcp.widgets.action_tool_button import ActionToolButton
7+
from qtvcp.widgets.axisPickTool_button import AxisPickToolButton
78
from qtvcp.widgets.qtvcp_icons import Icon
89

910
ICON = Icon()
@@ -94,3 +95,46 @@ def domXml(self):
9495

9596
def includeFile(self):
9697
return "qtvcp.widgets.action_tool_button"
98+
99+
####################################
100+
# AxisPickToolButton
101+
####################################
102+
class AxisPickToolButtonPlugin(QPyDesignerCustomWidgetPlugin):
103+
def __init__(self, parent=None):
104+
super(AxisPickToolButtonPlugin, self).__init__(parent)
105+
self.initialized = False
106+
107+
def initialize(self, formEditor):
108+
if self.initialized:
109+
return
110+
self.initialized = True
111+
112+
def isInitialized(self):
113+
return self.initialized
114+
115+
def createWidget(self, parent):
116+
return AxisPickToolButton(parent)
117+
118+
def name(self):
119+
return "AxisPickToolButton"
120+
121+
def group(self):
122+
return "Linuxcnc - Widgets"
123+
124+
def icon(self):
125+
return QtGui.QIcon(QtGui.QPixmap(ICON.get_path('AxisPicktoolbutton')))
126+
127+
def toolTip(self):
128+
return "Tool Button for selecting an available Axis"
129+
130+
def whatsThis(self):
131+
return ""
132+
133+
def isContainer(self):
134+
return False
135+
136+
def domXml(self):
137+
return '<widget class="AxisPickToolButton" name="axispicktoolbutton" />\n'
138+
139+
def includeFile(self):
140+
return "qtvcp.widgets.axisPickTool_button"

lib/python/qtvcp/plugins/widgets_plugin.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from PyQt5 import QtGui
44
from PyQt5.QtDesigner import QPyDesignerCustomWidgetPlugin
55
from qtvcp.widgets.dro_widget import DROLabel
6+
from qtvcp.widgets.user_dro_label import UserDROLabel
67
from qtvcp.widgets.mdi_line import MDILine
78
from qtvcp.widgets.operator_value_line import OperatorValueLine
89
from qtvcp.widgets.tool_chooser import ToolChooser
@@ -64,6 +65,48 @@ def domXml(self):
6465
def includeFile(self):
6566
return "qtvcp.widgets.dro_widget"
6667

68+
####################################
69+
# Axis Position UserDROLabel
70+
####################################
71+
class UserDROLabelPlugin(QPyDesignerCustomWidgetPlugin):
72+
def __init__(self, parent=None):
73+
super(UserDROLabelPlugin, self).__init__(parent)
74+
self.initialized = False
75+
76+
def initialize(self, formEditor):
77+
if self.initialized:
78+
return
79+
self.initialized = True
80+
81+
def isInitialized(self):
82+
return self.initialized
83+
84+
def createWidget(self, parent):
85+
return UserDROLabel(parent)
86+
87+
def name(self):
88+
return "UserDROLabel"
89+
90+
def group(self):
91+
return "Linuxcnc - Widgets"
92+
93+
def icon(self):
94+
return QtGui.QIcon(QtGui.QPixmap(ICON.get_path('UserDROLabel')))
95+
96+
def toolTip(self):
97+
return "User Referenced Axis Position Display Widget"
98+
99+
def whatsThis(self):
100+
return ""
101+
102+
def isContainer(self):
103+
return False
104+
105+
def domXml(self):
106+
return '<widget class="UserDROLabel" name="userdro" />\n'
107+
108+
def includeFile(self):
109+
return "qtvcp.widgets.user_dro_label"
67110

68111
####################################
69112
# MDI edit line
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from PyQt5.QtWidgets import (QToolButton, QMenu, QAction,
2+
QComboBox, QWidgetAction, QSizePolicy)
3+
from PyQt5.QtCore import pyqtProperty, pyqtSignal
4+
from PyQt5.QtGui import QIcon
5+
6+
from qtvcp.widgets.widget_baseclass import _HalWidgetBase
7+
from qtvcp.widgets.indicatorMixIn import IndicatedMixIn
8+
from qtvcp.core import Status, Action, Info
9+
from qtvcp import logger
10+
11+
# Instiniate the libraries with global reference
12+
# STATUS gives us status messages from linuxcnc
13+
# AUX_PRGM holds helper program loader
14+
# INI holds ini details
15+
# ACTION gives commands to linuxcnc
16+
# LOG is for running code logging
17+
STATUS = Status()
18+
INFO = Info()
19+
ACTION = Action()
20+
LOG = logger.getLogger(__name__)
21+
# Force the log level for this module
22+
#LOG.setLevel(logger.DEBUG) # One of DEBUG, INFO, WARNING, ERROR, CRITICAL
23+
24+
class AxisPickToolButton(QToolButton, IndicatedMixIn):
25+
AxisSelected = pyqtSignal(str)
26+
CurrentAxisPosition = pyqtSignal(str,float)
27+
28+
def __init__(self, parent=None):
29+
super(AxisPickToolButton, self).__init__(parent)
30+
self._textTemplate = 'Axis: %s'
31+
self._currentAxis = 'X'
32+
33+
34+
def _hal_init(self):
35+
self.createAxisButton(self._currentAxis)
36+
self.axisTriggered(self._currentAxis)
37+
38+
def createAxisButton(self, text):
39+
tmpl = lambda s: self._textTemplate % s
40+
self.setText(tmpl(text))
41+
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
42+
self.setMinimumSize(70, 40)
43+
self.clicked.connect(self.axisClicked)
44+
SettingMenu = QMenu()
45+
self.settingMenu = SettingMenu
46+
for i in INFO.AVAILABLE_AXES:
47+
axisButton = QAction(QIcon('exit24.png'), i, self)
48+
# weird lambda i=i to work around 'function closure'
49+
axisButton.triggered.connect(lambda state, i=i: self.axisTriggered(i))
50+
SettingMenu.addAction(axisButton)
51+
self.setMenu(SettingMenu)
52+
53+
def axisTriggered(self, data):
54+
tmpl = lambda s: self._textTemplate % s
55+
self.setText(tmpl(data))
56+
self.AxisSelected.emit(data)
57+
58+
def axisClicked(self):
59+
conversion = {'X':0, 'Y':1, "Z":2, 'A':3, "B":4, "C":5, 'U':6, 'V':7, 'W':8}
60+
digitValue = 0.0
61+
try:
62+
p,relp,dtg = STATUS.get_position()
63+
text = self.text()
64+
for let in INFO.AVAILABLE_AXES:
65+
if let == text[-1]:
66+
digitValue = round(p[conversion[let]],5)
67+
break
68+
except Exception as e:
69+
print(e)
70+
return
71+
print(let, digitValue)
72+
self.AxisSelected.emit(let)
73+
self.CurrentAxisPosition.emit(let, digitValue)
74+
75+
def setTextTemplate(self, data):
76+
self._textTemplate = data
77+
def getTextTemplate(self):
78+
return self._textTemplate
79+
def resetTextTemplate(self):
80+
self._textTemplate = 'Axis: %s'
81+
textTemplate = pyqtProperty(str, getTextTemplate, setTextTemplate, resetTextTemplate)
82+
83+
def setCurrentAxis(self, data):
84+
self._currentAxis = data
85+
def getCurrentAxis(self):
86+
return self._currentAxis
87+
def resetCurrentAxis(self):
88+
self._currentAxis = 'X'
89+
currentAxis = pyqtProperty(str, getCurrentAxis, setCurrentAxis, resetCurrentAxis)
90+

0 commit comments

Comments
 (0)