Skip to content

Commit f98567f

Browse files
committed
upload code
0 parents  commit f98567f

File tree

14 files changed

+2605
-0
lines changed

14 files changed

+2605
-0
lines changed

.vscodeignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.vscode/**
2+
.vscode-test/**
3+
test/**
4+
.gitignore
5+
.yarnrc
6+
vsc-extension-quickstart.md
7+
**/jsconfig.json
8+
**/*.map
9+
**/.eslintrc.json

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Change Log

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# QSSEditor

data/qss.json

Lines changed: 1979 additions & 0 deletions
Large diffs are not rendered by default.

images/designer.png

4.07 KB
Loading

package.json

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"name": "qsseditor",
3+
"displayName": "QSSEditor",
4+
"description": "Qt StyleSheet Editor",
5+
"version": "0.0.1",
6+
"publisher": "Irony",
7+
"author": {
8+
"name": "Irony",
9+
"url": "https://pyqt.site"
10+
},
11+
"engines": {
12+
"vscode": "^1.67.0"
13+
},
14+
"keywords": [
15+
"qss",
16+
"qt",
17+
"designer",
18+
"style sheet"
19+
],
20+
"categories": [
21+
"Programming Languages",
22+
"Other"
23+
],
24+
"icon": "./images/designer.png",
25+
"repository": {
26+
"type": "git",
27+
"url": "https://github.com/PyQt5/DesignerPlugin.git"
28+
},
29+
"homepage": "https://github.com/PyQt5/DesignerPlugin.git",
30+
"activationEvents": [
31+
"onLanguage:css",
32+
"onCommand:qsseditor.applyStyle",
33+
"onCommand:qsseditor.setPort"
34+
],
35+
"main": "./src/extension.js",
36+
"contributes": {
37+
"css": {
38+
"customData": [
39+
"./data/qss.json"
40+
]
41+
},
42+
"languages": [{
43+
"id": "css",
44+
"aliases": [
45+
"CSS",
46+
"QSS"
47+
],
48+
"extensions": [
49+
".qss",
50+
".css",
51+
".style"
52+
],
53+
"filenames": [
54+
".css",
55+
".qss",
56+
".style"
57+
]
58+
}],
59+
"commands": [{
60+
"command": "qsseditor.applyStyle",
61+
"title": "%qsseditor.applyStyle.title%"
62+
},
63+
{
64+
"command": "qsseditor.setPort",
65+
"title": "%qsseditor.setPort.title%"
66+
}
67+
],
68+
"keybindings": [{
69+
"command": "qsseditor.applyStyle",
70+
"key": "Shift+Alt+P",
71+
"when": "editorTextFocus && editorLangId =~ /^css$|^qss$/"
72+
}],
73+
"menus": {
74+
"editor/context": [{
75+
"when": "editorTextFocus && editorLangId =~ /^css$|^qss$/",
76+
"command": "qsseditor.applyStyle",
77+
"group": "navigation"
78+
}]
79+
},
80+
"configuration": {
81+
"type": "object",
82+
"title": "QSSEditor Configure",
83+
"properties": {
84+
"qsseditor.autoApply": {
85+
"type": "boolean",
86+
"default": true,
87+
"description": "Auto apply style sheet"
88+
},
89+
"qsseditor.serverPort": {
90+
"type": "integer",
91+
"default": 61052,
92+
"minimum": 1,
93+
"maximum": 65535,
94+
"description": "DesignerProxy Port"
95+
}
96+
}
97+
}
98+
},
99+
"scripts": {
100+
"vscode:prepublish": "cd scripts && python generate_data.py",
101+
"lint": "eslint .",
102+
"pretest": "npm run lint",
103+
"test": "node ./test/runTest.js"
104+
},
105+
"devDependencies": {
106+
"@types/glob": "^7.2.0",
107+
"@types/mocha": "^9.1.1",
108+
"@types/node": "14.x",
109+
"@types/vscode": "^1.67.0",
110+
"@vscode/test-electron": "^2.1.3",
111+
"eslint": "^8.14.0",
112+
"glob": "^8.0.1",
113+
"mocha": "^9.2.2",
114+
"typescript": "^4.6.4",
115+
"vscode": "^1.1.37"
116+
},
117+
"dependencies": {
118+
"rpc-websockets": "^7.4.18"
119+
}
120+
}

package.nls.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"qsseditor.applyStyle.title": "Apply Style",
3+
"qsseditor.setPort.title": "Set Connect DesignerProxy Port"
4+
}

package.nls.zh-cn.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"qsseditor.applyStyle.title": "应用样式",
3+
"qsseditor.setPort.title": "设置连接DesignerProxy的端口"
4+
}

package.nls.zh-tw.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"qsseditor.applyStyle.title": "應用樣式",
3+
"qsseditor.setPort.title": "設定連接DesignerProxy的端口"
4+
}

