def get_selected_rows(listCtrl: wx.ListCtrl) -> list: """ Gets the selected items for the list control. Selection is returned as a list of selected indices, low to high. """ selection = [] index = listCtrl.GetFirstSelected() while index >= 0: # GetFirstSelected & GetNextSelected return -1 if there is nothing selected selection.append(index) index = listCtrl.GetNextSelected(index) return selection
def dark_row_formatter(listctrl: wx.ListCtrl, dark: bool = False) -> None: """Toggles the row in a ListCtrl""" items = [listctrl.GetItem(i) for i in range(listctrl.GetItemCount())] for index, item in enumerate(items): if dark: if index % 2: item.SetBackgroundColor(DARK_BACKGROUND_COLOUR) else: item.SetBackgroundColor(DARK_LIGHTGREY_COLOUR) listctrl.SetItem(item)
def _set_data_view_with_df(grid: wx.ListCtrl, df: Optional[pd.DataFrame]): """Set data view with data frame.""" grid.ClearAll() if df is None: return cols = df.columns.tolist() n_col = len(cols) for i, col in enumerate(cols): grid.InsertColumn(i, col) for i, row in df.iterrows(): grid.InsertItem(i, row[cols[0]]) for n in range(1, n_col): grid.SetItem(i, n, row[cols[n]])
def listctrl(element, instance: wx.ListCtrl): props = {**element['props']} if 'style' in props: del props['style'] set_basic_props(instance, props) # TODO: what events...? instance.DeleteAllColumns() instance.DeleteAllItems() for e, col in enumerate(props.get('column_defs', [])): instance.InsertColumn(e, col['title']) for row_idx, item in enumerate(props.get('data', [])): instance.InsertItem(row_idx, '') for col_idx, coldef in enumerate(props.get('column_defs', [])): instance.SetItem(row_idx, col_idx, coldef['column'](item)) return instance
def dark_row_formatter(listctrl: wx.ListCtrl, dark: bool = False) -> None: """Toggles the row in a ListCtrl""" items = [listctrl.GetItem(i) for i in range(listctrl.GetItemCount())] for index, item in enumerate(items): if dark: if index % 2: item.SetBackgroundColor("Dark Grey") else: item.SetBackgroundColor("Light Grey") else: if index % 2: item.SetBackgroundColor("Light Blue") else: item.SetBackgroundColor("Yellow") listctrl.SetItem(item)
def SetItemData(self, item, data): retval = ListCtrl.SetItemData(self, item, data) datamap = list() for col in xrange(0, self.GetColumnCount()): listitem = self.GetItem(item, col) datamap.append(listitem.GetText()) self.itemDataMap[item] = datamap return retval
def __init__(self, *args, **kwargs): # *args, **kwargs ensures it can be used with GUI builders unmodified ListCtrl.__init__(self, *args, **kwargs) # Initialize needed dictionary for ColumSorterMixin self.itemDataMap = dict() ColumnSorterMixin.__init__(self, 0) # start with 0 columns
def __init__(self): self.cols = {} ListCtrl.__init__(self) self.Bind(EVT_WINDOW_CREATE, self.on_create)
def DeleteItem(self, item): data = self.GetItemData(item) self.itemDataMap.pop(data, None) # try to delete and avoid errors return ListCtrl.DeleteItem(item)
def DeleteAllItems(self): self.itemDataMap.clear() return ListCtrl.DeleteAllItems(self)
def DeleteAllColumns(self): retval = ListCtrl.DeleteAllColumns(self) ColumnSorterMixin.SetColumnCount(self, self.GetColumnCount()) return retval
def DeleteColumn(self, col): retval = ListCtrl.DeleteColumn(self, col) ColumnSorterMixin.SetColumnCount(self, self.GetColumnCount()) return retval
def InsertColumn(self, col, info): retval = ListCtrl.InsertColumn(self, *args, **kwargs) ColumnSorterMixin.SetColumnCount(self, self.GetColumnCount()) return retval
def __init__(self, parent, id, style, sort=5): ListCtrl.__init__(self, parent, id, style=style) ListCtrlAutoWidthMixin.__init__(self) ColumnSorterMixin.__init__(self, sort)