def _test():
    from kivy.app import runTouchApp
    from kivy.factory import Factory

    root = Factory.Label(
        text='Hello',
        font_size='100sp',
        markup=True,
        outline_color=(
            1,
            1,
            1,
            1,
        ),
        outline_width=2,
    )

    @callbackgoaway
    def animate_label(label):
        from callbackgoaway.kivy import Sleep as S

        yield S(1.5)
        while True:
            label.text = 'Do'
            label.color = (
                0,
                0,
                0,
                1,
            )
            yield S(.5)
            label.text = 'You'
            yield S(.5)
            label.text = 'Like'
            yield S(.5)
            label.text = 'Kivy?'
            yield S(2)
            label.text = 'Answer me!'
            label.color = (
                1,
                0,
                0,
                1,
            )
            yield S(3)

    gen = animate_label(root)

    def on_touch_down(label, touch):
        gen.close()
        label.text = 'The animation\nwas cancelled.'
        label.color = (
            .5,
            0,
            .5,
            1,
        )

    root.bind(on_touch_down=on_touch_down)
    runTouchApp(root)
def _test():
    from kivy.app import runTouchApp
    from kivy.lang import Builder

    root = Builder.load_string(r'''
FloatLayout:
    Widget:
        id: target
        size_hint: 0.6, 0.6
        pos_hint: {'center_x': 0.5, 'center_y': 0.5, }
        canvas:
            Rectangle:
                pos: 98, 198
                size: 3, 3
    ''')

    def on_touch_down(widget, touch):
        play_stretch_animation(parent=widget,
                               widget=Factory.Button(),
                               root_pos=(
                                   100,
                                   200,
                               ),
                               head_pos=touch.pos,
                               anim_duration=2)

    root.bind(on_touch_down=on_touch_down)
    runTouchApp(root)
Beispiel #3
0
def start_android_beta():
    DEFAULT_PATH = os.path.join(os.path.dirname(__file__), 'appdata.db')
    conn = sqlite3.connect(DEFAULT_PATH)
    c = conn.cursor()
    c.execute("SELECT * FROM TALLY")

    elements = [
        "Sort No", "Date", "Name", "Amount", "Category", "Payement", "Site No"
    ]

    layout = GridLayout(cols=7, spacing=10, size_hint_y=None)
    # Make sure the height is such that there is something to scroll.
    layout.bind(minimum_height=layout.setter('height'))
    for element in elements:
        btn = Label(text=str(element), size_hint_y=None, height=40)
        layout.add_widget(btn)

    x = 1
    for row in c.fetchall():
        but1 = Label(text=str(x), size_hint_y=None, height=40)
        but2 = Label(text=str(row[0]), size_hint_y=None, height=40)
        but3 = Label(text=str(row[1]), size_hint_y=None, height=40)
        but4 = Label(text=str(row[2]), size_hint_y=None, height=40)
        but5 = Label(text=str(row[3]), size_hint_y=None, height=40)
        but6 = Label(text=str(row[4]), size_hint_y=None, height=40)
        but7 = Label(text=str(row[5]), size_hint_y=None, height=40)
        x += 1
        v = [but1, but2, but3, but4, but5, but6, but7]
        for ele in v:
            layout.add_widget(ele)

    root = ScrollView(size_hint=(1, None), size=(Window.width, Window.height))
    root.add_widget(layout)

    runTouchApp(root)
Beispiel #4
0
    def test_and_event(self):

        root = Builder.load_string(
            textwrap.dedent('''
        BoxLayout:
            Image:
                id: image
                source: 'data/logo/kivy-icon-256.png'
            Label:
                id: label
                text: "Test 'and' Event"
                font_size: sp(30)
        '''))

        @callbackgoaway
        def func():
            image = root.ids.image
            label = root.ids.label
            anim1 = Animation(opacity=0)
            anim2 = Animation(opacity=0, d=.5)
            anim1.start(image)
            anim2.start(label)
            yield Event(anim1, 'on_complete') & Event(anim2, 'on_complete')
            self.assertEqual(image.opacity, 0)
            self.assertEqual(label.opacity, 0)
            stopTouchApp()

        gen = func()
        self.assertEqual(getgeneratorstate(gen), GEN_SUSPENDED)
        runTouchApp(root)
        self.assertEqual(getgeneratorstate(gen), GEN_CLOSED)
Beispiel #5
0
def _test():
    from kivy.app import runTouchApp
    import random

    notificator = Notificator(
        size_hint=(0.5, 0.5, ),
        pos_hint={'center_x': 0.5, 'center_y': 0.5, },)

    args_tuple = (
        ('information', 'Kivy is awesome!', ),
        ('warning', 'Keep away!', ),
        ('disallowed', 'You can not get in.', ),
        ('lock', 'The chest is locked.', ),
        ('unlock', 'Unlocked the chest.', ),
        ('good', 'Gooood!', ),
        ('wifi', 'Connection is stable.', ),
        ('talk', "What's up.", ),
        ('close', 'This is close icon.', ),
        ('unknown key', 'unknown key', ),
        (None, 'None', ), )

    def on_touch_down_handler(widget, __):
        args = random.choice(args_tuple)
        widget.add_notification(
            text=args[1],
            icon_key=args[0],
            duration=4,
            font_size=20)

    notificator.bind(on_touch_down=on_touch_down_handler)
    root = Factory.FloatLayout()
    root.add_widget(notificator)
    runTouchApp(root)
