0

Python3.4 and Kivy 1.9.1

I am attempting to load (2) spinner widgets from__init__, however, I continually receive the following error:

Traceback Date: 02-09-2017, 11:44:10
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python34x86\lib\idlelib\run.py", line 124, in main
    ret = method(*args, **kwargs)
  File "C:\Python34x86\lib\idlelib\run.py", line 351, in runcode
    exec(code, self.locals)
  File "C:\Python34x86\projects\rtpr_app\draft2\operator_rtpr_main.py", line 191, in <module>
    OperatorRTPRApp().run()
  File "C:\Python34x86\lib\site-packages\kivy\app.py", line 801, in run
    self.load_kv(filename=self.kv_file)
  File "C:\Python34x86\lib\site-packages\kivy\app.py", line 598, in load_kv
    root = Builder.load_file(rfilename)
  File "C:\Python34x86\lib\site-packages\kivy\lang.py", line 1842, in load_file
    return self.load_string(data, **kwargs)
  File "C:\Python34x86\lib\site-packages\kivy\lang.py", line 1921, in load_string
    self._apply_rule(widget, parser.root, parser.root)
  File "C:\Python34x86\lib\site-packages\kivy\lang.py", line 2082, in _apply_rule
    child = cls(__no_builder=True)
  File "C:\Python34x86\projects\rtpr_app\draft2\operator_rtpr_main.py", line 82, in __init__
    self.load_login_view()
  File "C:\Python34x86\projects\rtpr_app\draft2\operator_rtpr_main.py", line 103, in load_login_view
    self.spinner_part_number.values = split_line[2:]
AttributeError: 'NoneType' object has no attribute 'values'

I have attempted the following solutions found here: Solution_1 Solution_2

It seems I have an error when referencing kivy ids and correctly using them in python. Please point out my error.

main.py

class LoginScreen(Screen):
    spinner_bay = ObjectProperty()#ListProperty()
    spinner_part_number = ObjectProperty()#ListProperty()

    def __init__(self, **kwargs):
        super(LoginScreen, self).__init__(**kwargs)
        self.load_login_view()

    def load_login_view(self):
        print("Loading login screen ... " + strftime("%H:%M:%S"))
        #Window.size = (300, 550) 

        PART_NUMBERS = []#ListProperty([])
        BAY_NUMBERS = []#ListProperty([])

        # Open configuration.txt file and find bay numbers & part numbers
        try:
            config_file = open('configuration.txt')
            list_config_file = config_file.readlines()
            #BAY_NUMBERS = bay_number_file.close
            config_file.close

            for line in list_config_file:
                split_line = line.split(' ')
                split_line[-1] = split_line[-1].strip()

                if 'PART_NUMBERS' in split_line:
                    self.spinner_part_number.values = split_line[2:]

                if 'BAY_NUMBERS' in split_line:
                    #for i in range(int(split_line[2]), int(split_line[3]) + 1, 1):
                    self.spinner_bay.values = split_line[2:]
                    print('Loaded bay numbers.')
        except:
            print("Error found.")

.kv file

#: import FadeTransition kivy.uix.screenmanager.FadeTransition

ScreenManagement:
    transition: FadeTransition()
    LoginScreen:
    #SimplifiedViewScreen:
    SettingScreen:

<LoginScreen>:
    box_login:box_login
    spinner_part_number: spinner_part_number
    spinner_bay: spinner_bay

    name: 'login'

    on_enter: 
        root.load_login_view()

    BoxLayout:
        id: box_login
        orientation: 'vertical'
        padding: 10

        canvas.before:
            Color:
                rgb: .082, .142, .138

            Rectangle:
                pos: self.pos
                size: self.size

            Color:
                rgb: .151, .172, .156

            Rectangle:
                pos: (0, root.height-50)
                size: (root.width,50)
        Label:
            text: 'A320neo RTPR'
            size_hint: (1,0.25)

        BoxLayout:
            orientation: 'horizontal'

            Label:
                text: 'Order Number'
                size_hint:(0.45, 1)

            Label:
                text: 'Part Number'
                size_hint:(0.45, 1)

        BoxLayout:
            orientation: 'horizontal'

            TextInput:
                id: textinput_order_number
                size_hint: (0.45, 1)
                multiline: 'False'
                on_text: root.validate_order_number()

            Spinner:
                id: spinner_part_number
                size_hint: (0.45, 1)

        BoxLayout:
            orientation: 'horizontal'

            Label:
                text: 'Bay Number'
                size_hint:(0.45, 1)

        BoxLayout:
            orientation: 'horizontal'

            Spinner:
                id: spinner_bay
                size_hint: (0.45, 1)

        BoxLayout:
            orientation: 'horizontal'

            Label:
                text: 'Assembler 1'
                size_hint:(0.45, 1)

            Label:
                text: 'Assembler 2'
                size_hint:(0.45, 1)

        BoxLayout:
            orientation: 'horizontal'

            TextInput:
                id: textinput_assembler_1
                size_hint: (0.45, 1)
                multiline: 'False'
                on_text: root.validate_assembler_1()

            TextInput:
                id: textinput_assembler_2
                size_hint: (0.45, 1)
                multiline: 'False'
                on_text: root.validate_assembler_2()

        Button:
            text: 'LOGIN'
            size_hint: (1, 1)
            on_press: root.test()

#<SimplifiedViewScreen>:

<SettingScreen>:
    name: 'settings'

    on_enter: self.load_settings()

    Label:
        text: 'RTPR Settings'

    Button:
        on_release: app.root.current = 'simple'
        text: 'Go Back'
        font_size: 25
Community
  • 1
  • 1
Kevin Alvarez
  • 311
  • 2
  • 15

1 Answers1

0

I have finally figured out how to correctly call ids on python after playing around with multiple solutions:

on .kv file

Create id character for widget. For example:

Spinner:
id: spinner_bay
size_hint: (None, 1)
width: root.width/5

on .py file

Create an ObjectProperty() using that exact id name given:

class LoginScreen(Screen):
    spinner_bay = ObjectProperty(None)

Alter the methods of that widget as follows:

def test_spinner(self):
    self.ids['spinner_bay_number'].values = ['Calibration', 'POU', 'Rework/Repairs']

And viola!

enter image description here

Kevin Alvarez
  • 311
  • 2
  • 15