summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
Diffstat (limited to 'alot')
-rw-r--r--alot/helper.py11
-rw-r--r--alot/widgets/globals.py29
-rw-r--r--alot/widgets/search.py7
-rw-r--r--alot/widgets/thread.py10
4 files changed, 35 insertions, 22 deletions
diff --git a/alot/helper.py b/alot/helper.py
index bd1e3621..2e523c88 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -499,17 +499,6 @@ def shell_quote(text):
return "'%s'" % text.replace("'", """'"'"'""")
-def tag_cmp(a, b):
- r'''
- Sorting tags using this function puts all tags of length 1 at the
- beginning. This groups all tags mapped to unicode characters.
- '''
- if min(len(a), len(b)) == 1 and max(len(a), len(b)) > 1:
- return cmp(len(a), len(b))
- else:
- return cmp(a.lower(), b.lower())
-
-
def humanize_size(size):
"""Create a nice human readable representation of the given number
(understood as bytes) using the "KiB" and "MiB" suffixes to indicate
diff --git a/alot/widgets/globals.py b/alot/widgets/globals.py
index 822d0ae9..60397104 100644
--- a/alot/widgets/globals.py
+++ b/alot/widgets/globals.py
@@ -7,6 +7,7 @@ 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
@@ -271,6 +272,7 @@ class HeadersList(urwid.WidgetWrap):
return headerlines
+@functools.total_ordering
class TagWidget(urwid.AttrMap):
"""
text widget that renders a tagstring.
@@ -313,3 +315,30 @@ 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.
+ """
+ if not isinstance(other, TagWidget):
+ return NotImplemented
+
+ self_len = len(self.translated)
+ 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()
+
+ def __eq__(self, other):
+ if not isinstance(other, TagWidget):
+ return NotImplemented
+ if len(self.translated) != len(other.translated):
+ return False
+ return self.translated.lower() == other.translated.lower()
+
+ def __ne__(self, other):
+ if not isinstance(other, TagWidget):
+ return NotImplemented
+ return self.translated.lower() != other.translated.lower()
diff --git a/alot/widgets/search.py b/alot/widgets/search.py
index a0f23b5e..32a078c7 100644
--- a/alot/widgets/search.py
+++ b/alot/widgets/search.py
@@ -10,7 +10,6 @@ import urwid
from ..settings import settings
from ..helper import shorten_author_string
-from ..helper import tag_cmp
from .utils import AttrFlipWidget
from .globals import TagWidget
@@ -116,10 +115,8 @@ class ThreadlineWidget(urwid.AttrMap):
if self.thread:
fallback_normal = struct[name]['normal']
fallback_focus = struct[name]['focus']
- tag_widgets = [TagWidget(t, fallback_normal, fallback_focus)
- for t in self.thread.get_tags()]
- tag_widgets.sort(tag_cmp,
- lambda tag_widget: tag_widget.translated)
+ tag_widgets = sorted(TagWidget(t, fallback_normal, fallback_focus)
+ for t in self.thread.get_tags())
else:
tag_widgets = []
cols = []
diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py
index 6084ebd5..70e7c840 100644
--- a/alot/widgets/thread.py
+++ b/alot/widgets/thread.py
@@ -15,7 +15,6 @@ from .globals import AttachmentWidget
from ..settings import settings
from ..db.utils import decode_header, X_SIGNATURE_MESSAGE_HEADER
from ..db.utils import extract_body
-from ..helper import tag_cmp
class MessageSummaryWidget(urwid.WidgetWrap):
@@ -47,12 +46,11 @@ class MessageSummaryWidget(urwid.WidgetWrap):
if settings.get('msg_summary_hides_threadwide_tags'):
thread_tags = message.get_thread().get_tags(intersection=True)
outstanding_tags = set(message.get_tags()).difference(thread_tags)
- tag_widgets = [TagWidget(t, attr, focus_att)
- for t in outstanding_tags]
+ tag_widgets = sorted(TagWidget(t, attr, focus_att)
+ for t in outstanding_tags)
else:
- tag_widgets = [TagWidget(t, attr, focus_att)
- for t in message.get_tags()]
- tag_widgets.sort(tag_cmp, lambda tag_widget: tag_widget.translated)
+ tag_widgets = sorted(TagWidget(t, attr, focus_att)
+ for t in message.get_tags())
for tag_widget in tag_widgets:
if not tag_widget.hidden:
cols.append(('fixed', tag_widget.width(), tag_widget))