From aab8aafefc5131db5ccc8183b3a5a7b4e5693bb6 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Wed, 3 Aug 2022 11:11:31 -0500 Subject: [PATCH] Introduced user selector controller for implementing user autocompletion in wxUI.dialogs.utils.selectUserDialog --- src/controller/userSelector.py | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/controller/userSelector.py diff --git a/src/controller/userSelector.py b/src/controller/userSelector.py new file mode 100644 index 00000000..b937795d --- /dev/null +++ b/src/controller/userSelector.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +""" Small utility dessigned to select users from the currently focused item or the autocomplete database. """ +import wx +import widgetUtils +from wxUI.dialogs import utils +from extra.autocompletionUsers import completion + +class userSelector(object): + + def __init__(self, users, session_id, title=_("Select user")): + """ Creates a dialog that chooses an user selector, from where users who have the autocomplete database already filled can also use that feature. + + :param users: lists of users extracted from the currently focused item. + :type users: list + :param session_id: ID of the session to instantiate autocomplete database. + :type session_id: str + :param title: Title of the user selector dialog. + :type title: str + """ + self.session_id = session_id + self.dlg = utils.selectUserDialog(users=users, title=title) + widgetUtils.connect_event(self.dlg.autocompletion, widgetUtils.BUTTON_PRESSED, self.on_autocomplete_users) + + def on_autocomplete_users(self, *args, **kwargs): + """ performs user autocompletion, if configured properly. """ + c = completion.autocompletionUsers(self.dlg, self.session_id) + c.show_menu("dm") + + def get_user(self): + """ Actually shows the dialog and returns an user if the dialog was accepted, None otherwise. + + :rtype: str or None + """ + if self.dlg.ShowModal() == wx.ID_OK: + user = self.dlg.get_user() + else: + user = None + self.dlg.Destroy() + return user