Reply
Thread Tools
santiago's Avatar
Posts: 518 | Thanked: 334 times | Joined on Mar 2010 @ italy
#1
hi guys i want to make a button pressed when clicked. Can you post me some exaples? I explain.. Button has to be clickable, has to play a sound and has to be of a different color when pressed. Buttons have some icons inside, and when one is pressed, has to repeat the sound until you 'll close the app can you help me to create this in PyQT ?

Last edited by santiago; 2011-05-19 at 05:12.
 
Posts: 1,086 | Thanked: 2,964 times | Joined on Jan 2010
#2
Originally Posted by santiago View Post
hi guys i want to make a button pressed when clicked. Can you post me some exaples? I explain.. Button has to be clickable, has to play a sound and has to be of a different color when pressed. Buttons have some icons inside, and when one is pressed, has to repeat the sound until you 'll close the app can you help me to create this in PyQT ?
Hi santiago, check out my 'Build your own fart app.. in 30 mins' tutorial - link in my signature - it sounds like it could help you. It's a tutorial in PyQt on how to create buttons that when clicked play a sound file. So it should get you most of the way there. Changing the color is a matter of the stylesheet. You'll see where I set the button to a red colour, similarly in the same place you can set the button's color for when it is clicked.

Just as a FYI, there is a Development section on the forum here. A lot of developers monitor the subforum so it's a good place to ask these kinds of questions in future, it will help your post get seen by the right people and get more replies
__________________
Follow me on my neglected twitter @kojacker

Cybot950 - Control a robot with your N9/N950
SMSPetFeeder - Build a Bluetooth/SMS dog feeder with Qt, N950, and arduino
Nerf950 - Use your N9/N950 to fire a Nerf gun

Last edited by kojacker; 2011-05-16 at 13:01.
 

The Following 2 Users Say Thank You to kojacker For This Useful Post:
santiago's Avatar
Posts: 518 | Thanked: 334 times | Joined on Mar 2010 @ italy
#3
Originally Posted by kojacker View Post
Hi santiago, check out my 'fart app in 30 mins' tutorial - link in my signature - it sounds like it could help you. It's a tutorial in PyQt on how to create buttons that when clicked play a sound file. So it should get you most of the way there. Changing the color is a matter of the stylesheet. You'll see where I set the button to a red colour, similarly in the same place you can set the button's color for when it is clicked.
I love uuu Marry meeeeeeeee thxxxx god bless uuu!!!
 

The Following User Says Thank You to santiago For This Useful Post:
Posts: 1,086 | Thanked: 2,964 times | Joined on Jan 2010
#4
Originally Posted by santiago View Post
I love uuu Marry meeeeeeeee thxxxx god bless uuu!!!
Erm.. I'll consider it..

Let me know if you have any problems working things out it should be pretty straight forward depending on your coding experience.

I have code to make phonon sound files loop at home (part of the original PyQt mFakeCaller project code I used to repeat the ringtone soundfile) - I can paste in if you need it. To stop the sound playing when the app closes you could create a call to stop it in the application's deconstructor. im interested though, what kind of application are you creating that it keeps playing a sound until the app is closed?
__________________
Follow me on my neglected twitter @kojacker

Cybot950 - Control a robot with your N9/N950
SMSPetFeeder - Build a Bluetooth/SMS dog feeder with Qt, N950, and arduino
Nerf950 - Use your N9/N950 to fire a Nerf gun
 
santiago's Avatar
Posts: 518 | Thanked: 334 times | Joined on Mar 2010 @ italy
#5
but to make a loop of a sound ? your app is very funny ahahhaha i'm creating a mosquito hunter to leave away mosquitos i have 2 buttons with twoo icons inside one to leave away mosquitos normally, the other to disturb mosquitos hardly

when closed it has to stop the sound

sounds worked very well yesterday

Last edited by santiago; 2011-05-16 at 13:20.
 

The Following User Says Thank You to santiago For This Useful Post:
Posts: 1,086 | Thanked: 2,964 times | Joined on Jan 2010
#6
Originally Posted by santiago View Post
but to make a loop of a sound ? your app is very funny ahahhaha i'm creating a mosquito hunter to leave away mosquitos i have 2 buttons with twoo icons inside one to leave away mosquitos normally, the other to disturb mosquitos hardly
lol! That sounds like madness! The N900 needs more crazy apps though, so looking forward to it!

Well the phonon sound player will give off a 'finished()' signal when it has completed playing. So using Qt's signals and slots methodology, one way to get it to loop is to connect the finished signal of the sound file playing to a slot that starts playing the sound file. And voila.. a looping sound have a try and see if you can get it to work
__________________
Follow me on my neglected twitter @kojacker

Cybot950 - Control a robot with your N9/N950
SMSPetFeeder - Build a Bluetooth/SMS dog feeder with Qt, N950, and arduino
Nerf950 - Use your N9/N950 to fire a Nerf gun
 

The Following User Says Thank You to kojacker For This Useful Post:
santiago's Avatar
Posts: 518 | Thanked: 334 times | Joined on Mar 2010 @ italy
#7
Originally Posted by kojacker View Post
lol! That sounds like madness! The N900 needs more crazy apps though, so looking forward to it!

