Does wxPython do the following well?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2007
Posts: 77
Reputation: aot is an unknown quantity at this point 
Solved Threads: 1
aot's Avatar
aot aot is offline Offline
Junior Poster in Training

Does wxPython do the following well?

 
0
  #1
May 19th, 2009
Okay, so I'm thinking of taking the plunge into wxPython. But it's especially important to me to know if wxPython can do the following things easily and well:

1) Display a vertical array of radio buttons (or perhaps any buttons will do). They must have no labels, and I need to record exactly which button the person pressed. Pressing needs to trigger going to the next screen.

2) Show images/play sounds for a certain duration. For example, I need to show an image for 500 milliseconds, pause for 400 ms, then show another for 500 ms.

Also, I'm looking forward to finding out if certain little annoyances from Tkinter are fixed (e.g., the difficulty in assigning a button command that involves parameters).

Thanks to vegaseat for enticing me with promises of making the cursor invisible...
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,297
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 178
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Does wxPython do the following well?

 
1
  #2
May 19th, 2009
The easiest way is to use a wx.RadioBox:
  1. import wx
  2.  
  3. class MyFrame(wx.Frame):
  4. def __init__(self, parent=None):
  5. wx.Frame.__init__(self, parent, wx.ID_ANY, size=(300, 160))
  6. # match to the number of radiobuttons
  7. self.mychoices = ['image1', 'image2', 'image3', 'image4']
  8.  
  9. # create a box with 4 radio buttons, no labels here
  10. label_choices = [' ', ' ', ' ', ' ']
  11. self.radiobox = wx.RadioBox(self, wx.ID_ANY,
  12. " click on a button ",
  13. choices=label_choices, style=wx.VERTICAL)
  14. # bind mouse click to an action
  15. self.radiobox.Bind(wx.EVT_RADIOBOX, self.onAction)
  16.  
  17. # show present selection
  18. self.onAction(None)
  19.  
  20. def onAction(self, event):
  21. """show the selected choice"""
  22. index = self.radiobox.GetSelection()
  23. s = "Selected " + self.mychoices[index]
  24. # show the result in the frame title
  25. self.SetTitle(s)
  26.  
  27.  
  28. app = wx.App(0)
  29. MyFrame().Show()
  30. app.MainLoop()
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 944
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 146
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Does wxPython do the following well?

 
1
  #3
May 19th, 2009
Showing images is easy with wx.StaticBitmap.
http://www.wxpython.org/docs/api/wx....map-class.html

NOTE:This code is borrowed from the sticky
  1. # show .jpg .png .bmp or .gif image on wx.Panel
  2.  
  3. import wx
  4.  
  5. class ImagePanel(wx.Panel):
  6. """ create the panel and put image on it """
  7. def __init__(self, parent, id):
  8. # create the panel, this will be self
  9. wx.Panel.__init__(self, parent, id)
  10. try:
  11. # pick your image file you have in the working folder
  12. # or use the full file path
  13. image_file = 'strawberry.jpg'
  14. bmp = wx.Bitmap(image_file)
  15. # show the bitmap, image's upper left corner anchors
  16. # at panel coordinates (5, 5), default is center
  17. wx.StaticBitmap(self, -1, bmp, (5, 5))
  18. # show some image information
  19. info = "%s %dx%d" % (image_file, bmp.GetWidth(), bmp.GetHeight())
  20. # the parent is the frame
  21. parent.SetTitle(info)
  22. except IOError:
  23. print "Image file %s not found" % imageFile
  24. raise SystemExit
  25.  
  26.  
  27. # redirect=False sends stdout/stderr to the console window
  28. # redirect=True sends stdout/stderr to a wx popup window (default)
  29. app = wx.App(redirect=False)
  30. # create window/frame, no parent, -1 is the default ID
  31. # also increase the size of the frame for larger images
  32. frame = wx.Frame(None, -1, size = (480, 320))
  33. # create the panel instance
  34. imp = ImagePanel(frame, -1)
  35. # show the frame
  36. frame.Show(True)
  37. # start the GUI event loop
  38. app.MainLoop()

Hope that helps
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 77
Reputation: aot is an unknown quantity at this point 
Solved Threads: 1
aot's Avatar
aot aot is offline Offline
Junior Poster in Training

