summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-08-18 18:04:42 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-08-19 12:52:26 -0700
commite36db1f99d0797f2b984e74fe2f14dafdecb7d39 (patch)
tree65c935d79c155f84d215bc543f5569acf8970624
parent22557647bdbc003b5ca70e39720cca78c77d9b39 (diff)
widgets/globals: drop functools.totalordering from TagWidget
Implementing the comparison functions as a shared method rather than in terms of each other (as functools.totalordering does) makes the search interface much snappier.
-rw-r--r--alot/widgets/globals.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/alot/widgets/globals.py b/alot/widgets/globals.py
index e4b9fada..f602add0 100644
--- a/alot/widgets/globals.py
+++ b/alot/widgets/globals.py
@@ -7,7 +7,6 @@ This contains alot-specific :class:`urwid.Widget` used in more than one mode.
"""
from __future__ import absolute_import
-import functools
import re
import operator
import urwid
@@ -272,7 +271,6 @@ class HeadersList(urwid.WidgetWrap):
return headerlines
-@functools.total_ordering
class TagWidget(urwid.AttrMap):
"""
text widget that renders a tagstring.
@@ -318,11 +316,8 @@ class TagWidget(urwid.AttrMap):
def set_unfocussed(self):
self.set_attr_map(self.attmaps['normal'])
- def __lt__(self, other):
- """Groups tags of 1 character first, then alphabetically.
-
- This groups tags unicode characters at the begnining.
- """
+ def __cmp(self, other, comparitor):
+ """Shared comparison method."""
if not isinstance(other, TagWidget):
return NotImplemented
@@ -330,8 +325,24 @@ class TagWidget(urwid.AttrMap):
oth_len = len(other.translated)
if (self_len == 1) is not (oth_len == 1):
- return self_len < oth_len
- return self.translated.lower() < other.translated.lower()
+ return comparitor(self_len, oth_len)
+ return comparitor(self.translated.lower(), other.translated.lower())
+
+ def __lt__(self, other):
+ """Groups tags of 1 character first, then alphabetically.
+
+ This groups tags unicode characters at the begnining.
+ """
+ return self.__cmp(other, operator.lt)
+
+ def __gt__(self, other):
+ return self.__cmp(other, operator.gt)
+
+ def __ge__(self, other):
+ return self.__cmp(other, operator.ge)
+
+ def __le__(self, other):
+ return self.__cmp(other, operator.le)
def __eq__(self, other):
if not isinstance(other, TagWidget):