summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/web/StylePreview.py
blob: 1ad6f9561cda1eeade33484fceb1e3f3fffef6ff (plain)
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
from common.FileAccess import FileAccess
import traceback

'''
@author rpiterman
the style preview, which is a OOo Document Preview in
an Image Control.
This class copies the files needed for this
preview from the web wizard work directory
to a given temporary directory, and updates them
on request, according to the current style/background selection
of the user.
'''

class StylePreview(object):

    '''
    copies the html file to the temp directory, and calculates the
    destination names of the background and css files.
    @param wwRoot is the root directory of the web wizard files (
    usually [oo]/share/template/[lang]/wizard/web
    '''

    def __init__(self, xmsf, wwRoot_):
        self.fileAccess = FileAccess(xmsf)
        self.tempDir = self.createTempDir(xmsf)
        self.htmlFilename = FileAccess.connectURLs(
            self.tempDir, "wwpreview.html")
        self.cssFilename = FileAccess.connectURLs(self.tempDir, "style.css")
        self.backgroundFilename = FileAccess.connectURLs(
            self.tempDir, "images/background.gif")
        self.wwRoot = wwRoot_
        self.fileAccess.copy(FileAccess.connectURLs(
            self.wwRoot, "preview.html"), self.htmlFilename)

    '''
    copies the given style and background files to the temporary
    directory.
    @param style
    @param background
    @throws Exception
    '''

    def refresh(self, style, background):
        css = FileAccess.connectURLs(self.wwRoot, "styles/" + style.cp_CssHref)
        if background is None or background == "":
            #delete the background image
            if self.fileAccess.exists(self.backgroundFilename, False):
                self.fileAccess.delete(self.backgroundFilename)
        else:
            # a solaris bug workaround
            # TODO
            #copy the background image to the temp directory.
            self.fileAccess.copy(background, self.backgroundFilename)

        #copy the actual css to the temp directory
        self.fileAccess.copy(css, self.cssFilename)

    def cleanup(self):
        try:
            self.fileAccess.delete(self.tempDir)
        except Exception:
            traceback.print_exc()

    '''
    creates a temporary directory.
    @param xmsf
    @return the url of the new directory.
    @throws Exception
    '''

    def createTempDir(self, xmsf):
        tempPath = FileAccess.getOfficePath2(xmsf, "Temp", "", "")
        s = self.fileAccess.createNewDir(tempPath, "wwiz")
        self.fileAccess.createNewDir(s, "images")
        return s