[Users] how to reply and run an action

Flavio Leitner fbl at sysclose.org
Tue Dec 11 02:05:57 CET 2012


On Mon, 10 Dec 2012 22:14:13 +0100
Holger Berndt <berndth at gmx.de> wrote:

> On Mo, 10.12.2012 08:59, Flavio Leitner wrote:
> 
> >Looks like the python plugin is the way to go. Is there any
> >example out there that you recommend for me to take a look?
> 
> Basically, you would choose Tools -> Python scripts -> Browse. This
> should open a file browser, where you would navigate to the "main"
> subdirectory. There, you would create a file - let's call it
> "reply-modify". The contents would look somewhat like this:
> 
> #=============8<====================8<===================8<==============
> import subprocess as sp
> 
> # Invoke "Reply" menu item
> clawsmail.get_mainwindow_action_group().get_action("Message/Reply").activate()
> 
> # The last opened ComposeWindow object is accessible as "clawsmail.compose_window"
> # Now, one would typically use PyGTK to modify the message body, which is
> # accessible as GtkTextView in "clawsmail.compose_window.text".
> # Menu items could also be called on the compose window via
> # "clawsmail.compose_window.ui_manager" - but as I said, for some strange reason
> # Claws Mail doesn't seem to put Compose Window Actions there.
> # So, get the body text as a string, use Python commands to operate on it, or
> # call external commands via Python, and write it back.
> body_buffer = clawsmail.compose_window.text.get_buffer()
> old_body = body_buffer.props.text
> proc = sp.Popen(["tr", "[a-z]", "[A-Z]"], stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.STDOUT)
> new_body = proc.communicate(old_body)[0]
> body_buffer.props.text = new_body
> #=============8<====================8<===================8<==============
> 
> (This example calls "tr [a-z] [A-Z]" on the body to convert it to upper
> case.)
> 
> Then you would choose Tools -> Python scripts -> Refresh (or restart
> Claws Mail).
> 
> You could then assign a keyboard shortcut to the script like it's done
> for other menu items in Claws Mail, or you could add the script to your
> toolbar via Configuration -> Preferences -> Toolbars -> Main Window
> (Item type "Plugins").
> 
> >I know python, but I don't know the plugin interface.
> 
> The startup script in the examples directory adds a "Python API
> Documentation" entry in Claws Mail's help menu, which introspects the clawsmail
> module and generates HTML on-the-fly. That might be easier to browse than the
> console view that Mones told you about.

That's a big help. Thank you so much. Unfortunately the code didn't
work as the reply content's window isn't modified by 'tr'.
Any idea?

I have my script ready to work like 'tr', so I am almost there :-)
thanks in advance!
-- 
fbl



More information about the Users mailing list