comparison sat_frontends/tools/xmlui.py @ 3040:fee60f17ebac

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.
author Goffi <goffi@goffi.org>
date Wed, 25 Sep 2019 08:56:41 +0200
parents ab2696e34d29
children 9d0df638c8b4
comparison
equal deleted inserted replaced
3039:a1bc34f90fa5 3040:fee60f17ebac
921 921
922 self._xmluiClose() 922 self._xmluiClose()
923 923
924 def show(self, *args, **kwargs): 924 def show(self, *args, **kwargs):
925 pass 925 pass
926
927
928 class AIOXMLUIPanel(XMLUIPanel):
929 """Asyncio compatible version of XMLUIPanel"""
930
931 async def onFormSubmitted(self, ignore=None):
932 """An XMLUI form has been submited
933
934 call the submit action associated with this form
935 """
936 selected_values = []
937 for ctrl_name in self.ctrl_list:
938 escaped = self.escape(ctrl_name)
939 ctrl = self.ctrl_list[ctrl_name]
940 if isinstance(ctrl["control"], ListWidget):
941 selected_values.append(
942 (escaped, "\t".join(ctrl["control"]._xmluiGetSelectedValues()))
943 )
944 else:
945 selected_values.append((escaped, ctrl["control"]._xmluiGetValue()))
946 data = dict(selected_values)
947 for key, value in self.hidden.items():
948 data[self.escape(key)] = value
949
950 if self.submit_id is not None:
951 await self.submit(data)
952 else:
953 log.warning(
954 _("The form data is not sent back, the type is not managed properly")
955 )
956 self._xmluiClose()
957
958 async def onFormCancelled(self, *__):
959 """Called when a form is cancelled"""
960 log.debug(_("Cancelling form"))
961 if self.submit_id is not None:
962 data = {C.XMLUI_DATA_CANCELLED: C.BOOL_TRUE}
963 await self.submit(data)
964 else:
965 log.warning(
966 _("The form data is not sent back, the type is not managed properly")
967 )
968 self._xmluiClose()
969
970 async def submit(self, data):
971 self._xmluiClose()
972 if self.submit_id is None:
973 raise ValueError("Can't submit is self.submit_id is not set")
974 if "session_id" in data:
975 raise ValueError(
976 "session_id must no be used in data, it is automaticaly filled with "
977 "self.session_id if present"
978 )
979 if self.session_id is not None:
980 data["session_id"] = self.session_id
981 await self._xmluiLaunchAction(self.submit_id, data)
982
983 async def _xmluiLaunchAction(self, action_id, data):
984 await self.host.launchAction(
985 action_id, data, callback=self.callback, profile=self.profile
986 )
926 987
927 988
928 class XMLUIDialog(XMLUIBase): 989 class XMLUIDialog(XMLUIBase):
929 dialog_factory = None 990 dialog_factory = None
930 991