docutil/dochtml.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 06 Oct 2017 17:52:34 +0300
changeset 1850 614396cbffbf
parent 1838 646245c1c0d9
child 1865 0bd5b3099144
permissions -rw-r--r--
fix pylint warning '(unused-import), Unused import connectors'
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
     9
# See COPYING file for copyrights details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    11
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    12
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    13
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    14
# of the License, or (at your option) any later version.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    16
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    19
# GNU General Public License for more details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    21
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    22
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1490
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    25
import subprocess
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    26
import wx
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    27
import wx.html
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
HtmlFrameOpened = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    31
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
def OpenHtmlFrame(self, title, file, size):
1838
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    33
    if title not in HtmlFrameOpened:
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    34
        HtmlFrameOpened.append(title)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    35
        window = HtmlFrame(self, HtmlFrameOpened)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    36
        window.SetTitle(title)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    37
        window.SetHtmlPage(file)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    38
        window.SetClientSize(size)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    39
        window.Show()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    41
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
[ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
EVT_HTML_URL_CLICK = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    45
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
class HtmlWindowUrlClick(wx.PyEvent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
    def __init__(self, linkinfo):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
        wx.PyEvent.__init__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
        self.SetEventType(EVT_HTML_URL_CLICK)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
        self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget())
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    51
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    52
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
class UrlClickHtmlWindow(wx.html.HtmlWindow):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
    """ HTML window that generates and OnLinkClicked event.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
    Use this to avoid having to override HTMLWindow
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
    """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
    def OnLinkClicked(self, linkinfo):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
        wx.PostEvent(self, HtmlWindowUrlClick(linkinfo))
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    60
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
    def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
        if event == HtmlWindowUrlClick:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
            self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
            wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    67
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
class HtmlFrame(wx.Frame):
1838
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    69
    def _init_ctrls(self, prnt):
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    70
        self.SetIcon(prnt.icon)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    71
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    72
1838
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    73
        self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT,
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    74
                                              name='HtmlContent', parent=self, pos=wx.Point(0, 0),
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    75
                                              size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO | wx.html.HW_NO_SELECTION)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    76
        self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
1838
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    78
    def __init__(self, parent, opened):
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    79
        wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame',
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    80
                          parent=parent, pos=wx.Point(320, 231),
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    81
                          size=wx.Size(853, 616),
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    82
                          style=wx.DEFAULT_FRAME_STYLE, title='')
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    83
        self._init_ctrls(parent)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    84
        self.HtmlFrameOpened = opened
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    85
1838
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    86
    def SetHtmlCode(self, htmlcode):
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    87
        self.HtmlContent.SetPage(htmlcode)
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    88
1838
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    89
    def SetHtmlPage(self, htmlpage):
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    90
        self.HtmlContent.LoadPage(htmlpage)
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    91
1838
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    92
    def OnCloseFrame(self, event):
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    93
        self.HtmlFrameOpened.remove(self.GetTitle())
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    94
        event.Skip()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    95
1838
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    96
    def OnLinkClick(self, event):
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    97
        url = event.linkinfo[0]
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    98
        try:
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
    99
            if wx.Platform == '__WXMSW__':
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
   100
                import webbrowser
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
   101
                webbrowser.open(url)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
   102
            elif subprocess.call("firefox %s" % url, shell=True) != 0:
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
   103
                wx.MessageBox("""Firefox browser not found.\nPlease point your browser at :\n%s""" % url)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
   104
        except ImportError:
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1836
diff changeset
   105
            wx.MessageBox('Please point your browser at: %s' % url)