import FSM import utils as u import menus as m from datetime import date import time #==================================== State = type("State", (object,), {}) #==================================== class State(object): def __init__(self, FSM): self.FSM = FSM def Enter(self): pass def Execute(self): pass def Exit(self): pass class Clock(State): def __init__(self,FSM): super(Clock, self).__init__(FSM) def Enter(self): o = self.FSM.owner current_time = time.strftime("%-I:%M:%S") self.ball_sizex, self.ball_sizey = o.h3.getsize("18:88:88") self.ball_sizex /= 2 self.ball_sizey /= 2 self.ballx = o.width / 2 self.bally = o.height / 2 self.ball_speed = .5 self.ball_x_dir = 1 self.ball_y_dir = 1 o.header_text = "Clock" o.pub.register("beat", self) if o.keyState[16] > 0 or o.keyState[17] > 0: pass else: pass super(Clock, self).Enter() def Execute(self): o = self.FSM.owner m.menu1_actions(self, o) if o.keyState[16] == 1: m.draw_menu1(o) o.update_display(0) if o.keyState[16] > 0 or o.keyState[17] > 0: pass else: current_time = time.strftime("%-I:%M:%S") s = int(time.strftime("%S")) if s % 2 == 0: current_time = time.strftime("%-I:%M.%S") if self.ballx > (o.width - self.ball_sizex) or self.ballx < (0 + self.ball_sizex): self.ball_x_dir *= -1 if (self.bally > o.height - self.ball_sizey - 20) or (self.bally < 0 + self.ball_sizey): self.ball_y_dir *= -1 x1 = self.ballx - self.ball_sizex x2 = self.ballx + self.ball_sizex y1 = self.bally - self.ball_sizey y2 = self.bally + self.ball_sizey self.ballx += self.ball_speed * self.ball_x_dir self.bally += self.ball_speed * self.ball_y_dir o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue) o.center_block(current_time, o.h3, [x1, y1, x2, y2], o.light_grey) today = date.today() current_date = today.strftime('%A') current_date += ', ' + today.strftime("%b %d, %Y") o.center_block(current_date, o.h2, [x1, y1 + 35, x2, y2 + 35], o.light_grey) o.update_display(0) def ReceiveMessage(self, message): o = self.FSM.owner u.play_seq(o, message) def Exit(self): self.FSM.owner.pub.unregister("beat", self)