Re: Does wxPython do the following well?

 
0
  #4
May 19th, 2009
Wow, thanks! You guys are great!

Now I just need to know if it can play sounds, and if the images can be displayed for a given duration? Tkinter has the after method for dealing with this. For example:
  1. frame.after(500, doSomethingElse)

Also, is there a better way to maximize the frame than just setting its size to the screen size? (When I do that I can still see the frame bar at the top -- in Mac -- and I'd prefer not to, although it's not a big deal.)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Does wxPython do the following well?

 
1
  #5
May 19th, 2009
Here is an example without a titlebar and showing fullscreen:
  1. # wx.Frame with no title bar and showing fullscreen
  2. # modified from vegaseat's example
  3.  
  4. import wx
  5.  
  6. def exit(event):
  7. frame.Close(True)
  8.  
  9. app = wx.App(0)
  10. # create a window, no-parent, -1 is default ID, style with no titlebar
  11. frame = wx.Frame(parent=None, id=-1, pos=(50,100), size=(300,200),
  12. style=wx.MINIMIZE_BOX)
  13. frame.SetBackgroundColour('green')
  14. frame.ShowFullScreen(True, style=wx.FULLSCREEN_ALL)
  15.  
  16. # provide exit for a frame without titlebar
  17. quit = wx.Button(frame, id=-1, label='Exit', pos=(0, 0))
  18. quit.Bind(wx.EVT_BUTTON, exit)
  19.  
  20. # show the window
  21. frame.Show(True)
  22.  
  23. # start the event loop
  24. app.MainLoop()
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Does wxPython do the following well?

 
0
  #6
May 20th, 2009
wxPython has its own wait/delay functions:
wx.Sleep(seconds)
wx.MilliSleep(milliseconds)

The best way is to use wx.FutureCall(), for an example see:
http://www.daniweb.com/forums/showpo...&postcount=108
Last edited by vegaseat; May 20th, 2009 at 2:32 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 77
Reputation: aot is an unknown quantity at this point 
Solved Threads: 1
aot's Avatar
aot aot is offline Offline
Junior Poster in Training

Re: Does wxPython do the following well?

 
0
  #7
May 20th, 2009
Brilliant! I just need to know now if it can play sounds...?
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,614
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 131
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: Does wxPython do the following well?

 
0
  #8
May 20th, 2009
Don't know about wx, but check out:

http://docs.python.org/library/winsound.html
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Does wxPython do the following well?

 
0
  #9
May 20th, 2009
Oh yeah, wxPython has its own sound functions, one of them is wx.Sound() ...
  1. # playing a wave file with wxPython's
  2. # wx.Sound(fileName, isResource=False)
  3. # and its method Play(flags=wx.SOUND_ASYNC)
  4. # vega
  5.  
  6. import wx
  7.  
  8. class MyFrame(wx.Frame):
  9. def __init__(self, parent, mytitle, mysize):
  10. wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
  11. self.SetBackgroundColour("red")
  12.  
  13. # pick a .wav sound file you have ...
  14. sound = wx.Sound('anykey.wav')
  15. # wx.SOUND_SYNC --> sound plays completely through
  16. # wx.SOUND_ASYNC --> sound can be stopped or reset
  17. # wx.SOUND_ASYNC|wx.SOUND_LOOP --> loop until stopped
  18. # with sound.Stop()
  19. sound.Play(wx.SOUND_SYNC)
  20.  
  21.  
  22. app = wx.App(0)
  23. # create a MyFrame instance and show the frame
  24. MyFrame(None, 'wx.Sound()', (300, 100)).Show()
  25. app.MainLoop()
Also check the example at:
http://www.daniweb.com/forums/post872330-109.html
Last edited by vegaseat; May 20th, 2009 at 3:06 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 77
Reputation: aot is an unknown quantity at this point 
Solved Threads: 1
aot's Avatar
aot aot is offline Offline
Junior Poster in Training

Re: Does wxPython do the following well?

 
0
  #10
May 22nd, 2009
I have to say, I am really impressed. Somehow when I was first looking at wxPython ages ago, I must have downloaded the worst tutorial ever, because it seemed so obtuse and useless for my needs -- yet now it seems so simple and has everything I need built in.

I'm going to make a go at switching over my program today... wish me luck! Thanks for all the help!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC