summaryrefslogtreecommitdiffstats
path: root/kspread/plugins/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'kspread/plugins/scripting')
-rwxr-xr-xkspread/plugins/scripting/scripts/exporthtml/ExportHtml.py9
-rwxr-xr-xkspread/plugins/scripting/scripts/scripteditor/ScriptEditor.py118
2 files changed, 65 insertions, 62 deletions
diff --git a/kspread/plugins/scripting/scripts/exporthtml/ExportHtml.py b/kspread/plugins/scripting/scripts/exporthtml/ExportHtml.py
index d38771fc..7d308ab2 100755
--- a/kspread/plugins/scripting/scripts/exporthtml/ExportHtml.py
+++ b/kspread/plugins/scripting/scripts/exporthtml/ExportHtml.py
@@ -18,7 +18,7 @@ import os, sys
try:
from TQt import qt
except (ImportError):
- raise "Failed to import the required PyTQt python module."
+ raise Exception("Failed to import the required PyTQt python module.")
class Dialog(tqt.QDialog):
def __init__(self, scriptpath, parent):
@@ -69,7 +69,7 @@ class Dialog(tqt.QDialog):
stylebox.setSpacing(6)
stylelabel = qt.TQLabel("Style:",stylebox)
self.stylecombo = qt.TQComboBox(stylebox)
- stylenames = self.styles.keys()
+ stylenames = list(self.styles.keys())
stylenames.sort()
for stylename in stylenames:
self.stylecombo.insertItem(stylename)
@@ -123,12 +123,13 @@ class Dialog(tqt.QDialog):
sheetname = str( self.sheetcombo.currentText() )
sheet = self.doc.sheetByName( sheetname )
- print "sheetname=%s sheet=%s" % (sheetname,sheet)
+ print("sheetname=%s sheet=%s" % (sheetname,sheet))
filename = str( self.fileedit.text() )
try:
file = open(filename, "w")
- except IOError, (errno, strerror):
+ except IOError as xxx_todo_changeme:
+ (errno, strerror) = xxx_todo_changeme.args
qt.TQMessageBox.critical(self,"Error","<qt>Failed to create HTML file \"%s\"<br><br>%s</qt>" % (filename,strerror))
return
diff --git a/kspread/plugins/scripting/scripts/scripteditor/ScriptEditor.py b/kspread/plugins/scripting/scripts/scripteditor/ScriptEditor.py
index e39bcc42..a6608014 100755
--- a/kspread/plugins/scripting/scripts/scripteditor/ScriptEditor.py
+++ b/kspread/plugins/scripting/scripts/scripteditor/ScriptEditor.py
@@ -16,7 +16,7 @@ import os, sys
try:
from TQt import qt
except (ImportError):
- raise "Failed to import the required PyTQt python module."
+ raise Exception("Failed to import the required PyTQt python module.")
####################################################################################
# Samples.
@@ -113,13 +113,13 @@ class Samples:
return (
'import krosskexidb',
'drivermanager = krosskexidb.DriverManager()',
- 'print "drivernames: %s" % drivermanager.driverNames()',
+ 'print("drivernames: %s" % drivermanager.driverNames())',
'',
'driver = drivermanager.driver( \"{DriverName}\" )',
- 'print "driver: {DriverName}"',
- 'print "version=%s.%s" % (driver.versionMajor(),driver.versionMinor())',
- 'print "mimetype=%s" % driver.fileDBDriverMimeType()',
- 'print "filedriver=%s" % driver.isFileDriver()',
+ 'print("driver: {DriverName}")',
+ 'print("version=%s.%s" % (driver.versionMajor(),driver.versionMinor())ú',
+ 'print("mimetype=%s" % driver.fileDBDriverMimeType()ú',
+ 'print("filedriver=%s" % driver.isFileDriver())',
)
class ConnectWithFile:
@@ -137,7 +137,7 @@ class Samples:
'',
'# Get the connectiondata from the project file.',
'connectiondata = drivermanager.createConnectionDataByFile( "{ProjectFile}" )',
- 'print "Connectiondata: %s" % connectiondata.serverInfoString()',
+ 'print("Connectiondata: %s" % connectiondata.serverInfoString())',
'',
'# Create the driver for the database backend.',
'driver = drivermanager.driver( connectiondata.driverName() )',
@@ -146,19 +146,19 @@ class Samples:
'connection = driver.createConnection(connectiondata)',
'if not connection.isConnected():',
' if not connection.connect():',
- ' raise "Failed to connect"',
+ ' raise Exception("Failed to connect")',
'',
'# Open the database for usage.',
- 'print "Databases: %s" % connection.databaseNames()',
+ 'print("Databases: %s" % connection.databaseNames())',
'if not connection.isDatabaseUsed():',
' if not connection.useDatabase( connectiondata.databaseName() ):',
' if not connection.useDatabase( connectiondata.fileName() ):',
- ' raise "Failed to use database"',
+ ' raise Exception("Failed to use database")',
'',
'# Print some infos.',
- 'print "All tables: %s" % connection.allTableNames()',
- 'print "Tables: %s" % connection.tableNames()',
- 'print "Queries: %s" % connection.queryNames()',
+ 'print("All tables: %s" % connection.allTableNames())',
+ 'print("Tables: %s" % connection.tableNames())',
+ 'print("Queries: %s" % connection.queryNames())',
)
class IterateThroughTable:
@@ -177,7 +177,7 @@ class Samples:
'',
'# Get the connectiondata from the project file.',
'connectiondata = drivermanager.createConnectionDataByFile( "{ProjectFile}" )',
- 'print "Connectiondata: %s" % connectiondata.serverInfoString()',
+ 'print("Connectiondata: %s" % connectiondata.serverInfoString())',
'',
'# Create the driver for the database backend.',
'driver = drivermanager.driver( connectiondata.driverName() )',
@@ -186,13 +186,13 @@ class Samples:
'connection = driver.createConnection(connectiondata)',
'if not connection.isConnected():',
' if not connection.connect():',
- ' raise "Failed to connect"',
+ ' raise Exception("Failed to connect")',
'',
'# Open the database for usage.',
'if not connection.isDatabaseUsed():',
' if not connection.useDatabase( connectiondata.databaseName() ):',
' if not connection.useDatabase( connectiondata.fileName() ):',
- ' raise "Failed to use database"',
+ ' raise Exception("Failed to use database")',
'',
'# Get the table and create a query for it.',
'table = connection.tableSchema( \"{TableName}\" )',
@@ -201,14 +201,14 @@ class Samples:
'# Create a cursor to walk through the records.',
'cursor = connection.executeQuerySchema( query )',
'if not cursor:',
- ' raise "Failed to create cursor."',
+ ' raise Exception("Failed to create cursor.")',
'',
'# Iterate through the records.',
'if not cursor.moveFirst():',
- ' raise "The cursor has no records to read from."',
+ ' raise Exception("The cursor has no records to read from.")',
'while not cursor.eof():',
' for i in range( cursor.fieldCount() ):',
- ' print "%s" % cursor.value(i)',
+ ' print("%s" % cursor.value(i))',
' cursor.moveNext()',
)
@@ -232,7 +232,7 @@ class Samples:
except:
import traceback
trace = "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
- print trace
+ print(trace)
class _CellsWidget(ListWidget):
def __init__(self, parentwidget):
@@ -279,13 +279,13 @@ class Samples:
'# Get the sheet defined by the sheetname.',
'sheet = document.sheetByName( \"{SheetName}\" )',
'if not sheet:',
- ' raise "No such sheet {SheetName} %s" % document.sheetNames()',
+ ' raise Exception("No such sheet {SheetName} %s" % document.sheetNames())',
'',
'( (col1,row1),(col2,row2) ) = {Cells}',
'for c in range(col1,col2):',
' for r in range(row1,row2):',
' cell = sheet.cell(c,r)',
- ' print "cell c=%s r=%s v=%s" % (c,r,cell.value())',
+ ' print("cell c=%s r=%s v=%s" % (c,r,cell.value()))',
' cell.setText( \"{Value}\" )',
)
@@ -311,7 +311,7 @@ class Samples:
'# Get the sheet defined by the sheetname.',
'sheet = document.sheetByName( \"{SheetName}\" )',
'if not sheet:',
- ' raise "No such sheet {SheetName} %s" % document.sheetNames()',
+ ' raise Exception("No such sheet {SheetName} %s" % document.sheetNames())',
'',
'( (col1,row1),(col2,row2) ) = {Cells}',
'for c in range(col1,col2):',
@@ -340,12 +340,12 @@ class Samples:
'# Get the sheet defined by the sheetname.',
'sheet = document.sheetByName( \"{SheetName}\" )',
'if not sheet:',
- ' raise "No such sheet {SheetName} %s" % document.sheetNames()',
+ ' raise Exception("No such sheet {SheetName} %s" % document.sheetNames())',
'',
'# Iterate through the cells that have content (aka that are not empty).',
'cell = sheet.firstCell()',
'while cell:',
- ' print "col=%s row=%s value=%s" % (cell.column(),cell.row(),cell.value())',
+ ' print("col=%s row=%s value=%s" % (cell.column(),cell.row(),cell.value()))',
' cell = cell.nextCell()',
)
@@ -367,10 +367,10 @@ class Samples:
'# Get the sheet defined by the sheetname.',
'sheet = document.sheetByName( \"{SheetName}\" )',
'if not sheet:',
- ' raise "No such sheet {SheetName} %s" % document.sheetNames()',
+ ' raise Exception("No such sheet {SheetName} %s" % document.sheetNames())',
'',
- 'print "name=%s" % sheet.name()',
- 'print "maxcolumns=%s maxrows=%s" % (sheet.maxColumn(),sheet.maxRow())',
+ 'print("name=%s" % sheet.name())',
+ 'print("maxcolumns=%s maxrows=%s" % (sheet.maxColumn(),sheet.maxRow()))',
)
class LoadDocFromNativeXML:
@@ -464,10 +464,10 @@ class Samples:
'document = krosskspreadcore.get("KSpreadDocument")',
'# Get the source sheet.',
'fromsheet = document.sheetByName( "{SourceSheet}" )',
- 'if not fromsheet: raise "No such sheet {SourceSheet} %s" % document.sheetNames()',
+ 'if not fromsheet: raise Exception("No such sheet {SourceSheet} %s" % document.sheetNames())',
'# Get the target sheet.',
'tosheet = document.sheetByName( "{TargetSheet}" )',
- 'if not fromsheet: raise "No such sheet {TargetSheet} %s" % document.sheetNames()',
+ 'if not fromsheet: raise Exception("No such sheet {TargetSheet} %s" % document.sheetNames())',
'# Copy the cells.',
'fromcell = fromsheet.firstCell()',
'while fromcell:',
@@ -492,13 +492,13 @@ class Samples:
'# Get the current document and the sheet.',
'document = krosskspreadcore.get("KSpreadDocument")',
'sheet = document.sheetByName( "{Sheet}" )',
- 'if not sheet: raise "No such sheet {Sheet} %s" % document.sheetNames()',
+ 'if not sheet: raise Exception("No such sheet {Sheet} %s" % document.sheetNames())',
'',
'filename = "{FileName}"',
'try:',
' file = open(filename, "r")',
'except IOError:',
- ' raise "Failed to open CSV File: %s" % filename',
+ ' raise Exception("Failed to open CSV File: %s" % filename)',
'',
'import csv',
'csvparser = csv.reader(file)',
@@ -530,7 +530,7 @@ class Samples:
'try:',
' file = open(filename, "w")',
'except IOError:',
- ' raise "Failed to write CSV File: %s" % filename',
+ ' raise Exception("Failed to write CSV File: %s" % filename)',
'# Prepare CSV-writer',
'import csv',
'csvwriter = csv.writer(file)',
@@ -539,7 +539,7 @@ class Samples:
'# Get the current document and the sheet.',
'document = krosskspreadcore.get("KSpreadDocument")',
'sheet = document.sheetByName( "{Sheet}" )',
- 'if not sheet: raise "No such sheet {Sheet} %s" % document.sheetNames()',
+ 'if not sheet: raise Exception("No such sheet {Sheet} %s" % document.sheetNames())',
'# Iterate over the cells.',
'cell = sheet.firstCell()',
'record = []',
@@ -572,7 +572,7 @@ class Samples:
return (
'from TQt import qt',
'openfilename = qt.TQFileDialog.getOpenFileName("{FileName}","*.txt *.html;;*", self)',
- 'print "openfile=%s" % openfilename',
+ 'print("openfile=%s" % openfilename)',
)
class SaveFileDialog:
@@ -587,7 +587,7 @@ class Samples:
return (
'from TQt import qt',
'savefilename = qt.TQFileDialog.getSaveFileName("{FileName}","*.txt *.html;;*", self)',
- 'print "savefile=%s" % savefilename',
+ 'print("savefile=%s" % savefilename)',
)
class CustomDialog:
@@ -631,9 +631,9 @@ class Samples:
'',
'text, ok = qt.TQInputDialog.getText("{Caption}", "{Message}", qt.TQLineEdit.Normal, "")',
'if ok:',
- ' print "Text defined: %s" % text',
+ ' print("Text defined: %s" % text)',
'else:',
- ' print "Dialog aborted."',
+ ' print("Dialog aborted.")',
)
####################################################################################
@@ -658,7 +658,7 @@ class Samples:
'd = dcopext.DCOPApp(apps[0], dcopclient)',
'result,typename,data = d.appclient.call(apps[0],"klipper","getClipboardContents()","")',
'ds = qt.TQDataStream(data, qt.IO_ReadOnly)',
- 'print "Clipboard content:\\n%s" % tdecore.dcop_next(ds, TQSTRING_OBJECT_NAME_STRING)',
+ 'print("Clipboard content:\\n%s" % tdecore.dcop_next(ds, TQSTRING_OBJECT_NAME_STRING))',
)
class AmarokCollectionInfos:
@@ -685,7 +685,7 @@ class Samples:
'',
'for funcname in ["totalAlbums","totalArtists","totalCompilations","totalGenres","totalTracks"]:',
' result,replytype,replydata = d.appclient.call("amarok", "collection", "%s()" % funcname,"")',
- ' print "%s: %s" % ( funcname, dataToList(replydata,["int"])[0] )',
+ ' print("%s: %s" % ( funcname, dataToList(replydata,["int"])[0] ))',
)
class KopeteContacts:
@@ -705,11 +705,11 @@ class Samples:
'd = dcopext.DCOPApp(app, dcopclient)',
'',
'(state,rtype,rdata) = d.appclient.call("kopete", "KopeteIface", "contacts()","")',
- 'if not state: raise "Failed to call the kopete contacts-function"',
+ 'if not state: raise Exception("Failed to call the kopete contacts-function")',
'',
'ds = qt.TQDataStream(rdata.data(), qt.IO_ReadOnly)',
'sl = tdecore.dcop_next (ds, TQSTRINGLIST_OBJECT_NAME_STRING)',
- 'print "contacts=%s" % [ str(s) for s in sl ]',
+ 'print("contacts=%s" % [ str(s) for s in sl ])',
)
class KWordSelectedText:
@@ -740,26 +740,26 @@ class Samples:
'# Get the KWord DCOP client.',
'dcopclient = tdecore.TDEApplication.dcopClient()',
'apps = [ app for app in dcopclient.registeredApplications() if str(app).startswith("kword") ]',
- 'if len(apps) < 1: raise "No KWord instance is running. Please start KWord before!"',
+ 'if len(apps) < 1: raise Exception("No KWord instance is running. Please start KWord before!")',
'appname = apps[0]',
'd = dcopext.DCOPApp(appname, dcopclient)',
'',
'# Call the getDocuments() function.',
'(state,rtype,rdata) = d.appclient.call(appname, "KoApplicationIface", "getDocuments()","")',
- 'if not state: raise "%s: Failed to call getDocuments-function" % appname',
+ 'if not state: raise Exception("%s: Failed to call getDocuments-function" % appname)',
'documents = dataToList(rdata,["QValueList<DCOPRef>"])[0]',
- 'print "documents=%s" % [ str( doc.obj() ) for doc in documents ]',
+ 'print("documents=%s" % [ str( doc.obj() ) for doc in documents ])',
'document = documents[0] # Let\'s just take the first document.',
'',
'# Get the frameset.',
'ba = listToData( [ ("int",0) ] )',
'(state,rtype,rdata) = d.appclient.call(appname, document.obj(), "textFrameSet(int)", ba)',
- 'if not state: raise "%s: Failed to call frameSet-function" % appname',
+ 'if not state: raise Exception("%s: Failed to call frameSet-function" % appname)',
'frameset = dataToList( rdata,["DCOPRef"] )[0] # Let\'s just take the first textframe.',
'',
'# Get the selected text.',
'(state,rtype,rdata) = d.appclient.call(appname, frameset.obj(), "selectedText()", "")',
- 'print "Selected Text: %s" % dataToList( rdata,[TQSTRING_OBJECT_NAME_STRING] )[0]',
+ 'print("Selected Text: %s" % dataToList( rdata,[TQSTRING_OBJECT_NAME_STRING] )[0])',
)
####################################################################################
@@ -815,8 +815,8 @@ class SampleDialog(qt.TQDialog):
def getCode(self):
if not hasattr(self,"code"): return None
code = "\n".join( self.code )
- for widgetname in self.samplechild.widgets.keys():
- print ".............. %s" % widgetname
+ for widgetname in list(self.samplechild.widgets.keys()):
+ print(".............. %s" % widgetname)
widget = self.samplechild.widgets[widgetname]
value = widget.value()
if value != None:
@@ -991,9 +991,9 @@ class MainDialog(qt.TQDialog):
self.scripttext.append( code )
def execCode(self,function):
- import sys, StringIO
- codeOut = StringIO.StringIO()
- codeErr = StringIO.StringIO()
+ import sys, io
+ codeOut = io.StringIO()
+ codeErr = io.StringIO()
sys.stdout = codeOut
sys.stderr = codeErr
@@ -1009,7 +1009,7 @@ class MainDialog(qt.TQDialog):
while hasattr(tb,"tb_next") and tb.tb_next:
tb = tb.tb_next
lineno = tb.tb_lineno
- print "EXCEPTION: lineno=%s" % lineno
+ print("EXCEPTION: lineno=%s" % lineno)
self.scripttext.setCursorPosition( lineno - 1, 0 )
except:
pass
@@ -1019,12 +1019,12 @@ class MainDialog(qt.TQDialog):
s = codeErr.getvalue()
if s:
- print "ERROR:\n%s\n" % s
+ print("ERROR:\n%s\n" % s)
self.console.append(s)
s = codeOut.getvalue()
if s:
- print s
+ print(s)
self.console.append(s)
codeOut.close()
@@ -1042,7 +1042,7 @@ class MainDialog(qt.TQDialog):
self.console.clear()
def doexecute(self):
code = str( self.scripttext.text() )
- exec code in globals(), locals()
+ exec(code, globals(), locals())
self.execCode(doexecute)
self.console.append("<b>Execution done!</b>")
@@ -1058,7 +1058,8 @@ class MainDialog(qt.TQDialog):
self.scripttext.setText( str( file.read() ) )
file.close()
__main__.scripteditorfilename = filename
- except IOError, (errno, strerror):
+ except IOError as xxx_todo_changeme:
+ (errno, strerror) = xxx_todo_changeme.args
qt.TQMessageBox.critical(self,"Error","<qt>Failed to open script file \"%s\"<br><br>%s</qt>" % (filename,strerror))
def openFileAs(self):
@@ -1073,7 +1074,8 @@ class MainDialog(qt.TQDialog):
file = open(__main__.scripteditorfilename, "w")
file.write( str( self.scripttext.text() ) )
file.close()
- except IOError, (errno, strerror):
+ except IOError as xxx_todo_changeme1:
+ (errno, strerror) = xxx_todo_changeme1.args
qt.TQMessageBox.critical(self,"Error","<qt>Failed to open script file \"%s\"<br><br>%s</qt>" % (__main__.scripteditorfilename,strerror))
def saveFileAs(self):