Skip to content

Commit d537126

Browse files
committed
First functional version
1 parent 1924427 commit d537126

File tree

5 files changed

+382
-0
lines changed

5 files changed

+382
-0
lines changed

.gitignore

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
#################
2+
## Eclipse
3+
#################
4+
5+
*.pydevproject
6+
.project
7+
.metadata
8+
bin/
9+
tmp/
10+
*.tmp
11+
*.bak
12+
*.swp
13+
*~.nib
14+
local.properties
15+
.classpath
16+
.settings/
17+
.loadpath
18+
19+
# External tool builders
20+
.externalToolBuilders/
21+
22+
# Locally stored "Eclipse launch configurations"
23+
*.launch
24+
25+
# CDT-specific
26+
.cproject
27+
28+
# PDT-specific
29+
.buildpath
30+
31+
32+
#################
33+
## Visual Studio
34+
#################
35+
36+
## Ignore Visual Studio temporary files, build results, and
37+
## files generated by popular Visual Studio add-ons.
38+
39+
# User-specific files
40+
*.suo
41+
*.user
42+
*.sln.docstates
43+
44+
# Build results
45+
46+
[Dd]ebug/
47+
[Rr]elease/
48+
x64/
49+
build/
50+
[Bb]in/
51+
[Oo]bj/
52+
53+
# MSTest test Results
54+
[Tt]est[Rr]esult*/
55+
[Bb]uild[Ll]og.*
56+
57+
*_i.c
58+
*_p.c
59+
*.ilk
60+
*.meta
61+
*.obj
62+
*.pch
63+
*.pdb
64+
*.pgc
65+
*.pgd
66+
*.rsp
67+
*.sbr
68+
*.tlb
69+
*.tli
70+
*.tlh
71+
*.tmp
72+
*.tmp_proj
73+
*.log
74+
*.vspscc
75+
*.vssscc
76+
.builds
77+
*.pidb
78+
*.log
79+
*.scc
80+
81+
# Visual C++ cache files
82+
ipch/
83+
*.aps
84+
*.ncb
85+
*.opensdf
86+
*.sdf
87+
*.cachefile
88+
89+
# Visual Studio profiler
90+
*.psess
91+
*.vsp
92+
*.vspx
93+
94+
# Guidance Automation Toolkit
95+
*.gpState
96+
97+
# ReSharper is a .NET coding add-in
98+
_ReSharper*/
99+
*.[Rr]e[Ss]harper
100+
101+
# TeamCity is a build add-in
102+
_TeamCity*
103+
104+
# DotCover is a Code Coverage Tool
105+
*.dotCover
106+
107+
# NCrunch
108+
*.ncrunch*
109+
.*crunch*.local.xml
110+
111+
# Installshield output folder
112+
[Ee]xpress/
113+
114+
# DocProject is a documentation generator add-in
115+
DocProject/buildhelp/
116+
DocProject/Help/*.HxT
117+
DocProject/Help/*.HxC
118+
DocProject/Help/*.hhc
119+
DocProject/Help/*.hhk
120+
DocProject/Help/*.hhp
121+
DocProject/Help/Html2
122+
DocProject/Help/html
123+
124+
# Click-Once directory
125+
publish/
126+
127+
# Publish Web Output
128+
*.Publish.xml
129+
*.pubxml
130+
*.publishproj
131+
132+
# NuGet Packages Directory
133+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
134+
#packages/
135+
136+
# Windows Azure Build Output
137+
csx
138+
*.build.csdef
139+
140+
# Windows Store app package directory
141+
AppPackages/
142+
143+
# Others
144+
sql/
145+
*.Cache
146+
ClientBin/
147+
[Ss]tyle[Cc]op.*
148+
~$*
149+
*~
150+
*.dbmdl
151+
*.[Pp]ublish.xml
152+
*.pfx
153+
*.publishsettings
154+
155+
# RIA/Silverlight projects
156+
Generated_Code/
157+
158+
# Backup & report files from converting an old project file to a newer
159+
# Visual Studio version. Backup files are not needed, because we have git ;-)
160+
_UpgradeReport_Files/
161+
Backup*/
162+
UpgradeLog*.XML
163+
UpgradeLog*.htm
164+
165+
# SQL Server files
166+
App_Data/*.mdf
167+
App_Data/*.ldf
168+
169+
#############
170+
## Windows detritus
171+
#############
172+
173+
# Windows image file caches
174+
Thumbs.db
175+
ehthumbs.db
176+
177+
# Folder config file
178+
Desktop.ini
179+
180+
# Recycle Bin used on file shares
181+
$RECYCLE.BIN/
182+
183+
# Mac crap
184+
.DS_Store
185+
186+
187+
#############
188+
## Python
189+
#############
190+
191+
*.py[cod]
192+
193+
# Packages
194+
*.egg
195+
*.egg-info
196+
dist/
197+
build/
198+
eggs/
199+
parts/
200+
var/
201+
sdist/
202+
develop-eggs/
203+
.installed.cfg
204+
205+
# Installer logs
206+
pip-log.txt
207+
208+
# Unit test / coverage reports
209+
.coverage
210+
.tox
211+
212+
#Translations
213+
*.mo
214+
215+
#Mr Developer
216+
.mr.developer.cfg
217+
218+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
219+
220+
*.iml
221+
222+
## Directory-based project format:
223+
.idea/
224+
# if you remove the above rule, at least ignore the following:
225+
226+
# User-specific stuff:
227+
# .idea/workspace.xml
228+
# .idea/tasks.xml
229+
# .idea/dictionaries
230+
231+
# Sensitive or high-churn files:
232+
# .idea/dataSources.ids
233+
# .idea/dataSources.xml
234+
# .idea/sqlDataSources.xml
235+
# .idea/dynamic.xml
236+
# .idea/uiDesigner.xml
237+
238+
# Gradle:
239+
# .idea/gradle.xml
240+
# .idea/libraries
241+
242+
# Mongo Explorer plugin:
243+
# .idea/mongoSettings.xml
244+
245+
## File-based project format:
246+
*.ipr
247+
*.iws
248+
249+
## Plugin-specific files:
250+
251+
# IntelliJ
252+
/out/
253+
254+
# mpeltonen/sbt-idea plugin
255+
.idea_modules/
256+
257+
# JIRA plugin
258+
atlassian-ide-plugin.xml
259+
260+
# Crashlytics plugin (for Android Studio and IntelliJ)
261+
com_crashlytics_export_strings.xml
262+
crashlytics.properties
263+
crashlytics-build.properties

examples/dummy.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
// This comment will not appear in generated css file
3+
/* This comment will appear in generated css file */
4+
5+
// !editable is not valid sass/css but is tolerated in qtsass since widespread in Qt stylesheets.
6+
QComboBox:!editable:on, QComboBox::drop-down:editable:on
7+
{
8+
color: blue;
9+
}
10+
11+
QTreeView::item:selected{
12+
$start: 0.2;
13+
$stops: $start #3f3f3f, $start + 0.6 red;
14+
// qlineargradient syntax changes a little bit
15+
// classic Qt: qlineargradient(x1: 0, y1: 0, x2: 0, y2:1, stop: 0.2 #3f3f3f, stop: 0.8 red)
16+
background-color: qlineargradient(0, 0, 0, 1, $stops);
17+
color: rgba(255, 10, 10, 0.5);
18+
}

