ProjectWeb/Html5ToJsConverter.py

branch
eric7
changeset 38
6a12561fc0b5
parent 35
a3f1dcf94fe4
child 40
a9b17341d181
equal deleted inserted replaced
37:01822a402c97 38:6a12561fc0b5
10 import os 10 import os
11 import re 11 import re
12 import datetime 12 import datetime
13 import getpass 13 import getpass
14 14
15 from PyQt5.QtCore import QObject 15 from PyQt6.QtCore import QObject
16 from PyQt5.QtWidgets import QDialog 16 from PyQt6.QtWidgets import QDialog
17 17
18 from .Html5ToJsConverterParameterDialog import ( 18 from .Html5ToJsConverterParameterDialog import (
19 Html5ToJsConverterParameterDialog 19 Html5ToJsConverterParameterDialog
20 ) 20 )
21 21
32 32
33 def __init__(self, html, parent=None): 33 def __init__(self, html, parent=None):
34 """ 34 """
35 Constructor 35 Constructor
36 36
37 @param html HTML text to be converted (string) 37 @param html HTML text to be converted
38 @param parent reference to the parent object (QObject) 38 @type str
39 @param parent reference to the parent object
40 @type QObject
39 """ 41 """
40 super().__init__(parent) 42 super().__init__(parent)
41 43
42 self.__html = html 44 self.__html = html
43 45
44 def getJavaScript(self): 46 def getJavaScript(self):
45 """ 47 """
46 Public method to get the converted JavaScript text. 48 Public method to get the converted JavaScript text.
47 49
48 @return JavaScript text (string) 50 @return JavaScript text
51 @rtype str
49 """ 52 """
50 dlg = Html5ToJsConverterParameterDialog() 53 dlg = Html5ToJsConverterParameterDialog()
51 if dlg.exec() == QDialog.Accepted: 54 if dlg.exec() == QDialog.DialogCode.Accepted:
52 indentation, scriptTags = dlg.getData() 55 indentation, scriptTags = dlg.getData()
53 56
54 self.__createSoup() 57 self.__createSoup()
55 58
56 alreadyDone = list(self.TagsToIgnore) 59 alreadyDone = list(self.TagsToIgnore)
131 def __getClasses(self): 134 def __getClasses(self):
132 """ 135 """
133 Private method to extract all classes of the HTML text. 136 Private method to extract all classes of the HTML text.
134 137
135 @return list of tuples containing the tag name and its classes 138 @return list of tuples containing the tag name and its classes
136 as a blank separated string (list of tuples of two strings) 139 as a blank separated string
140 @rtype list of tuples of (str, str)
137 """ 141 """
138 classes = [(t.name, " ".join(t["class"])) for t in 142 classes = [(t.name, " ".join(t["class"])) for t in
139 self.__soup.find_all(True, {"class": True})] 143 self.__soup.find_all(True, {"class": True})]
140 return sorted(list(set(classes))) 144 return sorted(list(set(classes)))
141 145
142 def __getIds(self): 146 def __getIds(self):
143 """ 147 """
144 Private method to extract all IDs of the HTML text. 148 Private method to extract all IDs of the HTML text.
145 149
146 @return list of tuples containing the tag name and its ID 150 @return list of tuples containing the tag name and its ID
147 (list of tuples of two strings) 151 @rtype list of tuples of (str, str)
148 """ 152 """
149 ids = [(t.name, t["id"]) for t in 153 ids = [(t.name, t["id"]) for t in
150 self.__soup.find_all(True, {"id": True})] 154 self.__soup.find_all(True, {"id": True})]
151 return sorted(list(set(ids))) 155 return sorted(list(set(ids)))

eric ide

mercurial