莫非at不能定时执行图形程序?
想趁晚上没有人使用网路时用amule下载一些东西,却发现使用at并不能定时执行图形化的程序,而定时执行console程序是没有问题的,man了一下又google了半天没有任何收获,只得用python临时写一个简单的先凑合用着(
下载
)。
[color="#ffa600"][color="#84a2ff"]#!/usr/bin/python
[color="#84a2ff"]#coding=UTF-8
[color="#ff82ff"]import wx
[color="#ff82ff"]import os
[color="#ffff63"]class [color="#42ffff"]MyApp(wx.App):
[color="#ffff63"]def [color="#42ffff"]OnInit(self):
self.frame = wx.Frame(None,-1,"[color="#ffa2a5"]RunAt",size=(290,77))
self.lblCmd = wx.StaticText(self.frame,-1,"[color="#ffa2a5"]命令:")
self.txtCmd = wx.TextCtrl(self.frame,-1,size=(150,-1))
self.btnSelect = wx.Button(self.frame,-1,"[color="#ffa2a5"]选择")
self.btnSelect.Bind(wx.EVT_BUTTON,self.Select)
self.lblTime = wx.StaticText(self.frame,-1,"[color="#ffa2a5"]时间:")
self.txtTime = wx.TextCtrl(self.frame,-1,size=(150,-1))
self.btnSet = wx.Button(self.frame,-1,"[color="#ffa2a5"]设定")
self.btnSet.Bind(wx.EVT_BUTTON,self.Set)
sizer1 = wx.BoxSizer(wx.HORIZONTAL)
sizer1.Add(self.lblCmd,0,wx.LEFT|wx.TOP|wx.ALIGN_CENTER,5)
sizer1.Add(self.txtCmd,0,wx.LEFT|wx.TOP|wx.ALIGN_CENTER,5)
sizer1.Add(self.btnSelect,0,wx.LEFT|wx.TOP|wx.ALIGN_CENTER,5)
sizer2 = wx.BoxSizer(wx.HORIZONTAL)
sizer2.Add(self.lblTime,0,wx.LEFT|wx.TOP|wx.ALIGN_CENTER,5)
sizer2.Add(self.txtTime,0,wx.LEFT|wx.TOP|wx.ALIGN_CENTER,5)
sizer2.Add(self.btnSet,0,wx.LEFT|wx.TOP|wx.ALIGN_CENTER,5)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(sizer1,0)
sizer.Add(sizer2,0)
self.frame.SetSizer(sizer)
self.runTime = None
self.timer = wx.Timer()
self.timer.Bind(wx.EVT_TIMER,self.OnTimer)
self.timer.Start()
self.frame.Bind(wx.EVT_ICONIZE,self.OnMin)
self.frame.Center()
self.frame.Show(True)
self.SetTopWindow(self.frame)
[color="#ffff63"]return True
[color="#ffff63"]def [color="#42ffff"]Select(self,event):
dlg = wx.FileDialog(self.frame)
[color="#ffff63"]if dlg.ShowModal() == wx.ID_OK:
self.txtCmd.SetValue(dlg.GetPath())
[color="#ffff63"]def [color="#42ffff"]OnTimer(self,event):
[color="#ffff63"]if self.runTime == None:
[color="#ffff63"]pass
t = wx.DateTime.Now()
str = "[color="#ffa2a5"]%02d:%02d" %(t.GetHour(),t.GetMinute())
[color="#ffff63"]if str == self.runTime [color="#ffff63"]and t.GetSecond() == 0:
os.system("[color="#ffa2a5"]%s&" %self.txtCmd.GetValue())
[color="#ffff63"]def [color="#42ffff"]Set(self,event):
self.runTime = self.txtTime.GetValue()
[color="#ffff63"]def [color="#42ffff"]OnMin(self,event):
self.frame.Show(False)
[color="#ffff63"]def [color="#42ffff"]main():
app = MyApp(0)
app.MainLoop()
[color="#ffff63"]if __name__ == "[color="#ffa2a5"]__main__":
main()