943,910 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1161
  • Python RSS
May 19th, 2009
0

Does wxPython do the following well?

Expand Post »
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...
Similar Threads
aot
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
aot is offline Offline
83 posts
since Feb 2007
May 19th, 2009
1

Re: Does wxPython do the following well?

The easiest way is to use a wx.RadioBox:
python Syntax (Toggle Plain Text)
  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()
Reputation Points: 961
Solved Threads: 211
Nearly a Posting Maven
sneekula is offline Offline
2,413 posts
since Oct 2006
May 19th, 2009
1

Re: Does wxPython do the following well?

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
python Syntax (Toggle Plain Text)
  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
Reputation Points: 264
Solved Threads: 183
Veteran Poster
Paul Thompson is offline Offline
1,095 posts
since May 2008
May 19th, 2009
0

Re: Does wxPython do the following well?

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:
Python Syntax (Toggle Plain Text)
  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.)
aot
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
aot is offline Offline
83 posts
since Feb 2007
May 19th, 2009
1

Re: Does wxPython do the following well?

Here is an example without a titlebar and showing fullscreen:
python Syntax (Toggle Plain Text)
  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()
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005
May 20th, 2009
0

Re: Does wxPython do the following well?

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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
May 20th, 2009
0

Re: Does wxPython do the following well?

Brilliant! I just need to know now if it can play sounds...?
aot
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
aot is offline Offline
83 posts
since Feb 2007
May 20th, 2009
0

Re: Does wxPython do the following well?

Don't know about wx, but check out:

http://docs.python.org/library/winsound.html
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
May 20th, 2009
0

Re: Does wxPython do the following well?

Oh yeah, wxPython has its own sound functions, one of them is wx.Sound() ...
python Syntax (Toggle Plain Text)
  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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
May 22nd, 2009
0

Re: Does wxPython do the following well?

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!
aot
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
aot is offline Offline
83 posts
since Feb 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: access login module from server to client....
Next Thread in Python Forum Timeline: Help with text-based game in Python





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC