[Tutor] wx.Notebook query in wxpython

2006-08-10 Thread Amresh Kulkarni
Hi all,I am developing a GUI which has a notebook with multiple tabs. The tabs are formed by adding pages to the notebook.I have a check menu to select/deselect the tabs(pages) i want. On checking on an item it will must show the respective tab and unchecking should hide it.
Simple as it may sound, i cant seem to find a hide method for notebook.Like if i have tabs x, y, z and i have unchecked x item in menu. it will trigger the foll  codepageX = self.Notebook.GetPage(xid) --> xid is the id assigned to page x
xid.Show(False)This does not work as there is no method show in Notebook. Is there a way to make this work.~~AMRESH~~
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Delete directories recursively

2006-06-16 Thread Amresh Kulkarni
Thanks guys,Error handling seems to be a nice idea to approach this problem. i checked Kent's code and it works fine.I was using a more crude method.def removeDir(dirName) :    #Remove any read-only permissions on file.
    removePermissions(dirName)    for name in os.listdir(dirName):    file = os.path.join(dirName, name)    if not os.path.islink(file) and os.path.isdir(file):    removeDir(file)    else:
    removePermissions(file)    os.remove(file)    os.rmdir(dirName)    returndef removePermissions(filePath) :    #if (os.access(filePath, os.F_OK)) : #If path exists    if (not 
os.access(filePath, os.W_OK)) :    os.chmod(filePath, 0666)    returnhowever shutil seems to be more simple and efficient here!Regards,Amresh On 6/16/06, 
Kent Johnson <[EMAIL PROTECTED]> wrote:
John Corry wrote:>> Amresh,>> I had this problem a few months back.  I approached it backwards.  Maybe> not the right way to do it.  I removed all the files and directories and> then had my exception handle the file if it was read only.  The
> exception  handler changes the file from read-only to not read only and> then calls the function again.>> Is there a better way to do it?  Would appreciate feedback on the code> below.
>> import shutil> import os>> def zaps(self):>> try:> shutil.rmtree('f:/m2m')>>> except OSError, inst:> print OSError
> os.chmod(inst.filename, 0666)> self.zaps()I imagine this could be expensive if you have a deep directory hierarchywith lots of read-only files - you have to start the traversal from
scratch each time you get an error. If you have more than 1000 read-onlyfiles you will get a stack overflow from the recursion.shutil.rmtree() actually takes an optional error handler argument.According to the docs, "If onerror is provided, it must be a callable
that accepts three parameters: function, path, and excinfo. The firstparameter, function, is the function which raised the exception; it willbe os.listdir(), os.remove() or os.rmdir()."So something like this should work and be faster because the directory
traversal doesn't restart each time (UNTESTED!!):def handle_error(fn, path, excinfo):   if fn is os.rmdir: # handle readonly dir os.chmod(path, 0666) # ?? not sure if this is correct for a dir
 os.rmdir(path) # try again   elif fn is os.remove: os.chmod(path, 0666) os.remove(path)shutil.rmtree(top, >Kent___
Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
-- ~~AMRESH~~
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Delete directories recursively

2006-06-16 Thread Amresh Kulkarni
Hi,I need to delete a directory and its sub directories. However all dir's, sub dir;s and files have read only access. How do i do this efficeintly using the os.walk command. I cannot run this command on the dir as it gives me an error due to the read only attribute. Is there any other way to do this?
-- ~~AMRESH~~
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor