예제 #1
0
 async def draw_rect(self, touch):
     from kivy.graphics import Line, Color, Rectangle, InstructionGroup
     from kivy.utils import get_random_color
     inst_group = InstructionGroup()
     self.canvas.add(inst_group)
     inst_group.add(Color(*get_random_color()))
     line = Line(width=2)
     inst_group.add(line)
     ox, oy = self.to_local(*touch.opos)
     on_touch_move_was_fired = False
     async for __ in ak.rest_of_touch_moves(self, touch):
         # Don't await anything during this async-for-loop
         on_touch_move_was_fired = True
         x, y = self.to_local(*touch.pos)
         min_x = min(x, ox)
         min_y = min(y, oy)
         max_x = max(x, ox)
         max_y = max(y, oy)
         line.rectangle = [min_x, min_y, max_x - min_x, max_y - min_y]
     if on_touch_move_was_fired:
         inst_group.add(Color(*get_random_color(alpha=.3)))
         inst_group.add(
             Rectangle(
                 pos=(min_x, min_y),
                 size=(
                     max_x - min_x,
                     max_y - min_y,
                 ),
             ))
     else:
         self.canvas.remove(inst_group)
예제 #2
0
 async def draw_rect(self, touch):
     from kivy.graphics import Line, Color, Rectangle, InstructionGroup
     from kivy.utils import get_random_color
     inst_group = InstructionGroup()
     self.canvas.add(inst_group)
     inst_group.add(Color(*get_random_color()))
     line = Line(width=2)
     inst_group.add(line)
     ox, oy = x, y = self.to_local(*touch.opos)
     async for __ in ak.rest_of_touch_moves(self,
                                            touch,
                                            stop_dispatching=True):
         # Don't await anything during the iteration
         x, y = self.to_local(*touch.pos)
         min_x, max_x = (x, ox) if x < ox else (ox, x)
         min_y, max_y = (y, oy) if y < oy else (oy, y)
         line.rectangle = (
             min_x,
             min_y,
             max_x - min_x,
             max_y - min_y,
         )
     if x == ox and y == oy:
         self.canvas.remove(inst_group)
     else:
         inst_group.add(Color(*get_random_color(alpha=.3)))
         inst_group.add(
             Rectangle(
                 pos=(min_x, min_y),
                 size=(
                     max_x - min_x,
                     max_y - min_y,
                 ),
             ))
예제 #3
0
    def test_get_random_color_fixed_alpha(self):
        actual = get_random_color()
        self.assertEqual(len(actual), 4)
        self.assertEqual(actual[3], 1.)

        actual = get_random_color(alpha=.5)
        self.assertEqual(len(actual), 4)
        self.assertEqual(actual[3], .5)
예제 #4
0
    def test_get_random_color_fixed_alpha(self):
        actual = get_random_color()
        self.assertEqual(len(actual), 4)
        self.assertEqual(actual[3], 1.)

        actual = get_random_color(alpha=.5)
        self.assertEqual(len(actual), 4)
        self.assertEqual(actual[3], .5)
예제 #5
0
async def animate_label(label):
    from kivy.utils import get_random_color
    sleep = trio.sleep
    await sleep(2)
    while True:
        label.text = 'Kivy + Trio'
        label.color = get_random_color()
        await sleep(.5)
        label.text = '=='
        label.color = get_random_color()
        await sleep(.5)
        label.text = 'Awesome!'
        label.color = get_random_color()
        await sleep(2)
예제 #6
0
 def update_bg_anim(self):
     self.bg_color_animation = Animation(
         bg_color=utils.get_random_color(), duration=4.)
     self.bg_color_animation.bind(
         on_complete=lambda idk,
         a=self: update_bg_anim(a))
     self.bg_color_animation.start(self)
예제 #7
0
    def __init__(self, **kvargs):
        super(Gllearn, self).__init__(**kvargs)
        Window.bind(on_keyboard=self.events_program)
        Window.soft_input_mode = 'below_target'

        self.list_previous_screens = ['base']
        self.window = Window
        self.config = ConfigParser()
        self.manager = None
        self.window_language = None
        self.window_game_language = None
        self.exit_interval = False
        self.dict_language = literal_eval(
            open(os.path.join(self.directory, 'data', 'locales',
                              'locales.txt')).read())

        self.translation = Translation(
            self.lang, 'Gllearn',
            os.path.join(self.directory, 'data', 'locales'))
        self.translation_game = Translation(
            self.lang_games, 'Games',
            os.path.join(self.directory, 'data', 'locales'))

        self.snake_words_with_color = [{
            word: get_random_color(alpha=1.0)
            for word in words
        } for words in [
            s.split(' ')
            for s in self.translation_game._('snake_rounds').split(' | ')
        ]]
        self.current_round_snake = 0
