Beispiel #1
0
    def add_cards(self, instance_grid_card):
        """Adds MDCardPost objects to the screen Cards
        when the screen is open."""

        from kivymd.uix.card import MDCardPost

        def callback(instance, value):
            if value is None:
                toast("Delete post %s" % str(instance))
            elif isinstance(value, int):
                toast("Set like in %d stars" % value)
            elif isinstance(value, str):
                toast("Repost with %s " % value)
            elif isinstance(value, list):
                toast(value[1])

        if not self.cards_created:
            self.cards_created = True
            menu_items = [{
                "viewclass": "MDMenuItem",
                "text": "Example item %d" % i,
                "callback": self.callback_for_menu_items,
            } for i in range(2)]
            buttons = ["facebook", "vk", "twitter"]

            instance_grid_card.add_widget(
                MDCardPost(text_post="Card with text",
                           swipe=True,
                           callback=callback))
            instance_grid_card.add_widget(
                MDCardPost(
                    right_menu=menu_items,
                    swipe=True,
                    text_post="Card with a button to open the menu MDDropDown",
                    callback=callback,
                ))
            instance_grid_card.add_widget(
                MDCardPost(
                    likes_stars=True,
                    callback=callback,
                    swipe=True,
                    text_post="Card with asterisks for voting.",
                ))

            instance_grid_card.add_widget(
                MDCardPost(
                    source="./assets/kitten-1049129_1280.png",
                    tile_text="Little Baby",
                    tile_font_style="H5",
                    text_post="This is my favorite cat. He's only six months "
                    "old. He loves milk and steals sausages :) "
                    "And he likes to play in the garden.",
                    with_image=True,
                    swipe=True,
                    callback=callback,
                    buttons=buttons,
                ))
Beispiel #2
0
    def on_start(self, screen):
        def callback_for_menu_items(text_item):
            toast(text_item)

        def callback(instance, value):
            if value and isinstance(value, int):
                toast('Set like in %d stars' % value)
            elif value and isinstance(value, str):
                toast('Repost with %s ' % value)
            elif value and isinstance(value, list):
                toast(value[1])
            else:
                toast('Delete post %s' % str(instance))

        instance_grid_card = self.ids.grid_card
        buttons = ['facebook', 'vk', 'twitter']
        menu_items = [{
            'viewclass': 'MDMenuItem',
            'text': 'Share Post',
            'callback': callback_for_menu_items
        }, {
            'viewclass': 'MDMenuItem',
            'text': 'Edit Post',
            'callback': callback_for_menu_items
        }]

        if not self.cards_created:
            self.cards_created = True

            config = {
                "apiKey":
                "AIzaSyAhOVY1khHv6nLk5g9tmcMt6X5eIQZpk1I",
                "authDomain":
                "party-app-e1f63.firebaseapp.com",
                "databaseURL":
                "https://party-app-e1f63.firebaseio.com",
                "storageBucket":
                "party-app-e1f63.appspot.com",
                "serviceAccount":
                "party-app-e1f63-firebase-adminsdk-b6c6o-26ecb29ae3.json"
            }
            firebase = pyrebase.initialize_app(config)
            auth = firebase.auth()
            # authenticate a user
            user = auth.sign_in_with_email_and_password(
                "*****@*****.**", "password")
            db = firebase.database()

            all_events = db.child('events').get(user['idToken']).val()
            keys = list(all_events.keys())

            for i in range(len(keys)):
                key = keys[i]
                instance_grid_card.add_widget(
                    MDCardPost(text_post=all_events[key]['description'],
                               name_data=all_events[key]['user'] + "\n" +
                               all_events[key]['date'],
                               path_to_avatar='assets/defaultProfile.jpg',
                               right_menu=menu_items,
                               swipe=True,
                               callback=callback))
    def callback_for_menu_items(self, *args):
        toast(args[0])
        """Adds MDCardPost objects to the screen Cards
        when the screen is open."""

        from kivymd.uix.card import MDCardPost

        def callback(instance, value):
            if value is None:
                toast("Delete post %s" % str(instance))
            elif isinstance(value, int):
                toast("Set like in %d stars" % value)
            elif isinstance(value, str):
                toast("Repost with %s " % value)
            elif isinstance(value, list):
                toast(value[1])

        if not self.cards_created:
            self.cards_created = True
            menu_items = [{
                "viewclass": "MDMenuItem",
                "text": "Example item %d" % i,
                "callback": self.callback_for_menu_items,
            } for i in range(2)]
            buttons = ["facebook", "vk", "twitter"]

            instance_grid_card.add_widget(
                MDCardPost(text_post="Card with text",
                           swipe=True,
                           callback=callback))
            instance_grid_card.add_widget(
                MDCardPost(
                    right_menu=menu_items,
                    swipe=True,
                    text_post="Card with a button to open the menu MDDropDown",
                    callback=callback,
                ))
            instance_grid_card.add_widget(
                MDCardPost(
                    likes_stars=True,
                    callback=callback,
                    swipe=True,
                    text_post="Card with asterisks for voting.",
                ))

            image_for_card = (
                f"{demos_assets_path}kitten-for_card-1049129_1280-crop.png")
            if not os.path.exists(image_for_card):
                crop_image(
                    (int(Window.width), int(dp(200))),
                    f"{demos_assets_path}kitten-1049129_1280.png",
                    image_for_card,
                )
            instance_grid_card.add_widget(
                MDCardPost(
                    source=image_for_card,
                    tile_text="Little Baby",
                    tile_font_style="H5",
                    text_post="This is my favorite cat. He's only six months "
                    "old. He loves milk and steals sausages :) "
                    "And he likes to play in the garden.",
                    with_image=True,
                    swipe=True,
                    callback=callback,
                    buttons=buttons,
                ))
        """Set new label on the screen UpdateSpinner."""

        def update_screen(interval):
            self.tick += 1
            if self.tick > 2:
                instance.update = True
                self.tick = 0
                self.data["Update Screen Widget"][
                    "object"].ids.upd_lbl.text = "New string"
                Clock.unschedule(update_screen)

        Clock.schedule_interval(update_screen, 1)