コード例 #1
0
ファイル: example.py プロジェクト: xmonader/Kuai
    def _stroke(self, pressure):
        if pressure is 'hard':
            self.total += 10
        else:
            self.total += 1

        # ~&% Kuài %&~
        Kuai.emit('stroked')
コード例 #2
0
ファイル: example.py プロジェクト: xmonader/Kuai
 def get(self, item):
     try:
         rv = self._innerData[item]
     except KeyError:
         return None
     else:
         # ~&% Kuài %&~
         Kuai.emit("model-accessed", item)
         return rv
コード例 #3
0
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')
コード例 #4
0
 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')
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
 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
コード例 #8
0
ファイル: example.py プロジェクト: xmonader/Kuai
    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!")
コード例 #9
0
def draw_turtle(x, y):
    print("Draw turtle!")
    Kuai.emit('square', red, x, y, random.randrange(5, 20))
コード例 #10
0
def draw_worm(x, y):
    print("Draw worm!")
    Kuai.emit('line', white, (x, y),
              (random.randrange(0, 799), random.randrange(0, 599)), 1)
コード例 #11
0
def draw_squid(x, y):
    print("Draw squid!")
    Kuai.emit('circle', white, x, y, random.randrange(5, 15))
コード例 #12
0
 def draw_point(self, color, x, y):
     pygame.draw.rect(self.screen, color, (x, y, 1, 1))
     Kuai.emit('update-view')
コード例 #13
0
 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')
コード例 #14
0
 def draw_circle(self, color, x, y, radius, width=0):
     pygame.draw.circle(self.screen, color, (x, y), radius, width)
     Kuai.emit('update-view')
コード例 #15
0
ファイル: example.py プロジェクト: xmonader/Kuai
    def set(self, item, value):
        self._innerData[item] = value

        # ~&% Kuài %&~
        Kuai.emit("model-changed", data=(item, value))
コード例 #16
0
def draw_speck(x, y):
    print("Draw speck!")
    Kuai.emit('point', red, x, y)
コード例 #17
0
 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')
コード例 #18
0
from kuai import Kuai


def hello(world):
    print("Hello, {world}!".format(world=world))


Kuai.on('hello-world', hello)

Kuai.emit('hello-world', 'Kuài')