How to disable rangeselect in wxGrid

Hi !

I have a little problem with wxGrid.
In Delphi I can set in grids how I want to select cells.
I can select only individual cells, or ranges.

In my program I don't wanna use ranges. But I don't find any
methods or properties what can set this option.

The range selection mode is disturb the users.
Usually the ranges are used to select more cells, and do any operations with them.
But in my program the user can select only one(!) cell, and this cell set the
actual day, and actual person.
If many cells are selected, the user (and I too) cannot determine, which day/person
is the actual.

So if possible, I want to "protect users from this effect".

Is anyone can help me ?

Thanx for it: ft

fowlertrainer@anonym.hu wrote:

Hi !

Hi,

In my program I don't wanna use ranges. But I don't find any methods
or properties what can set this option.

<-cut->

Is anyone can help me ?

I hope...
Try to catch the events that select the cell for you, like:

EVT_GRID_SELECT_CELL
EVT_GRID_LABEL_LEFT_CLICK
EVT_GRID_CELL_LEFT_CLICK

and with appropriated event method, see what cell was pressed and work
with it.

Thanx for it: ft

Bye,
Michele

Hi !

I hope...
Try to catch the events that select the cell for you, like:

EVT_GRID_SELECT_CELL
EVT_GRID_LABEL_LEFT_CLICK
EVT_GRID_CELL_LEFT_CLICK

and with appropriated event method, see what cell was pressed and work
with it.

Can I prevent the event handler to it work with original methods ?

In Delphi I can prevent the running of original event handler method.

procedure MouseDown(X,Y:integer....);override;
begin
   if ..... then inherited(X,Y...) # I can call the original handler
   else domywork; # I don't call it, because it will doing a thing what I don't want
end;

So: how to prevent the range selection in mouse event handlers ?

Thanx for help: ft

One of the solutions is that, but that is ugly a little:

#Boa:Frame:Frame1

import wx
import wx.grid

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1GRID1,
] = [wx.NewId() for _init_ctrls in range(3)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(346, 180), size=wx.Size(400, 479),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(392, 445))

        self.grid1 = wx.grid.Grid(id=wxID_FRAME1GRID1, name='grid1',
              parent=self, pos=wx.Point(72, 40), size=wx.Size(296, 296),
              style=0)
        self.grid1.Bind(wx.grid.EVT_GRID_SELECT_CELL,
              self.OnGrid1GridSelectCell)
        self.grid1.Bind(wx.grid.EVT_GRID_RANGE_SELECT,
              self.OnGrid1GridRangeSelect)
        self.grid1.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
              self.OnGrid1GridCellChange)

        self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='button1',
              name='button1', parent=self, pos=wx.Point(72, 352),
              size=wx.Size(75, 23), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_FRAME1BUTTON1)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.grid1.CreateGrid(3,4)
        self.SelectedC=1
        self.SelectedR=1
        self.OnRangeSelectOn=0

    def OnGrid1GridSelectCell(self, event):
        self.SetTitle('%s %s'%(event.GetCol(),event.GetRow()))
        event.Skip()

    def OnButton1Button(self, event):
        self.grid1.SetGridCursor(2,3)
        self.grid1.MakeCellVisible(2,3)
        event.Skip()

    def OnGrid1GridRangeSelect(self, event):
        if self.OnRangeSelectOn: return
        m=event.GetTopLeftCoords()
        m=str(m)
        m=m.replace('(','')
        m=m.replace(')','')
        m=m.split(',')
        x=m[0].strip()
        y=m[1].strip()
        print x,y
        #sc=self.grid1.GetSelectionBlockTopLeft()
        #print sc
        self.OnRangeSelectOn=True
        try:
          x,y=self.SelectedC,self.SelectedR
          self.grid1.ClearSelection()
          #self.grid1.SetGridCursor(y,x)
          self.grid1.MakeCellVisible(y,x)
        finally:
          self.OnRangeSelectOn=False event.Skip()

    def OnGrid1GridCellChange(self, event):
        self.SelectedC=event.GetCol()
        self.SelectedR=event.GetRow()
        event.Skip()

if __name__ == '__main__':
    app = wx.PySimpleApp()
    wx.InitAllImageHandlers()
    frame = create(None)
    frame.Show()

    app.MainLoop()

fowlertrainer@anonym.hu wrote:

Hi !

I hope...
Try to catch the events that select the cell for you, like:

EVT_GRID_SELECT_CELL
EVT_GRID_LABEL_LEFT_CLICK
EVT_GRID_CELL_LEFT_CLICK

and with appropriated event method, see what cell was pressed and work
with it.

Can I prevent the event handler to it work with original methods ?

Don't call the event.Skip() method ...

Thanx for help: ft

Michele

Hi,

Are you aware of the Grid manual in the wiki?

http://wiki.wxpython.org/index.cgi/wxGrid#head-2893bf941bda8d24331f5e19d1c02e572527262a

    1.4 Selections and the Cursor

The grid has both a selection set (which may include disjoint ranges) and a single-cell focus cursor. The selection set can contain arbitrary blocks of cells, while the cursor can only point to a single cell.

See you
Werner

fowlertrainer@anonym.hu wrote:

···

Hi !

I hope...
Try to catch the events that select the cell for you, like:

EVT_GRID_SELECT_CELL
EVT_GRID_LABEL_LEFT_CLICK
EVT_GRID_CELL_LEFT_CLICK

and with appropriated event method, see what cell was pressed and work
with it.

Can I prevent the event handler to it work with original methods ?

In Delphi I can prevent the running of original event handler method.

procedure MouseDown(X,Y:integer....);override;
begin
  if ..... then inherited(X,Y...) # I can call the original handler
  else domywork; # I don't call it, because it will doing a thing what I don't want
end;

So: how to prevent the range selection in mouse event handlers ?

Thanx for help: ft

One of the solutions is that, but that is ugly a little:

Hi,

Are you aware of the Grid manual in the wiki?

http://wiki.wxpython.org/index.cgi/wxGrid#head-2893bf941bda8d24331f5e19d1c02e572527262a

    1.4 Selections and the Cursor

The grid has both a selection set (which may include disjoint ranges)
and a single-cell focus cursor. The selection set can contain arbitrary
blocks of cells, while the cursor can only point to a single cell.

See you
Werner

fowlertrainer@anonym.hu wrote:

···

Hi !

I hope...
Try to catch the events that select the cell for you, like:

EVT_GRID_SELECT_CELL
EVT_GRID_LABEL_LEFT_CLICK
EVT_GRID_CELL_LEFT_CLICK

and with appropriated event method, see what cell was pressed and work
with it.

Can I prevent the event handler to it work with original methods ?

In Delphi I can prevent the running of original event handler method.

procedure MouseDown(X,Y:integer....);override;
begin
  if ..... then inherited(X,Y...) # I can call the original handler
  else domywork; # I don't call it, because it will doing a thing what I don't want
end;

So: how to prevent the range selection in mouse event handlers ?

Thanx for help: ft

One of the solutions is that, but that is ugly a little: