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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
|
#!/usr/bin/env python3
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtDesigner import QPyDesignerCustomWidgetPlugin, \
QPyDesignerTaskMenuExtension, QExtensionFactory, \
QDesignerFormWindowInterface
from qtvcp.widgets.action_button import ActionButton
from qtvcp.widgets.action_button_round import RoundButton
from qtvcp.widgets.qtvcp_icons import Icon
from qtvcp.widgets.richtext_selector import RichTextEditorDialog
ICON = Icon()
Q_TYPEID = {
'QDesignerContainerExtension': 'org.qt-project.Qt.Designer.Container',
'QDesignerPropertySheetExtension': 'org.qt-project.Qt.Designer.PropertySheet',
'QDesignerTaskMenuExtension': 'org.qt-project.Qt.Designer.TaskMenu',
'QDesignerMemberSheetExtension': 'org.qt-project.Qt.Designer.MemberSheet'
}
####################################
# ActionBUTTON
####################################
class ActionButtonPlugin(QPyDesignerCustomWidgetPlugin):
# The __init__() method is only used to set up the plugin and define its
# initialized variable.
def __init__(self, parent=None):
super(ActionButtonPlugin, self).__init__(parent)
self.initialized = False
# The initialize() and isInitialized() methods allow the plugin to set up
# any required resources, ensuring that this can only happen once for each
# plugin.
def initialize(self, formEditor):
if self.initialized:
return
manager = formEditor.extensionManager()
if manager:
self.factory = ActionButtonTaskMenuFactory(manager)
manager.registerExtensions(self.factory, Q_TYPEID['QDesignerTaskMenuExtension'])
self.initialized = True
def isInitialized(self):
return self.initialized
# This factory method creates new instances of our custom widget
def createWidget(self, parent):
a = ActionButton(parent)
a._designer_init()
return a
# This method returns the name of the custom widget class
def name(self):
return "ActionButton"
# Returns the name of the group in Qt Designer's widget box
def group(self):
return "Linuxcnc - Controller"
# Returns the icon
def icon(self):
return QtGui.QIcon(':/qt-project.org/styles/commonstyle/images/standardbutton-apply-128.png')
# Returns a tool tip short description
def toolTip(self):
return "Action button widget"
# Returns a short description of the custom widget for use in a "What's
# This?" help message for the widget.
def whatsThis(self):
return ""
# Returns True if the custom widget acts as a container for other widgets;
def isContainer(self):
return False
# Returns an XML description of a custom widget instance that describes
# default values for its properties.
def domXml(self):
return '<widget class="ActionButton" name="actionbutton" />\n'
# Returns the module containing the custom widget class. It may include
# a module path.
def includeFile(self):
return "qtvcp.widgets.action_button"
class TreeComboBox(QtWidgets.QComboBox):
def __init__(self, parent=None):
super(TreeComboBox, self).__init__(parent)
self.__skip_next_hide = False
self._last_pick = None
tree_view = QtWidgets.QTreeView(self)
tree_view.setFrameShape(QtWidgets.QFrame.NoFrame)
tree_view.setEditTriggers(tree_view.NoEditTriggers)
tree_view.setAlternatingRowColors(True)
tree_view.setSelectionBehavior(tree_view.SelectRows)
tree_view.setWordWrap(True)
tree_view.setAllColumnsShowFocus(True)
self.setView(tree_view)
self.view().viewport().installEventFilter(self)
def showPopup(self):
self.setRootModelIndex(QtCore.QModelIndex())
super(TreeComboBox, self).showPopup()
def hidePopup(self):
self.setRootModelIndex(self.view().currentIndex().parent())
self.setCurrentIndex(self.view().currentIndex().row())
if self.__skip_next_hide:
self.__skip_next_hide = False
else:
super(TreeComboBox, self).hidePopup()
def selectIndex(self, index):
self.setRootModelIndex(index.parent())
self.setCurrentIndex(index.row())
def eventFilter(self, object, event):
if event.type() == QtCore.QEvent.MouseButtonPress and object is self.view().viewport():
index = self.view().indexAt(event.pos())
# print index.parent(),index.row(),index.column(),index.data(),index.data(QtCore.Qt.UserRole + 1)
# print self.view().isExpanded(self.view().currentIndex())
# if self.itemAt(event.pos()) is None
self.__skip_next_hide = not self.view().visualRect(index).contains(event.pos())
return False
def addItems(self, parent, elements):
for text, value, children in elements:
item = QtGui.QStandardItem(text)
item.setData(value[0], role=QtCore.Qt.UserRole + 1)
item.setData(value[1], role=QtCore.Qt.UserRole + 2)
parent.appendRow(item)
if children:
self.addItems(item, children)
def select(self, nodeNum, row):
# print 'select:', nodeNum, row
# select last row
newIndex = self.model().index(nodeNum, 0)
self.setRootModelIndex(newIndex)
self.setCurrentIndex(row)
# hacky work around
def updateLastPick(self, pick):
self._last_pick = pick
def getLastPick(self):
return self._last_pick
class ActionButtonDialog(QtWidgets.QDialog):
def __init__(self, widget, parent=None):
QtWidgets.QDialog.__init__(self, parent)
self.setWindowTitle(self.tr("Set Options"))
self.setGeometry(300, 300, 300, 300)
self.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
self.widget = widget
self.previewWidget = ActionButton()
self.tab = QtWidgets.QTabWidget()
self.tab1 = QtWidgets.QWidget()
self.tab2 = QtWidgets.QWidget()
self.tab3 = QtWidgets.QWidget()
self.tab.addTab(self.tab1, 'Actions')
self.tab.addTab(self.tab2, 'LED')
self.tab.addTab(self.tab3, 'Other')
self.buildtab1()
self.buildtab2()
self.buildtab3()
vbox = QtWidgets.QVBoxLayout()
vbox.addWidget(self.tab)
wid = QtWidgets.QWidget()
vbox2 = QtWidgets.QVBoxLayout(wid)
self.defaultTextTemplateEditBox = QtWidgets.QLineEdit()
self.defaultTextTemplateEditBox.setText(self.widget.text())
hbox = QtWidgets.QHBoxLayout()
label = QtWidgets.QLabel('Default Text Template')
hbox.addWidget(label)
# dialogButton = QtWidgets.QPushButton('RichText Editor')
# dialogButton.clicked.connect(lambda :self.launchDialog(self.defaultTextTemplateEditBox))
# hbox.addWidget(dialogButton)
vbox2.addLayout(hbox)
vbox2.addWidget(self.defaultTextTemplateEditBox)
vbox.addWidget(wid)
# Dialog control buttons
buttonBox = QtWidgets.QDialogButtonBox()
okButton = buttonBox.addButton(buttonBox.Ok)
cancelButton = buttonBox.addButton(buttonBox.Cancel)
okButton.clicked.connect(self.updateWidget)
cancelButton.clicked.connect(self.reject)
vbox.addWidget(buttonBox, 1)
self.setLayout(vbox)
self.onSetOptions()
def buildtab1(self):
self.combo = TreeComboBox()
model = QtGui.QStandardItemModel()
model.setHeaderData(0, QtCore.Qt.Horizontal, 'Name', QtCore.Qt.DisplayRole)
# (('Displayed name',['widget property name', code to show related data],[])
node_1 = (('Estop', ['estop', 0], []),
('Machine On', ['machine_on', 0], []),
('Home', ['home', 1], []),
('Unhome', ['unhome', 1], []),
('Home Selected', ['home_select', 0], []),
('Unhome Selected', ['unhome_select', 0], []),
('Run', ['run', 0], []),
('Run from Line Status', ['run_from_status', 0], []),
('Run From Line Slot', ['run_from_slot', 0], []),
('Abort', ['abort', 0], []),
('Pause', ['pause', 0], []),
('Step', ['step', 0], []),
('Override Limits', ['limits_override', 0], []),
('Zero Axis', ['zero_axis', 1], []),
('Zero G5x', ['zero_g5x', 0], []),
('Zero G92', ['zero_g92', 0], []),
('Zero Z Rotational', ['zero_zrot', 0], []),
('Lathe Mirror X', ['lathe_mirror_x', 0], []),
('Block Delete', ['block_delete', 0], []),
('Optional Stop', ['optional_stop', 0], []),
('Food Coolant', ['flood', 0], []),
('Mist Coolant', ['mist', 0], []),
('Exit Screen', ['exit', 0], []))
node_2 = (('Jog Joint Positive', ['jog_joint_pos', 1], []),
('Jog Joint Negative', ['jog_joint_neg', 1], []),
('Jog Selected Positive', ['jog_selected_pos', 0], []),
('Jog Selected Negative', ['jog_selected_neg', 0], []),
('Jog Increment', ['jog_incr', 1038], []),
('Jog Rate', ['jog_rate', 112], []))
node_3 = (('Load Dialog', ['load_dialog', 0], []),
('Macro Dialog', ['macro_dialog', 0], []),
('CamView Dialog', ['camview_dialog', 0], []),
('Machine Log Dialog', ['machine_log_dialog', 0], []),
('Origin Offset Dialog', ['origin_offset_dialog', 0], []),
('Tool Offset Dialog', ['tool_offset_dialog', 0], []))
node_4 = (('Launch HALmeter', ['launch_halmeter', 0], []),
('Launch Status', ['launch_status', 0], []),
('Launch HALshow', ['launch_halshow', 0], []),
('Launch HALscope', ['launch_halscope', 0], []),
('Launch Calibration', ['launch_calibration', 0], []))
node_5 = (('Set MDI Mode', ['mdi', 0], []),
('Set Auto Mode', ['auto', 0], []),
('Set Manual Mode', ['manual', 0], []))
node_6 = (('Set Feed Override', ['feed_over', 112], []),
('Set Rapid Override', ['rapid_over', 112], []),
('Set Spindle Override', ['spindle_over', 112], []),
('Set Max Velocity Override', ['max_velocity_over', 112], []))
node_7 = (('Set Spindle Forward', ['spindle_fwd', 0], []),
('Set Spindle Reverse', ['spindle_rev', 0], []),
('Set Spindle Stop', ['spindle_stop', 0], []),
('Set Spindle Up', ['spindle_up', 0], []),
('Set Spindle Down', ['spindle_down', 0], []))
node_8 = (('Set DRO to Relative', ['dro_relative', 0], []),
('Set DRO to Absolute', ['dro_absolute', 0], []),
('Set DRO to DTG', ['dro_dtg', 0], []),)
node_9 = (('View Change', ['view_change', 128], []),)
node_10 = (('MDI Commands', ['mdi_command', 256], []),
('MDI Commands From INI', ['ini_mdi_command', 512], []))
node_none = (('Unused', ['unused', 0], []),)
parent_node = [('Unset', [None, None], node_none),
('MACHINE CONTROL', [None, None], node_1),
('JOGGING CONTROLS', [None, None], node_2),
('DIALOG LAUNCH', [None, None], node_3),
('LAUNCH PROGRAMS', [None, None], node_4),
('MODE SETTING', [None, None], node_5),
('OVERRIDE SETTING', [None, None], node_6),
('SPINDLE CONTROLS', [None, None], node_7),
('DRO CONTROL', [None, None], node_8),
('GRAPHIC CONTROLS', [None, None], node_9),
('MDI', [None, None], node_10)]
self.combo.addItems(model, parent_node)
self.combo.setModel(model)
# self.combo.view().hideColumn (1)
# self.combo.resize(300, 30)
self.combo.activated.connect(self.selectionChanged)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.combo)
# related data selection - note the name 'self.ud' uses a number
# that doubles each time - binary coded. this is so we can specify
# multiple selectors code 1 give ud1, code 2 gives ud2, code 3 gives
# ud1 and ud2 etc
# Joint number selection
self.ud1 = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Joint/axis number')
self.JNumSpinBox = QtWidgets.QSpinBox()
self.JNumSpinBox.setRange(-1, 8)
self.JNumSpinBox.setValue(self.widget.joint_number)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.JNumSpinBox)
self.ud1.setLayout(hbox)
layout.addWidget(self.ud1)
self.ud1.hide()
# Jog imperial increment
self.ud2 = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Jog Increment Imperial')
self.jogIncImpSpinBox = QtWidgets.QDoubleSpinBox()
self.jogIncImpSpinBox.setRange(-1, 1000)
self.jogIncImpSpinBox.setDecimals(4)
self.jogIncImpSpinBox.setValue(self.widget.jog_incr_imperial)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.jogIncImpSpinBox)
self.ud2.setLayout(hbox)
layout.addWidget(self.ud2)
self.ud2.hide()
# Jog mm increment
self.ud4 = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Jog Increment mm')
self.jogIncMMSpinBox = QtWidgets.QDoubleSpinBox()
self.jogIncMMSpinBox.setRange(-1, 100000)
self.jogIncMMSpinBox.setDecimals(4)
self.jogIncMMSpinBox.setValue(self.widget.jog_incr_mm)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.jogIncMMSpinBox)
self.ud4.setLayout(hbox)
layout.addWidget(self.ud4)
self.ud4.hide()
# Jog Angular Increments
self.ud8 = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Jog Increment Angular')
self.jogIncAngSpinBox = QtWidgets.QDoubleSpinBox()
self.jogIncAngSpinBox.setRange(-1, 100000)
self.jogIncAngSpinBox.setDecimals(4)
self.jogIncAngSpinBox.setValue(self.widget.jog_incr_angle)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.jogIncAngSpinBox)
self.ud8.setLayout(hbox)
layout.addWidget(self.ud8)
self.ud8.hide()
# float
self.ud16 = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Float')
self.floatSpinBox = QtWidgets.QDoubleSpinBox()
self.floatSpinBox.setRange(-1000, 1000)
self.floatSpinBox.setDecimals(4)
self.floatSpinBox.setValue(self.widget.float)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.floatSpinBox)
self.ud16.setLayout(hbox)
layout.addWidget(self.ud16)
self.ud16.hide()
# Alternate float
self.ud32 = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Alternate Float')
self.floatAltSpinBox = QtWidgets.QDoubleSpinBox()
self.floatAltSpinBox.setRange(-1000, 1000)
self.floatAltSpinBox.setDecimals(4)
self.floatAltSpinBox.setValue(self.widget.float_alt)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.floatAltSpinBox)
self.ud32.setLayout(hbox)
layout.addWidget(self.ud32)
self.ud32.hide()
# Toggle float option
self.ud64 = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Toggle Float Option')
self.toggleCheckBox = QtWidgets.QCheckBox()
self.toggleCheckBox.setChecked(self.widget.toggle_float)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.toggleCheckBox)
self.ud64.setLayout(hbox)
layout.addWidget(self.ud64)
self.ud64.hide()
# View
self.ud128 = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Graphics View')
self.viewComboBox = QtWidgets.QComboBox()
flag = 0
for num, i in enumerate(('P', 'X', 'Y', 'Y2', 'Z', 'Z2', 'Clear',
'zoom-in', 'zoom-out', 'pan-up', 'pan-down', 'pan-left',
'pan-right', 'rotate-up', 'rotate-down', 'rotate-cw',
'rotate-ccw', 'reload', 'overlay_dro_on', 'overlay_dro_off',
'overlay-offsets-on', 'overlay-offsets-off',
'inhibit-selection-on', 'inhibit-selection-off',
'alpha-mode-on', 'alpha-mode-off', 'dimensions-on', 'dimensions-off')):
if self.widget.view_type.lower() == i.lower():
flag = num
self.viewComboBox.addItem(i)
self.viewComboBox.setCurrentIndex(flag)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.viewComboBox)
self.ud128.setLayout(hbox)
layout.addWidget(self.ud128)
self.ud128.hide()
# MDI command edit box
self.ud256 = QtWidgets.QWidget()
vbox = QtWidgets.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('MDI Command Line')
self.commandEditBox = QtWidgets.QLineEdit()
self.commandEditBox.setText(self.widget.command_text)
vbox.addWidget(label)
vbox.addWidget(self.commandEditBox)
self.ud256.setLayout(vbox)
layout.addWidget(self.ud256)
self.ud256.hide()
# MDI command from INI edit box
self.ud512 = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('MDI Command from INI File')
self.MDISpinBox = QtWidgets.QSpinBox()
self.MDISpinBox.setRange(0, 50)
# self.MDISpinBox.setValue(self.widget.INI_MDI_number)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.MDISpinBox)
self.ud512.setLayout(hbox)
layout.addWidget(self.ud512)
self.ud512.hide()
# text template edit box
self.ud1024 = QtWidgets.QWidget()
vbox = QtWidgets.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Template Label Option')
self.textTemplateCheckBox = QtWidgets.QCheckBox()
self.textTemplateCheckBox.setChecked(self.widget.template_label)
self.textTemplateCheckBox.clicked.connect(self.onSetOptions)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.textTemplateCheckBox)
vbox.addLayout(hbox)
self.vbox = QtWidgets.QWidget()
vbox2 = QtWidgets.QVBoxLayout(self.vbox)
label = QtWidgets.QLabel('Imperial Text Template')
self.textTemplateEditBox = QtWidgets.QLineEdit()
self.textTemplateEditBox.setText(self.widget._textTemplate)
vbox2.addWidget(label)
vbox2.addWidget(self.textTemplateEditBox)
label = QtWidgets.QLabel('Metric Text Template')
self.altTextTemplateEditBox = QtWidgets.QLineEdit()
self.altTextTemplateEditBox.setText(self.widget._alt_textTemplate)
vbox2.addWidget(label)
vbox2.addWidget(self.altTextTemplateEditBox)
vbox.addWidget(self.vbox)
self.ud1024.setLayout(vbox)
layout.addWidget(self.ud1024)
self.ud1024.hide()
self.tab1.setLayout(layout)
# set combo to currently set property
# widget[cdata[1][0]] will tell us the widgets property state
# eg widget.estop or widget.machine_on
flag = False
# print parent_node
for pnum, pdata in enumerate(parent_node):
# print pnum,pdata[0]
if pnum == 0: continue
if pdata[0]:
for cnum, cdata in enumerate(pdata[2]):
# print 'child,state:',cdata[1][0],self.widget[cdata[1][0]]
if self.widget[cdata[1][0]]:
flag = True
# print 'found index:',pnum,cnum
break
if flag:
break
if flag:
self.combo.select(pnum, cnum)
winPropertyName = self.combo.itemData(cnum, role=QtCore.Qt.UserRole + 1)
# print 'selected property,related data code:',winPropertyName
self.combo.updateLastPick(winPropertyName)
else:
self.combo.select(0, 0)
def selectionChanged(self, i):
winPropertyName = self.combo.itemData(i, role=QtCore.Qt.UserRole + 1)
userDataCode = self.combo.itemData(i, role=QtCore.Qt.UserRole + 2)
# print 'selected property,related data code:',winPropertyName,userDataCode,i
self.combo.updateLastPick(winPropertyName)
if winPropertyName is None:
# collapsed = self.combo.view().isExpanded(self.combo.view().currentIndex())
# if collapsed: return True
return True
if not userDataCode is None:
for i in (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024):
widg = self['ud%s' % i]
if userDataCode & i:
widg.show()
else:
widg.hide()
self.adjustSize()
# Indicator Tab
def buildtab2(self):
statusProperties = [['None', None], ['Is Estopped', 'is_estopped'],
['Is On', 'is_on'], ['All Homed', 'is_homed'],
['Is Joint Homed', 'is_joint_homed'],
['Idle', 'is_idle'], ['Paused', 'is_paused'],
['Flood', 'is_flood'], ['Mist', 'is_mist'],
['Block Delete', 'is_block_delete'],
['Optional Stop', 'is_optional_stop'],
['Manual', 'is_manual'], ['MDI', 'is_mdi'],
['Auto', 'is_auto'],
['Spindle Stopped', 'is_spindle_stopped'],
['Spindle Fwd', 'is_spindle_fwd'],
['Spindle Reverse', 'is_spindle_rev'],
['On Limits', 'is_limits_overridden']]
layout = QtWidgets.QGridLayout()
# Indicator option
self.indicatorO = QtWidgets.QFrame()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('<b>Led Indicator Option<\b>')
self.indicatorCheckBox = QtWidgets.QCheckBox()
self.indicatorCheckBox.setChecked(self.widget.draw_indicator)
self.indicatorCheckBox.clicked.connect(self.onSetOptions)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.indicatorCheckBox)
self.indicatorO.setLayout(hbox)
layout.addWidget(self.indicatorO)
# self.indicatorO.hide()
# HAL pin LED option
self.halP = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Hal Pin Controlled LED')
self.halCheckBox = QtWidgets.QCheckBox()
self.halCheckBox.setChecked(self.widget._HAL_pin)
self.halCheckBox.clicked.connect(self.onSetOptions)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.halCheckBox)
self.halP.setLayout(hbox)
layout.addWidget(self.halP)
self.halP.hide()
line = QtWidgets.QFrame()
line.setFrameShape(QtWidgets.QFrame.HLine)
line.setFrameShadow(QtWidgets.QFrame.Sunken)
layout.addWidget(line)
# Linuxcnc Status LED option
self.statusO = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Status Controlled LED')
self.statusCheckBox = QtWidgets.QCheckBox()
self.statusCheckBox.setChecked(self.widget._ind_status)
self.statusCheckBox.clicked.connect(self.onSetOptions)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.statusCheckBox)
self.statusO.setLayout(hbox)
layout.addWidget(self.statusO)
self.statusO.hide()
# Invert Status LED option
self.invertStatus = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Invert Status LED State')
self.invertCheckBox = QtWidgets.QCheckBox()
self.invertCheckBox.setChecked(self.widget._invert_status)
self.invertCheckBox.clicked.connect(self.onSetOptions)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.invertCheckBox)
self.invertStatus.setLayout(hbox)
layout.addWidget(self.invertStatus)
# self.invertStatus.hide()
# status watch combo box
self.watch = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Watch Status:')
self.statusCombo = QtWidgets.QComboBox()
flag = 0
for index, data in enumerate(statusProperties):
if data[1] and self.widget['_{}'.format(data[1])]:
flag = index
self.statusCombo.addItem(data[0])
self.statusCombo.setItemData(index, data[1], QtCore.Qt.UserRole + 1)
self.statusCombo.setCurrentIndex(flag)
self.statusCombo.activated.connect(self.statusSelectionChanged)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.statusCombo)
self.watch.setLayout(hbox)
layout.addWidget(self.watch)
self.watch.hide()
# joint number selection
self.jnum = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Joint/Spindle Selection')
self.jnumCombo = QtWidgets.QComboBox()
self.jnumCombo.activated.connect(self.onSetOptions)
for i in range(0, 10):
self.jnumCombo.addItem('{}'.format(i), i)
self.jnumCombo.setCurrentIndex(self.widget._joint_number)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.jnumCombo)
self.jnum.setLayout(hbox)
layout.addWidget(self.jnum)
self.jnum.hide()
line = QtWidgets.QFrame()
line.setFrameShape(QtWidgets.QFrame.HLine)
line.setFrameShadow(QtWidgets.QFrame.Sunken)
layout.addWidget(line)
# Shape selection
self.shape = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Shape Selection')
self.shapeCombo = QtWidgets.QComboBox()
self.shapeCombo.activated.connect(self.onSetOptions)
self.shapeCombo.addItem('Triangle', 0)
self.shapeCombo.addItem('Circle', 1)
self.shapeCombo.addItem('TopBar', 2)
self.shapeCombo.addItem('SideBar', 3)
self.shapeCombo.setCurrentIndex(self.widget._shape)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.shapeCombo)
self.shape.setLayout(hbox)
layout.addWidget(self.shape)
self.shape.hide()
# Round indicator diameter
self.diam = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Round Diameter')
self.diamSpinBox = QtWidgets.QDoubleSpinBox()
self.diamSpinBox.setRange(2, 100)
self.diamSpinBox.setDecimals(1)
self.diamSpinBox.setSingleStep(1)
self.diamSpinBox.setValue(self.widget._diameter)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.diamSpinBox)
self.diam.setLayout(hbox)
layout.addWidget(self.diam)
self.diam.hide()
# Triangle indicator size
self.size = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Triangle Size')
self.floatSpinBox = QtWidgets.QDoubleSpinBox()
self.floatSpinBox.setRange(0, 2)
self.floatSpinBox.setDecimals(4)
self.floatSpinBox.setSingleStep(0.1)
self.floatSpinBox.setValue(self.widget._size)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.floatSpinBox)
self.size.setLayout(hbox)
layout.addWidget(self.size)
self.size.hide()
# Bar LED corner radius
self.radius = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Corner Radius')
self.radiusSpinBox = QtWidgets.QDoubleSpinBox()
self.radiusSpinBox.setRange(0, 20)
self.radiusSpinBox.setDecimals(1)
self.radiusSpinBox.setSingleStep(1)
self.radiusSpinBox.setValue(self.widget._corner_radius)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.radiusSpinBox)
self.radius.setLayout(hbox)
layout.addWidget(self.radius)
self.radius.hide()
# Bar LED right edge offset
self.rightedgeoffset = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Right Edge Offset')
self.rightedgeoffsetSpinBox = QtWidgets.QDoubleSpinBox()
self.rightedgeoffsetSpinBox.setRange(0, 50)
self.rightedgeoffsetSpinBox.setDecimals(1)
self.rightedgeoffsetSpinBox.setSingleStep(.1)
self.rightedgeoffsetSpinBox.setValue(self.widget._right_edge_offset)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.rightedgeoffsetSpinBox)
self.rightedgeoffset.setLayout(hbox)
layout.addWidget(self.rightedgeoffset)
self.rightedgeoffset.hide()
# Bar LED top edge offset
self.topedgeoffset = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Top Edge Offset')
self.topedgeoffsetSpinBox = QtWidgets.QDoubleSpinBox()
self.topedgeoffsetSpinBox.setRange(0, 50)
self.topedgeoffsetSpinBox.setDecimals(1)
self.topedgeoffsetSpinBox.setSingleStep(.1)
self.topedgeoffsetSpinBox.setValue(self.widget._top_edge_offset)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.topedgeoffsetSpinBox)
self.topedgeoffset.setLayout(hbox)
layout.addWidget(self.topedgeoffset)
self.topedgeoffset.hide()
# Bar LED height fraction
self.hfraction = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Height Fraction')
self.hfractionSpinBox = QtWidgets.QDoubleSpinBox()
self.hfractionSpinBox.setRange(0, 1)
self.hfractionSpinBox.setDecimals(1)
self.hfractionSpinBox.setSingleStep(.1)
self.hfractionSpinBox.setValue(self.widget._h_fraction)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.hfractionSpinBox)
self.hfraction.setLayout(hbox)
layout.addWidget(self.hfraction)
self.hfraction.hide()
# Bar LED width fraction
self.wfraction = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('Width Fraction')
self.wfractionSpinBox = QtWidgets.QDoubleSpinBox()
self.wfractionSpinBox.setRange(0, 1)
self.wfractionSpinBox.setDecimals(1)
self.wfractionSpinBox.setSingleStep(.1)
self.wfractionSpinBox.setValue(self.widget._w_fraction)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.wfractionSpinBox)
self.wfraction.setLayout(hbox)
layout.addWidget(self.wfraction)
self.wfraction.hide()
# true state indicator color
self.colorTrue = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
button = QtWidgets.QLabel('True State LED Color')
self.trueColorButton = QtWidgets.QPushButton()
self.trueColorButton.setToolTip('Opens color dialog')
self.trueColorButton.clicked.connect(self.on_trueColorClick)
self.trueColorButton.setStyleSheet('QPushButton {background-color: %s ;}' % self.widget._on_color.name())
self._onColor = self.widget._on_color.name()
hbox.addWidget(button)
hbox.addWidget(self.trueColorButton)
self.colorTrue.setLayout(hbox)
layout.addWidget(self.colorTrue)
self.colorTrue.hide()
# False state indicator color
self.colorFalse = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
button = QtWidgets.QLabel('False State LED Color')
self.falseColorButton = QtWidgets.QPushButton()
self.falseColorButton.setToolTip('Opens color dialog')
self.falseColorButton.clicked.connect(self.on_falseColorClick)
self.falseColorButton.setStyleSheet('QPushButton {background-color: %s ;}' % self.widget._off_color.name())
self._offColor = self.widget._off_color.name()
hbox.addWidget(button)
hbox.addWidget(self.falseColorButton)
self.colorFalse.setLayout(hbox)
layout.addWidget(self.colorFalse)
self.colorFalse.hide()
line = QtWidgets.QFrame()
line.setFrameShape(QtWidgets.QFrame.HLine)
line.setFrameShadow(QtWidgets.QFrame.Sunken)
layout.addWidget(line)
self.tab2.setLayout(layout)
def statusSelectionChanged(self, index):
choice = self.statusCombo.itemData(self.statusCombo.currentIndex(), QtCore.Qt.UserRole + 1)
if choice is None:
self.jnum.hide()
return
if choice == 'is_joint_homed' or 'is_spindle' in choice:
self.jnum.show()
else:
self.jnum.hide()
# Indicator Tab 3
def buildtab3(self):
layout = QtWidgets.QGridLayout()
# State Text option
self.textO = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('<b>State Changes Text Option<\b?')
self.textCheckBox = QtWidgets.QCheckBox()
self.textCheckBox.setChecked(self.widget._state_text)
self.textCheckBox.clicked.connect(self.onSetOptions)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.textCheckBox)
self.textO.setLayout(hbox)
layout.addWidget(self.textO)
# self.textO.hide()
# True text edit box
self.txtTrue = QtWidgets.QWidget()
vbox = QtWidgets.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('True State Text Line')
self.tTextEditBox = QtWidgets.QLineEdit()
self.tTextEditBox.setText(self.widget._true_string)
vbox.addWidget(label)
vbox.addWidget(self.tTextEditBox)
self.txtTrue.setLayout(vbox)
layout.addWidget(self.txtTrue)
self.txtTrue.hide()
# False text edit box
self.txtFalse = QtWidgets.QWidget()
vbox = QtWidgets.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('False State Text Line')
self.fTextEditBox = QtWidgets.QLineEdit()
self.fTextEditBox.setText(self.widget._false_string)
vbox.addWidget(label)
vbox.addWidget(self.fTextEditBox)
self.txtFalse.setLayout(vbox)
layout.addWidget(self.txtFalse)
self.txtFalse.hide()
# Python Command option
self.cmdPython = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('<b>State Calls Python Command<\b>')
self.pythonCheckBox = QtWidgets.QCheckBox()
self.pythonCheckBox.setChecked(self.widget._python_command)
self.pythonCheckBox.clicked.connect(self.onSetOptions)
hbox.addWidget(label)
hbox.addStretch(1)
hbox.addWidget(self.pythonCheckBox)
self.cmdPython.setLayout(hbox)
layout.addWidget(self.cmdPython)
# self.cmdPython.hide()
# True command edit box
self.cmdTrue = QtWidgets.QWidget()
vbox = QtWidgets.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('True State Command Line')
self.tCommandEditBox = QtWidgets.QLineEdit()
self.tCommandEditBox.setText(self.widget.true_python_command)
vbox.addWidget(label)
vbox.addWidget(self.tCommandEditBox)
self.cmdTrue.setLayout(vbox)
layout.addWidget(self.cmdTrue)
self.cmdTrue.hide()
# False command edit box
self.cmdFalse = QtWidgets.QWidget()
vbox = QtWidgets.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
label = QtWidgets.QLabel('False State Command Line')
self.fCommandEditBox = QtWidgets.QLineEdit()
self.fCommandEditBox.setText(self.widget.false_python_command)
vbox.addWidget(label)
vbox.addWidget(self.fCommandEditBox)
self.cmdFalse.setLayout(vbox)
layout.addWidget(self.cmdFalse)
self.cmdFalse.hide()
self.tab3.setLayout(layout)
def launchDialog(self, widget):
d = RichTextEditorDialog()
style = d.showDialog(pretext=widget.text())
if style:
self.defaultTextTemplateEditBox.setText(style)
widget.setText(style)
def onSetOptions(self):
if self.textTemplateCheckBox.isChecked():
self.vbox.show()
else:
self.vbox.hide()
# mutually exclusive options
if self.halCheckBox.isChecked() and self.statusCheckBox.isChecked():
if self.sender() == self.halCheckBox:
self.statusCheckBox.setChecked(False)
elif self.sender() == self.statusCheckBox:
self.halCheckBox.setChecked(False)
if self.statusCheckBox.isChecked():
self.watch.show()
self.invertStatus.show()
else:
self.watch.hide()
self.invertStatus.hide()
if self.indicatorCheckBox.isChecked():
self.halP.show()
self.colorTrue.show()
self.colorFalse.show()
self.statusO.show()
self.shape.show()
self.rightedgeoffset.show()
self.topedgeoffset.show()
shape = self.shapeCombo.itemData(self.shapeCombo.currentIndex())
if shape == 0:
self.size.show()
self.diam.hide()
self.radius.hide()
self.hfraction.hide()
self.wfraction.hide()
elif shape == 1:
self.diam.show()
self.size.hide()
self.radius.hide()
self.hfraction.hide()
self.wfraction.hide()
elif shape in (1, 2):
self.size.hide()
self.diam.hide()
self.radius.show()
self.hfraction.show()
self.wfraction.show()
choice = self.statusCombo.itemData(self.statusCombo.currentIndex(), QtCore.Qt.UserRole + 1)
if choice is not None:
if choice == 'is_joint_homed' or 'is_spindle' in choice:
self.jnum.show()
else:
self.jnum.hide()
else:
self.halP.hide()
self.size.hide()
self.colorTrue.hide()
self.colorFalse.hide()
self.statusO.hide()
self.diam.hide()
self.shape.hide()
self.watch.hide()
self.invertStatus.hide()
self.rightedgeoffset.hide()
self.topedgeoffset.hide()
if self.pythonCheckBox.isChecked():
self.cmdTrue.show()
self.cmdFalse.show()
else:
self.cmdTrue.hide()
self.cmdFalse.hide()
if self.textCheckBox.isChecked():
self.txtTrue.show()
self.txtFalse.show()
else:
self.txtTrue.hide()
self.txtFalse.hide()
self.adjustSize()
def on_trueColorClick(self):
color = QtWidgets.QColorDialog.getColor()
if color.isValid():
self._onColor = color.name()
self.trueColorButton.setStyleSheet('QPushButton {background-color: %s ;}' % self._onColor)
def on_falseColorClick(self):
color = QtWidgets.QColorDialog.getColor()
if color.isValid():
self._offColor = color.name()
self.falseColorButton.setStyleSheet('QPushButton {background-color: %s ;}' % self._offColor)
def updateWidget(self):
# check action-combobox last pick because it sometimes
# forgets what's selected. anyways...
winProperty = self.combo.getLastPick()
if winProperty is None:
winProperty = 'unused'
formWindow = QDesignerFormWindowInterface.findFormWindow(self.widget)
if formWindow:
# set widget option
formWindow.cursor().setProperty('indicator_option',
QtCore.QVariant(self.indicatorCheckBox.isChecked()))
formWindow.cursor().setProperty('python_command_option',
QtCore.QVariant(self.pythonCheckBox.isChecked()))
formWindow.cursor().setProperty('checked_state_text_option',
QtCore.QVariant(self.textCheckBox.isChecked()))
formWindow.cursor().setProperty('indicator_HAL_pin_option',
QtCore.QVariant(self.halCheckBox.isChecked()))
formWindow.cursor().setProperty('indicator_status_option',
QtCore.QVariant(self.statusCheckBox.isChecked()))
formWindow.cursor().setProperty('indicator_size',
QtCore.QVariant(self.floatSpinBox.value()))
formWindow.cursor().setProperty('right_edge_offset',
QtCore.QVariant(self.rightedgeoffsetSpinBox.value()))
formWindow.cursor().setProperty('top_edge_offset',
QtCore.QVariant(self.topedgeoffsetSpinBox.value()))
formWindow.cursor().setProperty('corner_radius',
QtCore.QVariant(self.radiusSpinBox.value()))
formWindow.cursor().setProperty('height_fraction',
QtCore.QVariant(self.hfractionSpinBox.value()))
formWindow.cursor().setProperty('width_fraction',
QtCore.QVariant(self.wfractionSpinBox.value()))
formWindow.cursor().setProperty('circle_diameter',
QtCore.QVariant(self.diamSpinBox.value()))
formWindow.cursor().setProperty('shape_option',
QtCore.QVariant(self.shapeCombo.itemData(
self.shapeCombo.currentIndex())))
formWindow.cursor().setProperty('joint_number_status',
QtCore.QVariant(self.jnumCombo.itemData(
self.jnumCombo.currentIndex())))
formWindow.cursor().setProperty('on_color',
QtCore.QVariant(self._onColor))
formWindow.cursor().setProperty('off_color',
QtCore.QVariant(self._offColor))
formWindow.cursor().setProperty('true_state_string',
QtCore.QVariant(self.tTextEditBox.text()))
formWindow.cursor().setProperty('false_state_string',
QtCore.QVariant(self.fTextEditBox.text()))
formWindow.cursor().setProperty('true_python_cmd_string',
QtCore.QVariant(self.tCommandEditBox.text()))
formWindow.cursor().setProperty('false_python_cmd_string',
QtCore.QVariant(self.fCommandEditBox.text()))
if formWindow and winProperty == 'unused':
formWindow.cursor().setProperty('estop_action',
QtCore.QVariant(True))
formWindow.cursor().setProperty('estop_action',
QtCore.QVariant(False))
elif formWindow:
# set widget option
formWindow.cursor().setProperty(winProperty + '_action',
QtCore.QVariant(True))
# set status data from combo box
# we read all data from combo and set each property to its
# current dialog state (ie. selected is true, all others false)
for i in range(1, self.statusCombo.count()):
data = self.statusCombo.itemData(i, QtCore.Qt.UserRole + 1)
propertyText = '{}_status'.format(data)
if self.statusCombo.itemData(self.statusCombo.currentIndex(), QtCore.Qt.UserRole + 1) == data:
state = True
else:
state = False
formWindow.cursor().setProperty(propertyText,
QtCore.QVariant(state))
formWindow.cursor().setProperty('invert_the_status',
QtCore.QVariant(self.invertCheckBox.isChecked()))
#####################
# set related data
#####################
formWindow.cursor().setProperty('joint_number',
QtCore.QVariant(self.JNumSpinBox.value()))
formWindow.cursor().setProperty('incr_imperial_number',
QtCore.QVariant(self.jogIncImpSpinBox.value()))
formWindow.cursor().setProperty('incr_mm_number',
QtCore.QVariant(self.jogIncMMSpinBox.value()))
formWindow.cursor().setProperty('incr_angular_number',
QtCore.QVariant(self.jogIncAngSpinBox.value()))
formWindow.cursor().setProperty('float_num',
QtCore.QVariant(self.floatSpinBox.value()))
formWindow.cursor().setProperty('float_alt_num',
QtCore.QVariant(self.floatAltSpinBox.value()))
formWindow.cursor().setProperty('view_type_string',
QtCore.QVariant(self.viewComboBox.currentText()))
formWindow.cursor().setProperty('toggle_float_option',
QtCore.QVariant(self.toggleCheckBox.isChecked()))
formWindow.cursor().setProperty('command_text_string',
QtCore.QVariant(self.commandEditBox.text()))
formWindow.cursor().setProperty('ini_mdi_number',
QtCore.QVariant(self.MDISpinBox.value()))
formWindow.cursor().setProperty('template_label_option',
QtCore.QVariant(self.textTemplateCheckBox.isChecked()))
# block signal so button text doesn't change when selecting action
self.widget._designer_block_signal = True
formWindow.cursor().setProperty('text',
QtCore.QVariant(self.defaultTextTemplateEditBox.text()))
formWindow.cursor().setProperty('textTemplate',
QtCore.QVariant(self.textTemplateEditBox.text()))
formWindow.cursor().setProperty('alt_textTemplate',
QtCore.QVariant(self.altTextTemplateEditBox.text()))
self.widget._designer_block_signal = False
self.accept()
##############################
# required class boiler code #
##############################
def __getitem__(self, item):
return getattr(self, item)
def __setitem__(self, item, value):
return setattr(self, item, value)
class ActionButtonMenuEntry(QPyDesignerTaskMenuExtension):
def __init__(self, widget, parent):
super(QPyDesignerTaskMenuExtension, self).__init__(parent)
self.widget = widget
self.editStateAction = QtWidgets.QAction(
self.tr("Set Actions"), self)
self.editStateAction.triggered.connect(self.updateOptions)
def preferredEditAction(self):
return self.editStateAction
def taskActions(self):
return [self.editStateAction]
def updateOptions(self):
dialog = ActionButtonDialog(self.widget)
dialog.exec_()
class ActionButtonTaskMenuFactory(QExtensionFactory):
def __init__(self, parent=None):
QExtensionFactory.__init__(self, parent)
def createExtension(self, obj, iid, parent):
if not isinstance(obj, ActionButton):
return None
if iid == Q_TYPEID['QDesignerTaskMenuExtension']:
return ActionButtonMenuEntry(obj, parent)
return None
####################################
# RoundButton
####################################
class RoundButtonPlugin(QPyDesignerCustomWidgetPlugin):
def __init__(self, parent=None):
super(RoundButtonPlugin, self).__init__(parent)
self.initialized = False
def initialize(self, formEditor):
if self.initialized:
return
manager = formEditor.extensionManager()
if manager:
self.factory = ActionButtonTaskMenuFactory(manager)
manager.registerExtensions(self.factory, Q_TYPEID['QDesignerTaskMenuExtension'])
self.initialized = True
def isInitialized(self):
return self.initialized
def createWidget(self, parent):
return RoundButton(parent)
def name(self):
return "RoundButton"
def group(self):
return "Linuxcnc - Controller"
def icon(self):
return QtGui.QIcon(QtGui.QPixmap(ICON.get_path('roundbutton')))
def toolTip(self):
return "Round shaped Button for actions"
def whatsThis(self):
return ""
def isContainer(self):
return False
def domXml(self):
return '<widget class="RoundButton" name="Roundbutton" />\n'
def includeFile(self):
return "qtvcp.widgets.action_button_round"
|