<div dir="ltr">Hi, it's me again. I am still working on the kivy app, and now I am trying to add a function to the app - the server side has two seconds to decide if he wants to alter the original data sent from one client to other clients. If he would like to do so, he has to press a button. If he does not press the button in 2 seconds, the original data will be sent to other clients automatically.<div><br></div><div>Right now I am trying to achieve that with the following code - by calling the MultiClientEcho().dataReceived(msg, "censored") line in the function as if MultiClientEcho received another data, however once i click the button, the program crashed and said (MultiClientEcho().dataReceived(msg, "censored")</div><div> TypeError: __init__() takes exactly 3 arguments (1 given))</div><div><br></div><div>I wonder how can I fix this and achieve the function I am aiming at?</div><div><pre style="color:rgb(155,194,142);font-family:Menlo;font-size:11pt;background-color:rgb(64,64,64)"><span style="color:rgb(204,153,0);font-weight:bold">import </span>kivy<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.app <span style="color:rgb(204,153,0);font-weight:bold">import </span>App<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.uix.label <span style="color:rgb(204,153,0);font-weight:bold">import </span>Label<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.uix.scatter <span style="color:rgb(204,153,0);font-weight:bold">import </span>Scatter<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.uix.boxlayout <span style="color:rgb(204,153,0);font-weight:bold">import </span>BoxLayout<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.uix.scrollview <span style="color:rgb(204,153,0);font-weight:bold">import </span>ScrollView<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.uix.button <span style="color:rgb(204,153,0);font-weight:bold">import </span>Button<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.graphics.vertex_instructions <span style="color:rgb(204,153,0);font-weight:bold">import </span>Rectangle<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.graphics.context_instructions <span style="color:rgb(204,153,0);font-weight:bold">import </span>Color<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.graphics.instructions <span style="color:rgb(204,153,0);font-weight:bold">import </span>Instruction<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.base <span style="color:rgb(204,153,0);font-weight:bold">import </span>runTouchApp<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.lang <span style="color:rgb(204,153,0);font-weight:bold">import </span>Builder<br><span style="color:rgb(204,153,0);font-weight:bold">import </span>socket<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.core.window <span style="color:rgb(204,153,0);font-weight:bold">import </span>Window<br><span style="color:rgb(204,153,0);font-weight:bold">import </span>pygame<br><span style="color:rgb(204,153,0);font-weight:bold">import </span>random<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>kivy.support <span style="color:rgb(204,153,0);font-weight:bold">import </span>install_twisted_reactor<br>install_twisted_reactor<span style="font-weight:bold">()<br></span><span style="color:rgb(204,153,0);font-weight:bold">from </span>twisted.internet <span style="color:rgb(204,153,0);font-weight:bold">import </span>protocol<span style="color:rgb(204,120,50)">, </span>defer<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>time <span style="color:rgb(204,153,0);font-weight:bold">import </span>sleep<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>twisted.internet <span style="color:rgb(204,153,0);font-weight:bold">import </span>reactor<span style="color:rgb(204,120,50)">, </span>task<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>twisted.protocols.basic <span style="color:rgb(204,153,0);font-weight:bold">import </span>LineReceiver<br><span style="color:rgb(204,153,0);font-weight:bold">from </span>twisted.internet.protocol <span style="color:rgb(204,153,0);font-weight:bold">import </span>Protocol<span style="color:rgb(204,120,50)">, </span>Factory<br><br>censored <span style="color:rgb(255,255,255);font-weight:bold">= </span><span style="color:rgb(249,113,187)">0<br></span><span style="color:rgb(249,113,187)"><br></span><span style="color:rgb(204,153,0);font-weight:bold">class </span><span style="color:rgb(255,255,255);font-weight:bold">MultiClientEcho</span><span style="font-weight:bold">(</span>protocol.Protocol<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">    </span><span style="color:rgb(204,153,0);font-weight:bold">def </span><span style="color:rgb(131,214,241);font-weight:bold">__init__</span><span style="font-weight:bold">(</span>self<span style="color:rgb(204,120,50)">, </span>factory<span style="color:rgb(204,120,50)">, </span>app<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">        </span>self.factory <span style="color:rgb(255,255,255);font-weight:bold">= </span>factory<br>        self.app <span style="color:rgb(255,255,255);font-weight:bold">= </span>app<br><br>    <span style="color:rgb(204,153,0);font-weight:bold">def </span><span style="color:rgb(255,255,255);font-weight:bold">connectionMade</span><span style="font-weight:bold">(</span>self<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">        </span>self.factory.clients.append<span style="font-weight:bold">(</span>self<span style="font-weight:bold">)<br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold">    </span><span style="color:rgb(204,153,0);font-weight:bold">def </span><span style="color:rgb(255,255,255);font-weight:bold">dataReceived</span><span style="font-weight:bold">(</span>self<span style="color:rgb(204,120,50)">, </span>data<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold"><br></span><span style="color:rgb(255,255,255);font-weight:bold">        </span>storedmessage <span style="color:rgb(255,255,255);font-weight:bold">= </span>self.factory.app.handle_message<span style="font-weight:bold">(</span>data<span style="font-weight:bold">)<br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold">        </span><span style="color:rgb(204,153,0);font-weight:bold">global </span>censored<br><br>        <span style="color:rgb(204,153,0);font-weight:bold">def </span><span style="color:rgb(255,255,255);font-weight:bold">f</span><span style="font-weight:bold">(</span>data<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">                </span><span style="color:rgb(204,153,0);font-weight:bold">for </span>client <span style="color:rgb(204,153,0);font-weight:bold">in </span>self.factory.clients<span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">                    </span>client.transport.write<span style="font-weight:bold">(</span>data<span style="font-weight:bold">)<br></span><span style="font-weight:bold">                    </span><span style="color:rgb(204,153,0);font-weight:bold">print </span><span style="color:rgb(133,205,0);font-weight:bold">"this will run in 1 sec after it's scheduled: %s" </span><span style="color:rgb(255,255,255);font-weight:bold">% </span>data<br><br>        <span style="color:rgb(204,153,0);font-weight:bold">if </span>censored <span style="color:rgb(255,255,255);font-weight:bold">== </span><span style="color:rgb(249,113,187)">0 </span><span style="color:rgb(204,153,0);font-weight:bold">and </span>storedmessage<span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">                </span>reactor.callLater<span style="font-weight:bold">(</span><span style="color:rgb(249,113,187)">2</span><span style="color:rgb(204,120,50)">, </span>f<span style="color:rgb(204,120,50)">, </span>data<span style="font-weight:bold">)<br></span><span style="font-weight:bold">                </span><span style="color:rgb(255,102,102)"># client.transport.write(data)<br></span><span style="color:rgb(255,102,102)">        </span><span style="color:rgb(204,153,0);font-weight:bold">elif </span>censored <span style="color:rgb(255,255,255);font-weight:bold">== </span><span style="color:rgb(249,113,187)">1</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">                </span>reactor.callLater<span style="font-weight:bold">(</span><span style="color:rgb(249,113,187)">0</span><span style="color:rgb(204,120,50)">, </span>f<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(133,205,0);font-weight:bold">'censored'</span><span style="font-weight:bold">)<br></span><span style="font-weight:bold">                </span>censored <span style="color:rgb(255,255,255);font-weight:bold">== </span><span style="color:rgb(249,113,187)">0<br></span><span style="color:rgb(249,113,187)"><br></span><span style="color:rgb(249,113,187)"><br></span><span style="color:rgb(249,113,187)">    </span><span style="color:rgb(204,153,0);font-weight:bold">def </span><span style="color:rgb(255,255,255);font-weight:bold">connectionLost</span><span style="font-weight:bold">(</span>self<span style="color:rgb(204,120,50)">, </span>reason<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">        </span>self.factory.clients.remove<span style="font-weight:bold">(</span>self<span style="font-weight:bold">)<br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold"><br></span><span style="color:rgb(204,153,0);font-weight:bold">class </span><span style="color:rgb(255,255,255);font-weight:bold">MultiClientEchoFactory</span><span style="font-weight:bold">(</span>protocol.Factory<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">    </span>protocol <span style="color:rgb(255,255,255);font-weight:bold">= </span>MultiClientEcho<br><br>    <span style="color:rgb(204,153,0);font-weight:bold">def </span><span style="color:rgb(131,214,241);font-weight:bold">__init__</span><span style="font-weight:bold">(</span>self<span style="color:rgb(204,120,50)">, </span>app<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">        </span>self.clients <span style="color:rgb(255,255,255);font-weight:bold">= []<br></span><span style="color:rgb(255,255,255);font-weight:bold">        </span>self.app <span style="color:rgb(255,255,255);font-weight:bold">= </span>app<br><br>    <span style="color:rgb(204,153,0);font-weight:bold">def </span><span style="color:rgb(255,255,255);font-weight:bold">buildProtocol</span><span style="font-weight:bold">(</span>self<span style="color:rgb(204,120,50)">, </span>addr<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">        </span><span style="color:rgb(204,153,0);font-weight:bold">return </span>MultiClientEcho<span style="font-weight:bold">(</span>self<span style="color:rgb(204,120,50)">, </span>self.app<span style="font-weight:bold">)<br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold"><br></span><span style="color:rgb(204,153,0);font-weight:bold">class </span><span style="color:rgb(255,255,255);font-weight:bold">ServerApp</span><span style="font-weight:bold">(</span>App<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">    </span><span style="color:rgb(204,153,0);font-weight:bold">def </span><span style="color:rgb(255,255,255);font-weight:bold">build</span><span style="font-weight:bold">(</span>self<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">        </span>self.label <span style="color:rgb(255,255,255);font-weight:bold">= </span>Label<span style="font-weight:bold">(</span>text<span style="color:rgb(255,255,255);font-weight:bold">=</span><span style="color:rgb(133,205,0);font-weight:bold">"server started</span><span style="color:rgb(0,255,0);font-weight:bold">\n</span><span style="color:rgb(133,205,0);font-weight:bold">"</span><span style="font-weight:bold">)<br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold">        </span>self.approve_btn <span style="color:rgb(255,255,255);font-weight:bold">= </span>Button<span style="font-weight:bold">(</span>text<span style="color:rgb(255,255,255);font-weight:bold">=</span><span style="color:rgb(133,205,0);font-weight:bold">"approve"</span><span style="font-weight:bold">)<br></span><span style="font-weight:bold">        </span><span style="color:rgb(255,102,102)"># self.approve_btn.bind(on_release=self.send_message)<br></span><span style="color:rgb(255,102,102)">        </span>self.banned_btn <span style="color:rgb(255,255,255);font-weight:bold">= </span>Button<span style="font-weight:bold">(</span>text<span style="color:rgb(255,255,255);font-weight:bold">=</span><span style="color:rgb(133,205,0);font-weight:bold">"banned"</span><span style="font-weight:bold">)<br></span><span style="font-weight:bold">        </span>self.banned_btn.bind<span style="font-weight:bold">(</span>on_release<span style="color:rgb(255,255,255);font-weight:bold">=</span>self.banned_message<span style="font-weight:bold">)<br></span><span style="font-weight:bold">        </span>self.layout <span style="color:rgb(255,255,255);font-weight:bold">= </span>BoxLayout<span style="font-weight:bold">(</span>orientation<span style="color:rgb(255,255,255);font-weight:bold">=</span><span style="color:rgb(133,205,0);font-weight:bold">'vertical'</span><span style="color:rgb(204,120,50)">, </span>spacing<span style="color:rgb(255,255,255);font-weight:bold">=</span><span style="color:rgb(249,113,187)">10</span><span style="font-weight:bold">)<br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold">        </span>reactor.listenTCP<span style="font-weight:bold">(</span><span style="color:rgb(249,113,187)">8000</span><span style="color:rgb(204,120,50)">, </span>MultiClientEchoFactory<span style="font-weight:bold">(</span>self<span style="font-weight:bold">))<br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold">        </span>self.layout.add_widget<span style="font-weight:bold">(</span>self.label<span style="font-weight:bold">)<br></span><span style="font-weight:bold">        </span>self.layout.add_widget<span style="font-weight:bold">(</span>self.banned_btn<span style="font-weight:bold">)<br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold">        </span><span style="color:rgb(204,153,0);font-weight:bold">return </span>self.layout<br><br>    <span style="color:rgb(204,153,0);font-weight:bold">def </span><span style="color:rgb(255,255,255);font-weight:bold">banned_message</span><span style="font-weight:bold">(</span>self<span style="color:rgb(204,120,50)">, </span>msg<span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">        </span><span style="color:rgb(204,153,0);font-weight:bold">global </span>censored<br>        censored <span style="color:rgb(255,255,255);font-weight:bold">= </span><span style="color:rgb(249,113,187)">1<br></span><span style="color:rgb(249,113,187)">        </span>self.label.text <span style="color:rgb(255,255,255);font-weight:bold">+= </span><span style="color:rgb(133,205,0);font-weight:bold">"censored</span><span style="color:rgb(0,255,0);font-weight:bold">\n</span><span style="color:rgb(133,205,0);font-weight:bold">"<br></span><span style="color:rgb(133,205,0);font-weight:bold">        </span>MultiClientEcho<span style="font-weight:bold">()</span>.dataReceived<span style="font-weight:bold">(</span>msg<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(133,205,0);font-weight:bold">"censored"</span><span style="font-weight:bold">)<br></span><span style="font-weight:bold">        </span><span style="color:rgb(204,153,0);font-weight:bold">print </span>censored<br>        <span style="color:rgb(204,153,0);font-weight:bold">return </span>censored<br><br>    <span style="color:rgb(204,153,0);font-weight:bold">def </span><span style="color:rgb(255,255,255);font-weight:bold">handle_message</span><span style="font-weight:bold">(</span>self<span style="color:rgb(204,120,50)">, </span><span style="background-color:rgb(228,228,255)">msg</span><span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">        </span>self.label.text <span style="color:rgb(255,255,255);font-weight:bold">+= </span><span style="color:rgb(133,205,0);font-weight:bold">"%s</span><span style="color:rgb(0,255,0);font-weight:bold">\n</span><span style="color:rgb(133,205,0);font-weight:bold">" </span><span style="color:rgb(255,255,255);font-weight:bold">% </span><span style="background-color:rgb(228,228,255)">msg</span><br>        <span style="color:rgb(204,153,0);font-weight:bold">return </span><span style="background-color:rgb(228,228,255)">msg</span><br><br><br><span style="color:rgb(204,153,0);font-weight:bold">if </span>__name__ <span style="color:rgb(255,255,255);font-weight:bold">== </span><span style="color:rgb(133,205,0);font-weight:bold">'__main__'</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">    </span>ServerApp<span style="font-weight:bold">()</span>.run<span style="font-weight:bold">()<br></span><span style="font-weight:bold"><br></span><span style="color:rgb(204,153,0);font-weight:bold">for </span>i <span style="color:rgb(204,153,0);font-weight:bold">in </span><span style="color:rgb(0,204,204)">range</span><span style="font-weight:bold">(</span><span style="color:rgb(249,113,187)">0</span><span style="color:rgb(204,120,50)">,</span><span style="color:rgb(249,113,187)">1</span><span style="font-weight:bold">)</span><span style="color:rgb(255,255,255);font-weight:bold">:<br></span><span style="color:rgb(255,255,255);font-weight:bold">    </span><span style="color:rgb(204,153,0);font-weight:bold">print </span><span style="color:rgb(249,113,187)">1</span><span style="color:rgb(255,255,255);font-weight:bold">-</span>i<br>    sleep<span style="font-weight:bold">(</span><span style="color:rgb(249,113,187)">0.1</span><span style="font-weight:bold">)<br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold"><br></span><span style="font-weight:bold"><br></span></pre></div></div>