[pyar] [PyQt4] Problema con overload de keyPressEvent

Martin Chikilian slacklinucs en gmail.com
Mar Mayo 24 16:47:28 ART 2011


Hola listeros,

Como dice el subject, tengo el siguiente SyntaxError cuando intento correr
mi código:

mguillech en mguillech-laptop:~/Dropbox/Docs/Python/My Code/My_Notepad-1.0$
python mynotepad.py ~/reclamo_telecom
  File "mynotepad.py", line 93
    self.textEdit.keyPressEvent = lamba e: self.setWindowTitle('%s - %s*' %
(PROG_NAME, self._document))
                                        ^
SyntaxError: invalid syntax

Fragmento relevante:

def __init__(self):
        self.app = QtGui.QApplication(sys.argv)
        super(MainWindow, self).__init__()

        self.setWindowTitle('%s - %s' % (PROG_NAME, self._document))
        self.resize(600, 500)

        menubar = self.menuBar()

        self.m_file = menubar.addMenu('&File')
        self.a_new = createMenuItem(self.m_file, '&New', 'Ctrl+N',
'new.png', 'Create new file')
        self.a_open = createMenuItem(self.m_file, '&Open', 'Ctrl+O',
'open.png', 'Open a file')
        self.a_save = createMenuItem(self.m_file, '&Save', 'Ctrl+S',
'save.png', 'Save this file')
        self.m_file.addSeparator()
        self.a_quit = createMenuItem(self.m_file, '&Quit', 'Ctrl+Q',
'exit.png', 'Exit application')

        self.m_edit = menubar.addMenu('&Edit')
        self.a_cut = createMenuItem(self.m_edit, 'Cu&t', 'Ctrl+X',
'cut.png', 'Cut selected text')
        self.a_copy = createMenuItem(self.m_edit, '&Copy', 'Ctrl+C',
'copy.png', 'Copy selected text')
        self.a_paste = createMenuItem(self.m_edit, '&Paste', 'Ctrl+V',
'paste.png', 'Paste clipboard contents')
        self.m_edit.addSeparator()
        self.a_sel_all = createMenuItem(self.m_edit, '&Select all',
'Ctrl+E', menu_status_tip='Select all text')

        for item in self.a_save, self.a_cut, self.a_copy:
            enabledItem(item, False)

        self.toolbar = self.addToolBar('')
        for action in self.a_new, self.a_open, self.a_save:
            createToolItem(self.toolbar, action)

        self.toolbar.addSeparator()

        for action in self.a_cut, self.a_copy, self.a_paste:
            createToolItem(self.toolbar, action)

        self.textEdit = QtGui.QTextEdit()
        self.setCentralWidget(self.textEdit)

        self.textEdit.textChanged.connect(self.textChanged)
        self.textEdit.cursorPositionChanged.connect(self.updateCursorPos)
        self.textEdit.copyAvailable.connect(self.manageCopy)

        self.textEdit.keyPressEvent = lamba e: self.setWindowTitle('%s -
%s*' % (PROG_NAME, self._document))                 <-- LINEA QUE LE PIFIO
EN ALGO

A riesgo de ser repetitivo, en qué estoy errándole?

Gracias!

Martín
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20110524/ff5d575a/attachment.html>


More information about the pyar mailing list