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)
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)
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")
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))
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))
def _cmp(a, b): return cmp(a.sellable.description, b.sellable.description)
def sort_models(a, b): return cmp(a.lower(), b.lower())
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())
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)
def sort_sellable_code(a, b): return cmp(_split_parts(a), _split_parts(b))