massive refactoring to switch from camelCase to snake_case:

historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.

However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.

To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.

This is a massive change, and may result in some bugs.
This commit is contained in:
Goffi 2023-04-08 13:54:42 +02:00
commit 6a6f15707a
6 changed files with 9945 additions and 9945 deletions

View file

@ -31,7 +31,7 @@ def addListener(cb):
listeners.append(cb)
def callListeners(host):
def call_listeners(host):
"""Must be called by frontend when host is ready.
The call will launch all the callbacks, then remove the listeners list.

View file

@ -124,7 +124,7 @@ class JID(BaseJID):
return self.domain != ""
def newResource(entity, resource):
def new_resource(entity, resource):
"""Build a new JID from the given entity and resource.
@param entity (JID): original JID

View file

@ -19,7 +19,7 @@
class InputHistory(object):
def _updateInputHistory(self, text=None, step=None, callback=None, mode=""):
def _update_input_history(self, text=None, step=None, callback=None, mode=""):
"""Update the lists of previously sent messages. Several lists can be
handled as they are stored in a dictionary, the argument "mode" being
used as the entry key. There's also a temporary list to allow you play

View file

@ -28,7 +28,7 @@ RE_URL = re.compile(
# TODO: merge this class with an other module or at least rename it (strings is not a good name)
def getURLParams(url):
def get_url_params(url):
"""This comes from pyjamas.Location.makeUrlDict with a small change
to also parse full URLs, and parameters with no value specified
(in that case the default value "" is used).
@ -51,13 +51,13 @@ def getURLParams(url):
return dict_
def addURLToText(string, new_target=True):
def add_url_to_text(string, new_target=True):
"""Check a text for what looks like an URL and make it clickable.
@param string (unicode): text to process
@param new_target (bool): if True, make the link open in a new window
"""
# XXX: report any change to libervia.browser.strings.addURLToText
# XXX: report any change to libervia.browser.strings.add_url_to_text
def repl(match):
url = match.group(0)
if not re.match(r"""[a-z]{3,}://|mailto:|xmpp:""", url):
@ -68,12 +68,12 @@ def addURLToText(string, new_target=True):
return RE_URL.sub(repl, string)
def addURLToImage(string):
def add_url_to_image(string):
"""Check a XHTML text for what looks like an imageURL and make it clickable.
@param string (unicode): text to process
"""
# XXX: report any change to libervia.browser.strings.addURLToImage
# XXX: report any change to libervia.browser.strings.add_url_to_image
def repl(match):
url = match.group(1)
return '<a href="%s" target="_blank">%s</a>' % (url, match.group(0))
@ -82,7 +82,7 @@ def addURLToImage(string):
return re.sub(pattern, repl, string)
def fixXHTMLLinks(xhtml):
def fix_xhtml_links(xhtml):
"""Add http:// if the scheme is missing and force opening in a new window.
@param string (unicode): XHTML Content

View file

@ -23,7 +23,7 @@
# (e.g. NativeDOM in Libervia)
def inlineRoot(doc):
def inline_root(doc):
""" make the root attribute inline
@param root_node: minidom's Document compatible class
@return: plain XML

View file

@ -40,8 +40,8 @@ class ClassNotRegistedError(Exception):
pass
# FIXME: this method is duplicated in frontends.tools.xmlui.getText
def getText(node):
# FIXME: this method is duplicated in frontends.tools.xmlui.get_text
def get_text(node):
"""Get child text nodes
@param node: dom Node
@return: joined unicode text of all nodes
@ -168,7 +168,7 @@ class Container(Widget):
"""Widget which can contain other ones with a specific layout"""
@classmethod
def _xmluiAdapt(cls, instance):
def _xmlui_adapt(cls, instance):
"""Make cls as instance.__class__
cls must inherit from original instance class
@ -217,24 +217,24 @@ class Dialog(object):
def __init__(self, _xmlui_parent):
self._xmlui_parent = _xmlui_parent
def _xmluiValidated(self, data=None):
def _xmlui_validated(self, data=None):
if data is None:
data = {}
self._xmluiSetData(C.XMLUI_STATUS_VALIDATED, data)
self._xmluiSubmit(data)
self._xmlui_set_data(C.XMLUI_STATUS_VALIDATED, data)
self._xmlui_submit(data)
def _xmluiCancelled(self):
def _xmlui_cancelled(self):
data = {C.XMLUI_DATA_CANCELLED: C.BOOL_TRUE}
self._xmluiSetData(C.XMLUI_STATUS_CANCELLED, data)
self._xmluiSubmit(data)
self._xmlui_set_data(C.XMLUI_STATUS_CANCELLED, data)
self._xmlui_submit(data)
def _xmluiSubmit(self, data):
def _xmlui_submit(self, data):
if self._xmlui_parent.submit_id is None:
log.debug(_("Nothing to submit"))
else:
self._xmlui_parent.submit(data)
def _xmluiSetData(self, status, data):
def _xmlui_set_data(self, status, data):
pass
@ -253,7 +253,7 @@ class NoteDialog(Dialog):
class ConfirmDialog(Dialog):
"""Dialog with a OK/Cancel type configuration"""
def _xmluiSetData(self, status, data):
def _xmlui_set_data(self, status, data):
if status == C.XMLUI_STATUS_VALIDATED:
data[C.XMLUI_DATA_ANSWER] = C.BOOL_TRUE
elif status == C.XMLUI_STATUS_CANCELLED:
@ -283,12 +283,12 @@ class XMLUIBase(object):
- NO_CANCEL: the UI can't be cancelled
- FROM_BACKEND: the UI come from backend (i.e. it's not the direct result of
user operation)
@param callback(callable, None): if not None, will be used with launchAction:
@param callback(callable, None): if not None, will be used with action_launch:
- if None is used, default behaviour will be used (closing the dialog and
calling host.actionManager)
calling host.action_manager)
- if a callback is provided, it will be used instead, so you'll have to manage
dialog closing or new xmlui to display, or other action (you can call
host.actionManager)
host.action_manager)
The callback will have data, callback_id and profile as arguments
"""
self.host = host
@ -300,20 +300,20 @@ class XMLUIBase(object):
if flags is None:
flags = []
self.flags = flags
self.callback = callback or self._defaultCb
self.callback = callback or self._default_cb
self.profile = profile
@property
def user_action(self):
return "FROM_BACKEND" not in self.flags
def _defaultCb(self, data, cb_id, profile):
# TODO: when XMLUI updates will be managed, the _xmluiClose
def _default_cb(self, data, cb_id, profile):
# TODO: when XMLUI updates will be managed, the _xmlui_close
# must be called only if there is no update
self._xmluiClose()
self.host.actionManager(data, profile=profile)
self._xmlui_close()
self.host.action_manager(data, profile=profile)
def _isAttrSet(self, name, node):
def _is_attr_set(self, name, node):
"""Return widget boolean attribute status
@param name: name of the attribute (e.g. "read_only")
@ -323,7 +323,7 @@ class XMLUIBase(object):
read_only = node.getAttribute(name) or C.BOOL_FALSE
return read_only.lower().strip() == C.BOOL_TRUE
def _getChildNode(self, node, name):
def _get_child_node(self, node, name):
"""Return the first child node with the given name
@param node: Node instance
@ -337,7 +337,7 @@ class XMLUIBase(object):
return None
def submit(self, data):
self._xmluiClose()
self._xmlui_close()
if self.submit_id is None:
raise ValueError("Can't submit is self.submit_id is not set")
if "session_id" in data:
@ -347,14 +347,14 @@ class XMLUIBase(object):
)
if self.session_id is not None:
data["session_id"] = self.session_id
self._xmluiLaunchAction(self.submit_id, data)
self._xmlui_launch_action(self.submit_id, data)
def _xmluiLaunchAction(self, action_id, data):
self.host.launchAction(
def _xmlui_launch_action(self, action_id, data):
self.host.action_launch(
action_id, data, callback=self.callback, profile=self.profile
)
def _xmluiClose(self):
def _xmlui_close(self):
"""Close the window/popup/... where the constructor XMLUI is
this method must be overrided
@ -427,7 +427,7 @@ class XMLUIPanel(XMLUIBase):
self._whitelist = whitelist
else:
self._whitelist = None
self.constructUI(parsed_dom)
self.construct_ui(parsed_dom)
@staticmethod
def escape(name):
@ -449,10 +449,10 @@ class XMLUIPanel(XMLUIBase):
raise ValueError(_("XMLUI can have only one main container"))
self._main_cont = value
def _parseChilds(self, _xmlui_parent, current_node, wanted=("container",), data=None):
def _parse_childs(self, _xmlui_parent, current_node, wanted=("container",), data=None):
"""Recursively parse childNodes of an element
@param _xmlui_parent: widget container with '_xmluiAppend' method
@param _xmlui_parent: widget container with '_xmlui_append' method
@param current_node: element from which childs will be parsed
@param wanted: list of tag names that can be present in the childs to be SàT XMLUI
compliant
@ -473,16 +473,16 @@ class XMLUIPanel(XMLUIBase):
self.main_cont = _xmlui_parent
if type_ == "tabs":
cont = self.widget_factory.createTabsContainer(_xmlui_parent)
self._parseChilds(_xmlui_parent, node, ("tab",), {"tabs_cont": cont})
self._parse_childs(_xmlui_parent, node, ("tab",), {"tabs_cont": cont})
elif type_ == "vertical":
cont = self.widget_factory.createVerticalContainer(_xmlui_parent)
self._parseChilds(cont, node, ("widget", "container"))
self._parse_childs(cont, node, ("widget", "container"))
elif type_ == "pairs":
cont = self.widget_factory.createPairsContainer(_xmlui_parent)
self._parseChilds(cont, node, ("widget", "container"))
self._parse_childs(cont, node, ("widget", "container"))
elif type_ == "label":
cont = self.widget_factory.createLabelContainer(_xmlui_parent)
self._parseChilds(
self._parse_childs(
# FIXME: the "None" value for CURRENT_LABEL doesn't seem
# used or even useful, it should probably be removed
# and all "is not None" tests for it should be removed too
@ -507,15 +507,15 @@ class XMLUIPanel(XMLUIBase):
"can't have selectable=='no' and callback_id at the same time"
)
cont._xmlui_callback_id = callback_id
cont._xmluiOnSelect(self.onAdvListSelect)
cont._xmlui_on_select(self.on_adv_list_select)
self._parseChilds(cont, node, ("row",), data)
self._parse_childs(cont, node, ("row",), data)
else:
log.warning(_("Unknown container [%s], using default one") % type_)
cont = self.widget_factory.createVerticalContainer(_xmlui_parent)
self._parseChilds(cont, node, ("widget", "container"))
self._parse_childs(cont, node, ("widget", "container"))
try:
xmluiAppend = _xmlui_parent._xmluiAppend
xmluiAppend = _xmlui_parent._xmlui_append
except (
AttributeError,
TypeError,
@ -524,7 +524,7 @@ class XMLUIPanel(XMLUIBase):
self.main_cont = cont
else:
raise Exception(
_("Internal Error, container has not _xmluiAppend method")
_("Internal Error, container has not _xmlui_append method")
)
else:
xmluiAppend(cont)
@ -540,8 +540,8 @@ class XMLUIPanel(XMLUIBase):
name
) # XXX: awful hack because params need category and we don't keep parent
tab_cont = data["tabs_cont"]
new_tab = tab_cont._xmluiAddTab(label or name, selected)
self._parseChilds(new_tab, node, ("widget", "container"))
new_tab = tab_cont._xmlui_add_tab(label or name, selected)
self._parse_childs(new_tab, node, ("widget", "container"))
elif node.nodeName == "row":
try:
@ -550,8 +550,8 @@ class XMLUIPanel(XMLUIBase):
index = node.getAttribute("index") or None
else:
data["index"] += 1
_xmlui_parent._xmluiAddRow(index)
self._parseChilds(_xmlui_parent, node, ("widget", "container"))
_xmlui_parent._xmlui_add_row(index)
self._parse_childs(_xmlui_parent, node, ("widget", "container"))
elif node.nodeName == "widget":
name = node.getAttribute("name")
@ -565,12 +565,12 @@ class XMLUIPanel(XMLUIBase):
curr_label = data.pop(CURRENT_LABEL)
if curr_label is not None:
# if so, we remove it from parent
_xmlui_parent._xmluiRemove(curr_label)
_xmlui_parent._xmlui_remove(curr_label)
continue
type_ = node.getAttribute("type")
value_elt = self._getChildNode(node, "value")
value_elt = self._get_child_node(node, "value")
if value_elt is not None:
value = getText(value_elt)
value = get_text(value_elt)
else:
value = (
node.getAttribute("value") if node.hasAttribute("value") else ""
@ -597,39 +597,39 @@ class XMLUIPanel(XMLUIBase):
ctrl = self.widget_factory.createDividerWidget(_xmlui_parent, style)
elif type_ == "string":
ctrl = self.widget_factory.createStringWidget(
_xmlui_parent, value, self._isAttrSet("read_only", node)
_xmlui_parent, value, self._is_attr_set("read_only", node)
)
self.ctrl_list[name] = {"type": type_, "control": ctrl}
elif type_ == "jid_input":
ctrl = self.widget_factory.createJidInputWidget(
_xmlui_parent, value, self._isAttrSet("read_only", node)
_xmlui_parent, value, self._is_attr_set("read_only", node)
)
self.ctrl_list[name] = {"type": type_, "control": ctrl}
elif type_ == "password":
ctrl = self.widget_factory.createPasswordWidget(
_xmlui_parent, value, self._isAttrSet("read_only", node)
_xmlui_parent, value, self._is_attr_set("read_only", node)
)
self.ctrl_list[name] = {"type": type_, "control": ctrl}
elif type_ == "textbox":
ctrl = self.widget_factory.createTextBoxWidget(
_xmlui_parent, value, self._isAttrSet("read_only", node)
_xmlui_parent, value, self._is_attr_set("read_only", node)
)
self.ctrl_list[name] = {"type": type_, "control": ctrl}
elif type_ == "xhtmlbox":
ctrl = self.widget_factory.createXHTMLBoxWidget(
_xmlui_parent, value, self._isAttrSet("read_only", node)
_xmlui_parent, value, self._is_attr_set("read_only", node)
)
self.ctrl_list[name] = {"type": type_, "control": ctrl}
elif type_ == "bool":
ctrl = self.widget_factory.createBoolWidget(
_xmlui_parent,
value == C.BOOL_TRUE,
self._isAttrSet("read_only", node),
self._is_attr_set("read_only", node),
)
self.ctrl_list[name] = {"type": type_, "control": ctrl}
elif type_ == "int":
ctrl = self.widget_factory.createIntWidget(
_xmlui_parent, value, self._isAttrSet("read_only", node)
_xmlui_parent, value, self._is_attr_set("read_only", node)
)
self.ctrl_list[name] = {"type": type_, "control": ctrl}
elif type_ == "list":
@ -652,7 +652,7 @@ class XMLUIPanel(XMLUIBase):
self.ctrl_list[name] = {"type": type_, "control": ctrl}
elif type_ == "jids_list":
style = []
jids = [getText(jid_) for jid_ in node.getElementsByTagName("jid")]
jids = [get_text(jid_) for jid_ in node.getElementsByTagName("jid")]
ctrl = self.widget_factory.createJidsListWidget(
_xmlui_parent, jids, style
)
@ -660,7 +660,7 @@ class XMLUIPanel(XMLUIBase):
elif type_ == "button":
callback_id = node.getAttribute("callback")
ctrl = self.widget_factory.createButtonWidget(
_xmlui_parent, value, self.onButtonPress
_xmlui_parent, value, self.on_button_press
)
ctrl._xmlui_param_id = (
callback_id,
@ -683,7 +683,7 @@ class XMLUIPanel(XMLUIBase):
if self.type == "param" and type_ not in ("text", "button"):
try:
ctrl._xmluiOnChange(self.onParamChange)
ctrl._xmlui_on_change(self.on_param_change)
ctrl._param_category = self._current_category
except (
AttributeError,
@ -702,15 +702,15 @@ class XMLUIPanel(XMLUIBase):
field.getAttribute("name")
for field in node.getElementsByTagName("internal_field")
]
cb_data = self.getInternalCallbackData(callback, node)
cb_data = self.get_internal_callback_data(callback, node)
ctrl._xmlui_param_internal = (callback, fields, cb_data)
if type_ == "button":
ctrl._xmluiOnClick(self.onChangeInternal)
ctrl._xmlui_on_click(self.on_change_internal)
else:
ctrl._xmluiOnChange(self.onChangeInternal)
ctrl._xmlui_on_change(self.on_change_internal)
ctrl._xmlui_name = name
_xmlui_parent._xmluiAppend(ctrl)
_xmlui_parent._xmlui_append(ctrl)
if CURRENT_LABEL in data and not isinstance(ctrl, LabelWidget):
curr_label = data.pop(CURRENT_LABEL)
if curr_label is not None:
@ -721,7 +721,7 @@ class XMLUIPanel(XMLUIBase):
else:
raise NotImplementedError(_("Unknown tag [%s]") % node.nodeName)
def constructUI(self, parsed_dom, post_treat=None):
def construct_ui(self, parsed_dom, post_treat=None):
"""Actually construct the UI
@param parsed_dom: main parsed dom
@ -741,17 +741,17 @@ class XMLUIPanel(XMLUIBase):
if self.type == "param":
self.param_changed = set()
self._parseChilds(self, parsed_dom.documentElement)
self._parse_childs(self, parsed_dom.documentElement)
if post_treat is not None:
post_treat()
def _xmluiSetParam(self, name, value, category):
self.host.bridge.setParam(name, value, category, profile_key=self.profile)
def _xmlui_set_param(self, name, value, category):
self.host.bridge.param_set(name, value, category, profile_key=self.profile)
##EVENTS##
def onParamChange(self, ctrl):
def on_param_change(self, ctrl):
"""Called when type is param and a widget to save is modified
@param ctrl: widget modified
@ -759,29 +759,29 @@ class XMLUIPanel(XMLUIBase):
assert self.type == "param"
self.param_changed.add(ctrl)
def onAdvListSelect(self, ctrl):
def on_adv_list_select(self, ctrl):
data = {}
widgets = ctrl._xmluiGetSelectedWidgets()
widgets = ctrl._xmlui_get_selected_widgets()
for wid in widgets:
try:
name = self.escape(wid._xmlui_name)
value = wid._xmluiGetValue()
value = wid._xmlui_get_value()
data[name] = value
except (
AttributeError,
TypeError,
): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
pass
idx = ctrl._xmluiGetSelectedIndex()
idx = ctrl._xmlui_get_selected_index()
if idx is not None:
data["index"] = idx
callback_id = ctrl._xmlui_callback_id
if callback_id is None:
log.info(_("No callback_id found"))
return
self._xmluiLaunchAction(callback_id, data)
self._xmlui_launch_action(callback_id, data)
def onButtonPress(self, button):
def on_button_press(self, button):
"""Called when an XMLUI button is clicked
Launch the action associated to the button
@ -795,16 +795,16 @@ class XMLUIPanel(XMLUIBase):
escaped = self.escape(field)
ctrl = self.ctrl_list[field]
if isinstance(ctrl["control"], ListWidget):
data[escaped] = "\t".join(ctrl["control"]._xmluiGetSelectedValues())
data[escaped] = "\t".join(ctrl["control"]._xmlui_get_selected_values())
else:
data[escaped] = ctrl["control"]._xmluiGetValue()
self._xmluiLaunchAction(callback_id, data)
data[escaped] = ctrl["control"]._xmlui_get_value()
self._xmlui_launch_action(callback_id, data)
def onChangeInternal(self, ctrl):
def on_change_internal(self, ctrl):
"""Called when a widget that has been bound to an internal callback is changed.
This is used to perform some UI actions without communicating with the backend.
See sat.tools.xml_tools.Widget.setInternalCallback for more details.
See sat.tools.xml_tools.Widget.set_internal_callback for more details.
@param ctrl: widget modified
"""
action, fields, data = ctrl._xmlui_param_internal
@ -817,32 +817,32 @@ class XMLUIPanel(XMLUIBase):
"""Depending of 'action' value, copy or move from source to target."""
if isinstance(target, ListWidget):
if isinstance(source, ListWidget):
values = source._xmluiGetSelectedValues()
values = source._xmlui_get_selected_values()
else:
values = [source._xmluiGetValue()]
values = [source._xmlui_get_value()]
if action == "move":
source._xmluiSetValue("")
source._xmlui_set_value("")
values = [value for value in values if value]
if values:
target._xmluiAddValues(values, select=True)
target._xmlui_add_values(values, select=True)
else:
if isinstance(source, ListWidget):
value = ", ".join(source._xmluiGetSelectedValues())
value = ", ".join(source._xmlui_get_selected_values())
else:
value = source._xmluiGetValue()
value = source._xmlui_get_value()
if action == "move":
source._xmluiSetValue("")
target._xmluiSetValue(value)
source._xmlui_set_value("")
target._xmlui_set_value(value)
def groups_of_contact(source, target):
"""Select in target the groups of the contact which is selected in source."""
assert isinstance(source, ListWidget)
assert isinstance(target, ListWidget)
try:
contact_jid_s = source._xmluiGetSelectedValues()[0]
contact_jid_s = source._xmlui_get_selected_values()[0]
except IndexError:
return
target._xmluiSelectValues(data[contact_jid_s])
target._xmlui_select_values(data[contact_jid_s])
pass
source = None
@ -857,11 +857,11 @@ class XMLUIPanel(XMLUIBase):
groups_of_contact(source, widget)
source = None
def getInternalCallbackData(self, action, node):
def get_internal_callback_data(self, action, node):
"""Retrieve from node the data needed to perform given action.
@param action (string): a value from the one that can be passed to the
'callback' parameter of sat.tools.xml_tools.Widget.setInternalCallback
'callback' parameter of sat.tools.xml_tools.Widget.set_internal_callback
@param node (DOM Element): the node of the widget that triggers the callback
"""
# TODO: it would be better to not have a specific way to retrieve
@ -883,7 +883,7 @@ class XMLUIPanel(XMLUIBase):
data[jid_s].append(value_elt.getAttribute("name"))
return data
def onFormSubmitted(self, ignore=None):
def on_form_submitted(self, ignore=None):
"""An XMLUI form has been submited
call the submit action associated with this form
@ -894,10 +894,10 @@ class XMLUIPanel(XMLUIBase):
ctrl = self.ctrl_list[ctrl_name]
if isinstance(ctrl["control"], ListWidget):
selected_values.append(
(escaped, "\t".join(ctrl["control"]._xmluiGetSelectedValues()))
(escaped, "\t".join(ctrl["control"]._xmlui_get_selected_values()))
)
else:
selected_values.append((escaped, ctrl["control"]._xmluiGetValue()))
selected_values.append((escaped, ctrl["control"]._xmlui_get_value()))
data = dict(selected_values)
for key, value in self.hidden.items():
data[self.escape(key)] = value
@ -908,9 +908,9 @@ class XMLUIPanel(XMLUIBase):
log.warning(
_("The form data is not sent back, the type is not managed properly")
)
self._xmluiClose()
self._xmlui_close()
def onFormCancelled(self, *__):
def on_form_cancelled(self, *__):
"""Called when a form is cancelled"""
log.debug(_("Cancelling form"))
if self.submit_id is not None:
@ -920,9 +920,9 @@ class XMLUIPanel(XMLUIBase):
log.warning(
_("The form data is not sent back, the type is not managed properly")
)
self._xmluiClose()
self._xmlui_close()
def onSaveParams(self, ignore=None):
def on_save_params(self, ignore=None):
"""Params are saved, we send them to backend
self.type must be param
@ -930,13 +930,13 @@ class XMLUIPanel(XMLUIBase):
assert self.type == "param"
for ctrl in self.param_changed:
if isinstance(ctrl, ListWidget):
value = "\t".join(ctrl._xmluiGetSelectedValues())
value = "\t".join(ctrl._xmlui_get_selected_values())
else:
value = ctrl._xmluiGetValue()
value = ctrl._xmlui_get_value()
param_name = ctrl._xmlui_name.split(C.SAT_PARAM_SEPARATOR)[1]
self._xmluiSetParam(param_name, value, ctrl._param_category)
self._xmlui_set_param(param_name, value, ctrl._param_category)
self._xmluiClose()
self._xmlui_close()
def show(self, *args, **kwargs):
pass
@ -945,7 +945,7 @@ class XMLUIPanel(XMLUIBase):
class AIOXMLUIPanel(XMLUIPanel):
"""Asyncio compatible version of XMLUIPanel"""
async def onFormSubmitted(self, ignore=None):
async def on_form_submitted(self, ignore=None):
"""An XMLUI form has been submited
call the submit action associated with this form
@ -956,10 +956,10 @@ class AIOXMLUIPanel(XMLUIPanel):
ctrl = self.ctrl_list[ctrl_name]
if isinstance(ctrl["control"], ListWidget):
selected_values.append(
(escaped, "\t".join(ctrl["control"]._xmluiGetSelectedValues()))
(escaped, "\t".join(ctrl["control"]._xmlui_get_selected_values()))
)
else:
selected_values.append((escaped, ctrl["control"]._xmluiGetValue()))
selected_values.append((escaped, ctrl["control"]._xmlui_get_value()))
data = dict(selected_values)
for key, value in self.hidden.items():
data[self.escape(key)] = value
@ -970,9 +970,9 @@ class AIOXMLUIPanel(XMLUIPanel):
log.warning(
_("The form data is not sent back, the type is not managed properly")
)
self._xmluiClose()
self._xmlui_close()
async def onFormCancelled(self, *__):
async def on_form_cancelled(self, *__):
"""Called when a form is cancelled"""
log.debug(_("Cancelling form"))
if self.submit_id is not None:
@ -982,10 +982,10 @@ class AIOXMLUIPanel(XMLUIPanel):
log.warning(
_("The form data is not sent back, the type is not managed properly")
)
self._xmluiClose()
self._xmlui_close()
async def submit(self, data):
self._xmluiClose()
self._xmlui_close()
if self.submit_id is None:
raise ValueError("Can't submit is self.submit_id is not set")
if "session_id" in data:
@ -995,10 +995,10 @@ class AIOXMLUIPanel(XMLUIPanel):
)
if self.session_id is not None:
data["session_id"] = self.session_id
await self._xmluiLaunchAction(self.submit_id, data)
await self._xmlui_launch_action(self.submit_id, data)
async def _xmluiLaunchAction(self, action_id, data):
await self.host.launchAction(
async def _xmlui_launch_action(self, action_id, data):
await self.host.action_launch(
action_id, data, callback=self.callback, profile=self.profile
)
@ -1021,13 +1021,13 @@ class XMLUIDialog(XMLUIBase):
host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile
)
top = parsed_dom.documentElement
dlg_elt = self._getChildNode(top, "dialog")
dlg_elt = self._get_child_node(top, "dialog")
if dlg_elt is None:
raise ValueError("Invalid XMLUI: no Dialog element found !")
dlg_type = dlg_elt.getAttribute("type") or C.XMLUI_DIALOG_MESSAGE
try:
mess_elt = self._getChildNode(dlg_elt, C.XMLUI_DATA_MESS)
message = getText(mess_elt)
mess_elt = self._get_child_node(dlg_elt, C.XMLUI_DATA_MESS)
message = get_text(mess_elt)
except (
TypeError,
AttributeError,
@ -1045,7 +1045,7 @@ class XMLUIDialog(XMLUIBase):
)
elif dlg_type == C.XMLUI_DIALOG_CONFIRM:
try:
buttons_elt = self._getChildNode(dlg_elt, "buttons")
buttons_elt = self._get_child_node(dlg_elt, "buttons")
buttons_set = (
buttons_elt.getAttribute("set") or C.XMLUI_DATA_BTNS_SET_DEFAULT
)
@ -1059,7 +1059,7 @@ class XMLUIDialog(XMLUIBase):
)
elif dlg_type == C.XMLUI_DIALOG_FILE:
try:
file_elt = self._getChildNode(dlg_elt, "file")
file_elt = self._get_child_node(dlg_elt, "file")
filetype = file_elt.getAttribute("type") or C.XMLUI_DATA_FILETYPE_DEFAULT
except (
TypeError,
@ -1073,13 +1073,13 @@ class XMLUIDialog(XMLUIBase):
raise ValueError("Unknown dialog type [%s]" % dlg_type)
def show(self):
self.dlg._xmluiShow()
self.dlg._xmlui_show()
def _xmluiClose(self):
self.dlg._xmluiClose()
def _xmlui_close(self):
self.dlg._xmlui_close()
def registerClass(type_, class_):
def register_class(type_, class_):
"""Register the class to use with the factory
@param type_: one of:
@ -1090,7 +1090,7 @@ def registerClass(type_, class_):
# TODO: remove this method, as there are seme use cases where different XMLUI
# classes can be used in the same frontend, so a global value is not good
assert type_ in (CLASS_PANEL, CLASS_DIALOG)
log.warning("registerClass for XMLUI is deprecated, please use partial with "
log.warning("register_class for XMLUI is deprecated, please use partial with "
"xmlui.create and class_map instead")
if type_ in _class_map:
log.debug(_("XMLUI class already registered for {type_}, ignoring").format(
@ -1132,7 +1132,7 @@ def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None
cls = class_map[CLASS_DIALOG]
except KeyError:
raise ClassNotRegistedError(
_("You must register classes with registerClass before creating a XMLUI")
_("You must register classes with register_class before creating a XMLUI")
)
xmlui = cls(