~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to sheets/plugins/scripting/scripts/odfpyexport.py

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
The script could be used in two ways;
8
8
 
9
 
    1. Embedded in KSpread by execution via the "Tools=>Scripts"
 
9
    1. Embedded in Sheets by execution via the "Tools=>Scripts"
10
10
       menu or from the "Tools=>Script Manager". In that case
11
 
       the document currently loaded and displayed by KSpread
 
11
       the document currently loaded and displayed by Sheets
12
12
       will be exported.
13
13
 
14
14
    2. As standalone script by running;
15
15
 
16
16
            # make the script executable
17
 
            chmod 755 `kde4-config --install data`/kspread/scripts/extensions/odfpyexport.py
 
17
            chmod 755 `kde4-config --install data`/sheets/scripts/extensions/odfpyexport.py
18
18
            # run the script
19
19
            `kde4-config --install data`/kspread/scripts/extensions/odfpyexport.py
20
20
 
26
26
 
27
27
(C)2007 Sebastian Sauer <mail@dipe.org>
28
28
http://kross.dipe.org
29
 
http://www.calligra.org/kspread
 
29
http://www.calligra.org/sheets
30
30
Dual-licensed under LGPL v2+higher and the BSD license.
31
31
"""
32
32
 
33
33
try:
34
34
    import Kross
35
35
except:
36
 
    raise "Failed to import the Kross module."
 
36
    raise Exception, "Failed to import the Kross module."
 
37
 
 
38
T = Kross.module("kdetranslation")
37
39
 
38
40
try:
39
41
    import odf.opendocument
40
42
except:
41
 
    raise "<qt>Failed to import the ODFPY python module.<br><br>To use this odfpyexport.py python script to export to OpenDocument you need to install the <a href=\"http://opendocumentfellowship.org/projects/odfpy\">ODFPY</a> python module.</qt>"
 
43
    raise Exception, T.i18n("<qt>Failed to import the ODFPY python module.<br><br>To use this odfpyexport.py python script to export to OpenDocument you need to install the <a href=\"http://opendocumentfellowship.org/projects/odfpy\">ODFPY</a> python module.</qt>")
42
44
 
43
45
class OdfExporter:
44
46
 
53
55
                if r[2] > maxcolumn:
54
56
                    maxcolumn = r[2]
55
57
            if maxcolumn < 1:
56
 
                raise "Failed to determinate number of columns."
 
58
                raise Exception, T.i8n("Failed to determinate number of columns.")
57
59
            #mincolumn = maxcolumn
58
60
            #for r in ranges:
59
61
            #    if r[0] < mincolumn:
69
71
                if len(r) < 4:
70
72
                    r = (r[:2] + (lastColumn, lastRow))
71
73
                if r[0] > r[2]:
72
 
                    raise "Invalid range for sheet \"%s\" cause left column value \"%i\" is bigger then right column value \"%i\"." % (sheet.sheetName(),r[0],r[2])
 
74
                    raise Exception, T.i18n("Invalid range for sheet \"%1\" cause left column value \"%2\" is bigger then right column value \"%3\".", [sheet.sheetName()], [r[0]], [r[2]])
73
75
                if r[1] > r[3]:
74
 
                    raise "Invalid range for sheet \"%s\" cause top row value \"%i\" is bigger then bottom row value \"%i\"." % (sheet.sheetName(),r[1],r[3])
 
76
                    raise Exception, T.i18n("Invalid range for sheet \"%1\" cause top row value \"%2\" is bigger then bottom row value \"%3\".", [sheet.sheetName()], [r[1]], [r[3]])
75
77
                rangeList.append(r)
76
78
            if len(rangeList) < 1:
77
79
                rangeList.append( (1, 1, lastColumn, lastRow) )
78
80
            return rangeList
79
81
 
80
82
    class OpenDocumentText(_OpenDocumentInterface_):
81
 
        filtername = "OpenDocument Text"
 
83
        filtername = T.i18n("OpenDocument Text")
82
84
        filtermask = "*.odt"
83
85
 
84
86
        def __init__(self, kspread, exportSheets, writeOdfFile):
135
137
            self.doc.text.addElement(table)
136
138
 
137
139
    class OpenDocumentSpreadsheet(_OpenDocumentInterface_):
138
 
        filtername = "OpenDocument Spreadsheet"
 
140
        filtername = T.i18n("OpenDocument Spreadsheet")
139
141
        filtermask = "*.ods"
140
142
 
141
143
        def __init__(self, kspread, exportSheets, writeOdfFile):
211
213
            try:
212
214
                self.kspread = Kross.module("kspread")
213
215
            except ImportError:
214
 
                raise "Failed to import the Kross module. Please run this script with \"kross odtexport.py\""
 
216
                raise Exception, "Failed to import the Kross module. Please run this script with \"kross odtexport.py\""
215
217
 
216
218
        if readOdsFile:
217
219
            if not self.kspread.openUrl(readOdsFile):
218
 
                raise "Failed to read OpenDocument Spreadsheet file \"%s\"." % readOdsFile
 
220
                raise Exception, ("Failed to read OpenDocument Spreadsheet file \"%1\".", readOdsFile)
219
221
        elif not embeddedInKSpread:
220
 
            raise "No OpenDocument Spreadsheet file to read from defined."
 
222
            raise Exception, T.i18n("No OpenDocument Spreadsheet file to read from defined.")
221
223
 
222
224
        global OdfExporter
223
225
        self.exporterClasses = []
231
233
 
232
234
        if embeddedInKSpread or not exportSheets or not writeOdfFile:
233
235
            forms = Kross.module("forms")
234
 
            dialog = forms.createDialog("OdfPy Export")
 
236
            dialog = forms.createDialog(T.i18n("OdfPy Export"))
235
237
            dialog.setButtons("Ok|Cancel")
236
238
            dialog.setFaceType("List") #Auto Plain List Tree Tabbed
237
239
            try:
238
240
                if not writeOdfFile:
239
 
                    savepage = dialog.addPage("Save","Save to OpenDocument File","document-save")
 
241
                    savepage = dialog.addPage(T.i18nc("Options page name", "Save"),T.i18n("Save to OpenDocument File"),"document-save")
240
242
                    self.savewidget = forms.createFileWidget(savepage, "kfiledialog:///kspreadodfpyexport")
241
243
                    self.savewidget.setMode("Saving")
242
244
 
244
246
                    for f in self.exporterClasses:
245
247
                        filters.append("%s|%s" % (f.filtermask,f.filtername))
246
248
                    if len(self.exporterClasses) > 1:
247
 
                        filters.insert(0, "%s|All Supported Files" % " ".join([f.filtermask for f in self.exporterClasses]))
248
 
                    filters.append("*|All Files")
 
249
                        filters.insert(0, "%s|%s" % (" ".join([f.filtermask for f in self.exporterClasses]),T.i18n("All Supported Files")))
 
250
                    filters.append("*|%s" % T.i18n("All Files"))
249
251
                    self.savewidget.setFilter("\n".join(filters))
250
252
 
251
253
                if not exportSheets:
252
 
                    datapage = dialog.addPage("Sheets","Export Sheets","spreadsheet")
 
254
                    datapage = dialog.addPage(T.i18n("Sheets"), T.i18n("Export Sheets"), "spreadsheet")
253
255
                    self.sheetslistview = self.kspread.createSheetsListView(datapage)
254
256
                    self.sheetslistview.setSelectionType("MultiSelect")
255
257
                    self.sheetslistview.setEditorType("Range")
275
277
                exportSheets.append( [sheetname, True] )
276
278
 
277
279
        if not writeOdfFile:
278
 
            raise "No OpenDocument file to write to defined."
 
280
            raise Exception, T.i18n("No OpenDocument file to write defined.")
279
281
 
280
282
        if not odfExporterClass:
281
283
            if len(self.exporterClasses) == 1: