~oly/fabricad/testing

« back to all changes in this revision

Viewing changes to tutorials/tut1/generate.py

  • Committer: Oliver Marks
  • Date: 2013-07-15 13:06:57 UTC
  • Revision ID: oly@digitaloctave.com-20130715130657-5b7ar3ghlgeqzwoe
initial commit and first working version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#import required files
 
2
import os,sys
 
3
import tempfile
 
4
import webbrowser
 
5
 
 
6
#append this to module path so we can load from the parent directory
 
7
sys.path.append(os.path.abspath('../'))
 
8
from scaffold.web import web as html
 
9
 
 
10
 
 
11
#the heart of the system
 
12
web=html()
 
13
web.document_root=os.path.dirname(__file__)
 
14
#set the default theme folder
 
15
web.template.theme_full_path=os.path.abspath('../')+os.sep+'template'+os.sep
 
16
 
 
17
 
 
18
#these allow you to load in a static file to header and footer 
 
19
web.template.load_header()
 
20
web.template.load_footer()
 
21
 
 
22
#normally this will look for the defaults.css file in your theme we are not serving files so set local path 
 
23
web.template.css_includes.append('file:///'+web.template.theme_full_path+'default.css')
 
24
 
 
25
#generate the main content of the page here
 
26
web.page.header('Hello World Extended Header')
 
27
web.page.section('Hello World Extended Body Text')
 
28
 
 
29
 
 
30
#example of creating a table
 
31
web.table.create('My Table Title',('Column 1','Column 2','Column 3','Column 4','Column 5'))
 
32
for row in range(0,6):
 
33
        web.table.append([row,'a','b','c','d'])
 
34
        
 
35
#actually lets modify the rows for the table, just an example to show it possible as long as render has not been called
 
36
for row in web.table:
 
37
        row[2]='<b>'+row[2]+'</b>'
 
38
 
 
39
"""These tutorials will outline how to build a simple cad application using opengl and gtk 3 using python as the language making it simple for other to extend."""
 
40
 
 
41
"""First create your interface using glade interface designer or grab it from the launchpad repository"""
 
42
        
 
43
web.page.section(web.table.render())
 
44
#append the html into the document body
 
45
web.template.body.append(web.page.render())
 
46
 
 
47
 
 
48
 
 
49
#nothing special dump content to a file and open in browser
 
50
f = tempfile.NamedTemporaryFile(delete=False)
 
51
f.write(web.render().encode('UTF-8'))
 
52
f.close()
 
53
webbrowser.open_new_tab('file:///'+f.name)