def StopIconTimer(self): try: self.icontimer.Stop() self.Data['Message'] = 'Stopping timer.' logwrite.Write(self.Data,self.LogFile) self.SetFreshData() except: pass
def OnTaskBarRightClick(self, evt): # @todo: Find better way to make sure all threads close. self.StopIconTimer() self.tbicon.Destroy() self.Close(True) self.Data['Message'] = 'Owl Timer Shutting Down.' logwrite.Write(self.Data,self.LogFile) wx.GetApp().ProcessIdle() wx.GetApp().Exit() wx.Exit()
def Log(self, evt): if self.Data['Idle'] < idledetect.get_idle_duration(): self.Data['Idle'] = idledetect.get_idle_duration() if self.Data['Idle'] > idledetect.get_idle_duration(): #means we had activity since last self.Data['TotalIdle'] = self.Data['TotalIdle'] + self.Data['Idle'] self.Data['Idle'] = 0 if self.Data['ActiveText'] != GetWindowText(GetForegroundWindow()): p = threadname.get_threadname(self.Data['Active']) self.Data['AppThread'] = p.name self.Data['AppThreadID'] = p.pid self.Data['WinEnd'] = self.Now() self.Data['date_end_time'] = strftime("%d %b %Y - %H:%M:%S") logwrite.Write(self.Data,self.LogFile) # reset data after log is written. self.SetFreshData()
def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, -1, title, size=(1, 1), style=wx.FRAME_NO_TASKBAR | wx.NO_FULL_REPAINT_ON_RESIZE) self.ICON_STATE = 1 self.ID_ICON_TIMER = wx.NewId() self.tbicon = wx.TaskBarIcon() icon = wx.Icon('logon.ico', wx.BITMAP_TYPE_ICO) self.tbicon.SetIcon(icon, 'Logging') self.tbicon.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarLeftDClick) self.tbicon.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnTaskBarRightClick) self.Bind(wx.EVT_TIMER, self.Log, id=self.ID_ICON_TIMER) self.SetIconTimer() self.Show(True) # setup logging self.LogFile = 'logs/' + strftime("%Y-%b-%d", localtime()) # begin the data dictionary to be written as json entries in log self.Data = {} # call SetFreshData() to get time and any other available data self.SetFreshData() self.Data['Message'] = 'Starting a new logging session.' # write a session startup entry logwrite.Write(self.Data,self.LogFile) # most always set fresh data after logging self.SetFreshData()