Class method does not run when called upon in Kivy

luart

I am new to kivy. I have created a login page with 2 text fields. I am now trying to pass the variables to the next page, which will use a ssh client for python to connect to a server. However, when I run the program, it seems that the method I am calling in my second screen does not even run, as none of the debugging output shows up.

I have tried a few methods of passing in variables into a function of a different class, and temporarily I have set upon using global variables. I am sure there is an easier or better way, but I can't get the function to run in the first place.

main.py

from kivy.config import Config
Config.set('graphics', 'resizable', False)

from kivy.app import App

from kivy.properties import StringProperty

from kivy.core.window import Window

from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition

import csv
import paramiko
#import os

global username
global password

def load_csv(filepath):
    with open(filepath, newline='') as csvfile:
        file_array = list(csv.reader(csvfile))
        csvfile.close()
    return file_array

class Connect(Screen):
    Window.size = (600, 300)
    def routine(self):

        host = 'titanrobotics.ddns.net'
        port = 60022
        print(username, password)
        self.ids.status.text = "connecting"

        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        try:
            self.ids.status.text = "attempting to connect to " + host
            ssh.connect(host, port, username, password)
            yield ssh
            self.ids.status.text = "connected to " + host

        finally:
            ssh.close()
            self.ids.status.text = "connection failed"

        #print("here")
    #ssh = loginroutine(username, password)

class Login(Screen):
    Window.size = (600, 300)
    def do_login(self, loginText, passwordText):
        app = App.get_running_app()

        username = loginText
        password = passwordText

        self.manager.transition = SlideTransition(direction = "left")
        self.manager.current = "connect"

    def resetForm(self):
        self.ids['login'].text = ""
        self.ids['password'].text = ""

class BrummetApp(App):
    username = StringProperty(None)
    password = StringProperty(None)

    title = 'Brummet Client v ' + load_csv("data/meta")[0][1]

    def build(self):
        manager = ScreenManager()

        manager.add_widget(Login(name = 'login'))
        manager.add_widget(Connect(name = 'connect'))

        return manager

if __name__ == '__main__':
    BrummetApp().run()

brummet.kv

<Login>:
    BoxLayout
        id: login_layout
        orientation: 'vertical'
        padding: [10,10,10,10]
        spacing: 10

        BoxLayout:
            orientation:'vertical'
            padding: [0,0,0,0]
            spacing: 0

            Label:
                id: title
                text: 'Brummet Client'
                halign: 'center'
                valign: 'middle'
                font_size: 24

            Label:
                text: 'Please log in with IMSA SLURM credentials'
                halign: 'center'
                valign: 'middle'
                spacing: -20
                font_size: 24

        BoxLayout:
            orientation: 'vertical'

            Label:
                text: 'Username'
                font_size: 18
                halign: 'left'
                text_size: root.width-20, 0

            TextInput:
                id: username
                multiline: False
                font_size: 16
                write_tab: False

        BoxLayout:
            orientation: 'vertical'
            Label:
                text: 'Password'
                halign: 'left'
                font_size: 18
                text_size: root.width-20, 0

            TextInput:
                id: password
                multiline: False
                password: True
                font_size: 16
                write_tab: False

        Button:
            text: 'Log In'
            font_size: 24

            on_press:
                root.do_login(username.text, password.text)

<Connect>:
    on_enter:
        root.routine()
    BoxLayout:
        orientation: 'vertical'
        padding: [0,125,0,125]
        spacing: 0

        Label:
            text:'Logging In'
            font_size: 24
            halign: 'center'
            valign: 'middle'

        Label:
            id: status
            test:''
            font_size: 16
            halign: 'center'
            valign: 'middle'

It seems that loading the Connect class is fine, however I am unable to run the .routine() method on_enter.

ikolim

The yield ssh is preventing the Connect.routine() from executing. Try comment it off.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does this JS function run upon clicking on a button, but not when called within another function?

When does Unity execute the constructor code of a simple class if "new" instance was called upon variable declaration?

How and when does Configuration method in OwinStartup class is called/executed?

How do C# derived Attributes work internally?When are the methods inside it called to act upon the class/method/property on which they are declared?

UITableView returning nil when reloadData method is called upon it

What does "[()]" mean when called upon a numpy array?

Method in class inheriting QObject is identified as property when called, doesn't run method

Sub works when run but not when called? "Select method of Range Class failed"

Run a function every time a method in a class is called

In my shop project, my method "checkout" runs several times before stopping when it should only run once when called upon form direct

Flutter initState does not run the method called

Why does setting a method in a python class does not pass self when called?

How does a toString method automatically get run without being called when printing an object to the console?

Function stored in object does not run when called

AddEventListener by default when class method is called

When does the method doGetAuthorizationInfo get called in Shiro?

when does the `render()` method in react get called

Method does not execute when called. FIRESTORE

java class "a" run method when class "a" created

Why and by whom is this method called in kivy

onCheckedChanged Systematically Called Upon Initialising Method

static method does not run it in main class

Run a method in initialize after class has been called

How to run all tests in class repeatedly based upon config method in TestNG

Is it possible a base class gets informed when a method in derived class is called?

Does anyone know how to run a method form a other class when button is clicked in java

Does Activity method called from Fragment run in the UI thread?

Does new transaction starts when method b() is called from method a()?

how to run a method when class is initialized in dart