maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   SOLVED - Help pyQT buttons pressed and loop sound (https://talk.maemo.org/showthread.php?t=73137)

santiago 2011-05-16 12:48

SOLVED - Help pyQT buttons pressed and loop sound
 
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 ?

kojacker 2011-05-16 12:57

Re: Help pyQT buttons pressed
 
Quote:

Originally Posted by santiago (Post 1007402)
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 :)

santiago 2011-05-16 13:01

Re: Help pyQT buttons pressed
 
Quote:

Originally Posted by kojacker (Post 1007409)
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 :D thxxxx god bless uuu!!!:eek:

kojacker 2011-05-16 13:12

Re: Help pyQT buttons pressed
 
Quote:

Originally Posted by santiago (Post 1007412)
I love uuu Marry meeeeeeeee :D thxxxx god bless uuu!!!:eek:

Erm.. I'll consider it.. :D

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? :)

santiago 2011-05-16 13:14

Re: Help pyQT buttons pressed
 
but to make a loop of a sound ? your app is very funny :D ahahhaha i'm creating a mosquito hunter :D to leave away mosquitos :D 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 :D

kojacker 2011-05-16 13:24

Re: Help pyQT buttons pressed
 
Quote:

Originally Posted by santiago (Post 1007421)
but to make a loop of a sound ? your app is very funny :D ahahhaha i'm creating a mosquito hunter :D to leave away mosquitos :D 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 ;)

santiago 2011-05-16 13:27

Re: Help pyQT buttons pressed
 
1 Attachment(s)
Quote:

Originally Posted by kojacker (Post 1007426)
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 ;)

;) :D i'll post u a screenshot after :D
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

kojacker 2011-05-16 20:41

Re: Help pyQT buttons pressed
 
Those are some mean looking mosquitoes! The green one reminds me of Zorack from Space Ghost

http://www.oocities.org/goddamn_gree...otes/zorak.jpg

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 :)

santiago 2011-05-17 12:08

Re: Help pyQT buttons pressed
 
1 Attachment(s)
Quote:

Originally Posted by kojacker (Post 1007726)
Those are some mean looking mosquitoes! The green one reminds me of Zorack from Space Ghost

http://www.oocities.org/goddamn_gree...otes/zorak.jpg

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 :D brrrrrrrrrrrrr i'm afraid :D

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 :D
in ubuntu buttons stay pressed, in maemo they don't.. I have new ideas about this kind of apps :D 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

kojacker 2011-05-17 12:48

Re: Help pyQT buttons pressed
 
Quote:

Originally Posted by santiago (Post 1008100)
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. :o 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 :)


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

vBulletin® Version 3.8.8