/
StartPage.py
691 lines (599 loc) · 27 KB
/
StartPage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
#***************************************************************************
#* *
#* Copyright (c) 2012 *
#* Yorik van Havre <yorik@uncreated.net> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
# This is the start page template
import os,FreeCAD,FreeCADGui,tempfile,time,zipfile,urllib,re,sys
from PySide import QtGui
from xml.etree.ElementTree import parse
try:
import io as cStringIO
except:
import cStringIO
FreeCADGui.addLanguagePath(":/translations")
FreeCADGui.updateLocale()
def translate(context,text):
"convenience function for the Qt translator"
# return str(QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8).toUtf8())
try:
_encoding = QtGui.QApplication.UnicodeUTF8
u = QtGui.QApplication.translate(context, text, None, _encoding)
except AttributeError:
u = QtGui.QApplication.translate(context, text, None)
if sys.version_info.major < 3:
u = u.encode("utf8")
# s = cStringIO.StringIO()
# for i in u:
# if sys.version_info.major > 2: #below only works correctly in python3
# if i == 39:
# s.write("\\'")
# else:
# s.write(chr(i))
# else:
# if ord(i) == 39:
# s.write(unicode("\\'"))
# else:
# s.write(unicode(i))
# t = s.getvalue()
# s.close()
# return t
return u.replace(chr(39), "\\'")
# texts to be translated
text01 = translate("StartPage","FreeCAD Start Center")
text02 = translate("StartPage","Start a new project")
text03 = translate("StartPage","Recent Files")
text04 = translate("StartPage","Latest videos")
text05 = translate("StartPage","Latest commits")
text06 = translate("StartPage","On the web")
text07 = translate("StartPage","This is the FreeCAD Homepage. Here you will be able to find a lot of information about FreeCAD, including tutorials, examples and user documentation.")
text08 = translate("StartPage","FreeCAD Homepage")
text09 = translate("StartPage","Example projects")
text10 = translate("StartPage","Schenkel STEP file")
text11 = translate("StartPage","Load a PartDesign example")
text12 = translate("StartPage","Load a Drawing extraction")
text13 = translate("StartPage","Load a Robot simulation example")
text14 = translate("StartPage","Projects from the Web")
text15 = translate("StartPage","Schenkel STEP")
text16 = translate("StartPage","Complex Part")
text17 = translate("StartPage","Close this window after opening or creating a file")
text18 = translate("StartPage","Don't show me this window again next time")
text19 = translate("StartPage","Designing parts")
text20 = translate("StartPage","The <b>Part Design</b> workbench is designed to create complex pieces based on constrained 2D sketches. Use it to draw 2D shapes, constrain some of their elements and extrude them to form 3D pieces.")
text21 = translate("StartPage","Example workflow")
text22 = translate("StartPage","Part Design")
text23 = translate("StartPage","Designing architectural elements")
text24 = translate("StartPage","The <b>Architectural Design</b> workbench is specially designed for working with architectural elements such as walls or windows. Start by drawing 2D shapes, and use them as guides to build architecutral objects.")
text25 = translate("StartPage","Architectural Design")
text26 = translate("StartPage","Working with Meshes")
text27 = translate("StartPage","The <b>Mesh Workbench</b> is used to work with Mesh objects. Meshes are simpler 3D objects than Part objects, but they are often easier to import and export to/from other applications.")
text28 = translate("StartPage","FreeCAD offers you several tools to convert between Mesh and Part objects.")
text29 = translate("StartPage","Work with Meshes")
text30 = translate("StartPage","The complete workbench")
text31 = translate("StartPage","FreeCAD Complete workbench")
text32 = translate("StartPage","populated with some of the most commonly used tools.")
text33 = translate("StartPage","file size:")
text34 = translate("StartPage","creation time:")
text35 = translate("StartPage","last modified:")
text36 = translate("StartPage","location:")
text37 = translate("StartPage","User manual")
text38 = translate("StartPage","http://www.freecadweb.org/wiki/index.php?title=Online_Help_Toc")
text39 = translate("StartPage","Tutorials")
text40 = translate("StartPage","Python resources")
text41 = translate("StartPage","File not found")
text42 = translate("StartPage","from <a href=http://twitter.com/FreeCADNews>@FreeCADNews</a>")
text43 = translate("StartPage","The FreeCAD-tutorial blog")
text44 = translate("StartPage","from <a href=http://www.youtube.com/user/FreeCADNews?feature=mhee>FreeCADNews channel</a>")
text45 = translate("StartPage","This is the official user manual of FreeCAD, built, maintained and translated by the FreeCAD community.")
text46 = translate("StartPage","The tutorials section on the FreeCAD website")
text47 = translate("StartPage","The section of the FreeCAD website dedicated to python scripting, with examples, explanations, and API commands.")
text48 = translate("StartPage","A blog dedicated to teaching FreeCAD, maintained by members of the FreeCAD community")
text49 = translate("StartPage","Getting started")
text50 = translate("StartPage","The FreeCAD interface is divided in workbenches, which are sets of tools suited for a specific task. You can start with one of the workbenches in this list, or with the complete workbench, which presents you with some of the most used tools gathered from other workbenches. Click to read more about workbenches on the FreeCAD website.")
text51 = translate("StartPage","http://www.freecadweb.org/wiki/index.php?title=Workbenches")
text52 = translate("StartPage","Ship Design")
text53 = translate("StartPage","Designing and calculating ships")
text54 = translate("StartPage","The <b>Ship Design</b> module offers several tools to help ship designers to view, model and calculate profiles and other specific properties of ship hulls.")
text55 = translate("StartPage","Load an Architectural example model")
text56 = translate("StartPage","http://www.freecadweb.org/wiki/index.php?title=Tutorials")
text57 = translate("StartPage","http://www.freecadweb.org/wiki/index.php?title=Power_users_hub")
text58 = translate("StartPage","Your version of FreeCAD is up to date.")
text59 = translate("StartPage","There is a new release of FreeCAD available.")
text60 = translate("StartPage","Load an FEM 3D example analysis")
text61 = translate("StartPage","Obtain a development version")
text62 = translate("StartPage","<b>Development versions</b> are made available by community members from time to time and usually contain the latest changes, but are more likely to contain bugs.")
text63 = translate("StartPage","See all commits")
text64 = translate("StartPage","Load an FEM 2D example analysis")
# get FreeCAD version
v = FreeCAD.Version()
vmajor = v[0]
vminor = v[1]
vbuild = v[2].split(" ")[0]
# here is the html page skeleton
page = """
<html>
<head>
<title>FreeCAD - Start page</title>
<script language="javascript">
var linkDescriptions = [];
function JSONscriptRequest(fullUrl) {
// REST request path
this.fullUrl = fullUrl;
// Get the DOM location to put the script tag
this.headLoc = document.getElementsByTagName("head").item(0);
// Generate a unique script tag id
this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}
// Static script ID counter
JSONscriptRequest.scriptCounter = 1;
JSONscriptRequest.prototype.buildScriptTag = function () {
// Create the script tag
this.scriptObj = document.createElement("script");
// Add script object attributes
this.scriptObj.setAttribute("type", "text/javascript");
this.scriptObj.setAttribute("charset", "utf-8");
this.scriptObj.setAttribute("src", this.fullUrl);
this.scriptObj.setAttribute("id", this.scriptId);
}
JSONscriptRequest.prototype.removeScriptTag = function () {
// Destroy the script tag
this.headLoc.removeChild(this.scriptObj);
}
JSONscriptRequest.prototype.addScriptTag = function () {
// Create the script tag
this.headLoc.appendChild(this.scriptObj);
}
function show(theText) {
ddiv = document.getElementById("description");
if (theText == "") theText = " ";
ddiv.innerHTML = theText;
}
function checkVersion(data) {
vdiv = document.getElementById("versionbox");
var cmajor = """ + vmajor + """;
var cminor = """ + vminor + """;
var cbuild = """ + vbuild + """;
var amajor = data[0]['major'];
var aminor = data[0]['minor'];
var abuild = data[0]['build'];
if (cmajor >= amajor && cminor >= aminor && cbuild >= abuild) {
vdiv.innerHTML=" """ + text58 + """: """ + vmajor + """.""" + vminor + """.""" + vbuild + """";
} else {
vdiv.innerHTML="<a href=exthttp://github.com/FreeCAD/FreeCAD/releases/latest> """ + text59 + """:"+amajor+"."+aminor+"."+abuild+"</a>";
}
}
function load() {
// load latest news
ddiv = document.getElementById("news");
ddiv.innerHTML = "Connecting...";
var tobj=new JSONscriptRequest('https://api.github.com/repos/FreeCAD/FreeCAD/commits?callback=showTweets');
tobj.buildScriptTag(); // Build the script tag
tobj.addScriptTag(); // Execute (add) the script tag
ddiv.innerHTML = "Downloading latest news...";
// load version
var script = document.createElement('script');
script.src = 'http://www.freecadweb.org/version.php?callback=checkVersion';
document.body.appendChild(script);
}
function stripTags(text) {
// from http://www.pagecolumn.com/tool/all_about_html_tags.htm /<\s*\/?\s*span\s*.*?>/g
stripped = text.replace("<table", "<div");
stripped = stripped.replace("</table", "</div");
stripped = stripped.replace("<tr", "<tr");
stripped = stripped.replace("</tr", "</tr");
stripped = stripped.replace("<td", "<td");
stripped = stripped.replace("</td", "</td");
stripped = stripped.replace("555px", "auto");
stripped = stripped.replace("border:1px", "border:0px");
stripped = stripped.replace("color:#000000;","");
return stripped;
}
function showTweets(data) {
ddiv = document.getElementById('news');
ddiv.innerHTML = "Received";
var html = ['<ul>'];
for (var i = 0; i < 15; i++) {
html.push('<li><img src="web.png"> <a href="ext', data.data[i].commit.url, '" onMouseOver="showDescr(', i+1, ')" onMouseOut="showDescr()">', data.data[i].commit.message, '</a></li>');
if ("message" in data.data[i].commit) {
linkDescriptions.push(stripTags(data.data[i].commit.message)+'<br/>'+data.data[i].commit.author.name+'<br/>'+data.data[i].commit.author.date);
} else {
linkDescriptions.push("");
}
}
html.push('</ul>');
html.push('<a href="exthttp://github.com/FreeCAD/FreeCAD/commits/master">""" + text63 + """<a/>');
ddiv.innerHTML = html.join('');
}
function showDescr(d) {
if (d) {
show(linkDescriptions[d-1]);
} else {
show("");
}
}
function scroller() {
desc = document.getElementById("description");
base = document.getElementById("column").offsetTop;
scro = window.scrollY;
if (scro > base) {
desc.className = "stick";
} else {
desc.className = "";
}
}
document.onmousemove=scroller;
</script>
<style type="text/css">
body {
background: #basecolor;
color: #textcolor;
font-family: Arial, Helvetica, Sans;
font-size: 11px;
}
a {
color: #linkcolor;
font-weight: bold;
text-decoration: none;
padding: 2px;
}
a:hover {
color: white;
background: #linkcolor;
border-radius: 5px;
}
p {
text-align: justify;
}
.left {
text-align: left;
}
h1 {
font-size: 3em;
letter-spacing: 2px;
padding: 20px 0 0 80px;
align: bottom;
color: #ffffff;
}
h2 {
font-size: 1.2em;
}
ul {
list-style-type: none;
padding: 0;
}
#column {
margin: 0 350px 0 10px;
}
#column img {
max-width: 14px;
}
.block {
background: #windowcolor;
border-radius: 5px;
padding: 8px;
margin-bottom: 10px;
color: #windowtextcolor;
width: auto;
}
.options {
clear: both;
}
.from {
font-size: 0.7em;
font-weight: normal;
}
#versionbox {
float: right;
text-align: right;
font-size: 0.33em;
font-weight: normal;
padding-right: 20px;
letter-spacing: 0;
color: #ffffff;
}
#description {
background: #windowcolor;
border-radius: 5px;
padding: 8px;
color: #windowtextcolor;
float: right;
width: 316px;
right: 10px;
height: 100%;
position: relative;
}
#description img {
max-width: 300px;
clear: both;
}
pre {
width: 300px !important;
white-space: pre-wrap;
}
.stick {
position: fixed !important;
top: 0px;
right: 18px !important;
}
</style>
</head>
<body onload="load()">
<h1><img src="FreeCAD.png"> """ + text01 + """<div id=versionbox> </div></h1>
<div id="description">
</div>
<div id="column">
<div class="block">
<h2>""" + text02 + """</h2>
defaultworkbenches
</div>
<div class="block">
<h2>""" + text03 + """</h2>
recentfiles
</div>
<div class="block">
<h2>""" + text05 + """</h2>
<div id="news">news feed</div>
</div>
<div class="block">
<h2>""" + text06 + """</h2>
defaultlinks
</div>
<div class="block">
<h2>""" + text09 + """</h2>
defaultexamples
</div>
customblocks
</div>
<!--
<form class="options">
<input type="checkbox" name="closeThisDialog">
""" + text17 + """<br/>
<input type="checkbox" name="dontShowAgain">
""" + text18 + """
</form>
-->
</body>
</html>
"""
def getWebExamples():
return """
<ul>
<li><a href="http://freecad-project.de/svn/ExampleData/FileFormates/Schenkel.stp">""" + text15 + """</a></li>
<li><a href="http://freecad-project.de/svn/ExampleData/Examples/CAD/Complex.FCStd">""" + text16 + """</a></li>
</ul>"""
def getExamples():
return """
<ul>
<li><img src="FreeCAD.png" style="width: 16px"> <a href="LoadSchenkel.py">""" + text10 + """</a></li>
<li><img src="FreeCAD.png" style="width: 16px"> <a href="LoadPartDesignExample.py">""" + text11 + """</a></li>
<li><img src="FreeCAD.png" style="width: 16px"> <a href="LoadDrawingExample.py">""" + text12 + """</a></li>
<li><img src="FreeCAD.png" style="width: 16px"> <a href="LoadRobotExample.py">""" + text13 + """</a></li>
<li><img src="FreeCAD.png" style="width: 16px"> <a href="LoadArchExample.py">""" + text55 + """</a></li>
<li><img src="FreeCAD.png" style="width: 16px"> <a href="LoadFemExample2D.py">""" + text64 + """</a></li>
<li><img src="FreeCAD.png" style="width: 16px"> <a href="LoadFemExample3D.py">""" + text60 + """</a></li>
</ul>"""
def getLinks():
return """
<ul>
<li><img src="web.png">
<a onMouseover="show('<p>""" + text07 + """</p>')"
onMouseout="show('')"
href="exthttp://www.freecadweb.org/">""" + text08 + """</a></li>
<li><img src="web.png">
<a onMouseover="show('<p>""" + text45 + """</p>')"
onMouseout="show('')"
href=ext""" + text38 + """>""" + text37 + """</a></li>
<li><img src="web.png">
<a onMouseover="show('<p>""" + text46 + """</p>')"
onMouseout="show('')"
href=ext""" + text56 + """>""" + text39 + """</a></li>
<li><img src="web.png">
<a onMouseover="show('<p>""" + text47 + """</p>')"
onMouseout="show('')"
href=ext""" + text57 + """>""" + text40 + """</a></li>
<li><img src="web.png">
<a onMouseover="show('<p>""" + text48 + """</p>')"
onMouseout="show('')"
href="exthttp://freecad-tutorial.blogspot.com/">""" + text43 + """</a></li>
<li><img src="web.png">
<a href="exthttp://github.com/FreeCAD/FreeCAD/releases"
onMouseOver="show('<p>""" + text62 + """</p>')"
onMouseOut="show('')">""" + text61 + """</a></li>
</ul>"""
def getWorkbenches():
return """
<ul>
<li><img src="blank.png">
<a onMouseover="show('<h3>""" + text49 + """</h3> \
<p>""" + text50 + """</p>')"
onMouseout="show('')"
href=""" + text51 + """>""" + text49 + """</a>
</li>
<li><img src="PartDesign.png">
<a onMouseover="show('<h3>""" + text19 + """</h3> \
<p>""" + text20 + """</p><p><small>""" + text21 + """ \
:</small></p><img src=PartDesignExample.png>')"
onMouseout="show('')"
href="PartDesign.py">""" + text22 + """</a>
</li>
<li><img src="ArchDesign.png">
<a onMouseover="show('<h3>""" + text23 + """</h3> \
<p>""" + text24 + """</p><p><small>""" + text21 + """ \
:</small></p><img src=ArchExample.png>')"
onMouseout="show('')"
href="ArchDesign.py">""" + text25 + """</a>
</li>
<li><img src="Ship.png">
<a onMouseover="show('<h3>""" + text53 + """</h3> \
<p>""" + text54 + """</p><p><small>""" + text21 + """ \
:</small></p><img src=ShipExample.png>')"
onMouseout="show('')"
href="Ship.py">""" + text52 + """</a>
</li>
<li><img src="Mesh.png">
<a onMouseover="show('<h3>""" + text26 + """</h3> \
<p>""" + text27 + """</p><p>""" + text28 + """</p>')"
onMouseout="show('')"
href="Mesh.py">""" + text29 + """</a>
</li>
</ul>"""
def getInfo(filename):
"returns available file information"
def getLocalTime(timestamp):
"returns a local time from a timestamp"
return time.strftime("%m/%d/%Y %H:%M:%S",time.localtime(timestamp))
def getSize(size):
"returns a human-readable size"
if size > 1024*1024:
hsize = str(size/(1024*1024)) + "Mb"
elif size > 1024:
hsize = str(size/1024) + "Kb"
else:
hsize = str(size) + "b"
return hsize
html = '<h3>'+os.path.basename(filename)+'</h3>'
if os.path.exists(filename):
# get normal file info
s = os.stat(filename)
html += "<p>" + text33 + " " + getSize(s.st_size) + "<br/>"
html += text34 + " " + getLocalTime(s.st_ctime) + "<br/>"
html += text35 + " " + getLocalTime(s.st_mtime) + "<br/>"
html += "<span>" + text36 + " " + filename + "</span></p>"
# get additional info from fcstd files
if os.path.splitext(filename)[1].upper() in [".FCSTD"]:
zfile=zipfile.ZipFile(filename)
files=zfile.namelist()
# check for meta-file if it's really a FreeCAD document
if files[0] == "Document.xml":
html += "<p>FreeCAD Standard File</p>"
image="thumbnails/Thumbnail.png"
if image in files:
image=zfile.read(image)
thumbfile = tempfile.mkstemp(suffix='.png')[1]
thumb = open(thumbfile,"wb")
thumb.write(image)
thumb.close()
html += '<img src=file://'
html += thumbfile + '><br/>'
else:
html += "<p>" + text41 + "</p>"
return html
def getRecentFiles():
"returns a list of 3 latest recent files"
rf = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/RecentFiles")
ct = rf.GetInt("RecentFiles")
html = '<ul>'
for i in range(3):
if i < ct:
mr = rf.GetString("MRU%d" % (i))
if os.path.exists(mr):
fn = os.path.basename(mr)
html += '<li>'
if mr[-5:].upper() == "FCSTD":
html += '<img src="freecad-doc.png" style="width: 16px"> '
else:
html += '<img src="blank.png" style="width: 16px"> '
html += '<a '
html += 'onMouseover="show(\''+getInfo(mr)+'\')" '
html += 'onMouseout="show(\'\')" '
html += 'href="LoadMRU'+str(i)+'.py">'
html += fn
html += '</a></li>'
html += '</ul>'
return html
def getFeed(url,numitems=3):
"returns a html list with links from the given RSS feed url"
xml = parse(urllib.urlopen(url)).getroot()
items = []
channel = xml.find('channel')
for element in channel.findall('item'):
items.append({'title': element.find('title').text,
'description': element.find('description').text,
'link': element.find('link').text})
if len(items) > numitems:
items = items[:numitems]
resp = '<ul>'
for item in items:
descr = re.compile("style=\".*?\"").sub('',item['description'])
descr = re.compile("alt=\".*?\"").sub('',descr)
descr = re.compile("\"").sub('',descr)
d1 = re.findall("<img.*?>",descr)[0]
d2 = re.findall("<span>.*?</span>",descr)[0]
descr = "<h3>" + item['title'] + "</h3>"
descr += d1 + "<br/>"
descr += d2
resp += '<li><a onMouseover="show(\''
resp += descr
resp += '\')" onMouseout="show(\'\')" href="'
resp += item['link']
resp += '">'
resp += item['title']
resp += '</a></li>'
resp += '</ul>'
print(resp)
return resp
def getCustomBlocks():
"fetches custom html files in FreeCAD user dir"
output = ""
return output
def setColors(html):
"gets theme colors from the system, and sets appropriate styles"
defaults = {"#basecolor":"#191B26",
"#linkcolor":"#0092E8",
"#textcolor":"#FFFFFF",
"#windowcolor":"#FFFFFF",
"#windowtextcolor":"#000000"}
try:
palette = QtGui.qApp.palette()
except:
pass
else:
#defaults["#basecolor"] = palette.base().color().name()
defaults["#basecolor"] = "#171A2B url(Background.jpg)"
#defaults["#linkcolor"] = palette.link().color().name() # UGLY!!
defaults["#textcolor"] = palette.text().color().name()
defaults["#windowcolor"] = palette.window().color().name()
defaults["#windowtextcolor"] = palette.windowText().color().name()
for k,v in defaults.items():
html = html.replace(k,str(v))
return html
def handle():
"returns the complete html startpage"
# add recent files
recentfiles = getRecentFiles()
html = page.replace("recentfiles",recentfiles)
# add default workbenches
html = html.replace("defaultworkbenches",getWorkbenches())
# add default web links
html = html.replace("defaultlinks",getLinks())
# add default examples
html = html.replace("defaultexamples",getExamples())
# add web examples
#html = html.replace("webexamples",getWebExamples())
# add custom blocks
html = html.replace("customblocks",getCustomBlocks())
# fetches system colors
html = setColors(html)
return html
def exportTestFile():
f = open(os.path.expanduser("~")+os.sep+"freecad-startpage.html","wb")
f.write(handle())
f.close()