2

I've been trying to fine a solution for a while. I rather not create the button in python, as I'm trying to keep the style away from the functionality. It reports this error every time I try to use Object Property. I've scoured all over trying a bunch of solutions on stackoverflow, so I'm hoping someone can help me out.

TypeError: bind() takes exactly 2 positional arguments (0 given)

As for the actual code, here is the python:

# Function import libraries
import sys
import json
import googlemaps
import pygatt
import time
import asyncio
from bleak import discover
from urllib.request import urlopen
from twilio.rest import Client
import asynckivy as ak
from asynckivy.process_and_thread import \
    thread as ak_thread, process as ak_processt


# UI import libraries
from kivy.app import App
from  kivy.properties import ObjectProperty
from kivy.properties import StringProperty
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.label import Label
from kivy.uix.image import Image
from functools import partial
from kivy.event import EventDispatcher

class Screen1(Screen):
    def __init__ (self,**kwargs):
        super (Screen1, self).__init__(**kwargs)

        pairbtn = ObjectProperty(None)
        pairbtn.bind(on_press=self.pair_pressed)
        # self.add_widget(pairbtn)

    def pair_pressed(self, event):
        async def run():
            devices = await discover()
            for d in devices:
                print(d)
                if (str(d).find('DSD TECH') != -1):
                    address = str(d)[0:17]
                    print("Device Discovered" + address)
                    exit()
        loop = asyncio.get_event_loop()
        loop.run_until_complete(run())




class Screen2(Screen):
    pass



class esosApp(App):
    def build(self):
        screen_manager = ScreenManager()
        screenone = Screen1(name='s1')
        screentwo = Screen2(name='s2')

        screen_manager.add_widget(screenone)
        screen_manager.add_widget(screentwo)

        return screen_manager    


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

And here is the kv file (screen2 omitted):

#:kivy 1.11.1

<Screen1>:

    orientation: "vertical"
    pairbtn: pairbtn

    canvas.before:
        Color:

            rgb: 0.965,0.965, 0.965
        Rectangle:
            pos: self.pos
            size: self.size
    Image:
        source: 'icon.png'
        size: self.texture_size
    AnchorLayout:
        anchor_y: 'top'
        BoxLayout:
            size_hint: 1,.07

            canvas.before:
                Color:
                    rgb: 0.6745 , 0.8353 , 0.8784
                Rectangle:
                    pos: self.pos
                    size: self.size
            Image:
                source: 'Logo.PNG'
                size: self.texture_size
        AnchorLayout:
            anchor_x: 'center'
            anchor_y: 'bottom'
            padding: (0, 10, 0, 10)

            Button:
                id: pairbtn
                text: "Pair Device"
                background_normal: ''
                background_color: 0.6745 , 0.8353 , 0.8784, 1
                size_hint: (.8, .1)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Mrbeck101
  • 43
  • 5

1 Answers1

1

A property should not and cannot be declared within a method of the class but at the same level of a method, something like:

class Foo(Base):
    prop = XProperty(default_value)

    def __init__(self, **kwargs):
        super().__init__(self, **kwargs)
    # ...

And clearly your code does not meet that condition, also with your logic pairbtn is None so you cannot make the binding with on_press, and finally the easiest thing is to make the connection in kv:

# ...
Button:
    id: pairbtn
    text: "Pair Device"
    background_normal: ''
    background_color: 0.6745 , 0.8353 , 0.8784, 1
    size_hint: (.8, .1)
    on_press: root.pair_pressed()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241