#!/usr/bin/env python from wxPython.wx import * from random import Random import time import pickle import bpnn g = Random() h = Random() SeccondsinDay = range(86399) try: tom = open('concious_data.txt','r+') SeccondsinDay = pickle.load(tom) print 'sucsess' except IOError: print 'bummer' tom = open('concious_data.txt','w+') for i in range(86399): SeccondsinDay[i] = 0.0 def plant(): g.seed() h.seed() return abs(h.random()- g.random()) class TestTimer(wxTimer): def __init__(self): wxTimer.__init__(self) self.time = int(divmod(wxGetLocalTime(),86400.0)[1]) def Notify(self): self.time = int(divmod(wxGetLocalTime(),86400.0)[1]) SeccondsinDay[self.time] = SeccondsinDay[self.time] + plant() class GraphTimer(wxTimer): def __init__(self, parent): wxTimer.__init__(self) self.parent = parent def Notify(self): self.parent.OnPaintlines2(self.parent) MainTime = TestTimer() class MyFrame(wxFrame): def __init__(self, parent, id, title): wxFrame.__init__(self, parent, id, title, wxDefaultPosition, wxDefaultSize) EVT_CLOSE(self, self.OnCloseWindow) self.graphtime = GraphTimer(self) PlotWindowID = wxNewId() self.PlotWindow = wxScrolledWindow(self, PlotWindowID, wxPoint(0, 0), wxSize(1000,1000), wxSUNKEN_BORDER) self.mainmenu = wxMenuBar() menu=wxMenu() exitID=wxNewId() menu.Append(exitID, '&Load', 'Load Data') EVT_MENU(self, exitID, self.OnLoadData) exitID=wxNewId() menu.Append(exitID, '&Save', 'Save Data') EVT_MENU(self, exitID, self.OnSaveData) exitID=wxNewId() menu.Append(exitID, 'Save &As', 'Save Data As') EVT_MENU(self, exitID, self.OnSaveAsData) exitID=wxNewId() menu.Append(exitID, '&Clear', 'Clear Data') EVT_MENU(self, exitID, self.OnClearData) EVT_PAINT(self, self.OnPaint) self.mainmenu.Append (menu, '&Data') self.SetMenuBar (self.mainmenu) self.PlotWindow.SetBackgroundColour(wxNamedColor("WHITE")) StartButtonID = wxNewId() self.StartButton = wxButton(self, StartButtonID, "Go", wxPoint(20, 20)) EVT_BUTTON(self, StartButtonID, self.OnGoClick) self.StartButton.SetBackgroundColour(wxBLUE) self.StartButton.SetForegroundColour(wxWHITE) self.StartButton.SetDefault() StopButtonID = wxNewId() self.StopButton = wxButton(self, StopButtonID, "Stop", wxPoint(260, 20)) EVT_BUTTON(self, StopButtonID, self.OnStopClick) self.StopButton.SetBackgroundColour(wxRED) self.StopButton.SetForegroundColour(wxWHITE) self.main_sizer = wxBoxSizer(wxVERTICAL) self.button_sizer = wxBoxSizer(wxHORIZONTAL) self.button_sizer.Add(self.StartButton, 1, wxEXPAND) self.button_sizer.Add(self.StopButton, 1, wxEXPAND) self.main_sizer.Add(self.button_sizer, 1, wxEXPAND) self.main_sizer.Add(self.PlotWindow, 10, wxEXPAND) self.SetSizer(self.main_sizer) self.SetAutoLayout(1) self.main_sizer.Fit(self) def OnSaveAsData(self, event): dlg = wxFileDialog(self, "Data file name", ".", "", "*.txt", wxSAVE) if dlg.ShowModal() == wxID_OK: path = dlg.GetPath() tom = open(path,'w+') pickle.dump(SeccondsinDay[:], tom) dlg.Destroy() def onPaint(self,event): dc = wxPaintDC(self) self.OnPaintlines() def OnClearData(self, event): for i in range(86399): SeccondsinDay[i] = 0.0 self.OnPaintlines() def OnLoadData(self, event): dlg = wxFileDialog(self, "Data file name", ".", "", "*.txt", wxOPEN) if dlg.ShowModal() == wxID_OK: path = dlg.GetPath() tom = open(path,'r+') SeccondsinDay = pickle.load(tom) dlg.Destroy() def OnSaveData(self, event): pickle.dump(SeccondsinDay[:], tom) def OnCloseWindow(self, event): tom.close self.Destroy() def OnGoClick(self, event): MainTime.Start(10) self.graphtime.Start(30000) def OnStopClick(self, event): MainTime.Stop() self.graphtime.Stop() tom.seek(0) pickle.dump(SeccondsinDay[:], tom) self.OnPaintlines() def OnPaintlines(self): dc = wxClientDC(self.PlotWindow) self.PlotWindow.PrepareDC(dc) dc.BeginDrawing() dc.SetPen(wxPen(wxNamedColour('BLUE'), 4)) dc.DrawLine(0,400, 1000, 400) dc.SetFont(wxFont(14, wxSWISS, wxNORMAL, wxNORMAL)) dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF)) for i in range(23): dc.DrawText(str(i+1),(i +1) * 41, 420) dc.SetPen(wxPen(wxNamedColour('BLUE'), 1)) for i in range(86399): if SeccondsinDay[i] != 0.0: dc.DrawLine(int(i/86.4),400, int(i/86.4), 400 - int(SeccondsinDay[i] * 100)) dc.SetPen(wxPen(wxNamedColour('RED'), 1)) for i in range(int(divmod(wxGetLocalTime(),86400.0)[1]) - 100,int(divmod(wxGetLocalTime(),86400.0)[1])): dc.DrawLine(int(i/86.4),400, int(i/86.4), 400 - int(SeccondsinDay[i] * 100)) dc.EndDrawing() def OnPaintlines2(parent, self): dc = wxClientDC(self.PlotWindow) self.PlotWindow.PrepareDC(dc) dc.BeginDrawing() dc.SetPen(wxPen(wxNamedColour('BLUE'), 4)) dc.DrawLine(0,400, 1000, 400) dc.SetFont(wxFont(14, wxSWISS, wxNORMAL, wxNORMAL)) dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF)) for i in range(23): dc.DrawText(str(i+1),(i +1) * 41, 420) dc.SetPen(wxPen(wxNamedColour('BLUE'), 1)) for i in range(86399): if SeccondsinDay[i] != 0.0: dc.DrawLine(int(i/86.4),400, int(i/86.4), 400 - int(SeccondsinDay[i] * 100)) dc.SetPen(wxPen(wxNamedColour('RED'), 1)) for i in range(int(divmod(wxGetLocalTime(),86400.0)[1]) - 100,int(divmod(wxGetLocalTime(),86400.0)[1])): dc.DrawLine(int(i/86.4),400, int(i/86.4), 400 - int(SeccondsinDay[i] * 100)) dc.EndDrawing() class MyApp(wxApp): def OnInit(self): frame = MyFrame(None, -1, "Global concious") frame.Show(true) self.SetTopWindow(frame) return true app = MyApp(0) app.MainLoop()