Skip to main content

Cannot access ID from method in kivy

I'm trying to create a card in which I can place a scroll view on that appears on the viewdecks screen after the user has logged in to do this I called the ViewDecks.ShowDecks() method from inside of the login class, I think this is creating a problem as when I run the code I get this error: deck_list = self.ids.deck_scroll File "kivy\properties.pyx", line 964, in kivy.properties.ObservableDict.getattr AttributeError: 'super' object has no attribute 'getattr'.I'm not sure how to fix this.

from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
import mysql.connector
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDRaisedButton
from kivy.uix.scrollview import ScrollView
from kivymd.uix.card import MDCard
from kivymd.uix.label import MDLabel

class Login(Screen):
    def sign(self):
        if self.ids.user.text == "" or self.ids.passw.text == "" or self.ids.email.text == "":
            dialog = MDDialog(
                text="All fields required",
                buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
            )
            dialog.open()

        else:
            try:
                mydb = mysql.connector.connect(
                    host="localhost",
                    user="root",
                    passwd="root",
                    database="mydb"
                )
                mycursor = mydb.cursor()
            except:
                dialog = MDDialog(
                    text="Error, connection is not established try again later",
                    buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
                )
                dialog.open()
                return
            query = "SELECT * FROM users WHERE username=%s"
            mycursor.execute(query, (self.ids.user.text,))
            existing = mycursor.fetchone()
            if existing != None:
                dialog = MDDialog(
                    text="Username already in use",
                    buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
                )
                dialog.open()
            else:
                mycursor.execute("INSERT INTO users(username,pass,email) VALUES(%s,%s,%s)",
                                 (self.ids.user.text, self.ids.passw.text, self.ids.email.text))
                mydb.commit()

    def log(self):
        if self.ids.user.text == "" or self.ids.passw.text == "":
            dialog = MDDialog(
                text="Username and Password required.",
                buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
            )
            dialog.open()
        else:
            try:
                mydb = mysql.connector.connect(
                    host="localhost",
                    user="root",
                    passwd="root",
                    database="mydb"
                    )
                mycursor = mydb.cursor()
            except:
                dialog = MDDialog(
                    text="Error, connection is not established try again later",
                    buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
                )
                dialog.open()
                return
            query = "SELECT * FROM users WHERE username=%s AND pass=%s"
            mycursor.execute(query, (self.ids.user.text, self.ids.passw.text))
            existing = mycursor.fetchone()
            if existing == None:
                dialog = MDDialog(
                    text="Invalid username or password",
                    buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
                )
                dialog.open()
            else:
                self.user_id=existing[0]
                self.manager.current="deck_view"
                ViewDecks.ShowDecks(self)
                print(self.user_id)

    def clear(self):
        self.ids.user.text = ""
        self.ids.passw.text = ""
        self.ids.email.text = ""


class ViewDecks(Screen):

    def ShowDecks(self):
        try:
            mydb = mysql.connector.connect(
                host="localhost",
                user="root",
                passwd="root",
                database="mydb"
            )
            mycursor = mydb.cursor()
        except:
            dialog = MDDialog(
                text="Error, connection is not established try again later",
                buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
            )
            dialog.open()
        mycursor.execute('SELECT deck_name FROM decks WHERE user_id = %s', (self.user_id,))
        decks = mycursor.fetchall()
        deck_list = self.ids.deck_scroll
        for deck_name in decks:
            deck_card = MDCard(orientation='horizontal', size_hint=(None, None), size=(200, 300))
            deck_card.add_widget(MDLabel(text=deck_name[0]))
            deck_list.add_widget(deck_card)


class WindowManager(ScreenManager):
    pass


class Myapp(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = 'DeepPurple'

        return Builder.load_file('flashcards.kv')


Myapp().run()

kv file:

WindowManager:
    Login
    ViewDecks
<Login>:

    MDCard:
        size_hint:None, None
        size:300,400
        pos_hint:{"center_x":0.5, "center_y": 0.5}
        padding:25
        spacing:25
        orientation: "vertical"

        MDLabel:
            id:welcome_label
            text:"Welcome"
            font_size:40
            halign: 'center'
            size_hint_y: None
            height:self.texture_size[1]
            padding_y:15

        MDTextField:
            id:user
            mode:"round"
            hint_text: "username"
            icon_right: "account"
            size_hint_x: None
            width:205
            font_size:18
            pos_hint:{"center_x":0.5}

        MDTextField:
            id:passw
            mode:"round"
            hint_text: "password"
            icon_right: "eye-off"
            size_hint_x: None
            width:205
            font_size:18
            pos_hint:{"center_x":0.5}
            password:True

        MDTextField:
            id:email
            mode:"round"
            hint_text: "email(only for signup)"
            icon_right: "email"
            size_hint_x: None
            width:205
            font_size:18
            pos_hint:{"center_x":0.5}

        Widget:
            size_hint_x:None
            height:10

        BoxLayout:

            MDRoundFlatButton:
                text: "Signup"
                text_color: "white"
                font_size: 15
                pos_hint:{"center_x":0.2, "center_y":0.7}
                size_hint_x: 0.05
                on_press:root.sign()

            Widget:
                size_hint_x:None
                width:10

            MDRoundFlatButton:
                text: "Login"
                text_color: "white"
                font_size: 15
                pos_hint:{"center_x":0.7, "center_y":0.7}
                size_hint_x: 0.05
                on_press:root.log()

        MDRoundFlatButton:
            text: "Clear"
            text_color: "white"
            font_size: 15
            pos_hint:{"center_x":0.5}
            size_hint_x: 0.5
            on_press: root.clear()

<ViewDecks>:
    name:"deck_view"
    BoxLayout:
        orientation :'horizontal'

        ScrollView:
            BoxLayout:
                orientation:'vertical'
                id:deck_scroll


source https://stackoverflow.com/questions/77040054/cannot-access-id-from-method-in-kivy

Comments

Popular posts from this blog

Prop `className` did not match in next js app

I have written a sample code ( Github Link here ). this is a simple next js app, but giving me error when I refresh the page. This seems to be the common problem and I tried the fix provided in the internet but does not seem to fix my issue. The error is Warning: Prop className did not match. Server: "MuiBox-root MuiBox-root-1" Client: "MuiBox-root MuiBox-root-2". Did changes for _document.js, modified _app.js as mentioned in official website and solutions in stackoverflow. but nothing seems to work. Could someone take a look and help me whats wrong with the code? Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console