@ -14,30 +14,30 @@ Dual-licensed under LGPL v2+higher and the BSD license.
import os , sys
import os , sys
try :
try :
from TQt import qt
from TQt import t qt
except ( ImportError ) :
except ( ImportError ) :
raise Exception ( " Failed to import the required PyTQt python module. " )
raise Exception ( " Failed to import the required PyTQt python module. " )
####################################################################################
####################################################################################
# Samples.
# Samples.
class Widget ( qt. TQHBox ) :
class Widget ( t qt. TQHBox ) :
def __init__ ( self , parentwidget , label = None ) :
def __init__ ( self , parentwidget , label = None ) :
self . parentwidget = parentwidget
self . parentwidget = parentwidget
from TQt import qt
from TQt import t qt
qt. TQHBox . __init__ ( self , parentwidget )
t qt. TQHBox . __init__ ( self , parentwidget )
self . setMargin ( 4 )
self . setMargin ( 4 )
self . setSpacing ( 4 )
self . setSpacing ( 4 )
if label != None : qt. TQLabel ( label , self )
if label != None : t qt. TQLabel ( label , self )
def value ( self ) :
def value ( self ) :
return None
return None
class ListWidget ( Widget ) :
class ListWidget ( Widget ) :
def __init__ ( self , parentwidget , label ) :
def __init__ ( self , parentwidget , label ) :
from TQt import qt
from TQt import t qt
global Widget
global Widget
Widget . __init__ ( self , parentwidget , label )
Widget . __init__ ( self , parentwidget , label )
self . combo = qt. TQComboBox ( self )
self . combo = t qt. TQComboBox ( self )
self . combo . setEditable ( True )
self . combo . setEditable ( True )
self . setStretchFactor ( self . combo , 1 )
self . setStretchFactor ( self . combo , 1 )
def value ( self ) :
def value ( self ) :
@ -45,10 +45,10 @@ class ListWidget(Widget):
class EditWidget ( Widget ) :
class EditWidget ( Widget ) :
def __init__ ( self , parentwidget , label ) :
def __init__ ( self , parentwidget , label ) :
from TQt import qt
from TQt import t qt
global Widget
global Widget
Widget . __init__ ( self , parentwidget , label )
Widget . __init__ ( self , parentwidget , label )
self . edit = qt. TQLineEdit ( self )
self . edit = t qt. TQLineEdit ( self )
self . setStretchFactor ( self . edit , 1 )
self . setStretchFactor ( self . edit , 1 )
def value ( self ) :
def value ( self ) :
return self . edit . text ( )
return self . edit . text ( )
@ -57,20 +57,20 @@ class FileWidget(Widget):
def __init__ ( self , parentwidget , label , filtermask , openfiledialog = True ) :
def __init__ ( self , parentwidget , label , filtermask , openfiledialog = True ) :
self . filtermask = filtermask
self . filtermask = filtermask
self . openfiledialog = openfiledialog
self . openfiledialog = openfiledialog
from TQt import qt
from TQt import t qt
global Widget
global Widget
Widget . __init__ ( self , parentwidget , label )
Widget . __init__ ( self , parentwidget , label )
self . edit = qt. TQLineEdit ( self )
self . edit = t qt. TQLineEdit ( self )
self . setStretchFactor ( self . edit , 1 )
self . setStretchFactor ( self . edit , 1 )
btn = qt. TQPushButton ( " ... " , self )
btn = t qt. TQPushButton ( " ... " , self )
qt. TQObject . connect ( btn , qt. SIGNAL ( " clicked() " ) , self . btnClicked )
t qt. TQObject . connect ( btn , t qt. SIGNAL ( " clicked() " ) , self . btnClicked )
def btnClicked ( self ) :
def btnClicked ( self ) :
from TQt import qt
from TQt import t qt
text = str ( self . edit . text ( ) )
text = str ( self . edit . text ( ) )
if self . openfiledialog :
if self . openfiledialog :
filename = str ( qt. TQFileDialog . getOpenFileName ( text , self . filtermask , self . parentwidget ) )
filename = str ( t qt. TQFileDialog . getOpenFileName ( text , self . filtermask , self . parentwidget ) )
else :
else :
filename = qt. TQFileDialog . getSaveFileName ( text , self . filtermask , self . parentwidget )
filename = t qt. TQFileDialog . getSaveFileName ( text , self . filtermask , self . parentwidget )
if filename != " " : self . edit . setText ( filename )
if filename != " " : self . edit . setText ( filename )
def value ( self ) :
def value ( self ) :
return self . edit . text ( )
return self . edit . text ( )
@ -384,7 +384,7 @@ class Samples:
def getCode ( self ) :
def getCode ( self ) :
return (
return (
' # Import the PyTQt module. ' ,
' # Import the PyTQt module. ' ,
' from TQt import qt' ,
' from TQt import t qt' ,
' ' ,
' ' ,
' def loadFile(filename): ' ,
' def loadFile(filename): ' ,
' # Import the krosskspreadcore module. ' ,
' # Import the krosskspreadcore module. ' ,
@ -395,7 +395,7 @@ class Samples:
' xml = file.read() ' ,
' xml = file.read() ' ,
' file.close() ' ,
' file.close() ' ,
' except IOError, (errno, strerror): ' ,
' except IOError, (errno, strerror): ' ,
' qt.TQMessageBox.critical(self," Error " , " <qt>Failed to read file %s <br><br> %s </qt> " % (filename,strerror)) ' ,
' t qt.TQMessageBox.critical(self," Error " , " <qt>Failed to read file %s <br><br> %s </qt> " % (filename,strerror)) ' ,
' return ' ,
' return ' ,
' ' ,
' ' ,
' # Get the current document. ' ,
' # Get the current document. ' ,
@ -405,7 +405,7 @@ class Samples:
' ' ,
' ' ,
' # Show the openfile dialog ' ,
' # Show the openfile dialog ' ,
' filename = " {FileName} " ' ,
' filename = " {FileName} " ' ,
' openfilename = qt.TQFileDialog.getOpenFileName(filename," *.xml;;* " , self) ' ,
' openfilename = t qt.TQFileDialog.getOpenFileName(filename," *.xml;;* " , self) ' ,
' if str(openfilename) != " " : ' ,
' if str(openfilename) != " " : ' ,
' loadFile( openfilename ) ' ,
' loadFile( openfilename ) ' ,
)
)
@ -421,7 +421,7 @@ class Samples:
def getCode ( self ) :
def getCode ( self ) :
return (
return (
' # Import the PyTQt module. ' ,
' # Import the PyTQt module. ' ,
' from TQt import qt' ,
' from TQt import t qt' ,
' ' ,
' ' ,
' def saveFile(filename): ' ,
' def saveFile(filename): ' ,
' # Import the krosskspreadcore module. ' ,
' # Import the krosskspreadcore module. ' ,
@ -430,7 +430,7 @@ class Samples:
' try: ' ,
' try: ' ,
' file = open(filename, " w " ) ' ,
' file = open(filename, " w " ) ' ,
' except IOError, (errno, strerror): ' ,
' except IOError, (errno, strerror): ' ,
' qt.TQMessageBox.critical(self," Error " , " <qt>Failed to create file %s <br><br> %s </qt> " % (filename,strerror)) ' ,
' t qt.TQMessageBox.critical(self," Error " , " <qt>Failed to create file %s <br><br> %s </qt> " % (filename,strerror)) ' ,
' return ' ,
' return ' ,
' # Get the current document. ' ,
' # Get the current document. ' ,
' document = krosskspreadcore.get( " KSpreadDocument " ) ' ,
' document = krosskspreadcore.get( " KSpreadDocument " ) ' ,
@ -443,7 +443,7 @@ class Samples:
' ' ,
' ' ,
' # Show the savefile dialog ' ,
' # Show the savefile dialog ' ,
' filename = " {FileName} " ' ,
' filename = " {FileName} " ' ,
' savefilename = qt.TQFileDialog.getSaveFileName(filename," *.xml;;* " , self) ' ,
' savefilename = t qt.TQFileDialog.getSaveFileName(filename," *.xml;;* " , self) ' ,
' if str(savefilename) != " " : ' ,
' if str(savefilename) != " " : ' ,
' saveFile( savefilename ) ' ,
' saveFile( savefilename ) ' ,
)
)
@ -561,7 +561,7 @@ class Samples:
self . parentwidget = parentwidget
self . parentwidget = parentwidget
class OpenFileDialog :
class OpenFileDialog :
""" Show the usage of the openfile dialog with QFileDialog. """
""" Show the usage of the openfile dialog with T QFileDialog. """
name = " Open File Dialog "
name = " Open File Dialog "
def __init__ ( self , parent ) :
def __init__ ( self , parent ) :
pass
pass
@ -570,13 +570,13 @@ class Samples:
}
}
def getCode ( self ) :
def getCode ( self ) :
return (
return (
' from TQt import qt' ,
' from TQt import t qt' ,
' openfilename = qt.TQFileDialog.getOpenFileName(" {FileName} " , " *.txt *.html;;* " , self) ' ,
' openfilename = t qt.TQFileDialog.getOpenFileName(" {FileName} " , " *.txt *.html;;* " , self) ' ,
' print( " openfile= %s " % o penfilename) ' ,
' print( " openfile= %s " % o penfilename) ' ,
)
)
class SaveFileDialog :
class SaveFileDialog :
""" Show the usage of the savefile dialog with QFileDialog. """
""" Show the usage of the savefile dialog with T QFileDialog. """
name = " Save File Dialog "
name = " Save File Dialog "
def __init__ ( self , parent ) :
def __init__ ( self , parent ) :
pass
pass
@ -585,13 +585,13 @@ class Samples:
}
}
def getCode ( self ) :
def getCode ( self ) :
return (
return (
' from TQt import qt' ,
' from TQt import t qt' ,
' savefilename = qt.TQFileDialog.getSaveFileName(" {FileName} " , " *.txt *.html;;* " , self) ' ,
' savefilename = t qt.TQFileDialog.getSaveFileName(" {FileName} " , " *.txt *.html;;* " , self) ' ,
' print( " savefile= %s " % s avefilename) ' ,
' print( " savefile= %s " % s avefilename) ' ,
)
)
class CustomDialog :
class CustomDialog :
""" Show a custom dialog that inherits a QDialog. """
""" Show a custom dialog that inherits a T QDialog. """
name = " Custom Dialog "
name = " Custom Dialog "
def __init__ ( self , parent ) :
def __init__ ( self , parent ) :
pass
pass
@ -599,25 +599,25 @@ class Samples:
}
}
def getCode ( self ) :
def getCode ( self ) :
return (
return (
' from TQt import qt' ,
' from TQt import t qt' ,
' ' ,
' ' ,
' class MyDialog( qt.TQDialog):' ,
' class MyDialog( t qt.TQDialog):' ,
' def __init__(self, parent): ' ,
' def __init__(self, parent): ' ,
' from TQt import qt' ,
' from TQt import t qt' ,
' qt.TQDialog.__init__(self, parent, " MyDialog " , 1, qt.TQt.WDestructiveClose)' ,
' t qt.TQDialog.__init__(self, parent, " MyDialog " , 1, t qt.TQt.WDestructiveClose)' ,
' self.setCaption( " My Dialog " ) ' ,
' self.setCaption( " My Dialog " ) ' ,
' btn = qt.TQPushButton(" Click me " ,self) ' ,
' btn = t qt.TQPushButton(" Click me " ,self) ' ,
' qt.TQObject.connect(btn, qt.SIGNAL(" clicked() " ), self.buttonClicked) ' ,
' t qt.TQObject.connect(btn, t qt.SIGNAL(" clicked() " ), self.buttonClicked) ' ,
' def buttonClicked(self): ' ,
' def buttonClicked(self): ' ,
' from TQt import qt' ,
' from TQt import t qt' ,
' qt.TQMessageBox.information(self, " The Caption " , " This is the message string. " ) ' ,
' t qt.TQMessageBox.information(self, " The Caption " , " This is the message string. " ) ' ,
' ' ,
' ' ,
' dialog = MyDialog(self) ' ,
' dialog = MyDialog(self) ' ,
' dialog.exec_loop() ' ,
' dialog.exec_loop() ' ,
)
)
class InputDialog :
class InputDialog :
""" Show how to use a QInputDialog. """
""" Show how to use a T QInputDialog. """
name = " Input Dialog "
name = " Input Dialog "
def __init__ ( self , parent ) :
def __init__ ( self , parent ) :
global EditWidget
global EditWidget
@ -627,9 +627,9 @@ class Samples:
}
}
def getCode ( self ) :
def getCode ( self ) :
return (
return (
' from TQt import qt' ,
' from TQt import t qt' ,
' ' ,
' ' ,
' text, ok = qt.TQInputDialog.getText(" {Caption} " , " {Message} " , qt.TQLineEdit.Normal, " " ) ' ,
' text, ok = t qt.TQInputDialog.getText(" {Caption} " , " {Message} " , t qt.TQLineEdit.Normal, " " ) ' ,
' if ok: ' ,
' if ok: ' ,
' print( " Text defined: %s " % text) ' ,
' print( " Text defined: %s " % text) ' ,
' else: ' ,
' else: ' ,
@ -651,13 +651,13 @@ class Samples:
}
}
def getCode ( self ) :
def getCode ( self ) :
return (
return (
' from TQt import qt' ,
' from TQt import t qt' ,
' import tdecore, dcop, dcopext ' ,
' import tdecore, dcop, dcopext ' ,
' dcopclient = tdecore.TDEApplication.dcopClient() ' ,
' dcopclient = tdecore.TDEApplication.dcopClient() ' ,
' apps = [ app for app in dcopclient.registeredApplications() if str(app).startswith( " klipper " ) ] ' ,
' apps = [ app for app in dcopclient.registeredApplications() if str(app).startswith( " klipper " ) ] ' ,
' d = dcopext.DCOPApp(apps[0], dcopclient) ' ,
' d = dcopext.DCOPApp(apps[0], dcopclient) ' ,
' result,typename,data = d.appclient.call(apps[0], " klipper " , " getClipboardContents() " , " " ) ' ,
' result,typename,data = d.appclient.call(apps[0], " klipper " , " getClipboardContents() " , " " ) ' ,
' ds = qt.TQDataStream(data, qt.IO_ReadOnly)' ,
' ds = t qt.TQDataStream(data, t 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)) ' ,
)
)
@ -669,7 +669,7 @@ class Samples:
}
}
def getCode ( self ) :
def getCode ( self ) :
return (
return (
' from TQt import qt' ,
' from TQt import t qt' ,
' import tdecore, dcop, dcopext ' ,
' import tdecore, dcop, dcopext ' ,
' ' ,
' ' ,
' dcopclient = tdecore.TDEApplication.dcopClient() ' ,
' dcopclient = tdecore.TDEApplication.dcopClient() ' ,
@ -678,9 +678,9 @@ class Samples:
' d = dcopext.DCOPApp(app, dcopclient) ' ,
' d = dcopext.DCOPApp(app, dcopclient) ' ,
' ' ,
' ' ,
' def dataToList(data, types = []): ' ,
' def dataToList(data, types = []): ' ,
' from TQt import qt' ,
' from TQt import t qt' ,
' import tdecore ' ,
' import tdecore ' ,
' ds = qt.TQDataStream(data, qt.IO_ReadOnly)' ,
' ds = t qt.TQDataStream(data, t qt.IO_ReadOnly)' ,
' return [ tdecore.dcop_next(ds, t) for t in types ] ' ,
' return [ tdecore.dcop_next(ds, t) for t in types ] ' ,
' ' ,
' ' ,
' for funcname in [ " totalAlbums " , " totalArtists " , " totalCompilations " , " totalGenres " , " totalTracks " ]: ' ,
' for funcname in [ " totalAlbums " , " totalArtists " , " totalCompilations " , " totalGenres " , " totalTracks " ]: ' ,
@ -696,7 +696,7 @@ class Samples:
}
}
def getCode ( self ) :
def getCode ( self ) :
return (
return (
' from TQt import qt' ,
' from TQt import t qt' ,
' import tdecore, dcop, dcopext ' ,
' import tdecore, dcop, dcopext ' ,
' ' ,
' ' ,
' dcopclient = tdecore.TDEApplication.dcopClient() ' ,
' dcopclient = tdecore.TDEApplication.dcopClient() ' ,
@ -707,7 +707,7 @@ class Samples:
' (state,rtype,rdata) = d.appclient.call( " kopete " , " KopeteIface " , " contacts() " , " " ) ' ,
' (state,rtype,rdata) = d.appclient.call( " kopete " , " KopeteIface " , " contacts() " , " " ) ' ,
' if not state: raise Exception( " 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)' ,
' ds = t qt.TQDataStream(rdata.data(), t qt.IO_ReadOnly)' ,
' sl = tdecore.dcop_next (ds, TQSTRINGLIST_OBJECT_NAME_STRING) ' ,
' 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 ]) ' ,
)
)
@ -720,19 +720,19 @@ class Samples:
}
}
def getCode ( self ) :
def getCode ( self ) :
return (
return (
' from TQt import qt' ,
' from TQt import t qt' ,
' import tdecore, dcop, dcopext ' ,
' import tdecore, dcop, dcopext ' ,
' ' ,
' ' ,
' def dataToList(data, types = []): ' ,
' def dataToList(data, types = []): ' ,
' from TQt import qt' ,
' from TQt import t qt' ,
' import tdecore ' ,
' import tdecore ' ,
' ds = qt.TQDataStream(data, qt.IO_ReadOnly)' ,
' ds = t qt.TQDataStream(data, t qt.IO_ReadOnly)' ,
' return [ tdecore.dcop_next(ds, t) for t in types ] ' ,
' return [ tdecore.dcop_next(ds, t) for t in types ] ' ,
' def listToData(listdict): ' ,
' def listToData(listdict): ' ,
' from TQt import qt' ,
' from TQt import t qt' ,
' import tdecore ' ,
' import tdecore ' ,
' ba= qt.TQByteArray()' ,
' ba= t qt.TQByteArray()' ,
' ds = qt.TQDataStream(ba, qt.IO_WriteOnly)' ,
' ds = t qt.TQDataStream(ba, t qt.IO_WriteOnly)' ,
' for (typename,value) in listdict: ' ,
' for (typename,value) in listdict: ' ,
' tdecore.dcop_add (ds, value, typename) ' ,
' tdecore.dcop_add (ds, value, typename) ' ,
' return ba ' ,
' return ba ' ,
@ -747,7 +747,7 @@ class Samples:
' # Call the getDocuments() function. ' ,
' # Call the getDocuments() function. ' ,
' (state,rtype,rdata) = d.appclient.call(appname, " KoApplicationIface " , " getDocuments() " , " " ) ' ,
' (state,rtype,rdata) = d.appclient.call(appname, " KoApplicationIface " , " getDocuments() " , " " ) ' ,
' if not state: raise Exception( " %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] ' ,
' documents = dataToList(rdata,[ " T 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. ' ,
' document = documents[0] # Let \' s just take the first document. ' ,
' ' ,
' ' ,
@ -765,48 +765,48 @@ class Samples:
####################################################################################
####################################################################################
# Dialog implementations.
# Dialog implementations.
class SampleDialog ( qt. TQDialog ) :
class SampleDialog ( t qt. TQDialog ) :
def __init__ ( self , parent , sampleclazz , samplechildclazz ) :
def __init__ ( self , parent , sampleclazz , samplechildclazz ) :
from TQt import qt
from TQt import t qt
qt. TQDialog . __init__ ( self , parent , " SampleDialog " , 1 )
t qt. TQDialog . __init__ ( self , parent , " SampleDialog " , 1 )
layout = qt. TQVBoxLayout ( self )
layout = t qt. TQVBoxLayout ( self )
box = qt. TQVBox ( self )
box = t qt. TQVBox ( self )
box . setMargin ( 4 )
box . setMargin ( 4 )
box . setSpacing ( 10 )
box . setSpacing ( 10 )
layout . addWidget ( box )
layout . addWidget ( box )
self . scrollview = qt. TQScrollView ( box )
self . scrollview = t qt. TQScrollView ( box )
self . scrollview . setResizePolicy ( qt. TQScrollView . AutoOne )
self . scrollview . setResizePolicy ( t qt. TQScrollView . AutoOne )
#self.scrollview.setFrameStyle( qt.TQFrame.NoFrame);
#self.scrollview.setFrameStyle( t qt.TQFrame.NoFrame);
self . scrollview . setResizePolicy ( qt. TQScrollView . AutoOneFit ) ;
self . scrollview . setResizePolicy ( t qt. TQScrollView . AutoOneFit ) ;
self . scrollview . viewport ( ) . setPaletteBackgroundColor ( self . paletteBackgroundColor ( ) )
self . scrollview . viewport ( ) . setPaletteBackgroundColor ( self . paletteBackgroundColor ( ) )
mainbox = qt. TQVBox ( self . scrollview . viewport ( ) )
mainbox = t qt. TQVBox ( self . scrollview . viewport ( ) )
mainbox . setMargin ( 6 )
mainbox . setMargin ( 6 )
mainbox . setSpacing ( 6 )
mainbox . setSpacing ( 6 )
desclabel = qt. TQLabel ( mainbox )
desclabel = t qt. TQLabel ( mainbox )
qt. TQFrame ( mainbox ) . setFrameStyle ( qt. TQFrame . HLine | qt. TQFrame . Sunken )
t qt. TQFrame ( mainbox ) . setFrameStyle ( t qt. TQFrame . HLine | t qt. TQFrame . Sunken )
self . sample = sampleclazz ( mainbox )
self . sample = sampleclazz ( mainbox )
self . samplechild = samplechildclazz ( self . sample )
self . samplechild = samplechildclazz ( self . sample )
desclabel . setText ( " <qt> %s </qt> " % self . samplechild . __doc__ )
desclabel . setText ( " <qt> %s </qt> " % self . samplechild . __doc__ )
mainbox . setStretchFactor ( qt. TQWidget ( mainbox ) , 1 )
mainbox . setStretchFactor ( t qt. TQWidget ( mainbox ) , 1 )
mainbox . show ( )
mainbox . show ( )
self . scrollview . addChild ( mainbox )
self . scrollview . addChild ( mainbox )
btnbox = qt. TQHBox ( box )
btnbox = t qt. TQHBox ( box )
btnbox . setMargin ( 6 )
btnbox . setMargin ( 6 )
btnbox . setSpacing ( 6 )
btnbox . setSpacing ( 6 )
okbtn = qt. TQPushButton ( btnbox )
okbtn = t qt. TQPushButton ( btnbox )
okbtn . setText ( " Ok " )
okbtn . setText ( " Ok " )
qt. TQObject . connect ( okbtn , qt. SIGNAL ( " clicked() " ) , self . okClicked )
t qt. TQObject . connect ( okbtn , t qt. SIGNAL ( " clicked() " ) , self . okClicked )
cancelbtn = qt. TQPushButton ( btnbox )
cancelbtn = t qt. TQPushButton ( btnbox )
cancelbtn . setText ( " Cancel " )
cancelbtn . setText ( " Cancel " )
qt. TQObject . connect ( cancelbtn , qt. SIGNAL ( " clicked() " ) , self . close )
t qt. TQObject . connect ( cancelbtn , t qt. SIGNAL ( " clicked() " ) , self . close )
self . setCaption ( self . samplechild . name )
self . setCaption ( self . samplechild . name )
box . setMinimumSize ( qt. TQSize ( 500 , 340 ) )
box . setMinimumSize ( t qt. TQSize ( 500 , 340 ) )
def okClicked ( self ) :
def okClicked ( self ) :
self . code = self . samplechild . getCode ( )
self . code = self . samplechild . getCode ( )
@ -823,7 +823,7 @@ class SampleDialog(qt.TQDialog):
code = code . replace ( " { %s } " % widgetname , str ( value ) )
code = code . replace ( " { %s } " % widgetname , str ( value ) )
return code
return code
class MainDialog ( qt. TQDialog ) :
class MainDialog ( t qt. TQDialog ) :
def __init__ ( self , scriptpath , parent ) :
def __init__ ( self , scriptpath , parent ) :
self . scriptpath = scriptpath
self . scriptpath = scriptpath
if not hasattr ( __main__ , " scripteditorfilename " ) :
if not hasattr ( __main__ , " scripteditorfilename " ) :
@ -833,118 +833,118 @@ class MainDialog(qt.TQDialog):
self . doc = krosskspreadcore . get ( " KSpreadDocument " )
self . doc = krosskspreadcore . get ( " KSpreadDocument " )
import os
import os
from TQt import qt
from TQt import t qt
qt. TQDialog . __init__ ( self , parent , " MainDialog " , 1 , qt. TQt . WDestructiveClose )
t qt. TQDialog . __init__ ( self , parent , " MainDialog " , 1 , t qt. TQt . WDestructiveClose )
self . setCaption ( " Script Editor " )
self . setCaption ( " Script Editor " )
layout = qt. TQVBoxLayout ( self )
layout = t qt. TQVBoxLayout ( self )
box = qt. TQVBox ( self )
box = t qt. TQVBox ( self )
box . setMargin ( 4 )
box . setMargin ( 4 )
box . setSpacing ( 10 )
box . setSpacing ( 10 )
layout . addWidget ( box )
layout . addWidget ( box )
menu = qt. TQMenuBar ( box )
menu = t qt. TQMenuBar ( box )
splitter = qt. TQSplitter ( box )
splitter = t qt. TQSplitter ( box )
splitter . setOrientation ( qt. TQt . Vertical )
splitter . setOrientation ( t qt. TQt . Vertical )
self . scripttext = qt. TQMultiLineEdit ( splitter )
self . scripttext = t qt. TQMultiLineEdit ( splitter )
self . scripttext . setWordWrap ( qt. TQTextEdit . NoWrap )
self . scripttext . setWordWrap ( t qt. TQTextEdit . NoWrap )
self . scripttext . setTextFormat ( qt. TQt . PlainText )
self . scripttext . setTextFormat ( t qt. TQt . PlainText )
qt. TQObject . connect ( self . scripttext , qt. SIGNAL ( " cursorPositionChanged(int,int) " ) , self . cursorPositionChanged )
t qt. TQObject . connect ( self . scripttext , t qt. SIGNAL ( " cursorPositionChanged(int,int) " ) , self . cursorPositionChanged )
self . console = qt. TQTextBrowser ( splitter )
self . console = t qt. TQTextBrowser ( splitter )
splitter . setResizeMode ( self . console , qt. TQSplitter . KeepSize )
splitter . setResizeMode ( self . console , t qt. TQSplitter . KeepSize )
statusbar = qt. TQStatusBar ( box )
statusbar = t qt. TQStatusBar ( box )
self . messagestatus = qt. TQLabel ( statusbar )
self . messagestatus = t qt. TQLabel ( statusbar )
statusbar . addWidget ( self . messagestatus , 1 )
statusbar . addWidget ( self . messagestatus , 1 )
self . cursorstatus = qt. TQLabel ( statusbar )
self . cursorstatus = t qt. TQLabel ( statusbar )
statusbar . addWidget ( self . cursorstatus )
statusbar . addWidget ( self . cursorstatus )
self . cursorPositionChanged ( )
self . cursorPositionChanged ( )
box . setMinimumSize ( qt. TQSize ( 680 , 540 ) )
box . setMinimumSize ( t qt. TQSize ( 680 , 540 ) )
filemenu = qt. TQPopupMenu ( menu )
filemenu = t qt. TQPopupMenu ( menu )
menu . insertItem ( " &File " , filemenu )
menu . insertItem ( " &File " , filemenu )
newaction = qt. TQAction ( " New " , qt. TQKeySequence ( " CTRL+N " ) , self )
newaction = t qt. TQAction ( " New " , t qt. TQKeySequence ( " CTRL+N " ) , self )
qt. TQObject . connect ( newaction , qt. SIGNAL ( " activated() " ) , self . newFile )
t qt. TQObject . connect ( newaction , t qt. SIGNAL ( " activated() " ) , self . newFile )
newaction . addTo ( filemenu )
newaction . addTo ( filemenu )
openaction = qt. TQAction ( " Open... " , qt. TQKeySequence ( " CTRL+O " ) , self )
openaction = t qt. TQAction ( " Open... " , t qt. TQKeySequence ( " CTRL+O " ) , self )
qt. TQObject . connect ( openaction , qt. SIGNAL ( " activated() " ) , self . openFileAs )
t qt. TQObject . connect ( openaction , t qt. SIGNAL ( " activated() " ) , self . openFileAs )
openaction . addTo ( filemenu )
openaction . addTo ( filemenu )
saveaction = qt. TQAction ( " Save " , qt. TQKeySequence ( " CTRL+S " ) , self )
saveaction = t qt. TQAction ( " Save " , t qt. TQKeySequence ( " CTRL+S " ) , self )
qt. TQObject . connect ( saveaction , qt. SIGNAL ( " activated() " ) , self . saveFile )
t qt. TQObject . connect ( saveaction , t qt. SIGNAL ( " activated() " ) , self . saveFile )
saveaction . addTo ( filemenu )
saveaction . addTo ( filemenu )
saveasaction = qt. TQAction ( " Save as... " , qt. TQKeySequence ( " CTRL+A " ) , self )
saveasaction = t qt. TQAction ( " Save as... " , t qt. TQKeySequence ( " CTRL+A " ) , self )
qt. TQObject . connect ( saveasaction , qt. SIGNAL ( " activated() " ) , self . saveFileAs )
t qt. TQObject . connect ( saveasaction , t qt. SIGNAL ( " activated() " ) , self . saveFileAs )
saveasaction . addTo ( filemenu )
saveasaction . addTo ( filemenu )
filemenu . insertSeparator ( )
filemenu . insertSeparator ( )
quitaction = qt. TQAction ( " Quit " , qt. TQKeySequence ( " CTRL+Q " ) , self )
quitaction = t qt. TQAction ( " Quit " , t qt. TQKeySequence ( " CTRL+Q " ) , self )
qt. TQObject . connect ( quitaction , qt. SIGNAL ( " activated() " ) , self . close )
t qt. TQObject . connect ( quitaction , t qt. SIGNAL ( " activated() " ) , self . close )
quitaction . addTo ( filemenu )
quitaction . addTo ( filemenu )
editmenu = qt. TQPopupMenu ( menu )
editmenu = t qt. TQPopupMenu ( menu )
menu . insertItem ( " &Edit " , editmenu )
menu . insertItem ( " &Edit " , editmenu )
undoaction = qt. TQAction ( " Undo " , qt. TQKeySequence ( " CTRL+Z " ) , self )
undoaction = t qt. TQAction ( " Undo " , t qt. TQKeySequence ( " CTRL+Z " ) , self )
qt. TQObject . connect ( undoaction , qt. SIGNAL ( " activated() " ) , self . scripttext . undo )
t qt. TQObject . connect ( undoaction , t qt. SIGNAL ( " activated() " ) , self . scripttext . undo )
undoaction . addTo ( editmenu )
undoaction . addTo ( editmenu )
redoaction = qt. TQAction ( " Redo " , qt. TQKeySequence ( " CTRL+Shift+Z " ) , self )
redoaction = t qt. TQAction ( " Redo " , t qt. TQKeySequence ( " CTRL+Shift+Z " ) , self )
qt. TQObject . connect ( redoaction , qt. SIGNAL ( " activated() " ) , self . scripttext . redo )
t qt. TQObject . connect ( redoaction , t qt. SIGNAL ( " activated() " ) , self . scripttext . redo )
redoaction . addTo ( editmenu )
redoaction . addTo ( editmenu )
editmenu . insertSeparator ( )
editmenu . insertSeparator ( )
cutaction = qt. TQAction ( " Cut " , qt. TQKeySequence ( " CTRL+X " ) , self )
cutaction = t qt. TQAction ( " Cut " , t qt. TQKeySequence ( " CTRL+X " ) , self )
qt. TQObject . connect ( cutaction , qt. SIGNAL ( " activated() " ) , self . scripttext . cut )
t qt. TQObject . connect ( cutaction , t qt. SIGNAL ( " activated() " ) , self . scripttext . cut )
cutaction . addTo ( editmenu )
cutaction . addTo ( editmenu )
copyaction = qt. TQAction ( " Copy " , qt. TQKeySequence ( " CTRL+C " ) , self )
copyaction = t qt. TQAction ( " Copy " , t qt. TQKeySequence ( " CTRL+C " ) , self )
qt. TQObject . connect ( copyaction , qt. SIGNAL ( " activated() " ) , self . scripttext . copy )
t qt. TQObject . connect ( copyaction , t qt. SIGNAL ( " activated() " ) , self . scripttext . copy )
copyaction . addTo ( editmenu )
copyaction . addTo ( editmenu )
pasteaction = qt. TQAction ( " Paste " , qt. TQKeySequence ( " CTRL+V " ) , self )
pasteaction = t qt. TQAction ( " Paste " , t qt. TQKeySequence ( " CTRL+V " ) , self )
qt. TQObject . connect ( pasteaction , qt. SIGNAL ( " activated() " ) , self . scripttext . paste )
t qt. TQObject . connect ( pasteaction , t qt. SIGNAL ( " activated() " ) , self . scripttext . paste )
pasteaction . addTo ( editmenu )
pasteaction . addTo ( editmenu )
clearaction = qt. TQAction ( " Clear " , qt. TQKeySequence ( " CTRL+Shift+X " ) , self )
clearaction = t qt. TQAction ( " Clear " , t qt. TQKeySequence ( " CTRL+Shift+X " ) , self )
qt. TQObject . connect ( clearaction , qt. SIGNAL ( " activated() " ) , self . scripttext . clear )
t qt. TQObject . connect ( clearaction , t qt. SIGNAL ( " activated() " ) , self . scripttext . clear )
clearaction . addTo ( editmenu )
clearaction . addTo ( editmenu )
editmenu . insertSeparator ( )
editmenu . insertSeparator ( )
selallaction = qt. TQAction ( " Select All " , 0 , self )
selallaction = t qt. TQAction ( " Select All " , 0 , self )
qt. TQObject . connect ( selallaction , qt. SIGNAL ( " activated() " ) , self . scripttext . selectAll )
t qt. TQObject . connect ( selallaction , t qt. SIGNAL ( " activated() " ) , self . scripttext . selectAll )
selallaction . addTo ( editmenu )
selallaction . addTo ( editmenu )
scriptmenu = qt. TQPopupMenu ( menu )
scriptmenu = t qt. TQPopupMenu ( menu )
menu . insertItem ( " &Script " , scriptmenu )
menu . insertItem ( " &Script " , scriptmenu )
compileaction = qt. TQAction ( " Compile " , qt. TQKeySequence ( " F9 " ) , self )
compileaction = t qt. TQAction ( " Compile " , t qt. TQKeySequence ( " F9 " ) , self )
qt. TQObject . connect ( compileaction , qt. SIGNAL ( " activated() " ) , self . compileScript )
t qt. TQObject . connect ( compileaction , t qt. SIGNAL ( " activated() " ) , self . compileScript )
compileaction . addTo ( scriptmenu )
compileaction . addTo ( scriptmenu )
executeaction = qt. TQAction ( " Execute " , qt. TQKeySequence ( " F10 " ) , self )
executeaction = t qt. TQAction ( " Execute " , t qt. TQKeySequence ( " F10 " ) , self )
qt. TQObject . connect ( executeaction , qt. SIGNAL ( " activated() " ) , self . executeScript )
t qt. TQObject . connect ( executeaction , t qt. SIGNAL ( " activated() " ) , self . executeScript )
executeaction . addTo ( scriptmenu )
executeaction . addTo ( scriptmenu )
self . samplemenu = qt. TQPopupMenu ( menu )
self . samplemenu = t qt. TQPopupMenu ( menu )
menu . insertItem ( " &Samples " , self . samplemenu )
menu . insertItem ( " &Samples " , self . samplemenu )
itemid = 500
itemid = 500
global Samples
global Samples
for samplename in dir ( Samples ) :
for samplename in dir ( Samples ) :
if samplename . startswith ( " _ " ) : continue
if samplename . startswith ( " _ " ) : continue
itemid + = 1
itemid + = 1
menu = qt. TQPopupMenu ( self . samplemenu )
menu = t qt. TQPopupMenu ( self . samplemenu )
qt. TQObject . connect ( menu , qt. SIGNAL ( " activated(int) " ) , self . sampleActivated )
t qt. TQObject . connect ( menu , t qt. SIGNAL ( " activated(int) " ) , self . sampleActivated )
self . samplemenu . insertItem ( samplename , menu , - 1 , self . samplemenu . count ( ) - 1 )
self . samplemenu . insertItem ( samplename , menu , - 1 , self . samplemenu . count ( ) - 1 )
attr = getattr ( Samples , samplename )
attr = getattr ( Samples , samplename )
for a in dir ( attr ) :
for a in dir ( attr ) :
@ -1048,7 +1048,7 @@ class MainDialog(qt.TQDialog):
def newFile ( self ) :
def newFile ( self ) :
self . console . clear ( )
self . console . clear ( )
#if qt.TQMessageBox.warning(self,"Remove?","Remove the selected item?",qt.TQMessageBox.Yes,qt.TQMessageBox.Cancel) != qt.TQMessageBox.Yes:
#if t qt.TQMessageBox.warning(self,"Remove?","Remove the selected item?",t qt.TQMessageBox.Yes,t qt.TQMessageBox.Cancel) != t qt.TQMessageBox.Yes:
self . scripttext . clear ( )
self . scripttext . clear ( )
def openFile ( self , filename ) :
def openFile ( self , filename ) :
@ -1060,12 +1060,12 @@ class MainDialog(qt.TQDialog):
__main__ . scripteditorfilename = filename
__main__ . scripteditorfilename = filename
except IOError as xxx_todo_changeme :
except IOError as xxx_todo_changeme :
( errno , strerror ) = xxx_todo_changeme . args
( errno , strerror ) = xxx_todo_changeme . args
qt. TQMessageBox . critical ( self , " Error " , " <qt>Failed to open script file \" %s \" <br><br> %s </qt> " % ( filename , strerror ) )
t qt. TQMessageBox . critical ( self , " Error " , " <qt>Failed to open script file \" %s \" <br><br> %s </qt> " % ( filename , strerror ) )
def openFileAs ( self ) :
def openFileAs ( self ) :
from TQt import qt
from TQt import t qt
self . console . clear ( )
self . console . clear ( )
filename = str ( qt. TQFileDialog . getOpenFileName ( __main__ . scripteditorfilename , " *.py;;* " , self ) )
filename = str ( t qt. TQFileDialog . getOpenFileName ( __main__ . scripteditorfilename , " *.py;;* " , self ) )
if filename == " " : return
if filename == " " : return
self . openFile ( filename )
self . openFile ( filename )
@ -1076,11 +1076,11 @@ class MainDialog(qt.TQDialog):
file . close ( )
file . close ( )
except IOError as xxx_todo_changeme1 :
except IOError as xxx_todo_changeme1 :
( errno , strerror ) = xxx_todo_changeme1 . args
( 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 ) )
t qt. TQMessageBox . critical ( self , " Error " , " <qt>Failed to open script file \" %s \" <br><br> %s </qt> " % ( __main__ . scripteditorfilename , strerror ) )
def saveFileAs ( self ) :
def saveFileAs ( self ) :
from TQt import qt
from TQt import t qt
filename = str ( qt. TQFileDialog . getSaveFileName ( __main__ . scripteditorfilename , " *.py;;* " , self ) )
filename = str ( t qt. TQFileDialog . getSaveFileName ( __main__ . scripteditorfilename , " *.py;;* " , self ) )
if filename == " " : return
if filename == " " : return
__main__ . scripteditorfilename = filename
__main__ . scripteditorfilename = filename
self . saveFile ( )
self . saveFile ( )
@ -1090,10 +1090,10 @@ class MainDialog(qt.TQDialog):
if __name__ == " __main__ " :
if __name__ == " __main__ " :
scriptpath = os . getcwd ( )
scriptpath = os . getcwd ( )
qtapp = qt. TQApplication ( sys . argv )
t qtapp = t qt. TQApplication ( sys . argv )
else :
else :
scriptpath = os . path . dirname ( __name__ )
scriptpath = os . path . dirname ( __name__ )
qtapp = qt. tqApp
t qtapp = t qt. tqApp
dialog = MainDialog ( scriptpath , qtapp. mainWidget ( ) )
dialog = MainDialog ( scriptpath , t qtapp. mainWidget ( ) )
dialog . exec_loop ( )
dialog . exec_loop ( )