As a fun little task to gain more knowledge of python, i decided to try to mimick the ipod UI with it. here's what i've got so far - #!/usr/bin/env python
-
# -*- coding: utf-8 -*-
-
# generated by wxGlade 0.5 on Sat Oct 27 15:46:36 2007
-
-
import wx, os, pygame
-
pygame.init()
-
-
class MyFrame2(wx.MDIChildFrame):
-
def __init__(self, *args, **kwds):
-
# begin wxGlade: MyFrame2.__init__
-
kwds["style"] = wx.DEFAULT_FRAME_STYLE
-
wx.MDIChildFrame.__init__(self, *args, **kwds)
-
self.__set_properties()
-
self.__do_layout()
-
# end wxGlade
-
-
def __set_properties(self):
-
# begin wxGlade: MyFrame2.__set_properties
-
self.SetTitle("frame_3")
-
# end wxGlade
-
-
def __do_layout(self):
-
# begin wxGlade: MyFrame2.__do_layout
-
sizer_2 = wx.BoxSizer(wx.VERTICAL)
-
sizer_2.Add(self.tree_2, 1, wx.EXPAND, 0)
-
self.SetSizer(sizer_2)
-
sizer_2.Fit(self)
-
self.Layout()
-
# end wxGlade
-
-
def zooey(self, event):
-
import time
-
time.sleep(2)
-
pygame.mixer.music.load(event.GetItem())
-
pygame.mixer.music.play()
-
-
-
# end of class MyFrame2
-
-
-
class MyFrame(wx.Frame):
-
def __init__(self, *args, **kwds):
-
# begin wxGlade: MyFrame.__init__
-
kwds["style"] = wx.DEFAULT_FRAME_STYLE
-
wx.Frame.__init__(self, *args, **kwds)
-
self.tree_ctrl_1 = wx.TreeCtrl(self, -1, style=wx.TR_HAS_BUTTONS|wx.TR_NO_LINES|wx.TR_EDIT_LABELS|wx.TR_FULL_ROW_HIGHLIGHT|wx.TR_HIDE_ROOT|wx.TR_ROW_LINES|wx.TR_DEFAULT_STYLE|wx.NO_BORDER)
-
-
self.__set_properties()
-
self.__do_layout()
-
-
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.boogienights, self.tree_ctrl_1)
-
# end wxGlade
-
-
root = self.tree_ctrl_1.AddRoot('Home')
-
ET = self.tree_ctrl_1.AppendItem(root, "Music")
-
-
artist_list = os.listdir('music')
-
for i in artist_list:
-
self.tree_ctrl_1.AppendItem(ET, i)
-
-
def __set_properties(self):
-
# begin wxGlade: MyFrame.__set_properties
-
self.SetTitle("frame_1")
-
self.tree_ctrl_1.SetBackgroundColour(wx.Colour(255, 255, 255))
-
# end wxGlade
-
-
def __do_layout(self):
-
# begin wxGlade: MyFrame.__do_layout
-
sizer_1 = wx.BoxSizer(wx.VERTICAL)
-
sizer_1.Add(self.tree_ctrl_1, 1, wx.EXPAND, 0)
-
self.SetSizer(sizer_1)
-
sizer_1.Fit(self)
-
self.Layout()
-
# end wxGlade
-
-
def boogienights(self, event): # wxGlade: MyFrame.<event_handler>
-
self.Hide()
-
frame_2 = MyFrame2(None, -1, "")
-
frame_2.Show()
-
# end of class MyFrame
-
-
if __name__ == "__main__":
-
app = wx.PySimpleApp(0)
-
wx.InitAllImageHandlers()
-
frame_1 = MyFrame(None, -1, "")
-
app.SetTopWindow(frame_1)
-
frame_1.Show()
-
app.MainLoop()
-
-
-
everything works up to when it's time to play an mp3 file. as you can see, i have a TreeCtrl that lists the items in a folder. However, as you know, when you enter a new folder with an ipod it slides over to a new screen, so i had to have a go at that.. anyway, when it's time for pygame to play a song i get a seg fault (i expected as much).
what i'm trying to have the program do is...when it opens up that next frame (I haven't actually added the ipod-folder-slide effect yet..) and lists the contents and i click a file, i want pygame to play that file. the problem is that i have to idea how to tell pygame which file the user has selected...
all help would be greatly appreciated.
10 2025
solved: -
#!/usr/bin/env python
-
# -*- coding: utf-8 -*-
-
# generated by wxGlade 0.5 on Sat Oct 27 15:46:36 2007
-
-
import wx, os, pygame
-
pygame.init()
-
-
class MyFrame2(wx.MDIChildFrame):
-
def __init__(self, *args, **kwds):
-
# begin wxGlade: MyFrame2.__init__
-
kwds["style"] = wx.DEFAULT_FRAME_STYLE
-
wx.MDIChildFrame.__init__(self, *args, **kwds)
-
self.__set_properties()
-
self.__do_layout()
-
# end wxGlade
-
-
def __set_properties(self):
-
# begin wxGlade: MyFrame2.__set_properties
-
self.SetTitle("frame_3")
-
# end wxGlade
-
-
def __do_layout(self):
-
# begin wxGlade: MyFrame2.__do_layout
-
sizer_2 = wx.BoxSizer(wx.VERTICAL)
-
sizer_2.Add(self.tree_2, 1, wx.EXPAND, 0)
-
self.SetSizer(sizer_2)
-
sizer_2.Fit(self)
-
self.Layout()
-
# end wxGlade
-
-
#def zooey(self, self.event):
-
#3 import time
-
# print "nigga whats up" * 10
-
# time.sleep(2)
-
#music = pygame.mixer.music.load(event.GetItem())
-
#pygame.mixer.music.play()
-
-
-
# end of class MyFrame2
-
-
-
class MyFrame(wx.Frame):
-
def __init__(self, *args, **kwds):
-
# begin wxGlade: MyFrame.__init__
-
kwds["style"] = wx.DEFAULT_FRAME_STYLE
-
wx.Frame.__init__(self, *args, **kwds)
-
self.tree_ctrl_1 = wx.TreeCtrl(self, -1, style=wx.TR_HAS_BUTTONS|wx.TR_NO_LINES|wx.TR_EDIT_LABELS|wx.TR_FULL_ROW_HIGHLIGHT|wx.TR_HIDE_ROOT|wx.TR_ROW_LINES|wx.TR_DEFAULT_STYLE|wx.NO_BORDER)
-
-
self.__set_properties()
-
self.__do_layout()
-
-
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.boogienights, self.tree_ctrl_1)
-
# end wxGlade
-
-
root = self.tree_ctrl_1.AddRoot('Home')
-
ET = self.tree_ctrl_1.AppendItem(root, "Music")
-
-
artist_list = os.listdir('music')
-
os.chdir('music')
-
for i in artist_list:
-
self.tree_ctrl_1.AppendItem(ET, i)
-
-
def __set_properties(self):
-
# begin wxGlade: MyFrame.__set_properties
-
self.SetTitle("frame_1")
-
self.tree_ctrl_1.SetBackgroundColour(wx.Colour(255, 255, 255))
-
# end wxGlade
-
-
def __do_layout(self):
-
# begin wxGlade: MyFrame.__do_layout
-
sizer_1 = wx.BoxSizer(wx.VERTICAL)
-
sizer_1.Add(self.tree_ctrl_1, 1, wx.EXPAND, 0)
-
self.SetSizer(sizer_1)
-
sizer_1.Fit(self)
-
self.Layout()
-
# end wxGlade
-
-
def boogienights(self, event): # wxGlade: MyFrame.<event_handler>
-
item = event.GetItem()
-
item = self.tree_ctrl_1.GetItemText(item)
-
item = os.getcwd() + "/" + item
-
music = pygame.mixer.music.load(item)
-
pygame.mixer.music.play()# end of class MyFrame
-
-
if __name__ == "__main__":
-
app = wx.PySimpleApp(0)
-
wx.InitAllImageHandlers()
-
frame_1 = MyFrame(None, -1, "")
-
app.SetTopWindow(frame_1)
-
frame_1.Show()
-
app.MainLoop()
-
Right off the bat, I'd suggest a true subclass of wx.APP: -
class MyApp(wx.App):
-
def OnInit(self):
-
self.main = frame_1(None)
-
self.main.Show()
-
self.SetTopWindow(self.main)
-
return True
-
-
def main():
-
application = MyApp(redirect=False) # or True depending...
-
application.MainLoop()
I've noticed some differences in behavior between this an PySimpleApp.
Secondly, there's got to be a better module for playing MP3s than PyGame (unless you need other features of that package).
solved:
Can you tell us what you did differently? It's not totally obvious looking at the code.
Thanks.
Right off the bat, I'd suggest a true subclass of wx.APP: -
class MyApp(wx.App):
-
def OnInit(self):
-
self.main = frame_1(None)
-
self.main.Show()
-
self.SetTopWindow(self.main)
-
return True
-
-
def main():
-
application = MyApp(redirect=False) # or True depending...
-
application.MainLoop()
I've noticed some differences in behavior between this an PySimpleApp.
Secondly, there's got to be a better module for playing MP3s than PyGame (unless you need other features of that package).
hmm, i'll search around for a better module.
i'll try out what you suggested because after i got it to successfully play
[ here's what i did to get it to work:
once the directory is listed and displayed in the TreeCtrl, i use os.chdir('music'), then os.getcwd() (which would be /music) + "/" + filename; i then use pygaim to play that.
problem now is, when i try to open a frame and have pygaim play the song in that window i get a seg fault.
#edit..lol just noticed a little funnny string i used for debugging..whoops ^_^
here's where i'm at now.. -
#!/usr/bin/env python
-
# -*- coding: utf-8 -*-
-
# generated by wxGlade 0.5 on Sat Oct 27 15:46:36 2007
-
-
import wx, os, pygame
-
pygame.init()
-
-
-
class MyFrame2(wx.MDIChildFrame):
-
def __init__(self, *args, **kwds):
-
# begin wxGlade: MyFrame2.__init__
-
kwds["style"] = wx.DEFAULT_FRAME_STYLE
-
wx.MDIChildFrame.__init__(self, *args, **kwds)
-
self.tree_2 = wx.TreeCtrl(self, -1, style=wx.TR_HAS_BUTTONS|wx.TR_NO_LINES|wx.TR_EDIT_LABELS|wx.TR_DEFAULT_STYLE|wx.NO_BORDER)
-
-
self.__set_properties()
-
self.__do_layout()
-
-
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.boogie, self.tree_2)
-
# end wxGlade
-
-
def __set_properties(self):
-
# begin wxGlade: MyFrame2.__set_properties
-
self.SetTitle("frame_3")
-
# end wxGlade
-
-
def __do_layout(self):
-
# begin wxGlade: MyFrame2.__do_layout
-
sizer_2 = wx.BoxSizer(wx.VERTICAL)
-
sizer_2.Add(self.tree_2, 1, wx.EXPAND, 0)
-
self.SetSizer(sizer_2)
-
sizer_2.Fit(self)
-
self.Layout()
-
# end wxGlade
-
-
def boogie(self, event): # wxGlade: MyFrame2.<event_handler>
-
pygame.mixer.music.play()
-
# end of class MyFrame2
-
-
-
class MyFrame(wx.Frame):
-
def __init__(self, *args, **kwds):
-
# begin wxGlade: MyFrame.__init__
-
kwds["style"] = wx.DEFAULT_FRAME_STYLE
-
wx.Frame.__init__(self, *args, **kwds)
-
self.tree_ctrl_1 = wx.TreeCtrl(self, -1, style=wx.TR_HAS_BUTTONS|wx.TR_NO_LINES|wx.TR_EDIT_LABELS|wx.TR_FULL_ROW_HIGHLIGHT|wx.TR_HIDE_ROOT|wx.TR_ROW_LINES|wx.TR_DEFAULT_STYLE|wx.NO_BORDER)
-
-
self.__set_properties()
-
self.__do_layout()
-
-
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.boogienights, self.tree_ctrl_1)
-
# end wxGlade
-
-
root = self.tree_ctrl_1.AddRoot('Home')
-
ET = self.tree_ctrl_1.AppendItem(root, "Music")
-
-
artist_list = os.listdir('music')
-
os.chdir('music')
-
for i in artist_list:
-
self.tree_ctrl_1.AppendItem(ET, i)
-
-
def __set_properties(self):
-
# begin wxGlade: MyFrame.__set_properties
-
self.SetTitle("frame_1")
-
self.tree_ctrl_1.SetBackgroundColour(wx.Colour(255, 255, 255))
-
# end wxGlade
-
-
def __do_layout(self):
-
# begin wxGlade: MyFrame.__do_layout
-
sizer_1 = wx.BoxSizer(wx.VERTICAL)
-
sizer_1.Add(self.tree_ctrl_1, 1, wx.EXPAND, 0)
-
self.SetSizer(sizer_1)
-
sizer_1.Fit(self)
-
self.Layout()
-
# end wxGlade
-
-
def boogienights(self, event): # wxGlade: MyFrame.<event_handler>
-
item = event.GetItem()
-
item = self.tree_ctrl_1.GetItemText(item)
-
item = os.getcwd() + "/" + item
-
music = pygame.mixer.music.load(item)
-
# end of class MyFrame
-
-
-
class MyApp(wx.App):
-
def OnInit(self):
-
self.main = MyFrame(None)
-
self.main.Show()
-
self.SetTopWindow(self.main)
-
return True
-
-
def main():
-
application = MyApp(redirect=False) # or True depending...
-
application.MainLoop()
-
main()
-
hmm, i'll search around for a better module.
i'll try out what you suggested because after i got it to successfully play
[ here's what i did to get it to work:
once the directory is listed and displayed in the TreeCtrl, i use os.chdir('music'), then os.getcwd() (which would be /music) + "/" + filename; i then use pygaim to play that.
problem now is, when i try to open a frame and have pygaim play the song in that window i get a seg fault.
I deduce from - item = os.getcwd() + "/" + item
that you are on an "other" OS (lol). So please tell us about your OS and platform.
Thanks.
If you are on Linux you can use gstreamer.
In Debian/Ubuntu its:
python-gst0.10 - generic media-playing framework (Python bindings)
dont know about other distros, But i guess its something similar.
But something i think is nicer is MPD. The Music Playing Daemon (Realy geeky). Sorta easy to use. But the python bindings for it totaly sucks.
I deduce from - item = os.getcwd() + "/" + item
that you are on an "other" OS (lol). So please tell us about your OS and platform.
Thanks.
i don't know about being on an "other" OS ;)...Ubuntu is the only OS I have installed ^_^
I'll check into gstreamer, Smygis, thank you
i don't know about being on an "other" OS ;)...Ubuntu is the only OS I have installed ^_^
"Other" refers to OSes who's path names that don't start C:\. Knowing which one you are using is required info if we are to give relevant suggestions/solutions.
taking all suggestions on how to pursue coding this ipod UI
ANY advice is very welcomed
i'm check out pygtk to see if i like it better than wx..
i'll check out pygtk to see if i like it better than wx..
IMO, GTK is not as well structured as wx. We have on member on these boards who is required to use GTK and wishes he xould switch to wx. I've had a look at GTK's class structure and didn't see anything that I liked.
I also prefer Boa Constructor over wxGlade for GUI generation.
Just my two cents worth.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: AnsNum |
last post by:
hello,
when I start this program, the movie doesn't play smoothly, anybody has an
idea ?
(I use windowsXP)
import pygame
from pygame.display import flip
from pygame.locals import *
...
|
by: Erik Bethke |
last post by:
Hello All,
I am having a great time with python and pygame, and last night I took
a long look at the wxPython demo. I think that rocks as well.
So now, my question is do wxPython and PyGame...
|
by: Marian Aldenhövel |
last post by:
Hi,
I am trying to make pygame play music on windows. This simple program:
import pygame,time
pygame.init()
print "Mixer settings", pygame.mixer.get_init()
print "Mixer channels",...
|
by: boyanpn |
last post by:
I a newbie in python so excuse me if my question sounds stupid or
something :(
I wonder if my web host suports python (with pygame), if I download
game from www.pygame.org and upload it to my...
|
by: crystalattice |
last post by:
I'm making a GUI for a console-based program I just wrote. I figured
it would be mostly straight forward to convert it over in wxPython but
now I'm confused.
In my console program, I have...
|
by: zswartz |
last post by:
Hi All, I've been stuck here for some time now and can't figure this out. If ANYONE can assist me, that would be AMAZING!!
I have Windows XP, with Python 25 and Pygame for python 25. I am also...
|
by: joshuabraham |
last post by:
os version =windows xp
hi guys i'm having problems using pygame the following code just does not seem to work.
clock=pygame.time.Clock()
while True:
sound1.play()
clock.tick(60)
...
|
by: globalrev |
last post by:
http://www.pygame.org/docs/ref/mixer.html
import pygame
#pygame.mixer.init(frequency=22050, size=-16, channels=2,
buffer=3072) //it complained abiout words=
so i guess its only the nbrs...
|
by: dynamo |
last post by:
hi guy,when i run my program which contains the following portion of code in the mainloop
clock=pygame.time.Clock()
while True:
sound1.play()
clock.tick(60)
pKeys =...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |