Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Clean PyQt selection comboBox

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


threaderslash at gmail

Nov 5, 2009, 1:31 AM

Post #1 of 3 (37 views)
Permalink
Clean PyQt selection comboBox

Hello Everybody, [image: 8)]

I am using Qt and need to build a selection comboBox -- e.g.:
http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG .

The problem is - after one choice was made, and the code run, for the next
time the user select a different choice, both, the present and all past
choices run. See what I mean: [image: ;(]

Code:

selected color - blue
we are on runBlue
selected color - red
we are on runBlue
we are on runRed


Here is the code:

.........................................
QtCore.QObject.connect(self.selectComboBox,
QtCore.SIGNAL("currentIndexChanged(QString)"),
self.combo_activateInput)
.........................................
def combo_activateInput(self):
color=unicode(self.selectComboBox.currentText())
if(color == "blue"):
print "selected color - blue"
QtCore.QObject.connect(self.okButton,
QtCore.SIGNAL("clicked()"), self.combo_runBlue)
if(color == "red"):
print "selected color - red"
QtCore.QObject.connect(self.okButton,
QtCore.SIGNAL("clicked()"), self.combo_runRed)
if(color == "yellow"):
print "selected color - yellow"
QtCore.QObject.connect(self.okButton,
QtCore.SIGNAL("clicked()"), self.combo_runYellow)
del color
.........................................
def combo_runBlue(self):
print "we are on runBlue"

def combo_runRed(self):
print "we are on runRed"

def combo_runYellow(self):
print "we are on runYellow"

I run "del color" to clean the content returned by
selectComboBox.currentText, but it didn't clean the content indeed.

So, any suggestion? All comments and suggestions are highly
appreciated. [image:
:D] [image: :D] [image: :D]


python at mrabarnett

Nov 5, 2009, 7:37 AM

Post #2 of 3 (28 views)
Permalink
Re: Clean PyQt selection comboBox [In reply to]

Threader Slash wrote:
> Hello Everybody, 8)
>
> I am using Qt and need to build a selection comboBox -- e.g.:
> http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG .
>
> The problem is - after one choice was made, and the code run, for the
> next time the user select a different choice, both, the present and all
> past choices run. See what I mean: ;(
>
> Code:
>
> selected color - blue
> we are on runBlue
>
> selected color - red
> we are on runBlue
> we are on runRed
>
>
> Here is the code:
>
> .........................................
> QtCore.QObject.connect(self.selectComboBox,
> QtCore.SIGNAL("currentIndexChanged(QString)"),
> self.combo_activateInput)
> .........................................
>
> def combo_activateInput(self):
> color=unicode(self.selectComboBox.currentText())
> if(color == "blue"):
> print "selected color - blue"
> QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runBlue)
>
> if(color == "red"):
> print "selected color - red"
> QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runRed)
> if(color == "yellow"):
>
> print "selected color - yellow"
> QtCore.QObject.connect(self.okButton, QtCore.SIGNAL("clicked()"), self.combo_runYellow)
> del color
> .........................................
>
> def combo_runBlue(self):
> print "we are on runBlue"
>
> def combo_runRed(self):
> print "we are on runRed"
>
> def combo_runYellow(self):
> print "we are on runYellow"
>
> I run "del color" to clean the content returned by
> selectComboBox.currentText, but it didn't clean the content indeed.
>
"del color" doesn't "clean the content", it just says "forget this
name", in this case "forget the local variable called 'color'".

> So, any suggestion? All comments and suggestions are highly appreciated.
> :D :D :D
>
The ".connect" method connects something each time it's called. If you
call it multiple times then multiple things will be connected.

Try using ".disconnect" to disconnect what you no longer want connected.
--
http://mail.python.org/mailman/listinfo/python-list


threaderslash at gmail

Nov 5, 2009, 2:55 PM

Post #3 of 3 (25 views)
Permalink
Re: Clean PyQt selection comboBox [In reply to]

> ---------- Original message ----------
> From: MRAB <python[at]mrabarnett.plus.com>
> To: python-list[at]python.org
> Date: Thu, 05 Nov 2009 15:37:49 +0000
> Subject: Re: Clean PyQt selection comboBox
> Threader Slash wrote:
>
>> Hello Everybody, 8)
>>
>> I am using Qt and need to build a selection comboBox -- e.g.:
>> http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG.
>>
>> The problem is - after one choice was made, and the code run, for the next
>> time the user select a different choice, both, the present and all past
>> choices run. See what I mean: ;(
>>
>> Code:
>>
>> selected color - blue
>> we are on runBlue
>>
>> selected color - red
>> we are on runBlue
>> we are on runRed
>>
>>
>> Here is the code:
>>
>> .........................................
>> QtCore.QObject.connect(self.selectComboBox,
>> QtCore.SIGNAL("currentIndexChanged(QString)"),
>> self.combo_activateInput) .........................................
>>
>> def combo_activateInput(self):
>> color=unicode(self.selectComboBox.currentText())
>> if(color == "blue"):
>> print "selected color - blue"
>> QtCore.QObject.connect(self.okButton,
>> QtCore.SIGNAL("clicked()"), self.combo_runBlue)
>>
>> if(color == "red"):
>> print "selected color - red"
>> QtCore.QObject.connect(self.okButton,
>> QtCore.SIGNAL("clicked()"), self.combo_runRed) if(color
>> == "yellow"):
>>
>> print "selected color - yellow"
>> QtCore.QObject.connect(self.okButton,
>> QtCore.SIGNAL("clicked()"), self.combo_runYellow)
>> del color .........................................
>>
>> def combo_runBlue(self):
>> print "we are on runBlue"
>>
>> def combo_runRed(self):
>> print "we are on runRed"
>>
>> def combo_runYellow(self):
>> print "we are on runYellow"
>>
>> I run "del color" to clean the content returned by
>> selectComboBox.currentText, but it didn't clean the content indeed.
>>
>> "del color" doesn't "clean the content", it just says "forget this
> name", in this case "forget the local variable called 'color'".
>
> So, any suggestion? All comments and suggestions are highly appreciated.
>> :D :D :D
>>
>> The ".connect" method connects something each time it's called. If you
> call it multiple times then multiple things will be connected.
>
> Try using ".disconnect" to disconnect what you no longer want connected.
>
> ---------- ----------
>

Thanks Man! You saved the day. It solved the problem...
................................................................
def combo_runBlue(self):
print "we are on runBlue"
QtCore.QObject.disconnect(self.okButton, QtCore.SIGNAL("clicked()"),
self.combo_runBlue)
................................................................

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.