Ejemplo n.º 1
0
def sort_sellable_code(a, b):
    a_parts = _split_parts(a)
    b_parts = _split_parts(b)
    a_types = [type(i) for i in a_parts]
    b_types = [type(i) for i in b_parts]
    if a_types == b_types:
        return cmp(a_parts, b_parts)
    else:
        return cmp(a, b)
Ejemplo n.º 2
0
 def _datecmp(a, b):
     if a is None:
         if b is None:
             return 0
         return 1
     elif b is None:
         return -1
     else:
         return cmp(a, b)
Ejemplo n.º 3
0
 def _datecmp(a, b):
     if a is None:
         if b is None:
             return 0
         return 1
     elif b is None:
         return -1
     else:
         return cmp(a, b)
Ejemplo n.º 4
0
    def prefill(self, itemdata, sort=False):
        """
        See :class:`kiwi.interfaces.IEasyCombo.prefill`
        """

        if not isinstance(itemdata, (list, tuple)):
            raise TypeError("'data' parameter must be a list or tuple of item "
                            "descriptions, found %s") % type(itemdata)

        completion = self._get_entry_completion()
        model = completion.get_model()

        if len(itemdata) == 0:
            model.clear()
            return

        if (len(itemdata) > 0 and
            type(itemdata[0]) in (tuple, list) and
            len(itemdata[0]) == 2):
            mode = self._mode = ENTRY_MODE_DATA
        else:
            mode = self._mode

        values = set()
        if mode == ENTRY_MODE_TEXT:
            if sort:
                itemdata.sort()

            for item in itemdata:
                if item in values:
                    raise KeyError("Tried to insert duplicate value "
                                   "%r into the entry" % item)
                else:
                    values.add(item)

                model.append((item, None))
        elif mode == ENTRY_MODE_DATA:
            if sort:
                itemdata.sort(lambda x, y: cmp(x[0], y[0]))

            for item in itemdata:
                text, data = item
                # Add (n) to the end in case of duplicates
                count = 1
                orig = text
                while text in values:
                    text = orig + ' (%d)' % count
                    count += 1

                values.add(text)
                model.append((text, data))
        else:
            raise TypeError("Incorrect format for itemdata; see "
                            "docstring for more information")
Ejemplo n.º 5
0
    def prefill(self, itemdata, sort=False):
        """
        See :class:`kiwi.interfaces.IEasyCombo.prefill`
        """

        if not isinstance(itemdata, (list, tuple)):
            raise TypeError("'data' parameter must be a list or tuple of item "
                            "descriptions, found %s") % type(itemdata)

        completion = self._get_entry_completion()
        model = completion.get_model()

        if len(itemdata) == 0:
            model.clear()
            return

        if (len(itemdata) > 0 and type(itemdata[0]) in (tuple, list)
                and len(itemdata[0]) == 2):
            mode = self._mode = ENTRY_MODE_DATA
        else:
            mode = self._mode

        values = set()
        if mode == ENTRY_MODE_TEXT:
            if sort:
                itemdata.sort()

            for item in itemdata:
                if item in values:
                    raise KeyError("Tried to insert duplicate value "
                                   "%r into the entry" % item)
                else:
                    values.add(item)

                model.append((item, None))
        elif mode == ENTRY_MODE_DATA:
            if sort:
                itemdata.sort(lambda x, y: cmp(x[0], y[0]))

            for item in itemdata:
                text, data = item
                # Add (n) to the end in case of duplicates
                count = 1
                orig = text
                while text in values:
                    text = orig + ' (%d)' % count
                    count += 1

                values.add(text)
                model.append((text, data))
        else:
            raise TypeError("Incorrect format for itemdata; see "
                            "docstring for more information")