예제 #8
0
파일: __main__.py 프로젝트: bayang/KvBlink
    def set_color(self, *args):
        rdid = choice([key for key in self.ids.keys()])
        self.ids[rdid].background_color = (get_random_color())
        self.ids[rdid].blinking = True

        def restore_color(*args):
            self.ids[rdid].background_color = (0.6, 0.937, 0.133, 1)
            self.ids[rdid].blinking = False
        Clock.schedule_once(restore_color, 0.4)
예제 #9
0
    async def _async_main(self):
        from asynckivy import rest_of_touch_moves, event
        from kivy.graphics import Line, Color, Rectangle, InstructionGroup
        from kivy.utils import get_random_color

        def will_accept_touch(w, t) -> bool:
            return w.collide_point(*t.opos) and (not t.is_mouse_scrolling)

        while True:
            __, touch = await event(self,
                                    'on_touch_down',
                                    filter=will_accept_touch,
                                    stop_dispatching=True)
            inst_group = InstructionGroup()
            self.canvas.add(inst_group)
            inst_group.add(Color(*get_random_color()))
            line = Line(width=2)
            inst_group.add(line)
            ox, oy = x, y = self.to_local(*touch.opos)
            async for __ in rest_of_touch_moves(self,
                                                touch,
                                                stop_dispatching=True):
                # Don't await anything during the iteration
                x, y = self.to_local(*touch.pos)
                min_x, max_x = (x, ox) if x < ox else (ox, x)
                min_y, max_y = (y, oy) if y < oy else (oy, y)
                line.rectangle = (
                    min_x,
                    min_y,
                    max_x - min_x,
                    max_y - min_y,
                )
            if x == ox and y == oy:
                self.canvas.remove(inst_group)
            else:
                inst_group.add(Color(*get_random_color(alpha=.3)))
                inst_group.add(
                    Rectangle(
                        pos=(min_x, min_y),
                        size=(
                            max_x - min_x,
                            max_y - min_y,
                        ),
                    ))
예제 #10
0
 def select_game_locale(name_locale):
     for locale in self.dict_language.keys():
         if name_locale == self.dict_language[locale]:
             self.lang_games = locale
             self.config.set('Games', 'language', self.lang_games)
             self.config.write()
             self.translation_game.switch_lang(name_locale)
             self.snake_words_with_color = [{
                 word: get_random_color(alpha=1.0)
                 for word in words
             } for words in [
                 s.split(' ') for s in self.translation_game._(
                     'snake_rounds').split(' | ')
             ]]
예제 #11
0
 def __init__(self, pos, radius=10):
     super(SpaceObject, self).__init__()
     self.spaceid = SpaceObject.objectcount
     SpaceObject.objectcount += 1
     self.pos = list(pos)
     self.forces = {}
     self.radius = int(radius)
     self.color = get_random_color()
     self.mass = appsettings['density']*4.*math.pi*(self.radius**3.)/3.
     # self.mass *= 10
     self.merged = False
     self.velocity = [0., 0.]
     self.name = 'spaceobject_' + str(self.spaceid)
     self.show_label = False
     self.label = None
예제 #12
0
 async def main_task(label):
     from kivy.utils import get_random_color
     await ak.n_frames(4)
     for text in (
             'Zen of Python',
             'Beautiful is better than ugly.',
             'Explicit is better than implicit.',
             'Simple is better than complex.',
             'Complex is better than complicated.',
             '',
     ):
         async with ak.fade_transition(label):
             label.text = text
             label.color = get_random_color()
         await ak.event(label, 'on_touch_down')
     self.stop()
예제 #13
0
        def spawn_star():
            anims.locals['bounce_duration'] = random() * 4 + 2
            length = random() * 200 + 20

            star = Star(
                color=get_random_color(),
                size=(
                    length,
                    length,
                ),
                size_hint=(
                    None,
                    None,
                ),
                top=root.top,
                right=root.width - random() * 100,
                opacity=0,
            )
            root.add_widget(star)
            anim = anims['star_main']
            anim.bind(on_complete=lambda *args: root.remove_widget(star))
            anim.start(star)
 def anim_one_light(property_name):
     yield S(0)
     a = None
     try:
         while True:
             yield S(random_duration())
             a = A(
                 **{
                     property_name: get_random_color(),
                     'duration': random_duration()
                 })
             a.start(self)
             yield E(a, 'on_complete')
             yield S(random_duration())
             a = A(
                 **{
                     property_name: light_off_color[:],
                     'duration': random_duration()
                 })
             a.start(self)
             yield E(a, 'on_complete')
     finally:
         if a is not None:
             a.cancel(self)
예제 #15
0
 def test_get_random_color_random_alpha(self):
     actual = get_random_color(alpha='random')
     self.assertEqual(len(actual), 4)
예제 #16
0
 def fill_color(self):
     from kivy.utils import get_random_color
     return get_random_color(alpha=.5)
예제 #17
0
 def line_color(self):
     from kivy.utils import get_random_color
     return get_random_color(alpha=.8)
