|
1 | 1 | import os, time |
2 | 2 | from PyQt5 import QtCore, QtWidgets, QtGui |
| 3 | +from PyQt5.QtWidgets import QAction, QMenu |
| 4 | +from PyQt5.QtGui import QIcon |
3 | 5 | from PyQt5.QtCore import QCoreApplication |
4 | 6 | from qtvcp.widgets.gcode_editor import GcodeEditor as GCODE |
5 | 7 | from qtvcp.widgets.gcode_graphics import GCodeGraphics as GRAPHICS |
@@ -287,24 +289,7 @@ def initialized__(self): |
287 | 289 | self.w.layout_PDF.addWidget(self.PDFView) |
288 | 290 | self.PDFView.loadSample('setup_tab') |
289 | 291 |
|
290 | | - # Show assigned macrobuttons define in INI under [MDI_COMMAND_LIST] |
291 | | - flag = True |
292 | | - for b in range(0,10): |
293 | | - button = self.w['macrobutton{}'.format(b)] |
294 | | - # prefer named INI MDI commands |
295 | | - key = button.property('ini_mdi_key') |
296 | | - if key == '' or INFO.get_ini_mdi_command(key) is None: |
297 | | - # fallback to legacy nth line |
298 | | - key = button.property('ini_mdi_number') |
299 | | - try: |
300 | | - code = INFO.get_ini_mdi_command(key) |
301 | | - if code is None: raise Exception |
302 | | - flag = False |
303 | | - except: |
304 | | - button.hide() |
305 | | - # no buttons hide frame |
306 | | - if flag: |
307 | | - self.w.frame_macro_buttons.hide() |
| 292 | + self.configureMacroButtons() |
308 | 293 |
|
309 | 294 | self.log_version() |
310 | 295 |
|
@@ -2086,6 +2071,67 @@ def request_macro_call(self, data): |
2086 | 2071 | self.add_status(_translate("HandlerClass",'Running macro: {} {}\n{}'.format(key, text, e))) |
2087 | 2072 | break |
2088 | 2073 |
|
| 2074 | + # show/hide macro buttons depending on the INI definitions |
| 2075 | + def configureMacroButtons(self): |
| 2076 | + # Show assigned macrobuttons define in INI under [MDI_COMMAND_LIST] |
| 2077 | + flag = True |
| 2078 | + for b in range(0,10): |
| 2079 | + button = self.w['macrobutton{}'.format(b)] |
| 2080 | + # prefer named INI MDI commands |
| 2081 | + key = button.property('ini_mdi_key') |
| 2082 | + if key == '' or INFO.get_ini_mdi_command(key) is None: |
| 2083 | + # fallback to legacy nth line |
| 2084 | + key = button.property('ini_mdi_number') |
| 2085 | + try: |
| 2086 | + code = INFO.get_ini_mdi_command(key) |
| 2087 | + if code is None: raise Exception |
| 2088 | + flag = False |
| 2089 | + except: |
| 2090 | + button.hide() |
| 2091 | + # no buttons hide frame |
| 2092 | + if flag: |
| 2093 | + self.w.frame_macro_buttons.hide() |
| 2094 | + |
| 2095 | + # if there are more then 10 add a menu to the last button for selection |
| 2096 | + if len(INFO.MDI_COMMAND_DICT)>10: |
| 2097 | + button.setText('MORE\nMACROS') |
| 2098 | + button.setProperty('ini_mdi_command_action', False) |
| 2099 | + button.setProperty('no_action', True) |
| 2100 | + button.setToolTip('') |
| 2101 | + SettingMenu = QMenu(button) |
| 2102 | + button.setMenu(SettingMenu) |
| 2103 | + for i in range(0,len(INFO.MDI_COMMAND_DICT)-10): |
| 2104 | + try: |
| 2105 | + name = 'MACRO{}'.format(i+10) |
| 2106 | + label = INFO.MDI_COMMAND_DICT[name]['label'] |
| 2107 | + except: |
| 2108 | + label = INFO.MDI_COMMAND_LABEL_LIST[i+10] |
| 2109 | + |
| 2110 | + action = QAction(QIcon.fromTheme('application-exit'), label.replace("\\n"," "), button) |
| 2111 | + action.triggered.connect(lambda s, i=i, b=button : self.midiAction(b, i+10)) |
| 2112 | + # tooltips don't work on Qmenu items unless in toolbar |
| 2113 | + #tooltiplabel = 'INI MDI CMD {}:\n'.format(name) |
| 2114 | + #tooltiplabel += INFO.get_ini_mdi_command(key).replace(';', '\n') |
| 2115 | + #action.setToolTip(tooltiplabel) |
| 2116 | + |
| 2117 | + SettingMenu.addAction(action) |
| 2118 | + |
| 2119 | + # use the button to run macros selected from the buttons menu |
| 2120 | + def midiAction(self, button, num): |
| 2121 | + name = 'MACRO{}'.format(num) |
| 2122 | + try: |
| 2123 | + code = INFO.MDI_COMMAND_DICT[name]['cmd'] |
| 2124 | + button.setProperty('ini_mdi_key', name) |
| 2125 | + except: |
| 2126 | + code = INFO.MDI_COMMAND_LIST[num] |
| 2127 | + button.setProperty('ini_mdi_key', '') |
| 2128 | + button.setProperty('ini_mdi_number', num) |
| 2129 | + print('number',num,button.ini_mdi_num) |
| 2130 | + button.setProperty('ini_mdi_command_action', True) |
| 2131 | + |
| 2132 | + button.pressed.emit() |
| 2133 | + button.setProperty('ini_mdi_command_action', False) |
| 2134 | + |
2089 | 2135 | ##################### |
2090 | 2136 | # KEY BINDING CALLS # |
2091 | 2137 | ##################### |
|
0 commit comments