def _stroke(self, pressure): if pressure is 'hard': self.total += 10 else: self.total += 1 # ~&% Kuài %&~ Kuai.emit('stroked')
def get(self, item): try: rv = self._innerData[item] except KeyError: return None else: # ~&% Kuài %&~ Kuai.emit("model-accessed", item) return rv
def confirm_exit(msg=None): if msg: print("Select y or n..") conf = input("Sure you want to exit? n [y] $ ").lower() or 'y' if conf not in ['y', 'n']: confirm_exit(msg=True) else: if conf == 'y': Kuai.emit('display-is-done')
def __init__(self, screen_res): pygame.init() self.screen = pygame.display.set_mode(screen_res) self.background = pygame.Surface(self.screen.get_size()) Kuai.on('square', self.draw_square) Kuai.on('line', self.draw_line) Kuai.on('circle', self.draw_circle) Kuai.on('point', self.draw_point) Kuai.on('update-view', self.update) Kuai.emit('view-loaded')
def test_priority_backend(): set_backend('priority') def increment(): global x x += 1 Kuai.on('test', increment) Kuai.emit('test') assert x == 1 Kuai.emit('test') assert x == 2
def test_kuai_events(): set_backend('threaded') def increment(): global x x += 1 Kuai.on('test', increment) Kuai.emit('test') sleep(0.01) assert x == 1 Kuai.emit('test') sleep(0.01) assert x == 2
def run(self): while not self.is_done: time.sleep(0.01) x, y = pygame.mouse.get_pos() events = pygame.event.get() for event in events: if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: Kuai.emit('key-up', x, y) if event.key == pygame.K_DOWN: Kuai.emit('key-down', x, y) if event.key == pygame.K_LEFT: Kuai.emit('key-left', x, y) if event.key == pygame.K_RIGHT: Kuai.emit('key-right', x, y) if event.key == pygame.K_ESCAPE: Kuai.emit('key-escape') pass
def run(self): while True: job = random.choice(self.activities) if job == "queryModel": choice = random.choice("first second third".split(' ')) print( green( "Me: Better do some research on this {} one..".format( choice))) self.data.get(choice) print( green("Me: Okay so {} choice is the one then..".format( choice))) if job == "mutateModel": data = random.choice("first second third".split(' ')) this = random.randint(1, 100) print( green("Me: Hmm.. Think i'll change {} to {}..".format( data, this))) self.data.set(data, this) time.sleep(random.randint(3, 9)) # ~&% Kuài %&~ Kuai.emit("jobs-done", "Hm, a job well done I'd say!")
def draw_turtle(x, y): print("Draw turtle!") Kuai.emit('square', red, x, y, random.randrange(5, 20))
def draw_worm(x, y): print("Draw worm!") Kuai.emit('line', white, (x, y), (random.randrange(0, 799), random.randrange(0, 599)), 1)
def draw_squid(x, y): print("Draw squid!") Kuai.emit('circle', white, x, y, random.randrange(5, 15))
def draw_point(self, color, x, y): pygame.draw.rect(self.screen, color, (x, y, 1, 1)) Kuai.emit('update-view')
def draw_square(self, color, x, y, height, border=0): height = 20 pygame.draw.rect(self.screen, color, (x, y, height, height), border) Kuai.emit('update-view')
def draw_circle(self, color, x, y, radius, width=0): pygame.draw.circle(self.screen, color, (x, y), radius, width) Kuai.emit('update-view')
def set(self, item, value): self._innerData[item] = value # ~&% Kuài %&~ Kuai.emit("model-changed", data=(item, value))
def draw_speck(x, y): print("Draw speck!") Kuai.emit('point', red, x, y)
def draw_line(self, color, start_pos, end_pos, width=1): pygame.draw.line(self.screen, color, start_pos, end_pos, width) Kuai.emit('update-view')
from kuai import Kuai def hello(world): print("Hello, {world}!".format(world=world)) Kuai.on('hello-world', hello) Kuai.emit('hello-world', 'Kuài')