qtsass/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__author__ = 'yann.lanthony'

qtsass/qtsass.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import sass
2+
import argparse
3+
import logging
4+
5+
logging.basicConfig(level=logging.DEBUG)
6+
logger = logging.getLogger(__name__)
7+
8+
9+
def rgba(r, g, b, a):
10+
result = "rgba({}, {}, {}, {}%)"
11+
if isinstance(r, sass.SassNumber):
12+
return result.format(int(r.value), int(g.value), int(b.value), int(a.value)*100)
13+
elif isinstance(r, float):
14+
return result.format(int(r), int(g), int(b), int(a)*100)
15+
16+
17+
def rgba_from_color(color):
18+
"""
19+
Conform rgba
20+
:type color: sass.SassColor
21+
"""
22+
return rgba(color.r, color.g, color.b, color.a)
23+
24+
25+
def qlineargradient(x1, y1, x2, y2, stops):
26+
"""
27+
:type x1: sass.SassNumber
28+
:type y1: sass.SassNumber
29+
:type x2: sass.SassNumber
30+
:type y2: sass.SassNumber
31+
:type stops: sass.SassList
32+
:return:
33+
"""
34+
stops_str = ""
35+
for stop in stops[0]:
36+
pos, color = stop[0]
37+
stops_str += " stop: {} {}".format(pos.value, rgba_from_color(color))
38+
39+
return "qlineargradient(x1:{}, y1:{}, x2:{}, y2:{} {})".format(x1.value, y1.value, x2.value, y2.value, stops_str.rstrip(","))
40+
41+
42+
def css_conform(input_file):
43+
with open(input_file, "r") as f:
44+
# Remove "!" in selectors
45+
input_str = f.read().replace(":!", ":_qnot_")
46+
return input_str
47+
48+
49+
def qt_conform(input_str):
50+
"""
51+
:param input_str:
52+
:type input_str: string
53+
:return:
54+
"""
55+
conformed = input_str.replace(":_qnot_", ":!")
56+
return conformed
57+
58+
59+
def compile_to_css(input_file):
60+
return qt_conform(sass.compile(string=css_conform(input_file),
61+
source_comments=False,
62+
custom_functions={
63+
'qlineargradient': qlineargradient,
64+
'rgba': rgba
65+
}
66+
)
67+
)
68+
69+
70+
if __name__ == "__main__":
71+
parser = argparse.ArgumentParser(prog="QtSASS",
72+
description="Compile a Qt compliant CSS file from a SCSS stylesheet.",
73+
)
74+
parser.add_argument('input', type=str, help="The SCSS stylesheet file.")
75+
parser.add_argument('-o', '--output', type=str, help="The path of the generated Qt compliant CSS file.")
76+
77+
args = parser.parse_args()
78+
79+
stylesheet = compile_to_css(args.input)
80+
81+
if args.output:
82+
with open(args.output, 'w') as css_file:
83+
css_file.write(stylesheet)
84+
logger.info("Created CSS file {}".format(args.output))
85+
else:
86+
print(stylesheet)

setup.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from cx_Freeze import setup, Executable
2+
3+
build_exe_options = {
4+
'include_msvcr': True,
5+
'optimize': 2
6+
}
7+
8+
setup(
9+
name="qtsass",
10+
description="Compile a SCSS file to a valid Qt CSS.",
11+
executables=[Executable("qtsass/qtsass.py")],
12+
options={'build_exe': build_exe_options},
13+
requires=['libsass', 'cx_Freeze'],
14+
)

0 commit comments

Comments
 (0)