Beispiel #6
0
def add_staff_to_file(info):
    def displayname(instance):
        if ((not staff_name.text) or (not staff_position.text)
                or (not staff_points.text)):
            pass
        else:
            topbottom.clear_widgets()
            info.add_staff(staff_name.text, staff_position.text, instance.text,
                           staff_points.text)
            title_screen()

    def hook_keyboard(window, key, *largs):
        if key == 27:
            topbottom.clear_widgets()
            title_screen()

    EventLoop.window.bind(on_keyboard=hook_keyboard)

    topbottom = BoxLayout(orientation='vertical')

    top_layout = GridLayout(cols=2, spacing=20, padding=[10, 10, 10, 10])
    lbl1 = Label(text="Staff name")
    staff_name = TextInput(multiline=False, input_filter=None)

    lbl2 = Label(text="Position")
    staff_position = TextInput(multiline=False, input_filter=None)

    lbl3 = Label(text="Initial points")
    staff_points = TextInput(multiline=False, input_filter="int")

    top_layout.add_widget(lbl1)
    top_layout.add_widget(staff_name)
    top_layout.add_widget(lbl2)
    top_layout.add_widget(staff_position)
    top_layout.add_widget(lbl3)
    top_layout.add_widget(staff_points)

    bottom_layout = GridLayout(cols=5, spacing=20, padding=[10, 10, 10, 10])
    slytherin = Button(text="Slytherin")
    slytherin.bind(on_press=displayname)
    gryffindor = Button(text="Gryffindor")
    gryffindor.bind(on_press=displayname)
    hufflepuff = Button(text="Hufflepuff")
    hufflepuff.bind(on_press=displayname)
    ravenclaw = Button(text="Ravenclaw")
    ravenclaw.bind(on_press=displayname)
    oof = Button(text="Out of Facility")
    ravenclaw.bind(on_press=displayname)

    bottom_layout.add_widget(slytherin)
    bottom_layout.add_widget(gryffindor)
    bottom_layout.add_widget(hufflepuff)
    bottom_layout.add_widget(ravenclaw)
    bottom_layout.add_widget(oof)

    topbottom.add_widget(top_layout)
    topbottom.add_widget(bottom_layout)

    runTouchApp(topbottom)
Beispiel #7
0
 def createListView(self, inputArray):
     layout = GridLayout(cols=1, spacing=1, size_hint_y=None)
     layout.bind(minimum_height=layout.setter('height'))
     for elem in inputArray:
         btn = Button(text=str(elem), size_hint_y=None, height=100)
         layout.add_widget(btn)
     root = ScrollView(size_hint=(1, None),
                       size=(Window.width, Window.height))
     root.add_widget(layout)
     runTouchApp(root)
Beispiel #8
0
def main():
    scene_num = 4
    col_width = scene_num + 3
    root = SelectableGrid(cols=col_width,
                          up_count=5,
                          multiselect=True,
                          scroll_count=1)
    print("-------------------------")
    print(root.m.keyScenes)
    print("-------------------------")
    topCommand = [["reset"], ["c0"], ["c1"], ["c2"], ["c3"], ["c4"], ["c5"]]
    for i in range(col_width):
        c = Button(text=topCommand[i][0])
        c.type = "top"
        c.bind(on_touch_down=root.do_touch_menu)
        root.add_widget(c)

    sceneNames = []
    for i in root.m.scenes:
        sceneNames.append(i["name"])

    for i in root.m.keyScenes:
        c = Button(text=i)
        c.type = "scene"
        c.scene = i
        c.bind(on_touch_down=root.do_touch)
        root.add_widget(c)
        for j in range(1, 1 + scene_num):
            label = getSceneName(i, j)
            if label not in sceneNames:
                label = "**"
            c = Button(text=label)
            c.type = "move"
            c.scene = i
            c.idx = j
            c.bind(on_touch_down=root.do_touch)
            root.add_widget(c)

        c = Factory.Slider(value=20, min=10, max=50, size_hint_y=.3)
        c.scene = i
        c.bind(value=root.OnSliderValueChange)
        root.add_widget(c)

        c = CheckBox()
        c.type = "check"
        c.scene = i
        #c.bind(on_touch_down=root.do_touch)
        root.add_widget(c)

    runTouchApp(root)
Beispiel #9
0
def names(info, points):
    def hook_keyboard(window, key, *largs):
        if key == 27:
            layout.clear_widgets(children=None)
            title_screen()

    EventLoop.window.bind(on_keyboard=hook_keyboard)

    def points_added(instance):
        #This tells where the screen to go next
        name = instance.text
        layout.clear_widgets(children=None)
        info.add_points(name.split("\n")[0], int(points))
        title_screen()

    layout = GridLayout(cols=2,
                        spacing=20,
                        padding=[10, 10, 10, 10],
                        size_hint_y=None)
    # Make sure the height is such that there is something to scroll.
    layout.bind(minimum_height=layout.setter('height'))

    green = [0.26, 0.71, 0.42, 1]
    blue = [0.34, 0.47, 0.91, 1]
    red = [1.74, 0, 0.01, 1]
    yellow = [2.36, 1.85, 0.57, 1]
    grey = [2.2, 2.2, 2.2, 1]
    for key, value in sorted(info.staff.items(),
                             key=lambda e: int(e[1][2]),
                             reverse=True):
        color = [1, 1, 1, 1]
        if info.staff[key][1] == "Slytherin": color = green
        if info.staff[key][1] == "Hufflepuff": color = yellow
        if info.staff[key][1] == "Ravenclaw": color = blue
        if info.staff[key][1] == "Gryffindor": color = red
        if info.staff[key][1] == "Out of Facility": color = grey

        btn = Button(text=key + "\n" + info.staff[key][0] + "\n" +
                     info.staff[key][1] + "\n" + info.staff[key][2],
                     size_hint_y=None,
                     halign="center",
                     height=400,
                     background_color=color)
        btn.bind(on_press=points_added)
        layout.add_widget(btn)

    root = ScrollView(size_hint=(1, None), size=(Window.width, Window.height))
    root.add_widget(layout)
    runTouchApp(root)