Well the phonon sound player will give off a 'finished()' signal when it has completed playing. So using Qt's signals and slots methodology, one way to get it to loop is to connect the finished signal of the sound file playing to a slot that starts playing the sound file. And voila.. a looping sound have a try and see if you can get it to work
i'll post u a screenshot after
i'm very newbie in QT i gotta study better but i have not too much time, i used maeFarm code yet, i just have to change some values

green icon plays the Easy disturbing sound
blue icon plays the hardly disturbing sound
Attached Images
 

Last edited by santiago; 2011-05-16 at 13:33.
 

The Following User Says Thank You to santiago For This Useful Post:
Posts: 1,086 | Thanked: 2,964 times | Joined on Jan 2010
#8
Those are some mean looking mosquitoes! The green one reminds me of Zorack from Space Ghost



Oh, you're using the maeFarm code lol! I always meant to do something with that and never did have the time... I should think of something.

Let us know how you get on with the sound looping
__________________
Follow me on my neglected twitter @kojacker

Cybot950 - Control a robot with your N9/N950
SMSPetFeeder - Build a Bluetooth/SMS dog feeder with Qt, N950, and arduino
Nerf950 - Use your N9/N950 to fire a Nerf gun
 
santiago's Avatar
Posts: 518 | Thanked: 334 times | Joined on Mar 2010 @ italy
#9
Originally Posted by kojacker View Post
Those are some mean looking mosquitoes! The green one reminds me of Zorack from Space Ghost



Oh, you're using the maeFarm code lol! I always meant to do something with that and never did have the time... I should think of something.

Let us know how you get on with the sound looping
hahahahahaha brrrrrrrrrrrrr i'm afraid

do u like to help me ?
i have a problem by the way in ubuntu i can use Qt ui, in maemo it doesnt work in the wait .. i changed some icons
in ubuntu buttons stay pressed, in maemo they don't.. I have new ideas about this kind of apps i'll let u know bout the others first i want to complete this one. I'll apreciate your help becouse mine is just the concept and i changed just some paths, some icons and some sounds. I used MaeFarm code becouse i'm not expert in QT and unfortunatelly there's not a Italian FAQ (my en is too bad and for some reasons i need a right translation becouse its a complicated for me understanding )

in QT designer the ui uses right params about the buttons (when i click one, the other is unpressed and vice e versa..) no way on maemo i need a miracle
Attached Images
 

Last edited by santiago; 2011-05-17 at 12:12.
 

The Following User Says Thank You to santiago For This Useful Post:
Posts: 1,086 | Thanked: 2,964 times | Joined on Jan 2010
#10
Originally Posted by santiago View Post
in QT designer the ui uses right params about the buttons (when i click one, the other is unpressed and vice e versa..) no way on maemo i need a miracle
Hmm.. so you'd like the two buttons to toggle - when one is pressed the other should not be pressed, and vice versa. Im sure we can do this with a simple function When your mosquito is pushed, does the button background color change? Here's what Im thinking..

There would be 2 Boolean values for holding the pressed state of the two buttons - true = pressed, false = not pressed - and both set to false when the app loads (as user hasn't made a selection yet, unless u want a default). So imagine we have:

Code:
ClassicMosquitoPressed = false
ExtremeMosquitoPressed = false
then you'd need a toggle function/slot connected to your button press signals that'll do something like the following psuedocode:

Code:
if button pressed = ClassicMosquitoButton{
   set backgroundColour of Classic Mosquito Button to the pressed colour
   if (ExtremeMosquitoPressed is = true){
      // means it was previously selected and we got to set it to false again now
      set ExtremeMosquitoPressed to = false
      set backgroundColour of Extreme Mosquito Button to the not pressed colour
   }
   set sound file to classic mosquito sound file
   play sound
}
else{
   // it must be the ExtremeMosquitoButton that has been pressed, so do all the opposite of the above :p
..
}
Or as it's your first try at programming, it might be easier just to split it up into two slots instead of a single toggle function - for example a seperate onClassicMosqutioPressed() and a seperate onExtremeMosquitoPressed(). Connect your signal from each button to the corresponding ...Pressed() slot. The same principal applies in both ways - you set the properties of your button and sound file to equal the mosquito that was chosen, and at the same time make sure the properties of the button that isnt chosen is at the default states.

Something like that should work. It's in psuedocode as Ive moved on to QML and almost completely forgotten my Qt widgets, signal and slots, etc. Let me know if you try it properly in PyQt and it doesnt work for you, i'll knock up something proper and test it at home
__________________
Follow me on my neglected twitter @kojacker

Cybot950 - Control a robot with your N9/N950
SMSPetFeeder - Build a Bluetooth/SMS dog feeder with Qt, N950, and arduino
Nerf950 - Use your N9/N950 to fire a Nerf gun

Last edited by kojacker; 2011-05-17 at 12:53.
 

The Following User Says Thank You to kojacker For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 19:39.