I'm attempting to develop an application using Kivy where the the user will be running an analytical model on dynamic datasets (meaning there are multiple datasets, not that the dataset itself will be changing). Each dataset can have between 100-300 different fields/attributes that the analysts can choose from in order to run their simulation.
I figured out how to dynamically generate a series of checkboxes where the analyst can pick which fields he/she wants to use. I had to do it dynamically because it will change depending on which dataset is selected to run things on.
However, the way I finally ended up getting it to "work" created a new problem... namely that the checkboxes all respond VERY slowly. Often require me to click on them multiple times in order for the system to react at all. I have tried on a very small subset of data (only one or two fields displayed) and the problem persists, which tells me it (probably) isn't just a resource issue.
If I simplify the system so a single field that is inserted into a Layout with no specific formatting, it seems to work fine. Are my Layouts just too complex for the system to handle? Is there invisible padding or something that is somehow making the 'clickable' area significantly smaller than it appears visually?
Here is the relevant .kv section
<SelectFields>:
container: container
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
ScrollView:
size_hint: 1, 1
size: 500, 320
pos_hint: {'left': 1, 'center_y': .5}
GridLayout:
id: container
cols: 1
padding: 20
spacing: 20
height: self.minimum_height
size_hint: 1, None
do_scroll_x: False
BoxLayout:
size_hint_y: None
height: 30
Button:
text: "Cancel"
on_release: root.cancel()
Button:
text: "Select"
on_release: root.select()
Here is the relevant .py section:
class UploadModel(Screen):
''' Builder can select data (columns) and upload model file '''
def __init__(self, **kwargs):
super(UploadModel, self).__init__(**kwargs)
.
.
. <other functions are here>
.
.
def select_fields(self):
''' Create a popup window with ScrollView where users can select which field(s)
they want to include in their modeling. '''
content = SelectFields(select=self.selected, cancel=self.dismiss_popup)
self._popup = Popup(title="Select Fields", content=content,
size_hint=(1, 1))
self.fieldsDict = {} # Dictionary to save checkbox state
for index, field in enumerate(FIELDS):
subLayout = BoxLayout(orientation="horizontal")
field_name = Label(text = field) # Field Name
checkbox = CheckBox(active=True)
checkbox.bind(active=self.checked)
self.fieldsDict[checkbox] = [index, field, True]
subLayout.add_widget(field_name) # Add Label to 'row'
subLayout.add_widget(checkbox) # Add Checkbox to 'row'
content.container.add_widget(subLayout) # Add 'row' to layout
#if index > 1:
# break # Use to limit fields for testing
self._popup.open()
def checked(self, checkbox, value):
''' Method called by checkboxes that will save the current state of each checkbox '''
self.fieldsDict[checkbox][2] = value
print(self.fieldsDict[checkbox][1], self.fieldsDict[checkbox][2])
def selected(self):
''' Placeholder... Will eventually feed parser to get selected data subset '''
for field, value in self.fieldsDict.items():
if value[2] == True:
print(value[1])
class SelectFields(BoxLayout):
select = ObjectProperty(None)
cancel = ObjectProperty(None)
This gets me an interface that LOOKS how I want it to (more or less), but the response (or lack thereof) is an issue.
Example of what the interface looks like with above code
Aucun commentaire:
Enregistrer un commentaire