Beispiel #10
0
    def test_runtouchapp(self):
        # non-integrated approach
        from kivy.app import runTouchApp
        from kivy.uix.button import Button

        button = Button()
        runTouchApp(button)

        # get your Window instance safely
        from kivy.base import EventLoop
        EventLoop.ensure_window()
        window = EventLoop.window

        # your asserts
        self.assertEqual(window.children[0], button)
        self.assertEqual(window.children[0].height, window.height)
Beispiel #11
0
    def test_property_event(self):
        root = Factory.Label(
            text="Test property Event",
            font_size='30sp',
        )

        @callbackgoaway
        def func():
            Clock.schedule_once(lambda __: setattr(root, 'font_size', 20), .5)
            yield Event(root, 'font_size')
            self.assertEqual(root.font_size, 20)
            stopTouchApp()

        gen = func()
        self.assertEqual(getgeneratorstate(gen), GEN_SUSPENDED)
        runTouchApp(root)
        self.assertEqual(getgeneratorstate(gen), GEN_CLOSED)
Beispiel #12
0
    def test_single_event(self):
        root = Factory.Label(
            text="Test 'single' Event",
            font_size='30sp',
        )

        @callbackgoaway
        def func():
            anim = Animation(opacity=0)
            anim.start(root)
            yield Event(anim, 'on_complete')
            self.assertEqual(root.opacity, 0)
            stopTouchApp()

        gen = func()
        self.assertEqual(getgeneratorstate(gen), GEN_SUSPENDED)
        runTouchApp(root)
        self.assertEqual(getgeneratorstate(gen), GEN_CLOSED)
Beispiel #13
0
def foobar(info, name):
    def callback1(instance):
        layout.clear_widgets(children=None)
        duties(Duties('maintenance.csv'))

    layout = AnchorLayout(padding=[50, 50, 50, 50],
                          anchor_x='center',
                          anchor_y='center')
    btn = Button(text="Hello " + name + "\nYou have " + info.staff[name][2] +
                 " points",
                 halign="center")

    btn.bind(on_press=callback1)
    layout.add_widget(btn)

    root = ScrollView(size_hint=(1, None), size=(Window.width, Window.height))
    root.add_widget(layout)
    runTouchApp(root)
def _test():
    root = Factory.BoxLayout(orientation='vertical')
    root.add_widget(
        OutlinedPolygon.create_from_template('arrow2',
                                             color=(
                                                 0,
                                                 1,
                                                 0,
                                                 1,
                                             ),
                                             line_width=4))
    root.add_widget(
        Builder.load_string(r'''
OutlinedPolygon:
    color: 1, 1, 1, 1
    line_points: 0, 0, 0.5, 1, 1, 0,
    line_width: 4
'''))
    runTouchApp(root)
Beispiel #15
0
def _test_replace_widget():
    import random
    from kivy.lang import Builder
    from kivy.app import runTouchApp
    from kivy.garden.magnet import Magnet

    root = Builder.load_string(r'''
BoxLayout:
    GridLayout:
        id: id_grid
        spacing: 10
        padding: 10
        cols: 2
        rows: 2
        Magnet:
            TextInput:
        Magnet:
            Button:
        Magnet:
            Button:
        Magnet:
            TextInput:
    AnchorLayout:
        id: id_anchor
        Magnet:
            size_hint: None, None
            Widget:
    ''')

    # 親を持たないWidget同士の入れ替え
    replace_widget(Factory.Button(), Factory.Button())

    # 親を持つWidget と 持たないWidget の入れ替え
    replace_widget(root.ids.id_anchor.children[0].children[0],
                   Factory.Button(text='button'))

    # 親を持つWidget同士の入れ替え
    def on_touch_down(root, touch):
        replace_widget(root.ids.id_anchor.children[0],
                       random.choice(root.ids.id_grid.children))

    root.bind(on_touch_down=on_touch_down)
    runTouchApp(root)
Beispiel #16
0
def _test():
    from kivy.app import runTouchApp
    from kivy.resources import resource_add_path
    resource_add_path('../data/font')
    import set_default_font_to_japanese
    set_default_font_to_japanese.apply()

    root = Builder.load_string(r'''
BoxLayout:
    TurnEndButton:
        id: id_turnendbutton
    Button:
        text: 'disable'
        on_press: id_turnendbutton.disabled = True
    Button:
        text: 'enable'
        on_press: id_turnendbutton.disabled = False
    ''')
    runTouchApp(root)
