[PyKDE] QToolButton
claude.faath
claude.faath at wanadoo.fr
Fri Jan 16 11:51:00 GMT 2004
Hello
Here my code
#!/usr/bin/env python
import string
import sys
from qt import *
fileopen = [
'16 13 5 1',
'. c #040404',
'# c #808304',
'a c None',
'b c #f3f704',
'c c #f3f7f3',
'aaaaaaaaa...aaaa',
'aaaaaaaa.aaa.a.a',
'aaaaaaaaaaaaa..a',
'a...aaaaaaaa...a',
'.bcb.......aaaaa',
'.cbcbcbcbc.aaaaa',
'.bcbcbcbcb.aaaaa',
'.cbcb...........',
'.bcb.#########.a',
'.cb.#########.aa',
'.b.#########.aaa',
'..#########.aaaa',
'...........aaaaa'
]
filesave = [
'14 14 4 1',
'. c #040404',
'# c #808304',
'a c #bfc2bf',
'b c None',
'..............',
'.#.aaaaaaaa.a.',
'.#.aaaaaaaa...',
'.#.aaaaaaaa.#.',
'.#.aaaaaaaa.#.',
'.#.aaaaaaaa.#.',
'.#.aaaaaaaa.#.',
'.##........##.',
'.############.',
'.##.........#.',
'.##......aa.#.',
'.##......aa.#.',
'.##......aa.#.',
'b.............'
]
windowsList = []
class EdMainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self, None, "QtEd", Qt.WDestructiveClose)
self.menuBar = self.menuBar()
self.statusBar = self.statusBar()
fileMenu = QPopupMenu(self)
fileMenu.insertItem('&New', self.newFile, Qt.CTRL + Qt.Key_N)
fileMenu.insertItem('&Open', self.open, Qt.CTRL + Qt.Key_O)
fileMenu.insertItem('&Save', self.save, Qt.CTRL + Qt.Key_S)
fileMenu.insertSeparator()
fileMenu.insertItem('&Close', self, SLOT('close()'), Qt.CTRL + Qt.Key_W)
fileMenu.insertItem('&Quit', qApp, SLOT('closeAllWindows()'), Qt.CTRL + Qt.Key_Q)
self.menuBar.insertItem('&File', fileMenu)
toolBar = QToolBar(self)
self.fileOpen = QToolButton(QPixmap(fileopen), 'Open File', 'Opens a new file', self.open, \
toolBar, 'Open file')
self.fileSave = QToolButton(QPixmap(filesave), 'Save File', 'Saves current file', self.save, \
toolBar, 'Save file')
self.addToolBar(toolBar, "Main toolbar")
self.textView = QMultiLineEdit(self)
self.setCentralWidget(self.textView)
self.textView.setFocus()
self.statusBar.message("[New File]")
self.fileName = QString.null
self.resize(320, 240)
def newFile(self):
ed = EdMainWindow()
ed.show()
windowsList.append(ed)
def open(self):
file = QFileDialog.getOpenFileName(QString.null, QString.null, self)
if file.isEmpty():
self.statusBar.message('Loading aborted', 2000)
return
fileName = str(file)
self.textView.setAutoUpdate(0)
self.textView.clear()
try:
fstream = open(fileName, 'r')
except:
return
for line in fstream.readlines():
self.textView.append(string.rstrip(line))
fstream.close()
self.textView.setAutoUpdate(1)
self.textView.repaint()
self.textView.setEdited(0)
self.statusBar.message('Loaded document %s' % (fileName),2000)
def save(self):
if self.fileName.isEmpty():
self.saveAs()
return
try:
f = open(str(self.fileName), 'w+')
except:
self.statusBar.message('Could not write to %s' % (self.fileName), 2000)
return
f.write(str(self.textView.text()))
f.close()
self.textView.setEdited(0)
self.statusBar.message('File %s saved' % (self.fileName), 2000)
def saveAs(self):
file = QFileDialog.getSaveFileName(QString.null, QString.null, self)
if not file.isEmpty():
self.fileName = file
self.save()
else:
self.statusBar.message('Saving aborted', 2000)
app = QApplication(sys.argv)
mainWindow = EdMainWindow()
mainWindow.show()
app.connect(app, SIGNAL('lastWindowClosed()'), app, SLOT('quit()'))
app.exec_loop()
I have the traceback according to
File "qted.py", line ..., in ?
mainWindow = EdMainWindow()
File "qted.py", line..., in __init__
toolBar, 'Open file')
File "/usr/lib/python2.3/site-packages/qt.py", line 835, in __init__
libqtc.sipCallCtor(21,self,args)
TypeError:Argument 1 of QToolButton( )has an invalid type
My version Debian python2.3-qt3c102 python2.3-siop-qt3
[ SIP 3.8-2 QT 3.8-2.1 PYTHON 2.3 ]
Suggestions ?
Claude
More information about the PyQt
mailing list