[PyQt] hidden signals?

Jochen Georges jochengeorges at yahoo.de
Mon Dec 24 12:22:22 GMT 2007


On Monday 24 December 2007 12:25:14 Andreas Pakulat wrote:
> On 24.12.07 09:16:17, Jochen Georges wrote:

> Thats not a simple self-contained example that demonstrates the problem.
> Sorry, but you have to create an app that we can simply run to check
> what exactly happens and whats wrong with that behaviour. 

:-)

> Especially 
> when the verbal description is relatively unclear like in this case (at
> least to me).

sorry

> Andreas

to see what is going wrong, please 

1. click "list"
2. insert a number in the left lineedit
3. press return

now the right lineedit should have the focus.

i looked quite often on these lines, i think for today i'm kind of blind,
so thanks for any hint

beste gruesse
jochen

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Form(QDialog):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        
        self.mainLayout = QVBoxLayout()
        self.browser = QTextBrowser()
        self.mainLayout.addWidget(self.browser)
        
        self.btnLayout = QHBoxLayout()
        self.btnInteractive = QPushButton("interactive")
        self.btnList = QPushButton("list")
        self.btnLayout.addWidget(self.btnInteractive)
        self.btnLayout.addWidget(self.btnList)
        self.mainLayout.addLayout(self.btnLayout)
        
        self.lbInfo = QLabel("Info")
        self.lbInfo.setAlignment(Qt.AlignCenter)
        self.mainLayout.addWidget(self.lbInfo)
        
        self.editLayout = QHBoxLayout()
        #not OK: self.lineedit = QLineEdit("ü")
        #not OK: self.lineedit = QLineEdit(unicode("ü"))
        #OK: self.lineedit = QLineEdit(unicode("ue"))
        self.leFrom = QLineEdit("")
        self.leUntil = QLineEdit("")
        self.editLayout.addWidget(self.leFrom)
        self.editLayout.addWidget(self.leUntil)
        self.mainLayout.addLayout(self.editLayout)
        
        self.setLayout(self.mainLayout)
        
        self.connect(self.btnInteractive, SIGNAL("clicked()"), 
self.btnInteractive_Clicked)
        self.connect(self.btnList, SIGNAL("clicked()"), self.btnList_Clicked)
        self.connect(self.leFrom, SIGNAL("returnPressed()"), 
self.leFrom_ReturnPressed)
        self.connect(self.leUntil, SIGNAL("returnPressed()"), 
self.leUntil_ReturnPressed)
        
        self.setWindowTitle("EasyCalculator")

    def btnInteractive_Clicked(self):
        self.browser.append("btnInteractive_Clicked")
        self.interactiveModus = True
        #self.browser.append("interactive")
        self.lbInfo.setText("Welches Jahr moechten Sie ueberpruefen?")
        self.leFrom.setText("Jahr")
        self.leUntil.setDisabled(True)
        self.leFrom.selectAll()
        self.leFrom.setFocus()

    def btnList_Clicked(self):
        #self.browser.append("btnList_Clicked")
        self.interactiveModus = False
        #self.browser.append("list")
        self.lbInfo.setText("Geben sie einen Zeitraum an!")
        self.leFrom.setText("von")
        self.leUntil.setText("bis")
        self.leFrom.selectAll()
        self.leFrom.setFocus()

    
    def leFrom_ReturnPressed(self):
        if self.interactiveModus:
            #self.browser.append("leFrom_ReturnPressed, interactive")
            text = unicode(self.leFrom.text())
            self.browser.append(self.isLeapYear(text))
        else:
            self.leUntil.setDisabled(False)
            self.leUntil.selectAll()
            self.leUntil.setFocus()
        if self.btnInteractive.hasFocus():
            self.browser.append("btnInteractive.hasFocus")
        else:
            self.browser.append("btnInteractive.has NO Focus")

    def leUntil_ReturnPressed(self):
        #self.browser.append("leUntil_ReturnPressed")
        txt1 = unicode(self.leFrom.text())
        start = eval(txt1)
        txt2 = unicode(self.leUntil.text())
        end = eval(txt2)
        for i in range(start, end+1):
            self.browser.append(self.isLeapYear(i))

    def isLeapYear(self, inyear):
        try:
            #here eval works like "Integer.parseInt(string)"
            year = eval(inyear)
            if ((year % 4 == 0 and year % 100 != 0) or year % 400 == 0):
                return "%i ist ein Schaltjahr" % year
            else:
                return "%i ist kein Schaltjahr" % year
        except:
            return "<font color=red>isLeapYear: input is invalid!</font>"

app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()



More information about the PyQt mailing list