Beispiel #17
0
    def test_or_sleep(self):
        root = Factory.Label(
            text="Test 'or' Sleep",
            font_size='30sp',
        )

        @callbackgoaway
        def func():
            S = Sleep
            yield S(0)
            start_time = time()
            yield S(.5) | S(1)
            self.assertAlmostEqual(time() - start_time, .5, delta=self.DELTA)
            yield S(2) | S(1)
            self.assertAlmostEqual(time() - start_time, 1.5, delta=self.DELTA)
            stopTouchApp()

        gen = func()
        self.assertEqual(getgeneratorstate(gen), GEN_SUSPENDED)
        runTouchApp(root)
Beispiel #18
0
    def test_complex1(self):

        root = Builder.load_string(
            textwrap.dedent('''
        BoxLayout:
            Image:
                id: image
                source: 'data/logo/kivy-icon-256.png'
            Label:
                id: label
                text: "Complex Test"
                font_size: sp(30)
        '''))

        @callbackgoaway
        def func():
            A = Animation
            E = Event
            S = Sleep
            image = root.ids.image
            label = root.ids.label
            a1 = A(opacity=0, d=2)
            a2 = A(opacity=0)
            yield S(0)
            a1.start(image)
            a2.start(label)
            yield E(a1, 'on_complete') | S(.5) | E(a2, 'on_complete')
            self.assertAlmostEqual(image.opacity, 0.75, delta=0.1)
            self.assertAlmostEqual(label.opacity, 0.5, delta=0.1)
            yield E(a1, 'on_complete') | E(a2, 'on_complete')
            self.assertAlmostEqual(image.opacity, 0.5, delta=0.1)
            self.assertEqual(label.opacity, 0)
            yield E(a1, 'on_complete') | E(a2, 'on_complete')
            self.assertEqual(label.opacity, 0)
            self.assertEqual(image.opacity, 0)
            stopTouchApp()

        gen = func()
        self.assertEqual(getgeneratorstate(gen), GEN_SUSPENDED)
        runTouchApp(root)
        self.assertEqual(getgeneratorstate(gen), GEN_CLOSED)
Beispiel #19
0
    def __init__(self, **kwargs):  # defines initial properties of the GUI.
        super(BaseGUI,
              self).__init__(**kwargs)  # this has to be here, trust me...
        self.cols = 5
        self.size_hint_x = 1
        self.size_hint_y = 2
        self.spacing = 20

        for x in range(0, len(Inventory.drinks)):
            # for loop dynamically creates widgets for the GUI according to inventory data.
            self.add_widget(Label(text=Inventory.drinks[x].name))
            self.add_widget(Image(source=Inventory.drinks[x].image))
            Inventory.drinks[x].label = Label(
                text=Inventory.as_currency(Inventory.drinks[x].price))
            self.add_widget(Inventory.drinks[x].label)
            btn1 = Button(
                text="Buy")  # result of Button function assigned to btn1.
            btn1.bind(
                on_press=partial(TransactionHandler.IsTransactionPossible, x))
            # IsTransactionPossible is being delegated with a given parameter to the on_press event of btn1.
            self.add_widget(btn1)
            self.add_widget(Label(text=Inventory.drinks[x].description))

        walletLabel = Label(
            text="Wallet:\n" +
            Inventory.as_currency(TransactionHandler.userWallet))
        TransactionHandler.walletLabelReference = walletLabel

        brokeLabel = Label(text="", markup=True)
        TransactionHandler.brokeLabelReference = brokeLabel

        self.add_widget(walletLabel)
        self.add_widget(brokeLabel)
        btn2 = Button(text="Change currency")
        btn2.bind(on_press=partial(Inventory.currency_change))
        self.add_widget(btn2)

        # creates vertical scroll bar widget
        root = ScrollView(size_hint=(1, 1), size=(Window.width, Window.height))
        root.add_widget(self)
        runTouchApp(root)
Beispiel #20
0
    def test_and_sleep(self):
        root = Factory.Label(
            text="Test 'and' Sleep",
            font_size='30sp',
        )

        @callbackgoaway
        def func():
            S = Sleep
            yield S(0)
            start_time = time()
            yield S(.5) & S(1)
            self.assertAlmostEqual(time() - start_time, 1, delta=self.DELTA)
            yield S(.5) & S(1)
            self.assertAlmostEqual(time() - start_time, 2, delta=self.DELTA)
            stopTouchApp()

        gen = func()
        self.assertEqual(getgeneratorstate(gen), GEN_SUSPENDED)
        # Clock.schedule_once(func, 0)
        runTouchApp(root)
def _test():
    from kivy.app import runTouchApp
    from kivy.factory import Factory

    root = Factory.Label(font_size='30sp')

    @callbackgoaway
    def report_touch(label):
        from callbackgoaway.kivy import Event as E, Sleep as S

        yield S(0)
        while True:
            label.text = 'Touch anywhere'
            label.color = (1, 1, 1, 1, )
            param = yield E(label, 'on_touch_down')
            touch = param.args[1]
            label.text = f'You touched at pos {touch.pos}.'
            label.color = (1, 1, .3, 1, )
            yield E(label, 'on_touch_down')

    report_touch(root)
    runTouchApp(root)
Beispiel #22
0
def _test_Timer():
    from kivy.app import runTouchApp

    root = Builder.load_string(r'''
BoxLayout:
    orientation: 'vertical'
    Timer:
        id: id_timer
        size_hint_y: 0.9
        time_limit: 10
        line_width: 20
    BoxLayout:
        size_hint_y: 0.1
        spacing: 10
        Button:
            text: 'Start'
            on_press: id_timer.start()
        Button:
            text: 'Stop'
            on_press: id_timer.stop()
    ''')
    runTouchApp(root)
Beispiel #23
0
        def run(self):
            textIn = ""
            textOut = ""
            while self.running == True:

                g = GridLayout(cols=2, spacing=5, size_hint_y=None)
                b = BoxLayout(orientation='vertical')
                t = TextInput(font_size=28,
                              size_hint_y=None,
                              height=60,
                              text="Type Here",
                              valign='Top')

                send = Button(text=str("Send"),
                              size_hint_y=None,
                              height=40,
                              halign='right',
                              valign='top')
                send.bind(on_press=newLabel)
                # Make sure the height is such that there is something to scroll.
                g.bind(minimum_height=g.setter('height'))
                s = ScrollView(size_hint=(1, None),
                               size=(Window.width, Window.height))
                s.add_widget(g)
                b.add_widget(s)
                b.add_widget(t)
                b.add_widget(send)

                try:
                    chat_client.sock.sendall(textIn)
                except:
                    Exception
                try:
                    chat_server.conn.sendall(textOut)
                except:
                    Exception
                runTouchApp(b)
            time.sleep(0)
Beispiel #24
0
def duties(info, type):
    def go_to_names(instance):
        #This tells where the screen to go next
        layout.clear_widgets(children=None)
        names(Staff('staff.csv'), instance.text.split("\n")[2])
        pass

    def hook_keyboard(window, key, *largs):
        if key == 27:
            layout.clear_widgets(children=None)
            title_screen()

    EventLoop.window.bind(on_keyboard=hook_keyboard)

    layout = GridLayout(cols=1,
                        spacing=20,
                        padding=[10, 10, 10, 10],
                        size_hint_y=None)
    # Make sure the height is such that there is something to scroll.
    layout.bind(minimum_height=layout.setter('height'))
    color = [0.26, 0.71, 0.42, 1]
    green = [0.26, 0.71, 0.42, 1]
    red = [1.74, 0, 0.01, 1]
    for key in info.tasks:
        if info.tasks[key][0] == type:
            btn = Button(text=key + "\n\n" + info.tasks[key][1] + "\npoints",
                         text_size=(1000, None),
                         size_hint_y=None,
                         halign="center",
                         height=400,
                         background_color=color)
            btn.bind(on_press=go_to_names)
            layout.add_widget(btn)

    root = ScrollView(size_hint=(1, None), size=(Window.width, Window.height))
    root.add_widget(layout)
    runTouchApp(root)
def _test():
    import textwrap

    root = Builder.load_string(
        textwrap.dedent('''
    BoxLayout:
        orientation: 'vertical'
        padding: '20dp', '20dp'
        spacing: '20dp'
        BoxLayout:
            Widget:
                size_hint_x: 3
            GridLayout:
                cols: 2
                spacing: '5dp'
                Label:
                    text: 'normal'
                CheckBox:
                    group: 'anim'
                    on_active: if args[1]: light.anim_normal()
                Label:
                    text: 'blink center'
                CheckBox:
                    group: 'anim'
                    on_active: if args[1]: light.anim_blink_center_light()
                Label:
                    text: 'random'
                CheckBox:
                    group: 'anim'
                    on_active: if args[1]: light.anim_random()
            Widget:
                size_hint_x: 3
        TrafficLight:
            id: light
    '''))
    runTouchApp(root)
Beispiel #26
0
    def test_wait_sleep(self):
        root = Factory.Label(
            text="Test 'wait' Sleep",
            font_size='30sp',
        )

        @callbackgoaway
        def func():
            S = Sleep
            yield S(0)
            start_time = time()
            yield Wait(events=(
                S(.5),
                S(1),
            ))
            self.assertAlmostEqual(time() - start_time, 1.0, delta=self.DELTA)
            yield Wait(events=(S(.5), S(1), S(1.5)), n=2)
            self.assertAlmostEqual(time() - start_time, 2.0, delta=self.DELTA)
            stopTouchApp()

        gen = func()
        self.assertEqual(getgeneratorstate(gen), GEN_SUSPENDED)

        runTouchApp(root)
Beispiel #27
0
import kivy
kivy.require('1.8.0')

from kivy.app import runTouchApp
from kivy.lang import Builder

kv = '''
#:kivy 1.8.0

AnchorLayout:
    canvas:
        Color:
            rgba: 1,1,1,1
        Rectangle:
            pos: self.pos
            size: self.size
    Image:
        size_hint: None, None
        size: '128dp', '128dp'
        source: 'resources/loading_icon.gif'  
'''

if __name__ == '__main__':
    runTouchApp(Builder.load_string(kv))
Beispiel #28
0
            if child.text.startswith(key):
                return child, i
        return node, idx

    def select_node(self, node):
        node.background_color = (1, 0, 0, 1)
        return super(SelectableGrid, self).select_node(node)

    def deselect_node(self, node):
        node.background_color = (1, 1, 1, 1)
        super(SelectableGrid, self).deselect_node(node)

    def do_touch(self, instance, touch):
        if ('button' in touch.profile and touch.button in
                ('scrollup', 'scrolldown', 'scrollleft', 'scrollright')) or\
                instance.collide_point(*touch.pos):
            self.select_with_touch(instance, touch)
        else:
            return False
        return True


