from wxPython.wx import * from wxPython.grid import * from wxPython.lib.mixins.grid import wxGridAutoEditMixin import os LEN_HOR = 10 LEN_VER = 20 LEN_SPC = 5 LEN_DOT = 2 class Bean(wxPanel): def __init__(self,parent,id,label,pos,size): self.name = "Time ID: " + str(id) self.id = id wxPanel.__init__(self,parent,id,pos=pos,size=size) self.drawColor = self.GetForegroundColour() self.pen = wxPen(self.drawColor, 3, wxSOLID) self.pen.SetCap(wxCAP_PROJECTING) self.timer = wxTimer(self) self.timer.Start(1000, wxTIMER_CONTINUOUS) EVT_TIMER(self, -1, self.onTimer) self.started = 1 self.draw_num = [0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f] self.start_pos=[0*LEN_HOR+0*LEN_SPC,1*LEN_HOR+1*LEN_SPC,2*LEN_HOR+2*LEN_SPC, 2*LEN_HOR+3*LEN_SPC,3*LEN_HOR+4*LEN_SPC,4*LEN_HOR+5*LEN_SPC, 4*LEN_HOR+6*LEN_SPC,5*LEN_HOR+7*LEN_SPC] #EVT_SIZE(self, self.OnSize) EVT_PAINT(self, self.OnPaint) # required interface: def get_color(self): #return self.GetBackgroundColour() return self.drawColor def set_color(self, col): self.drawColor = col self.pen.SetColour(col) self.draw_all() #return self.SetBackgroundColour(col) def get_name(self): return self.name def support_firing(self): return 0 #no def support_recieving_fire(self): return 1 #yes def set_onfire(self, func): return def get_onfire(self): return self.stop_running # now non-interface functions # a more generalized version is implemented # instead of directly calling stop_running(), # the beanbox will call get_onfire() to get the function object to fire #and this function also toggles between running and stopping states def stop_running(self): if (self.started == 1): self.timer.Stop() self.started = 0 else: self.timer.Start() self.started = 1 def onTimer(self, evt): self.draw_all() def draw_all(self, dc=None): now = wxDateTime_Now() hours = now.GetHour() mins = now.GetMinute() secs = now.GetSecond() if (dc is None): dc = wxClientDC(self) dc.Clear() dc.SetPen(self.pen) self.draw_number(dc, hours/10, 0) self.draw_number(dc, hours%10, 1) self.draw_dotdot(dc, 2) self.draw_number(dc, mins/10, 3) self.draw_number(dc, mins%10, 4) self.draw_dotdot(dc, 5) self.draw_number(dc, secs/10, 6) self.draw_number(dc, secs%10, 7) def draw_number(self,dc, num, pos): sx = 0 + self.start_pos[pos] sy = 0 if (self.draw_num[num] & 0x01): dc.DrawLine(sx,sy,sx+LEN_HOR,sy) if (self.draw_num[num] & 0x02): dc.DrawLine(sx+LEN_HOR,sy,sx+LEN_HOR,sy+LEN_VER) if (self.draw_num[num] & 0x04): dc.DrawLine(sx+LEN_HOR,sy+LEN_VER,sx+LEN_HOR,sy+2*LEN_VER) if (self.draw_num[num] & 0x08): dc.DrawLine(sx+LEN_HOR,sy+2*LEN_VER,sx,sy+2*LEN_VER) if (self.draw_num[num] & 0x10): dc.DrawLine(sx,sy+2*LEN_VER,sx,sy+LEN_VER) if (self.draw_num[num] & 0x20): dc.DrawLine(sx,sy,sx,sy+LEN_VER) if (self.draw_num[num] & 0x40): dc.DrawLine(sx,sy+LEN_VER,sx+LEN_HOR,sy+LEN_VER) def draw_dotdot(self,dc, pos): sx = 0 + self.start_pos[pos] sy = 0 dc.DrawRectangle(sx - LEN_DOT/2, sy+LEN_VER/2 - LEN_DOT/2, LEN_DOT, LEN_DOT) dc.DrawRectangle(sx - LEN_DOT/2, sy+3*LEN_VER/2 - LEN_DOT/2, LEN_DOT, LEN_DOT) def OnPaint(self, event): dc = wxPaintDC(self) self.draw_all(dc)