@ -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 " % d rivermanager.driverNames( )' ,
' print ( " drivernames: %s " % d rivermanager.driverNames( ) )' ,
' ' ,
' driver = drivermanager.driver( \" {DriverName} \" ) ' ,
' print " driver: {DriverName} " ' ,
' print " version= %s . %s " % (driver.versionMajor(),driver.versionMinor()) ' ,
' print " mimetype= %s " % d river.fileDBDriverMimeType() ' ,
' print " filedriver= %s " % d river.isFileDriver( )' ,
' print ( " driver: {DriverName} " ) ' ,
' print ( " version= %s . %s " % (driver.versionMajor(),driver.versionMinor()) ú ' ,
' print ( " mimetype= %s " % d river.fileDBDriverMimeType() ú ' ,
' print ( " filedriver= %s " % d river.isFileDriver( ) )' ,
)
class ConnectWithFile :
@ -137,7 +137,7 @@ class Samples:
' ' ,
' # Get the connectiondata from the project file. ' ,
' connectiondata = drivermanager.createConnectionDataByFile( " {ProjectFile} " ) ' ,
' print " Connectiondata: %s " % c onnectiondata.serverInfoString( )' ,
' print ( " Connectiondata: %s " % c onnectiondata.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 " % c onnection.databaseNames( )' ,
' print ( " Databases: %s " % c onnection.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 " % c onnection.allTableNames( )' ,
' print " Tables: %s " % c onnection.tableNames( )' ,
' print " Queries: %s " % c onnection.queryNames( )' ,
' print ( " All tables: %s " % c onnection.allTableNames( ) )' ,
' print ( " Tables: %s " % c onnection.tableNames( ) )' ,
' print ( " Queries: %s " % c onnection.queryNames( ) )' ,
)
class IterateThroughTable :
@ -177,7 +177,7 @@ class Samples:
' ' ,
' # Get the connectiondata from the project file. ' ,
' connectiondata = drivermanager.createConnectionDataByFile( " {ProjectFile} " ) ' ,
' print " Connectiondata: %s " % c onnectiondata.serverInfoString( )' ,
' print ( " Connectiondata: %s " % c onnectiondata.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 " % c ursor.value(i )' ,
' print ( " %s " % c ursor.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 " % d ocument.sheetNames( )' ,
' raise Exception( " No such sheet {SheetName} %s " % d ocument.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 " % d ocument.sheetNames( )' ,
' raise Exception( " No such sheet {SheetName} %s " % d ocument.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 " % d ocument.sheetNames( )' ,
' raise Exception( " No such sheet {SheetName} %s " % d ocument.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 " % d ocument.sheetNames( )' ,
' raise Exception( " No such sheet {SheetName} %s " % d ocument.sheetNames( ) )' ,
' ' ,
' print " name= %s " % s heet.name( )' ,
' print " maxcolumns= %s maxrows= %s " % (sheet.maxColumn(),sheet.maxRow( ))' ,
' print ( " name= %s " % s heet.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 " % d ocument.sheetNames( )' ,
' if not fromsheet: raise Exception( " No such sheet {SourceSheet} %s " % d ocument.sheetNames( ) )' ,
' # Get the target sheet. ' ,
' tosheet = document.sheetByName( " {TargetSheet} " ) ' ,
' if not fromsheet: raise " No such sheet {TargetSheet} %s " % d ocument.sheetNames( )' ,
' if not fromsheet: raise Exception( " No such sheet {TargetSheet} %s " % d ocument.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 " % d ocument.sheetNames( )' ,
' if not sheet: raise Exception( " No such sheet {Sheet} %s " % d ocument.sheetNames( ) )' ,
' ' ,
' filename = " {FileName} " ' ,
' try: ' ,
' file = open(filename, " r " ) ' ,
' except IOError: ' ,
' raise " Failed to open CSV File: %s " % f ilename ' ,
' raise Exception( " Failed to open CSV File: %s " % f ilename ) ' ,
' ' ,
' 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 " % f ilename ' ,
' raise Exception( " Failed to write CSV File: %s " % f ilename ) ' ,
' # 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 " % d ocument.sheetNames( )' ,
' if not sheet: raise Exception( " No such sheet {Sheet} %s " % d ocument.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 " % o penfilename ' ,
' print ( " openfile= %s " % o penfilename ) ' ,
)
class SaveFileDialog :
@ -587,7 +587,7 @@ class Samples:
return (
' from TQt import qt ' ,
' savefilename = qt.TQFileDialog.getSaveFileName( " {FileName} " , " *.txt *.html;;* " , self) ' ,
' print " savefile= %s " % s avefilename ' ,
' print ( " savefile= %s " % s avefilename ) ' ,
)
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 () " % f uncname, " " ) ' ,
' 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 " % a ppname ' ,
' if not state: raise Exception( " %s : Failed to call getDocuments-function " % a ppname ) ' ,
' 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 " % a ppname ' ,
' if not state: raise Exception( " %s : Failed to call frameSet-function " % a ppname ) ' ,
' 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 " % d ataToList( rdata,[TQSTRING_OBJECT_NAME_STRING] )[0] ' ,
' print ( " Selected Text: %s " % d ataToList( 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 ) :