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.
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.
Comments