Ejemplo n.º 6
0
    def prefill(self, itemdata, sort=False):
        if not isinstance(itemdata, (list, tuple)):
            raise TypeError("'data' parameter must be a list or tuple of item "
                            "descriptions, found %s" % (type(itemdata),))

        self.clear()
        if len(itemdata) == 0:
            return

        if self.mode == ComboMode.UNKNOWN:
            first = itemdata[0]
            if isinstance(first, six.string_types):
                self.set_mode(ComboMode.STRING)
            elif isinstance(first, (tuple, list)):
                self.set_mode(ComboMode.DATA)
            else:
                raise TypeError("Could not determine type, items must "
                                "be strings or tuple/list")

        mode = self.mode
        if mode not in (ComboMode.STRING, ComboMode.DATA):
            raise TypeError("Incorrect format for itemdata; see "
                            "docstring for more information")

        model = self._combobox.get_model()

        values = set()
        if mode == ComboMode.STRING:
            if sort:
                itemdata.sort()

            for item in itemdata:
                if item in values:
                    raise KeyError("Tried to insert duplicate value "
                                   "%s into Combo!" % (item,))
                values.add(item)

                model.append((item, None))
        elif mode == ComboMode.DATA:
            if sort:
                itemdata.sort(lambda x, y: cmp(x[0], y[0]))

            for item in itemdata:
                text, data = item
                orig = text
                count = 1
                while text in values:
                    text = orig + ' (%d)' % count
                    count += 1
                values.add(text)
                model.append((text, data))
Ejemplo n.º 7
0
    def prefill(self, itemdata, sort=False):
        if not isinstance(itemdata, (list, tuple)):
            raise TypeError("'data' parameter must be a list or tuple of item "
                            "descriptions, found %s" % (type(itemdata), ))

        self.clear()
        if len(itemdata) == 0:
            return

        if self.mode == ComboMode.UNKNOWN:
            first = itemdata[0]
            if isinstance(first, six.string_types):
                self.set_mode(ComboMode.STRING)
            elif isinstance(first, (tuple, list)):
                self.set_mode(ComboMode.DATA)
            else:
                raise TypeError("Could not determine type, items must "
                                "be strings or tuple/list")

        mode = self.mode
        if mode not in (ComboMode.STRING, ComboMode.DATA):
            raise TypeError("Incorrect format for itemdata; see "
                            "docstring for more information")

        model = self._combobox.get_model()

        values = set()
        if mode == ComboMode.STRING:
            if sort:
                itemdata.sort()

            for item in itemdata:
                if item in values:
                    raise KeyError("Tried to insert duplicate value "
                                   "%s into Combo!" % (item, ))
                values.add(item)

                model.append((item, None))
        elif mode == ComboMode.DATA:
            if sort:
                itemdata.sort(lambda x, y: cmp(x[0], y[0]))

            for item in itemdata:
                text, data = item
                orig = text
                count = 1
                while text in values:
                    text = orig + ' (%d)' % count
                    count += 1
                values.add(text)
                model.append((text, data))
Ejemplo n.º 8
0
 def _cmp(a, b):
     return cmp(a.sellable.description, b.sellable.description)
Ejemplo n.º 9
0
def sort_models(a, b):
    return cmp(a.lower(), b.lower())
Ejemplo n.º 10
0
 def _sort_event_types(self, type_a, type_b):
     event_str_a = Event.types[type_a]
     event_str_b = Event.types[type_b]
     return cmp(event_str_a.lower(), event_str_b.lower())
Ejemplo n.º 11
0
 def _sort_event_types(self, type_a, type_b):
     event_str_a = Event.types[type_a]
     event_str_b = Event.types[type_b]
     return cmp(event_str_a.lower(), event_str_b.lower())
Ejemplo n.º 12
0
def sort_models(a, b):
    return cmp(a.lower(),
               b.lower())
Ejemplo n.º 13
0
 def table_sort(a, b):
     props_a = _get_table_packing_properties(widget, a)
     props_b = _get_table_packing_properties(widget, b)
     return cmp(props_a, props_b)
Ejemplo n.º 14
0
 def _cmp(a, b):
     return cmp(a.sellable.description, b.sellable.description)
Ejemplo n.º 15
0
def sort_sellable_code(a, b):
    return cmp(_split_parts(a), _split_parts(b))