root = SelectableGrid(cols=5, up_count=5, multiselect=True, scroll_count=1)
for i in range(40):
    c = Button(text=str(i))
    c.bind(on_touch_down=root.do_touch)
    root.add_widget(c)


runTouchApp(root)
        for r in range(k):
            for c in range(k):
                buff.extend([0, 0, 0] if matrix[r][c] else [cr, cg, cb])

        # then blit the buffer
        # join not neccesarry when using a byte array 
        # buff =''.join(map(chr, buff))
        # update texture in UI thread.
        Clock.schedule_once(lambda dt: self._upd_texture(buff))

    def _upd_texture(self, buff):
        texture = self._qrtexture
        if not texture:
            # if texture hasn't yet been created delay the texture updation
            Clock.schedule_once(lambda dt: self._upd_texture(buff))
            return
        
        texture.blit_buffer(buff, colorfmt='rgb', bufferfmt='ubyte')
        texture.flip_vertical()
        img = self.ids.qrimage
        img.anim_delay = -1
        img.texture = texture
        img.canvas.ask_update()

if __name__ == '__main__':
    from kivy.app import runTouchApp
    import sys
    data = str(sys.argv[1:])
    runTouchApp(QRCodeWidget(data=data))

Beispiel #30
0

def toast(message, duration=1.2, width='175dp', **kw):
    # TODO: if currently toasting, queue the toast
    # TODO: if the message is too wide, split it into multiple queued toasts

    toast_wid = ToastWidget(text=message,
                            opacity=0.0,
                            width=width,
                            **kw)

    anim = Animation(opacity=1.0,
                     duration=.3) + \
        Animation(opacity=1.0,
                  duration=duration) + \
        Animation(opacity=0.0,
                  duration=0.2)

    toast_wid.start()
    anim.start(toast_wid)


if __name__ == '__main__':
    from kivy.app import runTouchApp
    from kivy.uix.button import Button

    but = Button(text='toast!')
    but.bind(on_release=lambda *ar: toast("I'm toast!"))

    runTouchApp(but)
Beispiel #31
0
            self.textcache = txtc[no_of_bytes:]
        except IndexError:
            self.textcache = txtc
        return txtc[:no_of_bytes]

    def readline(self):
        if self.mode == "stdin":
            # stdin.readline
            Logger.exception("KivyConsole: can not read from a stdin pipe")
            return
        else:
            # process.stdout.readline
            if self.textcache is None:
                self.flush()
            txt = self.textcache
            x = txt.find("\n")
            if x < 0:
                Logger.Debug("console_shell: no more data")
                return
            self.textcache = txt[x:]
            # ##self. write to ...
            return txt[:x]

    def flush(self):
        self.textcache = u"".join(self.obj.textcache)
        return


if __name__ == "__main__":
    runTouchApp(KivyConsole())
Beispiel #32
0
        multiline: False
        on_text_validate:
            root.eval_input(self.text)
            self.text = ''
            Clock.schedule_once(lambda dt: setattr(self, 'focus', True), .1)
