Skip to content

Add togglemimetree command in thread buffer - #894

Closed
lucc wants to merge 6 commits into
pazz:masterfrom
lucc:feature/mime-tree
Closed

lucc wants to merge 6 commits into
pazz:masterfrom
lucc:feature/mime-tree

Conversation

@lucc

@lucc lucc commented Sep 14, 2016

Copy link
Copy Markdown
Collaborator

This is an attempt to implement #862.

The new command :togglemimetree will (similar to :togglesource and friends) change the displayed message. It will toggle between the previous used representation and a text representation of the mime tree.

TODO list (also see #862)

  • implement basic command logic
  • extract a mime tree from the message
  • add nicer tree visualisation (line drawings)
    • nicer indent, formatting and coherence with other ArrowTrees
  • make the mime parts in the tree accessible for other commands (see below)
  • add a command to display a mime part with an external program (mailcap entry)
  • add a command to save a single mime part to disk
  • add a command to pipe a mime part to a shell command

For the line drawing I could use something like https://github.com/jml/tree-format but as we already do display line drawings for the thread tree I suppose there is some code in alot that can maybe help me. @ Everybody: do you know where it might be?

@lucc
lucc force-pushed the feature/mime-tree branch from 87e4e3d to 6073f8e Compare September 14, 2016 07:12
@pazz

pazz commented Sep 14, 2016

Copy link
Copy Markdown
Owner

Quoting Lucas Hoffmann (2016-09-14 08:11:02)

This is an attempt to implement [1]#862.

The new command :togglemimetree will (similar to :togglesource and
friends) change the displayed message. It will toggle between the previous
used representation and a text representation of the mime tree.

TODO list (also see [2]#862)

 * [3][ ] implement basic command logic
 * [4][ ] extract a mime tree from the message
 * [5][ ] add nicer tree visualisation (line drawings)
 * [6][ ] make the mime parts in the tree accessible for other commands
   (see below)
 * [7][ ] add a command to display a mime part with an external program
   (mailcap entry)
 * [8][ ] add a command to save a single mime part to disk
 * [9][ ] add a command to pipe a mime part to a shell command

For the line drawing I could use something like
[10]https://github.com/jml/tree-format but as we already do display line
drawings for the thread tree I suppose there is some code in alot that can
maybe help me. @ Everybody: do you know where it might be?

Alot uses urwidtrees https://github.com/pazz/urwidtrees
for this. The respective code in alot can be found in

alot/widgets/thread.py (defines a Widget tree, equivalent to urwids'
List Walker objects: It provides the widgets displaying nodes)
and
https://github.com/pazz/alot/blob/master/alot/buffers.py#L362

where this is used to create a TreeBox (eq. to urwids' ListBox),
that will render the tree as list.
The arrow magic comes into play by sticking your Tree into an ArrowTree,
which adds some decoration. Docs are here:
https://urwidtrees.readthedocs.io/en/latest/

HTH,
P

@lucc

lucc commented Sep 14, 2016

Copy link
Copy Markdown
Collaborator Author

thanks @pazz for the pointers. I tried to use the trees but until now I failed. See the three last commits for my attempts. Maybe you spot some mistakes. Currently I get this exception

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/luc/vcs/alot-devel/alot/__main__.py", line 194, in <module>
    main()
  File "/home/luc/vcs/alot-devel/alot/__main__.py", line 186, in main
    UI(dbman, cmdstring)
  File "/home/luc/vcs/alot-devel/alot/ui.py", line 92, in __init__
    self.mainloop.run()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 278, in run
    self._run()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 376, in _run
    self.event_loop.run()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 1200, in wrapper
    rval = f(*args,**kargs)
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 1159, in _twisted_idle_callback
    callback()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 564, in entering_idle
    self.draw_screen()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 578, in draw_screen
    canvas = self._topmost_widget.render(self.screen_size, focus=True)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 141, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/decoration.py", line 225, in render
    canv = self._original_widget.render(size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 141, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/container.py", line 1083, in render
    focus and self.focus_part == 'body')
  File "/home/luc/vcs/alot-devel/alot/buffers.py", line 406, in render
    return self.body.render(size, focus)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 141, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 1751, in render
    canv = get_delegate(self).render(size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 141, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/listbox.py", line 457, in render
    (maxcol, maxrow), focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/listbox.py", line 402, in calculate_visible
    next, pos = self.body.get_next( pos )
  File "build/bdist.linux-x86_64/egg/urwidtrees/widgets.py", line 82, in get_next
  File "build/bdist.linux-x86_64/egg/urwidtrees/tree.py", line 109, in next_position
  File "build/bdist.linux-x86_64/egg/urwidtrees/nested.py", line 309, in next_sibling_position
  File "build/bdist.linux-x86_64/egg/urwidtrees/nested.py", line 37, in _sanitize_position
  File "build/bdist.linux-x86_64/egg/urwidtrees/nested.py", line 35, in _sanitize_position
  File "build/bdist.linux-x86_64/egg/urwidtrees/nested.py", line 48, in _lookup_entry
  File "build/bdist.linux-x86_64/egg/urwidtrees/tree.py", line 222, in __getitem__
  File "build/bdist.linux-x86_64/egg/urwidtrees/tree.py", line 210, in _get_node
  File "build/bdist.linux-x86_64/egg/urwidtrees/tree.py", line 222, in __getitem__
  File "build/bdist.linux-x86_64/egg/urwidtrees/tree.py", line 208, in _get_node
  File "build/bdist.linux-x86_64/egg/urwidtrees/tree.py", line 192, in _get_substructure
TypeError: object of type 'int' has no len()

and have to kill -9 alot.

@lucc

lucc commented Sep 17, 2016

Copy link
Copy Markdown
Collaborator Author

@pazz I tried several combinations but I am at loss. Maybe you can give me some pointers? What am I doing wrong?

I create the tree structure and have something like this ('(no filename) [text/plainiso-8859-1, 6K]', None) or

('no filename   multipart/signed, 203K',
 [('no filename   multipart/mixed, 202K',
   [('no filename   text/plainutf-8, 297', None),
    ('no filename   application/pdf, 201K', None)]),
  ('signature.asc   application/pgp-signatureus-ascii, 630', None)])

I then replace all the strings in this structure with the corresponding urwid.Text object.

According to the debugging output I then succed in generating a <urwidtrees.tree.SimpleTree object at 0x7fe398283e50> from that.

But at some later point I get an exception. I think it is during the rendering of the new widgets:

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/luc/vcs/alot-devel/alot/__main__.py", line 194, in <module>
    main()
  File "/home/luc/vcs/alot-devel/alot/__main__.py", line 186, in main
    UI(dbman, cmdstring)
  File "/home/luc/vcs/alot-devel/alot/ui.py", line 92, in __init__
    self.mainloop.run()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 278, in run
    self._run()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 376, in _run
    self.event_loop.run()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 1200, in wrapper
    rval = f(*args,**kargs)
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 1159, in _twisted_idle_callback
    callback()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 564, in entering_idle
    self.draw_screen()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 578, in draw_screen
    canvas = self._topmost_widget.render(self.screen_size, focus=True)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 141, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/decoration.py", line 225, in render
    canv = self._original_widget.render(size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 141, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/container.py", line 1083, in render
    focus and self.focus_part == 'body')
  File "/home/luc/vcs/alot-devel/alot/buffers.py", line 406, in render
    return self.body.render(size, focus)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 141, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 1751, in render
    canv = get_delegate(self).render(size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 141, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/listbox.py", line 457, in render
    (maxcol, maxrow), focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/listbox.py", line 402, in calculate_visible
    next, pos = self.body.get_next( pos )
  File "build/bdist.linux-x86_64/egg/urwidtrees/widgets.py", line 82, in get_next
  File "build/bdist.linux-x86_64/egg/urwidtrees/tree.py", line 109, in next_position
  File "build/bdist.linux-x86_64/egg/urwidtrees/nested.py", line 309, in next_sibling_position
  File "build/bdist.linux-x86_64/egg/urwidtrees/nested.py", line 37, in _sanitize_position
  File "build/bdist.linux-x86_64/egg/urwidtrees/nested.py", line 35, in _sanitize_position
  File "build/bdist.linux-x86_64/egg/urwidtrees/nested.py", line 48, in _lookup_entry
  File "build/bdist.linux-x86_64/egg/urwidtrees/tree.py", line 222, in __getitem__
  File "build/bdist.linux-x86_64/egg/urwidtrees/tree.py", line 210, in _get_node
TypeError: 'Text' object does not support indexing

@pazz

pazz commented Oct 17, 2016

Copy link
Copy Markdown
Owner

I'm not sure without looking at your code but I suspect that the list structure given to your SimpleTree is broken:
It looks like your are trying to access a Text widget, but instead of finding a pair (Text('la', None)
to denote that it's a leaf, you directly find the Text. Try to inspect your SimpleTree..

@lucc lucc mentioned this pull request Dec 2, 2016
@lucc
lucc force-pushed the feature/mime-tree branch from 87fb810 to 6bdae67 Compare December 9, 2016 16:54
@lucc lucc added the feature label Dec 10, 2016
@lucc
lucc force-pushed the feature/mime-tree branch 3 times, most recently from 7d6a9a7 to 167ba93 Compare December 15, 2016 22:42
@lucc
lucc force-pushed the feature/mime-tree branch 2 times, most recently from ba53094 to 440c880 Compare December 27, 2016 21:13
@lucc

lucc commented Dec 27, 2016

Copy link
Copy Markdown
Collaborator Author

I am slowly getting there. The first stack traces are gone, now I have to debug some ugly misbehavior when I toggle the mimetree for several messages and then move over the message border to the next message with the arrow key: the display is messed up and the focus is stuck in a loop.

@lucc
lucc force-pushed the feature/mime-tree branch 2 times, most recently from 6ba3a18 to b9e42af Compare December 27, 2016 23:31
@lucc
lucc force-pushed the feature/mime-tree branch from b9e42af to a5c456e Compare January 13, 2017 00:00
@lucc
lucc force-pushed the feature/mime-tree branch from a5c456e to f3bd425 Compare January 20, 2017 10:44
@lucc
lucc force-pushed the feature/mime-tree branch from f3bd425 to 8a9a384 Compare January 27, 2017 12:59
@lucc
lucc force-pushed the feature/mime-tree branch 2 times, most recently from 5449d9e to 1cd1c46 Compare June 3, 2017 18:39
@lucc

lucc commented Jun 3, 2017

Copy link
Copy Markdown
Collaborator Author

@pazz I am sorry to bother you but I might need some help from you again to return to this PR.

Currently I can display a mime tree for a message and return to the text view just fine. There is one specific bug. It needs

  1. a thread with more than one message
  2. a message with more than one mime part which is not a leaf node in the thread (it gets more interesting but more complicated to explain if there are "next siblings" for one of the ancestors of the message in question)

The bug:

  1. :togglemimetree on that message
  2. :move next or :move down (arrow key) to the next message
  3. you should be now be caught in a broken message tree. It is a kind of tree of all the messages that where displayed below the message one just moved into. It is hard to describe so I will try to supply screenshots.
  4. one can move {up,down} through that "subtree" but at the top one will loop back to the lowest representation of the message that was displayed on the screen where one was about to go.
  5. One can move {previous,first} or bclose to get out of this.

Screenshot 1 after step 1, shot 2 after step 2.
2017-06-03-211747_1366x768_scrot
2017-06-03-211753_1366x768_scrot

lucc added 5 commits August 8, 2017 04:51
The command is implemented analogous to togglesource and similar commands.
But this commit only contains the toggleing logic and no generation of actual
mime trees.
Only minimal information and no indenting is shown until now.
@meskio

meskio commented Jun 1, 2020

Copy link
Copy Markdown
Contributor

I belive #1480 covers already the content of this pull-req and it can be closed. Isn't it?

@lucc lucc closed this Jun 1, 2020
@lucc
lucc deleted the feature/mime-tree branch June 1, 2020 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants