jp: jp asyncio port:
/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\ This patch implements the port of jp to asyncio, so it is now correctly using the bridge asynchronously, and it can be used with bridges like `pb`. This also simplify the code, notably for things which were previously implemented with many callbacks (like pagination with RSM). During the process, some behaviours have been modified/fixed, in jp and backends, check diff for details.
This commit is contained in:
parent
5cee4fbab7
commit
76aadbb3fb
1 changed files with 3299 additions and 3300 deletions
|
|
@ -925,6 +925,67 @@ class XMLUIPanel(XMLUIBase):
|
|||
pass
|
||||
|
||||
|
||||
class AIOXMLUIPanel(XMLUIPanel):
|
||||
"""Asyncio compatible version of XMLUIPanel"""
|
||||
|
||||
async def onFormSubmitted(self, ignore=None):
|
||||
"""An XMLUI form has been submited
|
||||
|
||||
call the submit action associated with this form
|
||||
"""
|
||||
selected_values = []
|
||||
for ctrl_name in self.ctrl_list:
|
||||
escaped = self.escape(ctrl_name)
|
||||
ctrl = self.ctrl_list[ctrl_name]
|
||||
if isinstance(ctrl["control"], ListWidget):
|
||||
selected_values.append(
|
||||
(escaped, "\t".join(ctrl["control"]._xmluiGetSelectedValues()))
|
||||
)
|
||||
else:
|
||||
selected_values.append((escaped, ctrl["control"]._xmluiGetValue()))
|
||||
data = dict(selected_values)
|
||||
for key, value in self.hidden.items():
|
||||
data[self.escape(key)] = value
|
||||
|
||||
if self.submit_id is not None:
|
||||
await self.submit(data)
|
||||
else:
|
||||
log.warning(
|
||||
_("The form data is not sent back, the type is not managed properly")
|
||||
)
|
||||
self._xmluiClose()
|
||||
|
||||
async def onFormCancelled(self, *__):
|
||||
"""Called when a form is cancelled"""
|
||||
log.debug(_("Cancelling form"))
|
||||
if self.submit_id is not None:
|
||||
data = {C.XMLUI_DATA_CANCELLED: C.BOOL_TRUE}
|
||||
await self.submit(data)
|
||||
else:
|
||||
log.warning(
|
||||
_("The form data is not sent back, the type is not managed properly")
|
||||
)
|
||||
self._xmluiClose()
|
||||
|
||||
async def submit(self, data):
|
||||
self._xmluiClose()
|
||||
if self.submit_id is None:
|
||||
raise ValueError("Can't submit is self.submit_id is not set")
|
||||
if "session_id" in data:
|
||||
raise ValueError(
|
||||
"session_id must no be used in data, it is automaticaly filled with "
|
||||
"self.session_id if present"
|
||||
)
|
||||
if self.session_id is not None:
|
||||
data["session_id"] = self.session_id
|
||||
await self._xmluiLaunchAction(self.submit_id, data)
|
||||
|
||||
async def _xmluiLaunchAction(self, action_id, data):
|
||||
await self.host.launchAction(
|
||||
action_id, data, callback=self.callback, profile=self.profile
|
||||
)
|
||||
|
||||
|
||||
class XMLUIDialog(XMLUIBase):
|
||||
dialog_factory = None
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue