Skip to content

Commit 8875bc9

Browse files
committed
qtdragon/hd/hd_vert/lathe -add button menu for more then 10 macros
if there are mpre then 10 INI macros, a menu will be displayed on the last button for selecting more macros
1 parent 023fa5d commit 8875bc9

4 files changed

Lines changed: 255 additions & 72 deletions

File tree

share/qtvcp/screens/qtdragon/qtdragon_handler.py

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os, time
22
from PyQt5 import QtCore, QtWidgets, QtGui
3+
from PyQt5.QtWidgets import QAction, QMenu
4+
from PyQt5.QtGui import QIcon
35
from PyQt5.QtCore import QCoreApplication
46
from qtvcp.widgets.gcode_editor import GcodeEditor as GCODE
57
from qtvcp.widgets.gcode_graphics import GCodeGraphics as GRAPHICS
@@ -287,24 +289,7 @@ def initialized__(self):
287289
self.w.layout_PDF.addWidget(self.PDFView)
288290
self.PDFView.loadSample('setup_tab')
289291

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()
308293

309294
self.log_version()
310295

@@ -2086,6 +2071,67 @@ def request_macro_call(self, data):
20862071
self.add_status(_translate("HandlerClass",'Running macro: {} {}\n{}'.format(key, text, e)))
20872072
break
20882073

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+
20892135
#####################
20902136
# KEY BINDING CALLS #
20912137
#####################

share/qtvcp/screens/qtdragon_hd/qtdragon_hd_handler.py

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os, time
22
from PyQt5 import QtCore, QtWidgets, QtGui
3+
from PyQt5.QtWidgets import QAction, QMenu
4+
from PyQt5.QtGui import QIcon
35
from PyQt5.QtCore import QCoreApplication
46
from qtvcp.widgets.gcode_editor import GcodeEditor as GCODE
57
from qtvcp.widgets.gcode_graphics import GCodeGraphics as GRAPHICS
@@ -238,24 +240,7 @@ def initialized__(self):
238240

239241
self.w.setWindowFlags(QtCore.Qt.FramelessWindowHint)
240242

241-
# Show assigned macrobuttons define in INI under [MDI_COMMAND_LIST]
242-
flag = True
243-
for b in range(0,10):
244-
button = self.w['macrobutton{}'.format(b)]
245-
# prefer named INI MDI commands
246-
key = button.property('ini_mdi_key')
247-
if key == '' or INFO.get_ini_mdi_command(key) is None:
248-
# fallback to legacy nth line
249-
key = button.property('ini_mdi_number')
250-
try:
251-
code = INFO.get_ini_mdi_command(key)
252-
if code is None: raise Exception
253-
flag = False
254-
except:
255-
button.hide()
256-
# no buttons hide frame
257-
if flag:
258-
self.w.frame_macro_buttons.hide()
243+
self.configureMacroButtons()
259244

260245
self.log_version()
261246

@@ -2057,6 +2042,66 @@ def log_version(self):
20572042
self.add_status(mess, CRITICAL,noLog=True)
20582043
STATUS.emit('update-machine-log', mess, None)
20592044

2045+
# show/hide macro buttons depending on the INI definitions
2046+
def configureMacroButtons(self):
2047+
# Show assigned macrobuttons define in INI under [MDI_COMMAND_LIST]
2048+
flag = True
2049+
for b in range(0,10):
2050+
button = self.w['macrobutton{}'.format(b)]
2051+
# prefer named INI MDI commands
2052+
key = button.property('ini_mdi_key')
2053+
if key == '' or INFO.get_ini_mdi_command(key) is None:
2054+
# fallback to legacy nth line
2055+
key = button.property('ini_mdi_number')
2056+
try:
2057+
code = INFO.get_ini_mdi_command(key)
2058+
if code is None: raise Exception
2059+
flag = False
2060+
except:
2061+
button.hide()
2062+
# no buttons hide frame
2063+
if flag:
2064+
self.w.frame_macro_buttons.hide()
2065+
# if there are more then 10 add a menu to the last button for selection
2066+
if len(INFO.MDI_COMMAND_DICT)>10:
2067+
button.setText('MORE\nMACROS')
2068+
button.setProperty('ini_mdi_command_action', False)
2069+
button.setProperty('no_action', True)
2070+
button.setToolTip('')
2071+
SettingMenu = QMenu(button)
2072+
button.setMenu(SettingMenu)
2073+
for i in range(0,len(INFO.MDI_COMMAND_DICT)-10):
2074+
try:
2075+
name = 'MACRO{}'.format(i+10)
2076+
label = INFO.MDI_COMMAND_DICT[name]['label']
2077+
except:
2078+
label = INFO.MDI_COMMAND_LABEL_LIST[i+10]
2079+
2080+
action = QAction(QIcon.fromTheme('application-exit'), label.replace("\\n"," "), button)
2081+
action.triggered.connect(lambda s, i=i, b=button : self.midiAction(b, i+10))
2082+
# tooltips don't work on Qmenu items unless in toolbar
2083+
#tooltiplabel = 'INI MDI CMD {}:\n'.format(name)
2084+
#tooltiplabel += INFO.get_ini_mdi_command(key).replace(';', '\n')
2085+
#action.setToolTip(tooltiplabel)
2086+
2087+
SettingMenu.addAction(action)
2088+
2089+
# use the button to run macros selected from the buttons menu
2090+
def midiAction(self, button, num):
2091+
name = 'MACRO{}'.format(num)
2092+
try:
2093+
code = INFO.MDI_COMMAND_DICT[name]['cmd']
2094+
button.setProperty('ini_mdi_key', name)
2095+
except:
2096+
code = INFO.MDI_COMMAND_LIST[num]
2097+
button.setProperty('ini_mdi_key', '')
2098+
button.setProperty('ini_mdi_number', num)
2099+
print('number',num,button.ini_mdi_num)
2100+
button.setProperty('ini_mdi_command_action', True)
2101+
2102+
button.pressed.emit()
2103+
button.setProperty('ini_mdi_command_action', False)
2104+
20602105
#####################
20612106
# KEY BINDING CALLS #
20622107
#####################

share/qtvcp/screens/qtdragon_hd_vert/qtdragon_hd_vert_handler.py

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os, time
22
from PyQt5 import QtCore, QtWidgets, QtGui
3+
from PyQt5.QtWidgets import QAction, QMenu
4+
from PyQt5.QtGui import QIcon
35
from PyQt5.QtCore import QCoreApplication
46
from qtvcp.widgets.gcode_editor import GcodeEditor as GCODE
57
from qtvcp.widgets.gcode_graphics import GCodeGraphics as GRAPHICS
@@ -238,24 +240,7 @@ def initialized__(self):
238240

239241
self.w.setWindowFlags(QtCore.Qt.FramelessWindowHint)
240242

241-
# Show assigned macrobuttons define in INI under [MDI_COMMAND_LIST]
242-
flag = True
243-
for b in range(0,10):
244-
button = self.w['macrobutton{}'.format(b)]
245-
# prefer named INI MDI commands
246-
key = button.property('ini_mdi_key')
247-
if key == '' or INFO.get_ini_mdi_command(key) is None:
248-
# fallback to legacy nth line
249-
key = button.property('ini_mdi_number')
250-
try:
251-
code = INFO.get_ini_mdi_command(key)
252-
if code is None: raise Exception
253-
flag = False
254-
except:
255-
button.hide()
256-
# no buttons hide frame
257-
if flag:
258-
self.w.frame_macro_buttons.hide()
243+
self.configureMacroButtons()
259244

260245
self.log_version()
261246

@@ -2057,6 +2042,67 @@ def log_version(self):
20572042
self.add_status(mess, CRITICAL,noLog=True)
20582043
STATUS.emit('update-machine-log', mess, None)
20592044

2045+
# show/hide macro buttons depending on the INI definitions
2046+
def configureMacroButtons(self):
2047+
# Show assigned macrobuttons define in INI under [MDI_COMMAND_LIST]
2048+
flag = True
2049+
for b in range(0,10):
2050+
button = self.w['macrobutton{}'.format(b)]
2051+
# prefer named INI MDI commands
2052+
key = button.property('ini_mdi_key')
2053+
if key == '' or INFO.get_ini_mdi_command(key) is None:
2054+
# fallback to legacy nth line
2055+
key = button.property('ini_mdi_number')
2056+
try:
2057+
code = INFO.get_ini_mdi_command(key)
2058+
if code is None: raise Exception
2059+
flag = False
2060+
except:
2061+
button.hide()
2062+
# no buttons hide frame
2063+
if flag:
2064+
self.w.frame_macro_buttons.hide()
2065+
2066+
# if there are more then 10 add a menu to the last button for selection
2067+
if len(INFO.MDI_COMMAND_DICT)>10:
2068+
button.setText('MORE\nMACROS')
2069+
button.setProperty('ini_mdi_command_action', False)
2070+
button.setProperty('no_action', True)
2071+
button.setToolTip('')
2072+
SettingMenu = QMenu(button)
2073+
button.setMenu(SettingMenu)
2074+
for i in range(0,len(INFO.MDI_COMMAND_DICT)-10):
2075+
try:
2076+
name = 'MACRO{}'.format(i+10)
2077+
label = INFO.MDI_COMMAND_DICT[name]['label']
2078+
except:
2079+
label = INFO.MDI_COMMAND_LABEL_LIST[i+10]
2080+
2081+
action = QAction(QIcon.fromTheme('application-exit'), label.replace("\\n"," "), button)
2082+
action.triggered.connect(lambda s, i=i, b=button : self.midiAction(b, i+10))
2083+
# tooltips don't work on Qmenu items unless in toolbar
2084+
#tooltiplabel = 'INI MDI CMD {}:\n'.format(name)
2085+
#tooltiplabel += INFO.get_ini_mdi_command(key).replace(';', '\n')
2086+
#action.setToolTip(tooltiplabel)
2087+
2088+
SettingMenu.addAction(action)
2089+
2090+
# use the button to run macros selected from the buttons menu
2091+
def midiAction(self, button, num):
2092+
name = 'MACRO{}'.format(num)
2093+
try:
2094+
code = INFO.MDI_COMMAND_DICT[name]['cmd']
2095+
button.setProperty('ini_mdi_key', name)
2096+
except:
2097+
code = INFO.MDI_COMMAND_LIST[num]
2098+
button.setProperty('ini_mdi_key', '')
2099+
button.setProperty('ini_mdi_number', num)
2100+
print('number',num,button.ini_mdi_num)
2101+
button.setProperty('ini_mdi_command_action', True)
2102+
2103+
button.pressed.emit()
2104+
button.setProperty('ini_mdi_command_action', False)
2105+
20602106
#####################
20612107
# KEY BINDING CALLS #
20622108
#####################

0 commit comments

Comments
 (0)