def bind_to_grid(self, grid): """Bind to intercept events on the grid Binds on_mouse_motion and on_column_resize in order to do tooltips. Sets up editing / auto size and other to customize for table type. """ self.grid = grid grid.AutoSize() grid.EnableEditing(False) grid.SetDefaultCellOverflow(False) if self.v.corner_button is None: grid.fn_clicked = None else: fn_clicked = self.v.corner_button["fn_clicked"] def on_corner_button_clicked(): fn_clicked() self.update_grid() grid.ForceRefresh() grid.Parent.Layout() grid.fn_clicked = on_corner_button_clicked grid.label = self.v.corner_button.get("label", "Update") grid.tooltip = self.v.corner_button.get("tooltip", "") # # Below largely taken from # http://wiki.wxpython.org/wxGrid%20ToolTips # self.last_pos = (None, None) grid.GetGridWindow().Bind(wx.EVT_MOTION, self.on_mouse_motion) grid.Bind(wx.grid.EVT_GRID_COL_SIZE, self.on_column_resize)
def __init__(self, grid): self._tooltip = HtmlPopupWindow(grid, (250, 80), False, True) self._information_popup = HtmlPopupWindow(grid, (450, 300)) self._grid = grid self._tooltip_timer = wx.Timer(grid.GetGridWindow()) grid.GetGridWindow().Bind(wx.EVT_MOTION, self.OnMouseMotion) grid.GetGridWindow().Bind(wx.EVT_TIMER, self.OnShowToolTip) grid.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.OnGridEditorHidden)
def __init__(self, parent, id, G): wx.Frame.__init__(self, parent, id, 'Breadboard', size=(1194, 250)) grid = wx.grid.Grid(self) grid.CreateGrid(10, 64) grid.SetRowLabelSize(22) grid.SetColMinimalAcceptableWidth(10) for row in range(10): t1 = chr(row + 97) grid.SetRowLabelValue(row, t1) for col in range(64): t2 = str(col + 1) t = t1 + t2 grid.SetColLabelValue(col, t2) grid.SetColSize(col, 18) grid.SetCellValue(row, col, t) grid.SetCellBackgroundColour(row, col, wx.CYAN) grid.SetReadOnly(row, col, isReadOnly=True) print "Right click where you want to start." grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick) print G
def __init__(self, parent,lbl,hid): wx.Frame.__init__(self, parent, title='HDFGridView: '+lbl,size=wx.Size(750, 650)) imgDir=ut.Path.GetImage() icon = wx.Icon(os.path.join(imgDir,'h5pyViewer.ico'), wx.BITMAP_TYPE_ICO) self.SetIcon(icon) pan = wx.Panel(self, -1) t=type(hid) if t==h5py.h5d.DatasetID: data=h5py.Dataset(hid) elif t==np.ndarray: data=hid else: raise(TypeError('unhandled type')) grid = Grid(pan, data) tbl=grid.GetTable() sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(grid, 1, wx.EXPAND) wxAxCtrlLst=[] l=len(data.shape) if l==1: if type(hid.get_type())==h5py.h5t.TypeCompoundID: tbl = Table1DCompound(data) else: tbl = Table1DArray(data) else: idxXY=(l-2,l-1) #idxXY=(l-1,l-2) for idx,l in enumerate(data.shape): if idx in idxXY: continue wxAxCtrl=ut.SliderGroup(pan, label='Axis:%d'%idx,range=(0,l-1)) wxAxCtrl.idx=idx wxAxCtrlLst.append(wxAxCtrl) sizer.Add(wxAxCtrl.sizer, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, border=5) wxAxCtrl.SetCallback(Grid.OnSetView,wxAxCtrl) sl=ut.GetSlice(idxXY,data.shape,wxAxCtrlLst) if type(hid.get_type())==h5py.h5t.TypeCompoundID: tbl = Table2DArray(data) else: tbl = Table2DArray(data) tbl.idxXY=idxXY if idxXY[0]<idxXY[1]: tbl.view = tbl.data[sl] else: tbl.view = tbl.data[sl].T self.wxAxCtrlLst=wxAxCtrlLst #print type(tbl) grid.SetTable (tbl, True) #AutoSize must be called after SetTable, but takes lot of time on big tables! if tbl.GetNumberCols()*tbl.GetNumberRows()<50*50: grid.AutoSizeColumns(True);grid.AutoSizeRows(True) #grid.SetDefaultColSize(200, True) self.grid=grid pan.SetSizer(sizer) pan.Layout() self.Centre() self.BuildMenu() grid.Bind(wx.grid.EVT_GRID_CMD_COL_SIZE, self.OnColSize)