"""
)


if __name__ == "__main__":
    from kivy.clock import Clock

    dv = DNAVis()

    def the_deeds(*ar):
        n = DNANode()
        n.name = "NODE 1"
        dv.dna.head = n
        c = dv.dna.spawn_crawler()

        n = DNANode()
        n.name = "NODE 2"
        c.add_child(n, dv.dna.head)

        dv.crawler.reset()
        dv.redraw()

    Clock.schedule_once(the_deeds, 1.0)

    runTouchApp(dv)
Beispiel #33
0
            size_hint:.1,.8
            pos_hint:{"top":1}
            Button:
                text:"`"
            Button:
                text:"D"
            Button:
                text:"E"
            Button:
                text:"i"
    AnchorLayout:
        anchor_x:"left"
        acnhor_y:"top"
        AsyncImage:
            size_hint:0.9,.8
            id:_img
            source:"rotational.jpg"
    AnchorLayout:
        anchor_x:"center"
        anchor_y:"bottom"
        BoxLayout:
            size_hint:.1,0.1
            FButton:
                text:"H"
            FButton:
                text:"G"
''')
if __name__ == '__main__':
    LabelBase.register(name="ifont",fn_regular="PWSmallIcons.ttf")
    runTouchApp(kv)
Beispiel #34
0
                    self.set_draw(touch)
    def on_touch_move(self, touch):
        if self.collide_point(*touch.pos) and self.selected:
            w,h=touch.x-self.ix,touch.y-self.iy
            self.canvas.remove(self.selected)
            with self.canvas:
                    self.set_draw(touch)
        if self.collide_point(*touch.pos) and self.which=="free":
            touch.ud["line"].points += [touch.x, touch.y]



    def on_touch_up(self, touch):
        if self.collide_point(*touch.pos) and self.selected:
            w,h=touch.x-self.ix,touch.y-self.iy
            self.canvas.remove(self.selected)
            with self.canvas:
                self.set_draw(touch)

        super(MStencilView,self).on_touch_down(touch=touch)
class MRelativeLayout(RelativeLayout):
    def open_picker(self):
        m=MModal()
        m.cp.bind(color=self.color_select)
        m.open()
    def color_select(self,picker,val):
        Painter.mcolor=val
        self.clrbtn.background_color=Painter.mcolor

runTouchApp(MRelativeLayout())
Beispiel #35
0
        for i, child in items:
            if child.text.startswith(key):
                return child, i
        return node, idx

    def select_node(self, node):
        node.background_color = (1, 0, 0, 1)
        return super(SelectableGrid, self).select_node(node)

    def deselect_node(self, node):
        node.background_color = (1, 1, 1, 1)
        super(SelectableGrid, self).deselect_node(node)

    def do_touch(self, instance, touch):
        if ('button' in touch.profile and touch.button in
            ('scrollup', 'scrolldown', 'scrollleft', 'scrollright')) or\
            instance.collide_point(*touch.pos):
            self.select_with_touch(instance, touch)
        else:
            return False
        return True


root = SelectableGrid(cols=5, up_count=5, multiselect=True, scroll_count=1)
for i in range(40):
    c = Button(text=str(i))
    c.bind(on_touch_down=root.do_touch)
    root.add_widget(c)

runTouchApp(root)
Beispiel #36
0
class main(FloatLayout):

    def __init__(self,**kwargs):
        super(main,self).__init__(**kwargs)

        #self.add_widget(topBar_BG())

        self.add_widget(gameScreenManager())



#///////////////// Python ///////////////////# }



if __name__ == "__main__":
    runTouchApp(main())
    device_Geometry()












Beispiel #37
0
    'Delete Personal Info': 'personal_info.delete',
    'Get Result Update': 'result_update.get',
    'Get Course Form': 'course_form.get',
    'Get Broad-Sheet': 'broad_sheet.get',
    'Get Senate Version': 'senate_version.get',
    'Get GPA Card': 'gpa_cards.get',

    # 'Get Accounts': 'accounts.get',
    'Create Account': 'accounts.post',
    'Edit Account': 'accounts.patch',
    'Delete Account': 'accounts.delete',
    'List Backups': 'backups.get',
    'Download Backups': 'backups.download',
    'Backup Database': 'backups.backup',
    'Restore Backup': 'backups.restore',
    'Delete Backups': 'backups.delete',
    'Add Course': 'course_details.post',
    'Edit Course': 'course_details.patch',
    'Delete Course': 'course_details.delete',

    # 'results.get_single_results_stats': 'results.get_single_results_stats',
    # 'logs.get': 'logs.get',
    # 'logs.delete': 'logs.delete',
    # 'grading_rules.get': 'grading_rules.get',
}

if __name__ == '__main__':
    from kivy.app import runTouchApp

    runTouchApp(Logs())
Beispiel #38
0
        if self.overlay_widget.children and self.hidden_widget.children:
            Logger.debug('Drawer: Accepts only two widgets. discarding rest')
            return

        if not self.hidden_widget.children:
            self.hidden_widget.add_widget(widget)
        else:
            self.overlay_widget.add_widget(widget)
            widget.x = 0

    def remove_widget(self, widget):
        if self.overlay_widget.children[0] == widget:
            self.overlay_widget.clear_widgets()
            return
        if widget == self.hidden_widget.children:
            self.hidden_widget.clear_widgets()
            return

    def clear_widgets(self):
        self.overlay_widget.clear_widgets()
        self.hidden_widget.clear_widgets()

if __name__ == '__main__':
    from kivy.app import runTouchApp
    from kivy.lang import Builder
    runTouchApp(Builder.load_string('''
Drawer:
    Button:
    Button
'''))
    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())
Beispiel #40
0
from kivy.uix.widget import Widget
from kivy.properties import NumericProperty

import xp

class Grinder(BoxLayout):
  xp = NumericProperty()
  level = NumericProperty()
  def __init__(self, **kw):
    super(Grinder, self).__init__(**kw)
    self.ids['xp'] = Label(id='xp', size_hint=(1, 1))
    self.add_widget(self.ids['xp'])
    self.ids['lvl'] = Label(id='lvl', size_hint=(1, 1))
    self.add_widget(self.ids['lvl'])
    self.bind(xp=self.update_xp, level=self.update_level)
  def update_xp(self, *args):
    self.ids['xp'].text = str(self.xp)
  def update_level(self, *args):
    self.ids['lvl'].text = str(self.level)
  
def update_xp(dt):
  xp.inc_xp(grinder, 10)
  if grinder.level == grinder.level_max:
    return False

if __name__ == "__main__":
  grinder = Grinder()
  xp.init_xp(grinder)
  Clock.schedule_interval(update_xp, .1)
  runTouchApp(grinder)
Beispiel #41
0
from kivy.app import runTouchApp
from kivy.core.window import Window

from chessgrid import ChessGrid

Window.size = 400, 400

if __name__ == '__main__':
  runTouchApp(ChessGrid())
Beispiel #42
0
        cr, cg, cb, ca = self.background_color[:]
        cr, cg, cb = cr * 255, cg * 255, cb * 255

        for r in range(k):
            for c in range(k):
                bext([0, 0, 0] if matrix[r][c] else [cr, cg, cb])

        # then blit the buffer
        buff = ''.join(map(chr, buff))
        # update texture in UI thread.
        Clock.schedule_once(lambda dt: self._upd_texture(buff), .1)

    def _upd_texture(self, buff):
        texture = self._qrtexture
        if not texture:
            # if texture hasn't yet been created delay the texture updation
            Clock.schedule_once(lambda dt: self._upd_texture(buff), .1)
            return
        texture.blit_buffer(buff, colorfmt='rgb', bufferfmt='ubyte')
        img = self.ids.qrimage
        img.anim_delay = -1
        img.texture = texture
        img.canvas.ask_update()


if __name__ == '__main__':
    from kivy.app import runTouchApp
    import sys
    data = str(sys.argv[1:])
    runTouchApp(QRCodeWidget(data=data))
Beispiel #43
0
                btn = GridButton(grid_pos=(x, y))
                btn.bind(on_release=self.handle_click)
                self.add_widget(btn)
        self.update_all_buttons()

    def update_button(self, x, y):
        val = self.__game.get_val(x, y)
        b = self.children[-1 - y * self.__cols - x]
        b.text = val  # children are reversed, in Kivy

    def update_all_buttons(self):
        for y in range(self.__rows):
            for x in range(self.__cols):
                self.update_button(x, y)
                
    def handle_click(self, btn):
        self.__game.play_at(*btn.grid_pos)  # args unpacking
        self.update_all_buttons()

        if self.__game.finished():
            popup = Popup(title='Game finished',
                          content=Button(text=self.__game.message()))
            popup.content.bind(on_release=popup.dismiss)
            popup.open()
            stopTouchApp()

            
if __name__ == '__main__':
    game = Fifteen(4, 4)
    runTouchApp(GameGui(game))
Beispiel #44
0
    dv = ObjectProperty(None)

    selectable = BooleanProperty(False)
    multiselection = BooleanProperty(False)

    def get_dataviewer(self):
        return self.ids['dv'].dv


if __name__ == '__main__':
    from kivy.app import runTouchApp

    Builder.load_string('''
        #:import ImageButton imagebutton.ImageButton
        #:import CustomLabel label.CustomLabel
        #:import os os
        ''')

    # runTouchApp(ExtendableDataViewer2(cols=3, data=[[x, x + 1, x + 2] for x in range(0, 200, 3)], headers=[
    #             'Column #1', 'Column #2', 'Column #3'], widths=[100, 200, 300], prop={'disabled': True}))

    runTouchApp(
        ExtendableDataViewer2(cols=3,
                              widths=[100, 200, 300],
                              weightings=[.2, .2, .6],
                              headers=['Column #1', 'Column #2', 'Column #3'],
                              data=[[i, i + 1, i + 2]
                                    for i in range(0, 201, 3)],
                              selectable=True,
                              multiselection=0))
Beispiel #45
0
            circle: self.end_pos[0], self.end_pos[1], 5
            width: 2

""")


