×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Need help with binding keys and File Browser

    Hello,
    I recently started developing my own first python-symbian-app - A music player.

    I have some questions about how to do somethings -
    1) In order to show the current song name, and the songs list, I add list box to the appuifw.body, and create a top window. The problem is when I accidentally press the hang-up key(the red one) the application is closed and the top window isn't. How can i fix that?
    2) I want to add the ability to add files&folders to my play list. How can I make a folder-browser(one like in move-to-folder option in the main menu of symbian) to my software?
    3) How can I read id3 tag info?

    I want to mention that I searched it up in the pdf file of 1.4.1 and haven't found any solution to any of those.

    Thanks for your help,
    Ofir.
    Last edited by otadmor; 2007-10-24 at 01:06. Reason: Added question #3.

  2. #2
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Re: Need help with binding keys and File Browser

    Quote Originally Posted by otadmor View Post
    Hello,

    I have some questions about how to do somethings -
    3) How can I read id3 tag info?

    Thanks for your help,
    Ofir.
    Welcome Ofir to the Python DiBO

    Try this project http://id3-py.sourceforge.net/

    Cyke64
    pys60 1.4.5 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Re: Need help with binding keys and File Browser

    How I install it on symbian, or how I use it in my program?
    I can't use import, because its not installed on my(and others) phones.
    Is there build-in id3 tag reader?

    Thanks.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: Need help with binding keys and File Browser

    Welcome to Python for S60 community.

    1) This behaviour is expected since it's a feature of topwindows - they are displayed no matter what app is active. The solution is to use the appuifw.app.focus hook. This hook will be called when your app goes to background and when it is brought back to the front. So, you can show/hide your topwindow there. Read the docs for more info.

    2) PyS60 doesn't provide any file/directory dialogs. However, since there is the os module which allows you to list directories, you can code one yourself.

    3) Again, no built-in tools to do that. Either write your own parser or google for some python module capable of doing it, preferably written in pure python.

    Happy coding!

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Re: Need help with binding keys and File Browser

    10x for the answers.

    1) When I press the hang-up button the focus method don't called. It is a bug, Or I do something wrong? When I switch apps the focus method is called properly.

    2) 10x. I think I will, based on the file-browser in the net.

    3) I will use what cyke64 offered. The problem(or mostly, lake of my knowledge) is how to use it. I write "from ID3 import *" when ID3.py is in the same dir, but the python console throw me an error. Should I use "execfile('ID3.py')" insted of import?

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: Need help with binding keys and File Browser

    1) That's strange. It should be called on the hang-up key. I have just tested this code in the Python Shell on my 6600 and it works (hook is called).
    Code:
    import appuifw
    def hook(f):
        print f
    appuifw.app.focus = hook
    3) Python uses the sys.path list when searching for modules. Print it out to see what paths it contain. You can also add your own there at runtime. You have to use import/from..import, not execfile().

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Re: Need help with binding keys and File Browser

    1) I use 6120. Is this a bug I should report?
    3) I use:
    Code:
    import sys
    import os
    sys.path.append(os.path.split(sys.argv[0])[0])
    from ID3 import *
    But I get error(from the 'from ID3 import *'):

    inplatsec_import raiseImportError("No module named " +name)
    ImportError No module named ID3
    Theres a file named 'ID3.py' in the same directory as the main py file.
    Last edited by otadmor; 2007-10-24 at 13:41. Reason: Added error

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: Need help with binding keys and File Browser

    1) If my example doesn't work on your phone (you're not getting "0, 1" after pressing the hangup key and then bringing the shell to the front) then yes, file a bug report.

    3) In standalone apps, their directory is added to sys.path automatically AFAIK. So your call would be redundant. But if the path wasn't there already for some reason then yes, it is ok. Also the question is: does it help?

  9. #9
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Re: Need help with binding keys and File Browser

    3) You right. It doesn't work(Though it is working on my computer, weird). The sys.argv[0] returns me c:\private\somecode\default.py, although my script located in e:\python\musicplayer.py. Any way of getting the current running-script path?

    b.t.w I can use os.path.dirname insted of split, but still now a way to find the directory the python file located.
    Last edited by otadmor; 2007-10-24 at 15:25.

  10. #10
    Regular Contributor
    Join Date
    Oct 2007
    Posts
    67

    Re: Need help with binding keys and File Browser

    Does os.path.dirname(__file__) give what you want?

  11. #11
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Re: Need help with binding keys and File Browser

    I get: "Name error: __file__ not defined". What to do next?

    In the mean time, I wrote a file browser from a menu(with thanks to this thread: http://discussion.forum.nokia.com/fo...unicode+string). Please post your comments.

    You can use this browser if you want, but please, don't delete my name on the first line :-).

    Code:
    #Created By Ofir Tadmor
    
    import os
    import appuifw
    import e32
    
    class MenuFileBrowser:
        def __init__(self):
            self.dir_stack = []
    
        def show(self):
            selected_file = None
            focused_item = 0
            
            while 1:
                #show the list
                if len(self.dir_stack) == 0:
                    entries = e32.drive_list()
                    
                    index = appuifw.popup_menu(entries)
    
                    if index == None:
                        break
                    else:
                        self.dir_stack.append(entries[index])
                else:
                    old_path = os.sep.join(self.dir_stack).encode('utf-8')
                    entries = [x.decode('utf-8') for x in os.listdir(old_path)]
                    entries.insert(0, u"..")
                    entries.insert(1, u".")
    
                    index = appuifw.popup_menu(entries)
    
                    if index == None or index == 0: #go up one directory
                        focused_item = self.dir_stack.pop()
                    elif index == 1: #select current directory
                        selected_file = old_path
                        focused_item = self.dir_stack.pop()
                        break
                    else:
                        short_path = entries[index]
                        new_path = ("%s%s%s" % (old_path.decode('utf-8'), os.sep, short_path)).encode('utf-8')
                        if os.path.isdir(new_path):
                            self.dir_stack.append(short_path)
                        else:
                            selected_file = new_path
                            focused_item = self.dir_stack.pop()
                            break
                    
            return selected_file
    Also, when I try to use the ID3 tad reader you posted here early, I get message of :"ID3 has no attribute 'modified'" in method ID3.__del__ of instance ignored.

    Should I send coded or decoded strings to this module?
    Last edited by otadmor; 2007-10-24 at 19:41.

  12. #12
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Re: Need help with binding keys and File Browser

    A little update(I post a new post, and not edit, to make order in these messages, I hope it is ok with the mods).

    1) Can someone tell me please if he has same problem with 6120, Or the problem is in my code?

    2) Menu based File-Browser I've created is in the previous post. It also support other languages than English.

    3) I need to figure how to get the directory that my python script file located.

  13. #13
    Regular Contributor
    Join Date
    Oct 2007
    Posts
    67

    Re: Need help with binding keys and File Browser

    Quote Originally Posted by otadmor View Post
    I get: "Name error: __file__ not defined". What to do next?
    Ehm, i'm getting confused. First off, manipulating sys.path at runtime is generally not a wise thing to do.

    Then, if all you want to do is import a library, install the library in the right location. In your case that should probably be E:\Python\Lib\.

    Then, when importing, you don't have to know the library location nor your script location. Just name it by the module name and the import should work.

    Once imported, a module will normally have a __file__ attribute telling you the location it came from, in case you really need to know. There is also a __name__ attribute holding the imported module name (or the special value "__main__" if you are at the root script namespace).

  14. #14
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Re: Need help with binding keys and File Browser

    Ok. I left the python files im importing in the bin folder.

    Now to much bigger problem.
    When i listen to music, and then press the hang-off key, the music is still playing although I left the program. I can't use the focus hack:
    1) It is now working when I leave the program.
    2) Not all lose focus should stop the music(when I switch to other processes for example, I want to hear my music).

  15. #15
    Regular Contributor
    Join Date
    Oct 2007
    Posts
    67

    Re: Need help with binding keys and File Browser

    Quote Originally Posted by otadmor View Post
    When i listen to music, and then press the hang-off key, the music is still playing although I left the program. I can't use the focus hack:
    1) It is now working when I leave the program.
    2) Not all lose focus should stop the music(when I switch to other processes for example, I want to hear my music).
    I do not fully understand the question. However, you may be able to catch the endkey press using the keycapture module, and call stop() on the playing sound before python exits?

Similar Threads

  1. Unable to access activation keys
    By ashish_apj in forum Digital Rights Management & Content Downloading
    Replies: 11
    Last Post: 2008-11-19, 09:15
  2. OMA DRM media transfer using PC to Phone using USB
    By venky123 in forum Digital Rights Management & Content Downloading
    Replies: 1
    Last Post: 2008-08-13, 03:02
  3. Sky Explorer released, a file manager
    By leecm in forum Symbian
    Replies: 7
    Last Post: 2007-05-11, 12:42
  4. WML & WMLSCript problem ????
    By gemini_shooter in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-14, 06:02
  5. WML & WMLSCript problem ????
    By gemini_shooter in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-14, 06:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×