PluginProjectWeb.py

Thu, 30 Dec 2021 11:20:03 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 30 Dec 2021 11:20:03 +0100
branch
eric7
changeset 40
a9b17341d181
parent 38
6a12561fc0b5
child 41
836c696f9565
permissions
-rw-r--r--

Updated copyright for 2022.

1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
1 # -*- coding: utf-8 -*-
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
2
40
a9b17341d181 Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 38
diff changeset
3 # Copyright (c) 2014 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
4 #
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
5
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
6 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
7 Module implementing the Web project plugin.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
8 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
9
35
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
10 import contextlib
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
11 import os
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
12
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
13 from PyQt6.QtCore import QObject, QTranslator
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
14 from PyQt6.QtWidgets import QMenu
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
15
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
16 from EricWidgets.EricApplication import ericApp
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
17
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
18 import Preferences
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
19
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
20 try:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
21 from bs4 import BeautifulSoup # __IGNORE_EXCEPTION__
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
22 BeautifulSoupAvailable = True
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
23 except ImportError:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
24 BeautifulSoup = None
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
25 BeautifulSoupAvailable = False
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
26
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
27 # Start-Of-Header
17
ea6168970971 Corrected the name header variable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 15
diff changeset
28 name = "Generic Web Project Plug-in"
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
29 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
30 autoactivate = True
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
31 deactivateable = True
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
32 version = "1.0.0"
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
33 className = "ProjectWebPlugin"
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
34 packageName = "ProjectWeb"
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
35 shortDescription = "Support for Web projects and web related tools."
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
36 longDescription = (
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
37 """This plug-in provides support for ordinary web projects and some web"""
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
38 """ related tools.\n\nIt uses BeautifulSoup4 for some of its"""
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
39 """ functionality."""
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
40 )
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
41 needsRestart = False
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
42 pyqtApi = 2
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
43 # End-Of-Header
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
44
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
45 error = ""
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
46
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
47
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
48 class ProjectWebPlugin(QObject):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
49 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
50 Class implementing the Web project plugin.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
51 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
52 def __init__(self, ui):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
53 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
54 Constructor
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
55
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
56 @param ui reference to the user interface object
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
57 @type UserInterface
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
58 """
35
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
59 super().__init__(ui)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
60 self.__ui = ui
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
61 self.__initialize()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
62
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
63 self.__translator = None
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
64 self.__loadTranslator()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
65
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
66 self.__initMenu()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
67
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
68 def __initialize(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
69 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
70 Private slot to (re)initialize the plugin.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
71 """
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
72 self.__ericProject = ericApp().getObject("Project")
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
73
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
74 self.__editors = {}
12
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
75 self.__mainActions = []
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
76
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
77 def activate(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
78 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
79 Public method to activate this plugin.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
80
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
81 @return tuple of None and activation status
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
82 @rtype tuple of (None, bool)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
83 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
84 global error
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
85 error = "" # clear previous error
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
86
8
ac63923ca45b Prepared first development release.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
87 # it is not registered for a specific programming language
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
88 self.__ericProject.registerProjectType(
8
ac63923ca45b Prepared first development release.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
89 "Web", self.tr("Web"),
ac63923ca45b Prepared first development release.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
90 self.fileTypesCallback)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
91
30
38092622e612 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 29
diff changeset
92 from Project.ProjectBrowser import (
38092622e612 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 29
diff changeset
93 SourcesBrowserFlag, FormsBrowserFlag, OthersBrowserFlag
38092622e612 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 29
diff changeset
94 )
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
95 Preferences.setProjectBrowserFlagsDefault(
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
96 "Web",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
97 SourcesBrowserFlag | FormsBrowserFlag | OthersBrowserFlag,
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
98 )
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
99
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
100 self.__ui.showMenu.connect(self.__populateMenu)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
101
12
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
102 menu = self.__ui.getMenu("plugin_tools")
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
103 if menu is not None:
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
104 if not menu.isEmpty():
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
105 act = menu.addSeparator()
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
106 self.__mainActions.append(act)
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
107 act = menu.addMenu(self.__menu)
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
108 self.__mainActions.append(act)
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
109
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
110 ericApp().getObject("ViewManager").editorOpenedEd.connect(
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
111 self.__editorOpened)
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
112 ericApp().getObject("ViewManager").editorClosedEd.connect(
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
113 self.__editorClosed)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
114
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
115 for editor in ericApp().getObject("ViewManager").getOpenEditors():
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
116 self.__editorOpened(editor)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
117
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
118 return None, True
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
119
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
120 def deactivate(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
121 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
122 Public method to deactivate this plugin.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
123 """
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
124 self.__ericProject.unregisterProjectType("Web")
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
125
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
126 self.__ui.showMenu.disconnect(self.__populateMenu)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
127
12
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
128 menu = self.__ui.getMenu("plugin_tools")
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
129 if menu is not None:
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
130 for act in self.__mainActions:
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
131 menu.removeAction(act)
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
132 self.__mainActions = []
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
133
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
134 ericApp().getObject("ViewManager").editorOpenedEd.disconnect(
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
135 self.__editorOpened)
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
136 ericApp().getObject("ViewManager").editorClosedEd.disconnect(
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
137 self.__editorClosed)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
138
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
139 for editor, acts in self.__editors.items():
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
140 editor.showMenu.disconnect(self.__editorShowMenu)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
141 menu = editor.getMenu("Tools")
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
142 if menu is not None:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
143 for act in acts:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
144 menu.removeAction(act)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
145
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
146 self.__initialize()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
147
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
148 def __loadTranslator(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
149 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
150 Private method to load the translation file.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
151 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
152 if self.__ui is not None:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
153 loc = self.__ui.getLocale()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
154 if loc and loc != "C":
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
155 locale_dir = os.path.join(
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
156 os.path.dirname(__file__), "ProjectWeb", "i18n")
22
0da9392cdde8 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 21
diff changeset
157 translation = "web_{0}".format(loc)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
158 translator = QTranslator(None)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
159 loaded = translator.load(translation, locale_dir)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
160 if loaded:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
161 self.__translator = translator
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
162 ericApp().installTranslator(self.__translator)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
163 else:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
164 print("Warning: translation file '{0}' could not be"
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
165 " loaded.".format(translation))
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
166 print("Using default.")
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
167
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
168 def fileTypesCallback(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
169 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
170 Public method to get the filetype associations of the Web project type.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
171
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
172 @return dictionary with file type associations
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
173 @rtype dict
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
174 """
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
175 if self.__ericProject.getProjectType() == "Web":
30
38092622e612 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 29
diff changeset
176 return {
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
177 "*.html": "FORMS",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
178 "*.htm": "FORMS",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
179 "*.js": "SOURCES",
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
180 }
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
181 else:
30
38092622e612 Removed support for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 29
diff changeset
182 return {}
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
183
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
184 def __initMenu(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
185 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
186 Private method to initialize the web tools menu.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
187 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
188 self.__menu = QMenu(self.tr("Web"))
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
189
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
190 self.__html5ToCss3Act = self.__menu.addAction(self.tr(
7
e6fbd4a7484d Some small corrections, added source docu, translations and the other supporting files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
191 "HTML5 to CSS3"), self.__html5ToCss3)
3
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
192 self.__html5ToJsAct = self.__menu.addAction(self.tr(
7
e6fbd4a7484d Some small corrections, added source docu, translations and the other supporting files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
193 "HTML5 to JavaScript"), self.__html5ToJs)
5
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
194 self.__menu.addSeparator()
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
195 self.__html5PrettifyAct = self.__menu.addAction(self.tr(
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
196 "Prettify HTML"), self.__html5Prettify)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
197
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
198 self.__menu.aboutToShow.connect(self.__menuAboutToShow)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
199
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
200 def __menuAboutToShow(self):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
201 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
202 Private slot to prepare the menu before it is shown.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
203 """
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
204 editor = ericApp().getObject("ViewManager").activeWindow()
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
205 selectionAvailable = bool(editor and editor.selectedText() != "")
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
206 isHtml = bool(editor and
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
207 editor.getLanguage().lower().startswith("html"))
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
208
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
209 self.__html5ToCss3Act.setEnabled(
5
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
210 selectionAvailable and BeautifulSoupAvailable and isHtml)
3
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
211 self.__html5ToJsAct.setEnabled(
5
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
212 selectionAvailable and BeautifulSoupAvailable and isHtml)
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
213 self.__html5PrettifyAct.setEnabled(
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
214 BeautifulSoupAvailable and isHtml)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
215
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
216 def __populateMenu(self, name, menu):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
217 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
218 Private slot to populate the tools menu with our entries.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
219
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
220 @param name name of the menu
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
221 @type str
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
222 @param menu reference to the menu to be populated
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
223 @type QMenu
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
224 """
12
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
225 if name not in ["Tools", "PluginTools"]:
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
226 return
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
227
12
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
228 if name == "Tools":
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
229 if not menu.isEmpty():
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
230 menu.addSeparator()
231a6fbd6f0f Adaptation for the new plug-in tools menu handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
231 menu.addMenu(self.__menu)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
232
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
233 def __editorOpened(self, editor):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
234 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
235 Private slot called, when a new editor was opened.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
236
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
237 @param editor reference to the new editor
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
238 @type Editor
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
239 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
240 menu = editor.getMenu("Tools")
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
241 if menu is not None:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
242 self.__editors[editor] = []
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
243 if not menu.isEmpty():
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
244 act = menu.addSeparator()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
245 self.__editors[editor].append(act)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
246 act = menu.addMenu(self.__menu)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
247 self.__editors[editor].append(act)
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
248 editor.showMenu.connect(self.__editorShowMenu)
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
249
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
250 def __editorClosed(self, editor):
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
251 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
252 Private slot called, when an editor was closed.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
253
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
254 @param editor reference to the editor
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
255 @type Editor
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
256 """
35
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
257 with contextlib.suppress(KeyError):
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
258 del self.__editors[editor]
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
259
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
260 def __editorShowMenu(self, menuName, menu, editor):
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
261 """
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
262 Private slot called, when the the editor context menu or a submenu is
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
263 about to be shown.
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
264
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
265 @param menuName name of the menu to be shown
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
266 @type str
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
267 @param menu reference to the menu
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
268 @type QMenu
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
269 @param editor reference to the editor
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
270 @type Editor
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
271 """
35
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
272 if (
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
273 menuName == "Tools" and
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
274 self.__menu.menuAction() not in menu.actions()
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
275 ):
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
276 # Re-add our menu
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
277 self.__editors[editor] = []
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
278 if not menu.isEmpty():
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
279 act = menu.addSeparator()
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
280 self.__editors[editor].append(act)
35
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
281 act = menu.addMenu(self.__menu)
a3f1dcf94fe4 Implemented some code simplifications.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 34
diff changeset
282 self.__editors[editor].append(act)
6
a1600fa29542 A few fixes and code style corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5
diff changeset
283
7
e6fbd4a7484d Some small corrections, added source docu, translations and the other supporting files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
284 def __html5ToCss3(self):
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
285 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
286 Private slot handling the HTML5 to CSS3 conversion.
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
287 """
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
288 from ProjectWeb.Html5ToCss3Converter import Html5ToCss3Converter
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
289 vm = ericApp().getObject("ViewManager")
1
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
290 editor = vm.activeWindow()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
291 html = editor.selectedText()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
292
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
293 converter = Html5ToCss3Converter(html)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
294 css3 = converter.getCss3()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
295
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
296 if css3:
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
297 vm.newEditor()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
298 newEditor = vm.activeWindow()
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
299 newEditor.setText(css3)
e3a92a671aa5 Added the 'Web' project type and the HTML5 to CSS3 converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
300 newEditor.setLanguage("dummy.css")
3
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
301
7
e6fbd4a7484d Some small corrections, added source docu, translations and the other supporting files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
302 def __html5ToJs(self):
3
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
303 """
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
304 Private slot handling the HTML5 to JavaScript conversion.
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
305 """
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
306 from ProjectWeb.Html5ToJsConverter import Html5ToJsConverter
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
307 vm = ericApp().getObject("ViewManager")
3
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
308 editor = vm.activeWindow()
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
309 html = editor.selectedText()
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
310
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
311 converter = Html5ToJsConverter(html)
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
312 js = converter.getJavaScript()
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
313
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
314 if js:
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
315 vm.newEditor()
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
316 newEditor = vm.activeWindow()
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
317 newEditor.setText(js)
e478a359e1fb Added the HTML5 to JavaScript converter.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
318 newEditor.setLanguage("dummy.js")
5
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
319
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
320 def __html5Prettify(self):
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
321 """
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
322 Private slot handling the Prettify HTML action.
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
323 """
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
324 from ProjectWeb.Html5Prettifier import Html5Prettifier
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
325 editor = ericApp().getObject("ViewManager").activeWindow()
5
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
326 html = editor.text()
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
327
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
328 prettifier = Html5Prettifier(html)
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
329 newHtml = prettifier.getPrettifiedHtml()
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
330
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
331 if newHtml and newHtml != html:
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
332 cursorLine, cursorIndex = editor.getCursorPosition()
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
333
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
334 editor.beginUndoAction()
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
335 editor.selectAll()
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
336 editor.replaceSelectedText(newHtml)
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
337 editor.endUndoAction()
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
338
31bc1ef6f624 Added the HTML prettifier.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4
diff changeset
339 editor.setCursorPosition(cursorLine, cursorIndex)
22
0da9392cdde8 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 21
diff changeset
340
38
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
341
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
342 def installDependencies(pipInstall):
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
343 """
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
344 Function to install dependencies of this plug-in.
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
345
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
346 @param pipInstall function to be called with a list of package names.
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
347 @type function
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
348 """
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
349 try:
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
350 import bs4 # __IGNORE_WARNING__
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
351 except ImportError:
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
352 pipInstall(["beautifulsoup4"])
6a12561fc0b5 Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
353
22
0da9392cdde8 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 21
diff changeset
354 #
0da9392cdde8 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 21
diff changeset
355 # eflag: noqa = M801

eric ide

mercurial