if __name__ == '__main__':
    from kivy.app import runTouchApp
    from kivy.uix.boxlayout import BoxLayout
    from kivy.uix.widget import Widget
    from kivy.uix.label import Label

    b = BoxLayout(orientation='horizontal')

    w1 = Label(text='start')
    w2 = Widget()
    w3 = Label(text='end')

    a = Arrow(
        start=w1,
        end=w3
    )

    w1.add_widget(a)

    b.add_widget(w1)
    b.add_widget(w2)
    b.add_widget(w3)

    runTouchApp(b)
Beispiel #46
0
            elif dx <= -threshold: turtle.go_left()
            else: turtle.stay()
        else:
            if dy >= threshold: turtle.go_up()
            elif dy <= -threshold: turtle.go_down()
            else: turtle.stay()

    def advance_game(self, dt):
        arena.move_all()
        self.draw_game()

    def draw_game(self):
        self.canvas.clear()
        with self.canvas:
            Color(.5, 1, .5)
            Rectangle(size=self.size, pos=self.pos)
            t_orig = self._touch_orig
            if t_orig is not None:
                Color(.8, .8, .8)
                Ellipse(pos=(t_orig[0] - 10, t_orig[1] - 10), size=(20, 20))
            for c in arena.actors():
                x, y, w, h = c.rect()
                Color(1, 1, 1)
                xs, ys = c.symbol()
                img = sprites.get_region(xs, sprites.height - ys - h, w, h)
                Rectangle(texture=img, pos=(x, arena.size()[1] - y - h), size=(w, h))


if __name__ == '__main__':
    runTouchApp(GameWidget())
Beispiel #47
0
    from kivy.app import runTouchApp
    runTouchApp(Builder.load_string('''
#:import Animation kivy.animation.Animation
GridLayout:
    cols: 2
    canvas.before:
        Color:
            rgba: 1, 1, 1, 1
        Rectangle:
            size: self.size
            pos: self.pos
    BoxLayout:
        orientation: 'vertical'
        GearTick:
            id: gear_tick
            zoom_factor: 1.1
            # uncomment the following to use non default values
            #max: 100
            #background_image: 'background.png'
            #overlay_image: 'gear.png'
            #orientation: 'anti-clockwise'
            on_touch_up:
                if self.collide_point(*args[1].pos):\
                Animation.stop_all(self);\
                Animation(value=0).start(self)
        Label:
            size_hint: 1, None
            height: '22dp'
            color: 0, 1, 0, 1
            text: ('value: {}').format(gear_tick.value)
'''))