annotate frontends/src/tools/composition.py @ 1661:96ee986dab3c

plugin XEP-0277: added a trigger on data2entry and comments management
author Goffi <goffi@goffi.org>
date Tue, 24 Nov 2015 16:21:18 +0100
parents 069ad98b360d
children d17772b0fe22
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
3
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
4 """
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
1396
069ad98b360d 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 840
diff changeset
6 Copyright (C) 2013, 2014, 2015 Adrien Cossa <souliane@mailoo.org>
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
7
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
11 (at your option) any later version.
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
12
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
17
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
20 """
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
21
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
22 # Map the messages recipient types to their properties.
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
23 RECIPIENT_TYPES = {"To": {"desc": "Direct recipients", "optional": False},
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
24 "Cc": {"desc": "Carbon copies", "optional": True},
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
25 "Bcc": {"desc": "Blind carbon copies", "optional": True}}
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
26
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
27 # Rich text buttons icons and descriptions
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
28 RICH_BUTTONS = {
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
29 "bold": {"tip": "Bold", "icon": "media/icons/dokuwiki/toolbar/16/bold.png"},
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
30 "italic": {"tip": "Italic", "icon": "media/icons/dokuwiki/toolbar/16/italic.png"},
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
31 "underline": {"tip": "Underline", "icon": "media/icons/dokuwiki/toolbar/16/underline.png"},
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
32 "code": {"tip": "Code", "icon": "media/icons/dokuwiki/toolbar/16/mono.png"},
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
33 "strikethrough": {"tip": "Strikethrough", "icon": "media/icons/dokuwiki/toolbar/16/strike.png"},
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
34 "heading": {"tip": "Heading", "icon": "media/icons/dokuwiki/toolbar/16/hequal.png"},
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
35 "numberedlist": {"tip": "Numbered List", "icon": "media/icons/dokuwiki/toolbar/16/ol.png"},
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
36 "list": {"tip": "List", "icon": "media/icons/dokuwiki/toolbar/16/ul.png"},
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
37 "link": {"tip": "Link", "icon": "media/icons/dokuwiki/toolbar/16/linkextern.png"},
840
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
38 "horizontalrule": {"tip": "Horizontal rule", "icon": "media/icons/dokuwiki/toolbar/16/hr.png"},
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
39 "image": {"tip": "Image", "icon": "media/icons/dokuwiki/toolbar/16/image.png"},
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
40 }
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
41
835
c00d90bce252 tools: composition RICH_FORMATS constant has been renamed to RICH_SYNTAXES
souliane <souliane@mailoo.org>
parents: 811
diff changeset
42 # Define here your rich text syntaxes, the key must match the ones used in button.
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
43 # Tupples values must have 3 elements : prefix to the selection or cursor
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
44 # position, sample text to write if the marker is not applied on a selection,
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
45 # suffix to the selection or cursor position.
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
46 # FIXME: must not be hard-coded like this
835
c00d90bce252 tools: composition RICH_FORMATS constant has been renamed to RICH_SYNTAXES
souliane <souliane@mailoo.org>
parents: 811
diff changeset
47 RICH_SYNTAXES = {"markdown": {"bold": ("**", "bold", "**"),
840
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
48 "italic": ("*", "italic", "*"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
49 "code": ("`", "code", "`"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
50 "heading": ("\n# ", "Heading 1", "\n## Heading 2\n"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
51 "link": ("[desc](", "link", ")"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
52 "list": ("\n* ", "item", "\n + subitem\n"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
53 "horizontalrule": ("\n***\n", "", ""),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
54 "image": ("![desc](", "path", ")"),
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
55 },
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
56 "bbcode": {"bold": ("[b]", "bold", "[/b]"),
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
57 "italic": ("[i]", "italic", "[/i]"),
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
58 "underline": ("[u]", "underline", "[/u]"),
840
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
59 "code": ("[code]", "code", "[/code]"),
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
60 "strikethrough": ("[s]", "strikethrough", "[/s]"),
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
61 "link": ("[url=", "link", "]desc[/url]"),
840
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
62 "list": ("\n[list] [*]", "item 1", " [*]item 2 [/list]\n"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
63 "image": ("[img alt=\"desc\]", "path", "[/img]"),
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
64 },
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
65 "dokuwiki": {"bold": ("**", "bold", "**"),
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
66 "italic": ("//", "italic", "//"),
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
67 "underline": ("__", "underline", "__"),
840
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
68 "code": ("<code>", "code", "</code>"),
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
69 "strikethrough": ("<del>", "strikethrough", "</del>"),
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
70 "heading": ("\n==== ", "Heading 1", " ====\n=== Heading 2 ===\n"),
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
71 "link": ("[[", "link", "|desc]]"),
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
72 "list": ("\n * ", "item\n", "\n * subitem\n"),
840
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
73 "horizontalrule": ("\n----\n", "", ""),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
74 "image": ("{{", "path", " |desc}}"),
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
75 },
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
76 "XHTML": {"bold": ("<b>", "bold", "</b>"),
840
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
77 "italic": ("<i>", "italic", "</i>"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
78 "underline": ("<u>", "underline", "</u>"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
79 "code": ("<pre>", "code", "</pre>"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
80 "strikethrough": ("<s>", "strikethrough", "</s>"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
81 "heading": ("\n<h3>", "Heading 1", "</h3>\n<h4>Heading 2</h4>\n"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
82 "link": ("<a href=\"", "link", "\">desc</a>"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
83 "list": ("\n<ul><li>", "item 1", "</li><li>item 2</li></ul>\n"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
84 "horizontalrule": ("\n<hr/>\n", "", ""),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
85 "image": ("<img src=\"", "path", "\" alt=\"desc\"/>"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
86 }
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
87 }
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
88
840
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
89 # Define here the commands that are supported by the WYSIWYG edition.
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
90 # Keys must be the same than the ones used in RICH_SYNTAXES["XHTML"].
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
91 # Values will be used to call execCommand(cmd, False, arg), they can be:
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
92 # - a string used for cmd and arg is assumed empty
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
93 # - a tuple (cmd, prompt, arg) with cmd the name of the command,
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
94 # prompt the text to display for asking a user input and arg is the
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
95 # value to use directly without asking the user if prompt is empty.
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
96 COMMANDS = {"bold": "bold",
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
97 "italic": "italic",
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
98 "underline": "underline",
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
99 "code": ("formatBlock", "", "pre"),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
100 "strikethrough": "strikeThrough",
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
101 "heading": ("heading", "Please specify the heading level (h1, h2, h3...)", ""),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
102 "link": ("createLink", "Please specify an URL", ""),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
103 "list": "insertUnorderedList",
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
104 "horizontalrule": "insertHorizontalRule",
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
105 "image": ("insertImage", "Please specify an image path", ""),
58b4568ed4f2 frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents: 835
diff changeset
106 }
691
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
107
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
108 # These values should be equal to the ones in plugin_misc_text_syntaxes
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
109 # FIXME: should the plugin import them from here to avoid duplicity? Importing
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
110 # the plugin's values from here is not possible because Libervia would fail.
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
111 PARAM_KEY_COMPOSITION = "Composition"
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
112 PARAM_NAME_SYNTAX = "Syntax"
481e0f8ae47c tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff changeset
113