Skip to content

Commit

Permalink
adds Artisan Command visible(i,b) to change visibility of button …
Browse files Browse the repository at this point in the history
…`i` to `b` which has to be an expression which evaluates to a boolean, like 0, 1, false, true, ... (Issue #1301)
  • Loading branch information
MAKOMO committed Nov 17, 2023
1 parent 8e9e584 commit 9ac54b5
Show file tree
Hide file tree
Showing 36 changed files with 30,279 additions and 29,973 deletions.
Binary file modified doc/help_dialogs/Input_files/eventbuttons.xlsx
Binary file not shown.
7 changes: 6 additions & 1 deletion doc/help_dialogs/Output_html/eventbuttons_help.html
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@
<tr>
<td>&#160;</td>
<td>button(i,b)</td>
<td>sets button i to pressed if value b is yes, true, t, or 1, otherwise to normal</td>
<td>sets button i to pressed if value of b is yes, true, t, or 1, otherwise to normal</td>
</tr>
<tr>
<td>&#160;</td>
Expand All @@ -788,6 +788,11 @@
<td>button()</td>
<td>toggles the state of the button</td>
</tr>
<tr>
<td>&#160;</td>
<td>visible(i,b)</td>
<td>sets button i to visible if value of b is yes, true, t, or 1, otherwise to hidden</td>
</tr>
<tr>
<td>&#160;</td>
<td>palette(&lt;p&gt;)</td>
Expand Down
2 changes: 1 addition & 1 deletion src/artisanlib/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2663,9 +2663,9 @@ def savetableextraeventbutton(self):
self.aw.extraeventbuttontextcolor[visualIndex] = self.extraeventbuttontextcolor[i]

#Apply Event Button Changes
self.aw.update_extraeventbuttons_visibility()
self.aw.realignbuttons()
self.aw.settooltip() # has to be done after realignbuttons() to have set the aw.buttonlist correctly!
self.aw.update_extraeventbuttons_visibility()

@pyqtSlot()
def setlabeleventbutton(self):
Expand Down
29 changes: 29 additions & 0 deletions src/artisanlib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,8 @@ class ApplicationWindow(QMainWindow): # pyright: ignore [reportGeneralTypeIssue
updateSerialLogSignal = pyqtSignal()
updateErrorLogSignal = pyqtSignal()
establishQuantifiedEventSignal = pyqtSignal(int,float)
updateExtraEventButtonsVisibilitySignal = pyqtSignal()
realignButtonsSignal = pyqtSignal()

__slots__ = [ 'locale_str', 'app', 'superusermode', 'sample_loop_running', 'time_stopped', 'plus_account', 'plus_remember_credentials', 'plus_email', 'plus_language', 'plus_subscription',
'plus_paidUntil', 'plus_rlimit', 'plus_used', 'plus_readonly', 'appearance', 'mpl_fontproperties', 'full_screen_mode_active', 'processingKeyEvent', 'quickEventShortCut',
Expand Down Expand Up @@ -3955,6 +3957,8 @@ def __init__(self, parent:Optional[QWidget] = None, *, locale:str, WebEngineSupp
self.updateSerialLogSignal.connect(self.updateSerialLog)
self.updateErrorLogSignal.connect(self.updateErrorLog)
self.establishQuantifiedEventSignal.connect(self.establishQuantifiedEventSlot)
self.updateExtraEventButtonsVisibilitySignal.connect(self.update_extraeventbuttons_visibility)
self.realignButtonsSignal.connect(self.realignbuttons)

self.notificationManager:Optional[NotificationManager] = None
if not self.app.artisanviewerMode:
Expand Down Expand Up @@ -9281,6 +9285,29 @@ def eventaction_internal(self, action:int, cmd:str, eventtype:Optional[int]) ->
self.sendmessage(f'Artisan Command: {cs}')
except Exception as e: # pylint: disable=broad-except
_log.exception(e)

## visible(<i>,<b>) : sets the visibility of <button> visible
# (visibility=ON) if value b is yes, true, t, or 1, otherwise to hidden (visibility=OFF)
elif cs.startswith('visible'):
try:
cs_aac = eval(cs[len('visible'):]) # pylint: disable=eval-used
except Exception: # pylint: disable=broad-except
arg = cs[len('visible('):-1]
if ',' in arg and '(' not in arg:
# no function definition in arg, and exactly on comma, we split into the two args (could be just "button(1,false)" which does not eval above)
cs_aac = [a.strip() for a in arg.split(',')]
else:
cs_aac = [c[len('button('):-1].strip()]
if isinstance(cs_aac, (list, tuple)):
cs_len = len(cs_aac)
if cs_len == 2:
ci = max(0, toInt(cs_aac[0]) - 1)
vb = toBool(cs_aac[1])
if len(self.extraeventsvisibility) > ci:
self.extraeventsvisibility[ci] = (1 if vb else 0)
self.updateExtraEventButtonsVisibilitySignal.emit()
self.realignButtonsSignal.emit()

# button(<e>) with <e> one of { ON, START, CHARGE, DRY, FCs, FCe, SCs, SCe, DROP, COOL, OFF }
elif cs.startswith('button(') and cs.endswith(')'):
try:
Expand Down Expand Up @@ -23917,6 +23944,7 @@ def substButtonLabel(self, buttonNr:int, label:str, eventtype:int) -> str:


#orders extra event buttons based on max number of buttons
@pyqtSlot()
def realignbuttons(self):
#clear buttons
self.clearBoxLayout(self.e1buttonbarLayout)
Expand Down Expand Up @@ -24050,6 +24078,7 @@ def settooltip(self):
else:
bl.setToolTip('')

@pyqtSlot()
def update_extraeventbuttons_visibility(self):
for i, bl in enumerate(self.buttonlist):
try:
Expand Down
3 changes: 2 additions & 1 deletion src/help/eventbuttons_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ def content():
tbl_Commands.add_row(['&#160;','notify(<title>,[<msg>])',QApplication.translate('HelpDlg','sends notification with title <title> and optional message <msg>')])
tbl_Commands.add_row(['&#160;','setCanvasColor(<color>)',QApplication.translate('HelpDlg','sets canvas color to the RGB-hex <color> like #27f1d3')])
tbl_Commands.add_row(['&#160;','resetCanvasColor',QApplication.translate('HelpDlg','resets canvas color')])
tbl_Commands.add_row(['&#160;','button(i,b)',QApplication.translate('HelpDlg','sets button i to pressed if value b is yes, true, t, or 1, otherwise to normal')])
tbl_Commands.add_row(['&#160;','button(i,b)',QApplication.translate('HelpDlg','sets button i to pressed if value of b is yes, true, t, or 1, otherwise to normal')])
tbl_Commands.add_row(['&#160;','button(<name>|<bool>)',QApplication.translate('HelpDlg','activates button <name> from { START, CHARGE, DRY, FCs, FCe, SCs, SCe, DROP, COOL, OFF } ; sets calling button to “pressed” if argument is 1 or True')])
tbl_Commands.add_row(['&#160;','button()',QApplication.translate('HelpDlg','toggles the state of the button')])
tbl_Commands.add_row(['&#160;','visible(i,b)',QApplication.translate('HelpDlg','sets button i to visible if value of b is yes, true, t, or 1, otherwise to hidden')])
tbl_Commands.add_row(['&#160;','palette(<p>)',QApplication.translate('HelpDlg','activates palette <p> with <p> either a number 0-9 or a palette label')])
tbl_Commands.add_row(['&#160;','playbackmode(<int>)',QApplication.translate('HelpDlg','sets playback mode to 0: off, 1: time, 2: BT, 3: ET')])
tbl_Commands.add_row(['&#160;','openProperties',QApplication.translate('HelpDlg','opens the Roast Properties dialog')])
Expand Down
Loading

0 comments on commit 9ac54b5

Please sign in to comment.