Skip to content

Commit

Permalink
qtvcp -dialog_widget: allow lcncDialog/Calculator dialog to be answer…
Browse files Browse the repository at this point in the history
…ed through STATUS

So that a screen could answer the dialog through HAL pins or external controls
  • Loading branch information
c-morley committed Oct 11, 2024
1 parent 9f4ab52 commit 18d4dbc
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions lib/python/qtvcp/widgets/dialog_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ def __init__(self, parent=None):
self._geoName = 'LncMessage-geometry'
self.set_default_geometry()
self.hide()
self.buttonClicked.connect(self.msgbtn)
self.buttonClicked.connect(self.btn_callback)

def _hal_init(self):
self.read_preference_geometry(self._geoName)
STATUS.connect('dialog-request', self._external_request)
STATUS.connect('dialog-update', self._external_update)

# this processes STATUS called dialog requests
# We check the cmd to see if it was for us
Expand Down Expand Up @@ -285,7 +286,7 @@ def showEvent(self, event):
super(LcncDialog, self).showEvent(event)


def msgbtn(self, i):
def btn_callback(self, i):
LOG.debug('Button pressed is: {}'.format(i.text()))

# update the dialog position
Expand All @@ -299,7 +300,9 @@ def msgbtn(self, i):
btn = self.standardButton(self.clickedButton())
result = self.qualifiedReturn(btn)
LOG.debug('Value of {} pressed button: {}'.format(self, result))
self.process_result(result)

def process_result(self, result):
# these directly call a function with btn info
if not self._return_callback is None:
self._return_callback(self, result)
Expand Down Expand Up @@ -327,6 +330,23 @@ def setGeometry(self,*args):
else:
self.findChild(QLabel, "qt_msgbox_label").setFixedWidth(350)

# callback from status 'update-dialog'
def _external_update(self, w, message):
if message.get('NAME') == self._request_name:
if not self.isVisible(): return

response = message.get('response')
if not response is None:
LOG.debug('Response is: {}'.format(response))
# update the dialog position
self.record_geometry()
self.hide()

if response == 0:
self.process_result(False)
elif response == 1:
self.process_result(True)

# **********************
# Designer properties
# **********************
Expand Down Expand Up @@ -1571,6 +1591,7 @@ def _hal_init(self):
else:
self.play_sound = False
STATUS.connect('dialog-request', self._external_request)
STATUS.connect('dialog-update', self._external_update)

# this processes STATUS called dialog requests
# We check the cmd to see if it was for us
Expand Down Expand Up @@ -1606,6 +1627,18 @@ def _external_request(self, w, message):
else:
num = self.showdialog(preload=preload, overlay=overlay, cycle=cycle)

# callback from status 'update-dialog'
def _external_update(self, w, message):
if message.get('NAME') == self._request_name:
if not self.isVisible(): return

response = message.get('response')
if not response is None:
if response == 0:
self.reject()
elif response == 1:
self.accept()

def updatedialog(self, preload=None):
self.setWindowTitle(self._title);
if self.play_sound:
Expand Down

0 comments on commit 18d4dbc

Please sign in to comment.