Excel overwrite file dialog box going behind Python GUI.

I am using
Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)]
wxPython 2.8.12.1, Boa Constructor 0.6.1
Windows 7
win32com.client

I am writing Excel files using win32com and python from python GUI. My GUI occupies 1/3rd space on desktop. The problem I am facing is when there is already a .xlsx file with that name then "A file named …xlsx " already exists in this location.Do you want to replace it? dialog box appears behind my PYthon GUI and application gets hanged. Does anyone know how to tackle this in Windows 7? what can I do so that overwrite dialog box comes on top of Python GUI.

Thanks

Hi,

I am using
Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)]
wxPython 2.8.12.1, Boa Constructor 0.6.1
Windows 7
win32com.client

I am writing Excel files using win32com and python from python GUI. My GUI
occupies 1/3rd space on desktop. The problem I am facing is when there is
already a .xlsx file with that name then "A file named .....xlsx " already
exists in this location.Do you want to replace it? dialog box appears behind
my PYthon GUI and application gets hanged. Does anyone know how to tackle
this in Windows 7? what can I do so that overwrite dialog box comes on top
of Python GUI.

You should do the file existence checking yourself, not rely on Excel
or any external application messages. Something like this (untested):

if os.path.isfile(xlsx_file):
    dlg = wx.MessageDialog(parent, message="File already exists. Do
you want to replace it?",
                           caption="Warning",
style=wx.YES|wx.NO|wx.CANCEL|wx.ICON_QUESTION)

    if dlg.ShowModal() != wx.ID_YES:
        dlg.Destroy()
        return

    try:
        os.remove(xlsx_file)
    except OSError:
        wx.MessageBox("Unable to delete xlsx file", "Error")
        return

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."

# ------------------------------------------------------------- #
def ask_mailing_list_support(email):

    if mention_platform_and_version() and include_sample_app():
        send_message(email)
    else:
        install_malware()
        erase_hard_drives()
# ------------------------------------------------------------- #

···

On 13 December 2012 10:55, Prashant Deshmukh wrote: