Marus Gradinaru
Marus Gradinaru

Reputation: 3100

Is there a way to select a toga.Table row programmatically?

In my app I have a preferences panel with a toga.Table() in which the user must select one item (row). After it chooses the item I save it in the preferences database and when I restart the app, I want to read the preferences and select back that item. I tried to assign someting to the toga.Table().selection but it doesn't work. It seems that is read only... So, it is possible ? If the toga.Table object do not permit that, it should in the next version ! Because this is an important feature.

Upvotes: -2

Views: 103

Answers (2)

Marus Gradinaru
Marus Gradinaru

Reputation: 3100

Until this feature will be available, I will use this code to set the selection (only for Android platform):

class CustomTable(toga.Table):
    
  def SelectRow(self, row_index):
    if not onAndroid: return
    self._impl.clear_selection()
    if 0 <= row_index < len(self.data):
      row_index += 1  
      the_row = self._impl.table_layout.getChildAt(row_index)
      self._impl.add_selection(row_index, the_row)
      
  def FindRowIndex(self, column_name, data_value):
    for index, row in enumerate(self.data):
      if getattr(row, column_name) == data_value: return index
    return -1

  def SelectRowValue(self, colum_name, data_value):
    row_index = self.FindRowIndex(colum_name, data_value)
    self.SelectRow(row_index)

Upvotes: 0

mhsmith
mhsmith

Reputation: 8111

This isn't currently supported, but there's a feature request for it here.

Upvotes: 1

Related Questions