def __init__(self, parent): wx.grid.Grid.__init__(self, parent, -1) self.tablebase = TableBase() self.table = Table() self.tool = None self.Bind(wx.grid.EVT_GRID_RANGE_SELECT, self.on_select) self.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_CLICK, self.on_label) self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.on_cell) self.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK, self.on_cell) self.Bind(wx.EVT_IDLE, self.on_idle)
def table_obj_test(): df = pd.DataFrame(np.random.randn(100, 5)) table = Table() table.data = df table.name = 'Table Object' table.set_style(1, tc=(255, 0, 0), round=5) table.set_style(2, lc=(255, 0, 255), ln='both') cf = GridFrame(None) cf.set_data(table) cf.Show()
def _show_table(self, tab, title): grid = self.tablenb.add_grid() if not isinstance(tab, Table): tab = Table(tab, title) App.show_table(self, tab, tab.title) grid.set_data(tab) info = self.auimgr.GetPane(self.tablenbwrap) info.Show(True) self.auimgr.Update()
def _show_table(self, tab, title): cframe = GridFrame(self) grid = cframe.grid if not isinstance(tab, Table): tab = Table(tab, title) App.show_table(self, tab, tab.title) grid.set_data(tab) cframe.Bind(wx.EVT_ACTIVATE, self.on_active_table) cframe.Bind(wx.EVT_CLOSE, self.on_close_table) cframe.SetIcon(self.GetIcon()) cframe.Show()
def __init__(self, parent): wx.grid.Grid.__init__(self, parent, -1) self.tablebase = TableBase() self.Bind(wx.grid.EVT_GRID_RANGE_SELECT, self.on_select) self.table = Table() self.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_CLICK, self.on_label)
class Grid(wx.grid.Grid): def __init__(self, parent): wx.grid.Grid.__init__(self, parent, -1) self.tablebase = TableBase() self.Bind(wx.grid.EVT_GRID_RANGE_SELECT, self.on_select) self.table = Table() self.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_CLICK, self.on_label) def on_label(self, evt): row, col = evt.GetRow(), evt.GetCol() if row==-1: props = self.table.props cur = props[self.table.columns[col]] print(cur) para = {'accu':cur[0], 'tc':cur[1], 'lc':cur[2], 'ln':cur[3]} view = [(int, 'accu', (0, 10), 0, 'accuracy', ''), ('color', 'tc', 'text color', ''), ('color', 'lc', 'line color', ''), (list, 'ln', ['Text', 'Line', 'Both'], str, 'draw', '')] rst = get_para(para, view, 'Table Properties', self) if not rst :return print(para) if col!=-1: props[self.table.columns[col]] = [para[i] for i in ['accu', 'tc', 'lc', 'ln']] print(props[self.table.columns[col]]) print('===========') if col==-1: for c in self.table.columns: props[c] = [para[i] for i in ['accu', 'tc', 'lc', 'ln']] self.update() def set_data(self, tab): if isinstance(tab, Table): self.table = tab else: self.table.data = tab self.tablebase.set_data(self.table) self._rows, self._cols = tab.shape self.SetTable(self.tablebase) self.update() def set_style(self, name, **key): self.table.set_style(name, **key) self.update() def on_select(self, event): rs, cs = self.GetSelectedRows(), self.GetSelectedCols() lt, rb = self.GetSelectionBlockTopLeft(), self.GetSelectionBlockBottomRight() if len(lt)==1 and len(rb)==1: return self.table.select(range(lt[0][0],rb[0][0]+1), range(lt[0][1],rb[0][1]+1)) else: self.table.select(list(rs), list(cs), True) def update(self): self.tablebase.ResetView(self) def select(self): self.Bind(wx.grid.EVT_GRID_RANGE_SELECT, None) self.ClearSelection() for i in self.table.index.get_indexer(self.table.rowmsk): self.SelectRow(i, True) for i in self.table.columns.get_indexer(self.table.colmsk): self.SelectCol(i, True) self.Bind(Grid.EVT_GRID_RANGE_SELECT, self.on_select) def __del__(self): print('grid deleted!!!')
class Grid(wx.grid.Grid): def __init__(self, parent): wx.grid.Grid.__init__(self, parent, -1) self.tablebase = TableBase() self.table = Table() self.tool = None self.Bind(wx.grid.EVT_GRID_RANGE_SELECT, self.on_select) self.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_CLICK, self.on_label) self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.on_cell) self.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK, self.on_cell) self.Bind(wx.EVT_IDLE, self.on_idle) def on_label(self, evt): row, col = evt.GetRow(), evt.GetCol() if row == -1: props = self.table.props cur = props[self.table.columns[col]] print(cur) para = {'accu': cur[0], 'tc': cur[1], 'lc': cur[2], 'ln': cur[3]} view = [(int, 'accu', (0, 10), 0, 'accuracy', ''), ('color', 'tc', 'text color', ''), ('color', 'lc', 'line color', ''), (list, 'ln', ['Text', 'Line', 'Both'], str, 'draw', '')] rst = get_para(para, view, 'Table Properties', self) if not rst: return print(para) if col != -1: props[self.table.columns[col]] = [ para[i] for i in ['accu', 'tc', 'lc', 'ln'] ] print(props[self.table.columns[col]]) print('===========') if col == -1: for c in self.table.columns: props[c] = [para[i] for i in ['accu', 'tc', 'lc', 'ln']] self.update() def on_cell(self, me): x, y = me.GetCol(), me.GetRow() obj, tol = self.table, TableTool.default tool = self.tool or tol #ld, rd, md = me.LeftIsDown(), me.RightIsDown(), me.MiddleIsDown() sta = [me.AltDown(), me.ControlDown(), me.ShiftDown()] others = {'alt': sta[0], 'ctrl': sta[1], 'shift': sta[2], 'grid': self} tool.mouse_down(self.table, x, y, 0, **others) me.Skip() def set_data(self, tab): if isinstance(tab, Table): self.table = tab else: self.table.data = tab self.tablebase.set_data(self.table) self._rows, self._cols = tab.shape self.SetTable(self.tablebase) self.update() def set_style(self, name, **key): self.table.set_style(name, **key) self.update() def on_select(self, event): rs, cs = self.GetSelectedRows(), self.GetSelectedCols() lt, rb = self.GetSelectionBlockTopLeft( ), self.GetSelectionBlockBottomRight() if len(lt) == 1 and len(rb) == 1: return self.table.select(range(lt[0][0], rb[0][0] + 1), range(lt[0][1], rb[0][1] + 1)) else: self.table.select(list(rs), list(cs), True) def update(self): self.tablebase.ResetView(self) def select(self): self.Bind(wx.grid.EVT_GRID_RANGE_SELECT, None) self.ClearSelection() for i in self.table.index.get_indexer(self.table.rowmsk): self.SelectRow(i, True) for i in self.table.columns.get_indexer(self.table.colmsk): self.SelectCol(i, True) self.Bind(wx.grid.EVT_GRID_RANGE_SELECT, self.on_select) def on_idle(self, event): if not self.IsShown() or self.table is None\ or self.table.dirty == False: return self.select() self.tablebase.ResetView(self) self.table.dirty = False print('update') def __del__(self): print('grid deleted!!!')