scripts/generate_data.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on 2022/05/19
5+
@author: Irony
6+
@site: https://pyqt.site https://github.com/PyQt5
7+
@email: 892768447@qq.com
8+
@file: generate_data.py
9+
@description:
10+
"""
11+
12+
from collections import OrderedDict
13+
import re
14+
import json
15+
import requests
16+
from pyquery import PyQuery
17+
18+
g_syntax = {}
19+
20+
21+
def dealwith_pre(html):
22+
for code in re.findall(r'(<pre.*?</pre>)', html, re.S):
23+
html = html.replace(
24+
code,
25+
str('```\n{}\n```'.format(
26+
PyQuery(code).text(squash_space=False).strip())))
27+
return html
28+
29+
30+
def dealwith_a(html):
31+
for a in re.findall(r'(<a href="(.*?)">(.*?)</a>)', html, re.S):
32+
url = a[1].strip()
33+
html = html.replace(
34+
a[0], '[{}]({})'.format(
35+
a[2].strip(), url if url.startswith('http') else
36+
'https://doc.qt.io/qt-5/{}'.format(url)))
37+
return html
38+
39+
40+
def generate_desc(html):
41+
"""
42+
生成描述, 支持markdown
43+
44+
@param html: 原始描述内容
45+
@return: 格式化后的描述
46+
"""
47+
html = dealwith_pre(html)
48+
html = dealwith_a(html)
49+
return PyQuery(html).text(squash_space=False).strip()
50+
51+
52+
def generate_types(doc):
53+
"""
54+
生成属性类型节点
55+
"""
56+
for tr in doc('.table:nth-child(20) tr[class!=qt-style]').items():
57+
tds = list(tr('td').items())
58+
g_syntax[tds[0].text()] = {
59+
'url':
60+
'https://doc.qt.io/qt-5/stylesheet-reference.html#{}'.format(
61+
tds[0].text().lower().replace(' ', '-')),
62+
'syntax':
63+
PyQuery(tds[1].html()).text().strip(),
64+
'desc':
65+
generate_desc(tds[2].html())
66+
}
67+
68+
69+
def generate_props(doc):
70+
"""
71+
生成属性节点
72+
"""
73+
properties = []
74+
for tr in doc('.table:nth-child(10) tr[class!=qt-style]').items():
75+
tds = list(tr('td').items())
76+
77+
prop = OrderedDict()
78+
79+
desc = OrderedDict()
80+
desc['kind'] = 'markdown'
81+
desc['value'] = generate_desc(tds[2].html())
82+
83+
references = []
84+
syntax = tds[1].text().strip()
85+
if syntax in g_syntax:
86+
d = OrderedDict()
87+
d['name'] = syntax
88+
d['url'] = g_syntax[syntax]['url']
89+
references.append(d)
90+
91+
desc['value'] = desc['value'] + '\n\n`{}`:\n{}'.format(
92+
syntax, generate_desc(g_syntax[syntax]['desc']))
93+
94+
d = OrderedDict()
95+
d['name'] = 'list-of-properties'
96+
d['url'] = 'https://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties'
97+
references.append(d)
98+
99+
prop['name'] = tds[0].text().replace('*', '').strip()
100+
prop['description'] = desc
101+
prop['references'] = references
102+
if syntax in g_syntax:
103+
prop['syntax'] = g_syntax[syntax]['syntax']
104+
105+
properties.append(prop)
106+
return properties
107+
108+
109+
def generate_pseudoClasses(doc):
110+
pseudoClasses = []
111+
for tr in doc('.table:nth-child(24) tr[class!=qt-style]').items():
112+
tds = list(tr('td').items())
113+
pseudo = OrderedDict()
114+
pseudo['name'] = tds[0].text()
115+
pseudo['description'] = generate_desc(tds[1].html())
116+
pseudoClasses.append(pseudo)
117+
return pseudoClasses
118+
119+
120+
def generate_pseudoElements(doc):
121+
pseudoElements = []
122+
for tr in doc('.table:nth-child(29) tr[class!=qt-style]').items():
123+
tds = list(tr('td').items())
124+
pseudo = OrderedDict()
125+
pseudo['name'] = tds[0].text()
126+
pseudo['description'] = generate_desc(tds[1].html())
127+
pseudoElements.append(pseudo)
128+
return pseudoElements
129+
130+
131+
if __name__ == '__main__':
132+
print('generate qss.json started')
133+
doc = PyQuery(
134+
requests.get(
135+
'https://doc.qt.io/qt-5/stylesheet-reference.html').content)
136+
data = OrderedDict()
137+
data['version'] = 1.1
138+
generate_types(doc)
139+
data['properties'] = generate_props(doc)
140+
data['pseudoClasses'] = generate_pseudoClasses(doc)
141+
data['pseudoElements'] = generate_pseudoElements(doc)
142+
with open('../data/qss.json', 'wb') as fp:
143+
fp.write(json.dumps(data, indent=4).encode())
144+
print('generate qss.json finished')

0 commit comments

Comments
 (0)