#!/usr/bin/env python

from wxPython.wx import *
from wxPython.lib.anchors import LayoutAnchors

class MyFrame(wxFrame):
    """This class is the main window of my application"""
    def __init__(self, parent, id, title):
        wxFrame.__init__(self,parent, -4, title,style = wxDEFAULT_FRAME_STYLE)

##         self.panel = wxPanel(self, -1, wxDefaultPosition,wxDefaultSize , wxSIMPLE_BORDER)
        self.panel = wxPanel(self, -1, size=self.GetSize(),style = wxSIMPLE_BORDER)
        self.panel.SetBackgroundColour(wxColour(255, 255, 255))

        self.CreateStatusBar()

        self.image = wxBitmap('/home/commun/scripts/python/photo/appli/V_0.03/resource/001_star_butterfly.xpm', wxBITMAP_TYPE_XPM)
        butterfly = wxStaticBitmap(self.panel, -1, self.image)
        


        butterfly.SetConstraints(LayoutAnchors(butterfly, 1, 0, 1, 1))

        
        b = wxButton(self.panel, 100, ' Button ')
        lc = wxLayoutConstraints()
        lc.bottom.SameAs(self.panel, wxTop, 20)
        lc.right.SameAs(self.panel, wxRight, 40)
        lc.height.AsIs()
        lc.width.AsIs()
        b.SetConstraints(lc)
        
        self.statTxt = wxStaticText(self, -1, "", wxPoint(20, 10))
        self.connectedFlag = 0
        


        
        
        #seting up the menus
        
        #Creating the filemenu
        filemenu = wxMenu()
        ID_ABOUT = wxNewId()
        filemenu.Append(ID_ABOUT, "&About", "Information about this program")
        filemenu.AppendSeparator()
        
        ID_EXIT = wxNewId()
        filemenu.Append(ID_EXIT, "&Exit", "Terminate the program")
        

        #Creating the tools menu
        toolsmenu = wxMenu()
        #converting the picture to medium and small size
        ID_CONVERT = wxNewId()
        toolsmenu.Append(ID_CONVERT, "&Convert Photos", "Convert the photos to medium and small size")
        #Generating the html page index
        ID_GENERATE = wxNewId()
        toolsmenu.Append(ID_GENERATE, "&Generate Html", "Generate the html page index")
        #Uploading the photos from the camera
        ID_UPLOAD = wxNewId()
        toolsmenu.Append(ID_UPLOAD, "&Upload Photos", "Upload the photos from the camera")

        #Creating the internetmenu
        internetmenu = wxMenu()
        #Connect the computer to free Telecom
        ID_CONNECT = wxNewId()
        internetmenu.Append(ID_CONNECT, "&Connect", "Connect to Free Telecom")
        #Disconnect the computer from free Telecom
        ID_DISCONNECT = wxNewId()
        internetmenu.Append(ID_DISCONNECT, "&Disconnect", "Disconnect from Free Telecom")
        #Clear the window
        ID_CLEAR = wxNewId()
        internetmenu.Append(ID_CLEAR, "&Clear", "Clear the window")
        
        
        #Creating the menu Bar
        menuBar = wxMenuBar()
        menuBar.Append(filemenu, "&File")
        menuBar.Append(toolsmenu, "&Tools")
        menuBar.Append(internetmenu, "&Internet")
        self.SetMenuBar(menuBar)

        
        
        #Attaching the menu events

        EVT_MENU(self, ID_EXIT, self.OnExit)
        EVT_MENU(self, ID_ABOUT, self.OnAbout)
        EVT_MENU(self,ID_CONVERT, self.OnConvert)
        EVT_MENU(self,ID_GENERATE, self.OnGenerate)
        EVT_MENU(self, ID_UPLOAD, self.OnUpload)
        EVT_MENU(self, ID_CONNECT, self.OnConnect)
        EVT_MENU(self, ID_DISCONNECT, self.OnDisconnect)
        EVT_MENU(self, ID_CLEAR, self.OnClear)
        
##        EVT_PAINT(self,self.OnPaint)

        self.Show(true)



        
## ------------------------------------------------------------------------
        
    def OnExit(self, e):
        #close the frame
        self.Close(true)

    def OnAbout(self, e):
        dlg = wxMessageDialog(self, 'Sony handler was designed by Yann Malet',
                          'A Message Box', wxOK | wxICON_INFORMATION)
##                           #wxYES_NO | wxNO_DEFAULT | wxCANCEL | wxICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

## ------------------------------------------------------------------------

    def OnConvert(self, e):
        dlg = wxMessageDialog(self, 'This function is under development',
                          'A Message Box', wxOK | wxICON_INFORMATION)
##                           #wxYES_NO | wxNO_DEFAULT | wxCANCEL | wxICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

    def OnGenerate(self, e):
        dlg = wxMessageDialog(self, 'This function is under development',
                          'A Message Box', wxOK | wxICON_INFORMATION)
##                           #wxYES_NO | wxNO_DEFAULT | wxCANCEL | wxICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

    def OnUpload(self,e):
        from Camera import *
        dlg = wxDirDialog(self, "Choose a directory", "/home/commun/sony")
        if dlg.ShowModal() == wxID_OK:
            self.path = dlg.GetPath()
            sony = CameraClass()
            sony.Upload(self.path) 
        dlg.Destroy()

        dlg = wxMessageDialog(self, 'Le transfert est des photos est termin�!',
                          'A Message Box', wxOK | wxICON_INFORMATION)
##                           #wxYES_NO | wxNO_DEFAULT | wxCANCEL | wxICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
## ------------------------------------------------------------------------        

    def OnConnect(self, e):
        import os
        import time
        print "debut de la fonction OnConnect"
        
        self.statTxt.SetLabel("Connecting to internet")
        print self.statTxt.GetLabel()

##        time.sleep(5)    
        os.system("pon Free_Telecom")

        
        time.sleep(5)
        
        self.statTxt.SetLabel("The computer is connected to internet")
        self.connectedFlag = 1
        print "fin de la fonction OnConnect"
        print self.connectedFlag
        
 
    def OnDisconnect(self, e):
        import os
        os.system("poff")
        self.statTxt.SetLabel("The computer is disconnected")
 
    def OnClear(self, e):
        self.statTxt.SetLabel("")

        
## ------------------------------------------------------------------------

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(None, -1, "Sony Handler")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true
app = MyApp(0)    
app.MainLoop()




