# HG changeset patch # User souliane # Date 1381837161 -7200 # Node ID a565ce2facc013515b05974c063b6d57b698e733 # Parent b911f2b43fd462e0423bb2c071b9ecdf494ffceb browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen diff -r b911f2b43fd4 -r a565ce2facc0 browser_side/dialog.py --- a/browser_side/dialog.py Mon Oct 14 20:54:13 2013 +0200 +++ b/browser_side/dialog.py Tue Oct 15 13:39:21 2013 +0200 @@ -38,6 +38,7 @@ # List here the patterns that are not allowed in contact group names FORBIDDEN_PATTERNS_IN_GROUP = () + class ContactsChooser(DialogBox): def __init__(self, host, callback, nb_contact=None, text='Please select contacts'): @@ -46,12 +47,24 @@ @param host: SatWebFrontend instance @param callback: method to call when contacts have been choosed @param nb_contact: number of contacts that have to be selected, None for no limit + If a tuple is given instead of an integer, nb_contact[0] is the minimal and + nb_contact[1] is the maximal number of contacts to be chosen. """ self.host = host self.callback = callback + if isinstance(nb_contact, tuple): + if len(nb_contact) == 0: + nb_contact = None + elif len(nb_contact) == 1: + nb_contact = (nb_contact[0], nb_contact[0]) + elif nb_contact is not None: + nb_contact = (nb_contact, nb_contact) + if nb_contact is None: + print "Need to select as many contacts as you want" + else: + print "Need to select between %d and %d contacts" % nb_contact self.nb_contact = nb_contact DialogBox.__init__(self, centered=True) - content = VerticalPanel() content.setWidth('100%') self.contacts_list = ListBox() @@ -64,7 +77,7 @@ button_panel = HorizontalPanel() button_panel.addStyleName("marginAuto") self.choose_button = Button("Choose", self.onChoose) - if (nb_contact): + if nb_contact and nb_contact[0] > 0: self.choose_button.setEnabled(False) button_panel.add(self.choose_button) button_panel.add(Button("Cancel", self.onCancel)) @@ -74,7 +87,8 @@ def onChange(self, sender): if self.nb_contact: - if len(self.contacts_list.getSelectedValues()) == self.nb_contact: + selected = len(self.contacts_list.getSelectedValues()) + if selected >= self.nb_contact[0] and selected <= self.nb_contact[1]: self.choose_button.setEnabled(True) else: self.choose_button.setEnabled(False)