Untitled
unknown
python
2 years ago
4.1 kB
9
Indexable
# gamer_button # https://web.archive.org/web/20221214105801/https://discuss.wxpython.org/t/cant-make-it-work-wx-button-setbackgroundcolour-on-wx-evt-enter-window/35272/7 ######################################################################## class MyListCtrlPnl(wx.Panel): """ """ #---------------------------------------------------------------------- def __init__(self, parent): wx.Panel.__init__(self, parent, -1) #---------------------------------------------------------------------- #Man1stBut Function call to bin ### https://web.archive.org/web/20221214105801/https://discuss.wxpython.org/t/cant-make-it-work-wx-button-setbackgroundcolour-on-wx-evt-enter-window/35272/7 self.btn1Sizer.Add(Man1stBut(self, "Copy Grid Content"), wx.EXPAND) #------------- def SelectallGridCells(self, event): self.mygrid.SetSelectionMode(wx.grid.Grid.GridSelectCells) # self.event.Skip() #---------------------------------------------------------------------- def CopyallGridCells(self): # Number of rows and cols topleft = self.mygrid.GetSelectionBlockTopLeft() if list(topleft) == []: topleft = [] else: topleft = list(topleft[0]) bottomright = self.mygrid.GetSelectionBlockBottomRight() if list(bottomright) == []: bottomright = [] else: bottomright = list(bottomright[0]) if list(self.mygrid.GetSelectionBlockTopLeft()) == []: rows = 15 cols = 5 iscell = True else: rows = bottomright[0] - topleft[0] + 1 cols = bottomright[1] - topleft[1] + 1 iscell = False print("rows : " + str(rows)) print("cols : " + str(cols)) # data variable contain text that must be set in the clipboard data = "" # For each cell in selected range append the cell value in the data variable # Tabs ' ' for cols and '\r' for rows for r in range(rows): for c in range(cols): if iscell: data += str( self.mygrid.GetCellValue( self.mygrid.GetGridCursorRow() + r, self.mygrid.GetGridCursorCol() + c, ) ) else: data += str( self.mygrid.GetCellValue(topleft[0] + r, topleft[1] + c) ) if c < cols - 1: data += "\t" data += "\n" # Create text data object clipboard = wx.TextDataObject() # Set data object value clipboard.SetText(data) # Put the data in the clipboard if wx.TheClipboard.Open(): wx.TheClipboard.SetData(clipboard) wx.TheClipboard.Close() else: wx.MessageBox("Can't open the clipboard", "Error") #---------------------------------------------------------------------- ######################################################################## class Man1stBut(wx.Window): def __init__(self, parent, label): super().__init__(parent) #---------------------------------------------------------------------- def evt_button(_): btn.SetBackgroundColour(None) # btn.SetBackgroundColour(wx.Colour("#FFFFFF")) # btn.SetLabel("yes, I'm a button..") btn.Bind( wx.EVT_BUTTON, MyListCtrlPnl.SelectallGridCells(parent, event=None), ) btn.Bind( wx.EVT_BUTTON, MyListCtrlPnl.CopyallGridCells(parent), ) self.Bind(wx.EVT_BUTTON, evt_button) #----------------------------------------------------------------------
Editor is loading...