Hello wxpython community,
I need to display a progress bar while a an R program is running in the background. I am not sure how to this. The following is what I have, but doing it this way, the timer doesn't start. I am guessing the subprocess.call should be placed somewhere else, but I am not sure where. As always, your help is very appreciated.
Thank you.
Here is the code:
import subprocess
import wx
class MyFrame(wx.Frame):
def __init__(self,parent,id, title, tpval=""):
wx.Frame.__init__(self,parent,id,title='An application',size=(900,750))
self.SetBackgroundColour('tan')
menuBar=wx.MenuBar()
menu0=wx.Menu()
menu0.Append(97, "&Open file","")
menuBar.Append(menu0,"&File")
self.Bind(wx.EVT_MENU,self.openfile,id=97)
def openfile(self,event):
dlgg=wx.FileDialog(self,"Choose a file",os.getcwd(),"","*.*",wx.OPEN)
if dlgg.ShowModal() == wx.ID_OK:
frame6=analysis(self,-1, "")
frame6.Show(True)
dlgg.Destroy
class analysis(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,None,-1,title="Running analysis", size=(350,150))
panel55=wx.Panel(self,-1)
self.count=0
self.timer=wx.Timer(self,-1)
self.Bind(wx.EVT_TIMER,self.OnTimer,self.timer)
self.gauge=wx.Gauge(panel55,-1,100,(20,50),(250,25))
self.gauge.SetBezelFace(3)
self.gauge.SetShadowWidth(3)
self.timer.Start(100)
def OnTimer(self,event):
# This is where the R process is called.
command0='R CMD BATCH myRscript.R'
subprocess.call(command0,shell=True)
self.count=self.count+1
self.gauge.SetValue(self.count)
if self.count==100:
self.timer.Stop()
self.Close()
class MyApp(wx.App):
def OnInit(self):
myframe=MyFrame(None,-1,"commondialogs.py")
myframe.Center
myframe.Show(True)
app=MyApp(0)
app.MainLoop()