[Tutor] how to get the confirmation that a cmd done using os.system is corectely
done?
kbond
kbond@free.fr
Sun Feb 23 05:33:02 2003
This is a multi-part message in MIME format.
--------------080900030406010204050505
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hello,
I have a problem in Onconnect() function (I put the code bellow). This
function is called by an event in a menu of wxPython application.
The goal of this function is to connect my linux box to the internet.
The connection works fine but I have the following problem:
During the connection the application informs the user on the status of
the connection. I want to display the message ("The computer is
connected to internet") in a wxStaticText when the command "pon
Free_Telecom" is succesfully finish.
The actual status is the message is coming during the connection and not
when the connection is done.
I am attaching the complete code to this mail.
Any suggestion to improve it are welcome.
Regards,
Yann
def OnConnect(self, e):
import os
import time
print "debut de la fonction OnConnect"
self.statTxt.SetLabel("Connecting to internet")
print self.statTxt.GetLabel()
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
--------------080900030406010204050505
Content-Type: text/plain;
name="mainWindow.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="mainWindow.py"
#!/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, size = (550,300),style = wxDEFAULT_FRAME_STYLE)
self.SetAutoLayout(true)
self.panelA = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
wxSUNKEN_BORDER)
self.panelA.SetBackgroundColour(wxColour(red=255, green=189, blue=255) )
txt = wxStaticText(self.panelA, -1,
"Shortcut to your favorite\n"
"web aplications\n",
wxPoint(5,5), wxSize(-1, 50))
txt.SetForegroundColour(wxBLACK)
lc = wxLayoutConstraints()
lc.top.SameAs(self, wxTop, 10)
lc.left.SameAs(self, wxLeft, 10)
lc.bottom.SameAs(self, wxBottom, 10)
lc.right.SameAs(self, wxLeft, -200)
self.panelA.SetConstraints(lc)
self.panelC = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize)
lc = wxLayoutConstraints()
lc.top.SameAs(self ,wxBottom, -70)
lc.right.SameAs(self, wxRight, 10)
lc.bottom.SameAs(self, wxBottom, 10)
lc.left.RightOf(self.panelA, 10)
self.panelC.SetConstraints(lc)
self.panelB = wxWindow(self, -1, wxDefaultPosition, wxDefaultSize,
wxRAISED_BORDER)
self.LabelPanelB = wxStaticText(self.panelB, -1, "Connection Status", wxPoint(4, 4))
self.panelB.SetBackgroundColour(wxWHITE)
lc = wxLayoutConstraints()
lc.top.SameAs(self, wxTop, 10)
lc.right.SameAs(self, wxRight, 10)
lc.bottom.Above(self.panelC)
lc.left.RightOf(self.panelA, 10)
self.panelB.SetConstraints(lc)
b = wxButton(self.panelA, 100, ' Panel A ')
lc = wxLayoutConstraints()
lc.centreX.SameAs (self.panelA, wxCentreX)
lc.centreY.SameAs (self.panelA, wxCentreY)
lc.height.AsIs ()
lc.width.PercentOf (self.panelA, wxWidth, 50)
b.SetConstraints(lc);
self.statTxt = wxStaticText(self.panelB, -1, "", wxPoint(20, 10))
lc = wxLayoutConstraints()
lc.top.Below (self.LabelPanelB, 2)
lc.right.AsIs ()
lc.left.SameAs (self.panelB, wxLeft, 2)
lc.bottom.AsIs ()
self.statTxt.SetConstraints(lc);
self.connectedFlag = 0
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.panelC, -1, self.image)
lc = wxLayoutConstraints()
lc.bottom.SameAs(self.panelC, wxBottom,6 )
lc.right.SameAs(self.panelC, wxRight, 4)
lc.height.AsIs()
lc.width.AsIs()
butterfly.SetConstraints(lc)
b = wxButton(self.panelC, 100, ' Button ')
lc = wxLayoutConstraints()
lc.bottom.SameAs(self.panelC, wxTop, 20)
lc.right.SameAs(self.panelC, wxRight, 40)
lc.height.AsIs()
lc.width.AsIs()
b.SetConstraints(lc)
#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
photosmenu = wxMenu()
#converting the picture to medium and small size
ID_CONVERT = wxNewId()
photosmenu.Append(ID_CONVERT, "&Convert Photos", "Convert the photos to medium and small size")
#Generating the html page index
ID_GENERATE = wxNewId()
photosmenu.Append(ID_GENERATE, "&Generate Html", "Generate the html page index")
#Uploading the photos from the camera
ID_UPLOAD = wxNewId()
photosmenu.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 toolsmenu
toolsmenu = wxMenu()
#Change the panel's color
ID_COLOR = wxNewId()
toolsmenu.Append(ID_COLOR, "&Change Color", "Change the Color of the selected panel")
#Creating the menu Bar
menuBar = wxMenuBar()
menuBar.Append(filemenu, "&File")
menuBar.Append(photosmenu, "&Photos")
menuBar.Append(internetmenu, "&Internet")
menuBar.Append(toolsmenu, "&Tools")
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_MENU(self, ID_COLOR, self.OnColor)
EVT_BUTTON(self, 100, self.OnButton)
self.Show(true)
## ----------------------------------------------------------------------
def OnButton(self, event):
wxBell()
## ----------------------------------------------------------------------
def OnColor(self, event):
data = wxColourData()
data.SetChooseFull(true)
dlg = wxColourDialog(self, data)
if dlg.ShowModal() == wxID_OK:
data = dlg.GetColourData()
dlg.Destroy()
self.panelA.SetBackgroundColour(data.GetColour())
## wxPaintDC(self)
## ---------------------------------------------------------------------
## def OnPaint(self):
## wxPaintDC(self)
## ------------------------------------------------------------------------
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, 'The Photos have been transfered!',
'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()
--------------080900030406010204050505--