App not responding in kivy

44 views
Skip to first unread message

akash tyagi

unread,
Jul 28, 2017, 5:37:03 PM7/28/17
to kivy-...@googlegroups.com
Actually i was trying to make a chatting app through kivy and using twisted with it, a made a kv button that starts a method which contains reactor.connectTCP("") function. when i tested the app after pessing the button, it gets connected to the server but after that it dont changes the screen and it stops responding .Please help and tell me what i am doing wrong in programming below is the code.

chat.py:-

    from twisted.internet import protocol,reactor
    
    class ChatClient(protocol.Protocol):
        def connectionMade(self):
            self.transport.write("hlo")
    
        def dataReceived(self,data):
            print(data)
            #user2.sendMsg(data)
    
    class EchoFactory(protocol.ClientFactory):
        def buildProtocol(self,addr):
            user1.connectuser1()
            return ChatClient()
    
        def Conn_network(self):
            reactor.connectTCP("localhost",8000,EchoFactory())
            reactor.run()
    
    
    from kivy.app import App
    from kivy.uix.relativelayout import RelativeLayout
    from kivy.uix.scrollview import ScrollView
    from kivy.lang import Builder
    from kivy.uix.screenmanager import ScreenManager, Screen, ObjectProperty
    
    Builder.load_file("chat.kv")
    Builder.load_file("chat2.kv")
    
    
    class User1(Screen):
        def connectuser1(self):
            if self.ids.login_page.text=="akash" and self.ids.Password.text=="hello":
                print ("logged in")
                self.parent.current="chat_screen"
            else:
                print("username or password wrong")
    
    
    class User2(Screen):
        #def sendMsg(self,data):
         #   self.ids.show_msg.text +=4
    
        def connectuser2(self):
            self.ids.show_msg.text +=self.ids.txt_msg.text +'\n'
            self.ids.txt_msg.text =''
    
    user1=User1()
    sm=ScreenManager()
    sm.add_widget(User1(name="login_screen"))
    sm.add_widget(User2(name="chat_screen"))
    class ChatApp(App,EchoFactory):
    
        def build(self):
            return sm
    if __name__=="__main__":
        ChatApp().run()

chat.kv

    <User1>:
        login:login_page
        RelativeLayout:
    
            TextInput:
                on_parent:self.focus = True
                id:login_page
                pos_hint:{"center_x": .5, "center_y": .7}
                size_hint: .3, .2
            TextInput:
                on_parent:self.focus = True
                id:Password
                pos_hint:{"center_x": .5, "center_y": .5}
                size_hint: .3, .2
            Button:
                text:"send"
                pos_hint:{"center_x": .5, "center_y": .3}
                size_hint: .3, .2
                on_press:
                    app.Conn_network()

server.py:-

from twisted.internet import reactor,protocol

class Echo(protocol.Protocol):
    def dataReceived(self,data):
        print("connected")
        self.transport.write(data)

class EchoFactory(protocol.Factory):
    def buildProtocol(self,addr):
        return Echo()

reactor.listenTCP(8000, EchoFactory())
reactor.run()

 
Reply all
Reply to author
Forward
Message has been deleted
0 new messages