예제 #18
0
    state = False
    i = random.randint(0, 4)
    while i < len(words):
        if ' ' in words[i] or '\n' in words[i]:  # skip spaces
            i += 1
            continue
        if not state:
            words[i] = pre.format(callable(), words[i])
        else:
            words[i] = post.format(words[i])
        state = not state
        i += random.randint(1, 7)


annotate('[size={0}]{1}', '{0}[/size]', partial(random.randint, 8, 24), words)
annotate('[b]{1}', '{0}[/b]', str, words)
annotate('[i]{1}', '{0}[/i]', str, words)
annotate('[color={0}]{1}', '{0}[/color]',
         lambda: get_hex_from_color(get_random_color()), words)
annotated_text = ''.join(words)


class LabelTest(GridLayout):
    text = StringProperty(text)
    sized_text = StringProperty(annotated_text)


if __name__ in ('__main__', ):
    Builder.load_string(kv)
    runTouchApp(LabelTest())
예제 #19
0
from kivy.app import App
#kivy.require("1.10.0")
from kivy.lang import Builder
from kivy import utils
from kivy.uix.screenmanager import ScreenManager, Screen
import threading
from TCP_over_UDP import TCP

cur_color = str(utils.get_hex_from_color(utils.get_random_color()))
cur_nick = ""
cur_ip = ""
cur_port = 0
cur_sock = None
recv_lock = threading.Lock()
keep_going = True


class WelcomeScreen(Screen):
    def get_info(self, nick, ip, port):
        global cur_sock, cur_nick, cur_ip, cur_port
        cur_nick = nick.capitalize() + ": "
        cur_ip = ip
        cur_port = int(port)
        try:
            cur_sock = TCP()
            cur_sock.connect((cur_ip, cur_port))
            self.parent.current = "chat_screen"
        except Exception as error:
            print "An error has occured: error is:%s." % error

예제 #20
0
    state = False
    i = random.randint(0, 4)
    while i < len(words):
        if " " in words[i] or "\n" in words[i]:  # skip spaces
            i += 1
            continue
        if not state:
            words[i] = pre.format(callable(), words[i])
        else:
            words[i] = post.format(words[i])
        state = not state
        i += random.randint(1, 7)


annotate("[size={0}]{1}", "{0}[/size]", partial(random.randint, 8, 24), words)
annotate("[b]{1}", "{0}[/b]", str, words)
annotate("[i]{1}", "{0}[/i]", str, words)
annotate("[color={0}]{1}", "{0}[/color]", lambda: get_hex_from_color(get_random_color()), words)
annotated_text = "".join(words)


class LabelTest(GridLayout):

    text = StringProperty(text)
    sized_text = StringProperty(annotated_text)


if __name__ in ("__main__",):
    Builder.load_string(kv)
    runTouchApp(LabelTest())
예제 #21
0
 def __init__(self, **kwargs):
     super(Menu_Button, self).__init__(**kwargs)
     self.background_color = get_random_color()
     if 'screenmanager' and 'screen' in kwargs:
         self.sm = kwargs['screenmanager']
         self.screen = kwargs['screen']
예제 #22
0
    state = False
    i = random.randint(0, 4)
    while i < len(words):
        if ' ' in words[i] or '\n' in words[i]:  # skip spaces
            i += 1
            continue
        if not state:
            words[i] = pre.format(callable(), words[i])
        else:
            words[i] = post.format(words[i])
        state = not state
        i += random.randint(1, 7)

annotate('[size={0}]{1}', '{0}[/size]', partial(random.randint, 8, 24), words)
annotate('[b]{1}', '{0}[/b]', str, words)
annotate('[i]{1}', '{0}[/i]', str, words)
annotate('[color={0}]{1}', '{0}[/color]',
         lambda: get_hex_from_color(get_random_color()), words)
annotated_text = ''.join(words)


class LabelTest(GridLayout):

    text = StringProperty(text)
    sized_text = StringProperty(annotated_text)


if __name__ in ('__main__', ):
    Builder.load_string(kv)
    runTouchApp(LabelTest())
예제 #23
0
 def test_get_random_color_random_alpha(self):
     actual = get_random_color(alpha='random')
     self.assertEqual(len(actual), 4)
예제 #24
0
import re
import time

from kivy.app import App
from kivy.clock import Clock
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.properties import ColorProperty
from kivy.utils import get_random_color

Window.clearcolor = get_random_color()
from Client.client import Client

FG_Color = ColorProperty(list(map(
    lambda x: min(x + 0.5, 1) if max(Window.clearcolor[:-1]) < 0.5 else max(x - 0.5, 0) if max(
        Window.clearcolor[:-1]) > 0.5 else x, Window.clearcolor[:-1])) + [1.0])
BG_Color = ColorProperty(Window.clearcolor)

network = Client()


class MainScreen(Screen):
    fgcolor = FG_Color
    bgcolor = BG_Color

    def refresh(self, dt):
        try:
            if self.parent.current == "MainScreen":
                network.messages = network.get('messages', {"token": network.token})['data']['messages']
                children = self.children[0].children[::-1]