Skip to content

Instantly share code, notes, and snippets.

@Crowbrammer
Created February 7, 2017 17:22
Show Gist options
  • Save Crowbrammer/469d10e90d7500c323ee07b17d60e0fc to your computer and use it in GitHub Desktop.
Save Crowbrammer/469d10e90d7500c323ee07b17d60e0fc to your computer and use it in GitHub Desktop.
#Test code
import libs.apa_database
import inspect
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty, StringProperty, Property
from kivy.uix.screenmanager import ScreenManager, Screen#, FadeTransition
from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button
class PositionerLayout(BoxLayout):
def __init__(self, **kwargs): # Don't know **kwargs
super(PositionerLayout, self).__init__(**kwargs)
machine_list = libs.apa_database.get_data('machineID_modelID_status', order_by_column='machineID')
model_list = set([x[0] for x in libs.apa_database.get_data('modelID_positionnum', order_by_column='modelID')])
global position_chart
position_chart = libs.apa_database.assign_people_to_positions()
dropdown = []
mmpm = []
for each_machine in range(0, len(machine_list)):
dropdown.append(DropDown()) # Because if I use a single DropDown instance, it'll either change every model_button, or only change one.
print('Dropdown ID: ' + str(id(dropdown[each_machine])))
for model in model_list:
btn = Button(text='{}'.format(model), size_hint_y=None, height=44)
btn.bind(on_release=lambda btn: dropdown[each_machine].select(btn.text))
dropdown[each_machine].add_widget(btn)
mmpm.append(MmpModule())
mmpm[each_machine].ids.machine_button.text = 'Wow: {}'.format(machine_list[each_machine][0])
mmpm[each_machine].ids.model_button.text = 'Wow: {}'.format(machine_list[each_machine][1])
mmpm[each_machine].ids.model_button.bind(on_release=dropdown[each_machine].open)
# # # # # # # # # # # # # # # # # # # #
# Why does this change the 5th 'cluster's' model, instead of the one the DropDown's over?
# # # # # # # # # # # # # # # # # # # #
dropdown[each_machine].bind(on_select=lambda instance, x: setattr(mmpm[each_machine].ids.model_button, 'text', x))
# # # # # # # # # # # # # # # # # # # #
# ^ ^ ^ ^ ^
# # # # # # # # # # # # # # # # # # # #
for each in position_chart:
if each[0][0] == machine_list[each_machine][1]:
if each[0][1] == 3:
mmpm[each_machine].ids.position3.text = 'Wow: {}'.format(each[1])
elif each[0][1] == 2:
mmpm[each_machine].ids.position2.text = 'Wow: {}'.format(each[1])
else:
mmpm[each_machine].ids.position1.text = 'Wow: {}'.format(each[1])
mymodel = mmpm[each_machine].ids.machine_button.text
self.add_widget(mmpm[each_machine])
class AutopositionerApp(App):
def build(self):
PositionerLayout()
if __name__ == '__main__':
AutopositionerApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment