Reputation: 59
I am trying to make a code of file chooser using kivy & python on client & server base...Rest part of the code works nice but given part gives attribute error as "'ClientScreen' has no attribute 'openfile_from_filechooser'"
In which part i am making mistake...i have search that how can i resolve attribute error but none of the worked...
class ClientScreen(Screen):
def __init__(self, **kwargs):
super(ClientScreen, self).__init__(**kwargs)
def openfile(self, path, filename):
f = open(os.path.join(path, filename[0]))
print f.read()
#self.clear_widgets()
def selected(self, filename):
print "selected: %s" % filename[0]
def openfile_from_filechooser(self, filechooser):
self.openfile(filechooser.path, filechooser.selection)
def selected_from_filechooser(self, filechooser):
self.selected(filechooser.selection)
def terminate(instance):
sys.exit()
def data(instance):
global IP
global conn
global host
global port
global address
print("Inside Data")
self.clear_widgets()
print("Inside File Operation")
button1 = Button(text = 'Open',size_hint = (None,None),pos = (0,0))
self.add_widget(button1)
button1.bind(on_release=partial(self.openfile_from_filechooser, filechooser))
button2 = Button(text = 'Send',size_hint = (None,None),pos = (100,0))
self.add_widget(button2)
#button2.bind(on_release=partial(self.selected_from_filechooser, filechooser))
def connection(instance):
global IP
global conn
global host
global port
global address
self.clear_widgets()
text = IP.text
print(text)
self.add_widget(Label (text = text))
print "Imported socket module"
print "Imported sys module used for termination condition"
conn = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
print('Socket created')
host = IP.text
print "Host Name:",host
port = 8000
print "Port value accessed",port
try:
self.clear_widgets()
address = (host,port)
print('Value of Address:',address)
print('Trying to connect...')
print('Initiating TCP server connection')
self.add_widget(Label(text = 'Connected....Press Next To Proceed...'))
button1 = Button(text = 'Next',size_hint = (None,None),pos = (0,0))
self.add_widget(button1)
button1.bind(on_press = data)
except socket.error as msg:
self.clear_widgets()
self.add_widget(Label(text = 'Sorry...Unable to create socket...press Finish to terminate...'))
button2 = Button(text = 'Finish',size_hint = (None,None),pos = (0,0))
self.add_widget(button2)
button2.bind(on_press = terminate)
print('Socket not created')
def ip_addr(instance):
global IP
self.clear_widgets()
self.add_widget(Label (text = "Enter the destination device's IP address"))
IP = TextInput(multiline=False, size_hint = (1,0.1), pos = (0,200))
print(IP.text)
self.add_widget(IP)
button1 = Button(text = 'Enter',size_hint = (None,None),pos = (0,0))
self.add_widget(button1)
button1.bind(on_press = connection)
global IP
self.add_widget(Label(text = 'Working as Client...Press Next to proceed'))
button1 = Button(text = 'Next',size_hint = (None,None),pos = (0,0))
self.add_widget(button1)
button1.bind(on_press = ip_addr)
It would be really helpful if anyone could point that where is my mistake & how can i correct that mistake
Upvotes: 0
Views: 654
Reputation: 29488
Your indentation is wrong, all the functions are declared in your __init__
rather than as methods.
You also don't call super(ClientScreen, self).__init__(**kwargs)
, which would lead to other problems since it means the screen and widget internals aren't initialised.
Upvotes: 1