a few questions about wx.Grid

a few questions about wx.Grid
Greetings,

I am using a custom renderer to create a read-only grid with a tree structure drawn in the first column. Since my grid is read-only, I don’t want a cursor. Is there a way to ‘hide’ the cursor so it is never drawn?

My other question involves rows/columns that I want to be hidden. Something like, rows with 0 height, or columns with 0 width. Is there a way to prevent a row or column from being visible?

The custom renderer example and the custom tree example have been very helpful in getting my “treeGrid” to work. I would be happy to submit it as an example, when it is a bit more polished.

Regards, Vern Muhr

Greetings,

I am using a custom renderer to create a read-only grid with a tree
structure drawn in the first column. Since my grid is read-only, I don't
want a cursor. Is there a way to 'hide' the cursor so it is never drawn?

SetCellHighlightPenWidth(0). Note that the cursor will still be
"present" and that may affect the way your user interacts with the
grid unless you provide overridden behavior. For example, arrow keys
to navigate may not be intuitive (since they'll be moving the
invisible cursor, not scrolling the grid).

My other question involves rows/columns that I want to be hidden. Something
like, rows with 0 height, or columns with 0 width. Is there a way to prevent
a row or column from being visible?

Set them to 0 height/width.

The custom renderer example and the custom tree example have been very
helpful in getting my "treeGrid" to work. I would be happy to submit it as
an example, when it is a bit more polished.

Congratulations, I look forward to seeing it.

···

On 2/13/07, Vern Muhr <VernM@berkeleyprocess.com> wrote:

Regards, Vern Muhr

Vern,

  Check out HotScripts.com for a nice example of a simple MySQL query
grid. You should find some use in it.

Telly

Chris,

Thanks for the very quick reply! SetCellHighlightPenWidth(0) eliminated the cursor, as long as it is called after the grid has been populated. I don't really understand what the real prequisite is, but I get an exception if I set it too soon.

I was also able to hide a column if:
1. I call SetColMinimalAcceptableWidth(col, 0)
2. I later call SetColSize(col,0)
3. finally, renderer.GetBestSize() returns a with of 0 for cells in the hidden column.

Thanks again for the help,

Vern

···

-----Original Message-----
From: Chris Mellon [mailto:arkanes@gmail.com]
Sent: Tuesday, February 13, 2007 1:30 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] a few questions about wx.Grid

On 2/13/07, Vern Muhr <VernM@berkeleyprocess.com> wrote:

Greetings,

I am using a custom renderer to create a read-only grid with a tree
structure drawn in the first column. Since my grid is read-only, I don't
want a cursor. Is there a way to 'hide' the cursor so it is never drawn?

SetCellHighlightPenWidth(0). Note that the cursor will still be
"present" and that may affect the way your user interacts with the
grid unless you provide overridden behavior. For example, arrow keys
to navigate may not be intuitive (since they'll be moving the
invisible cursor, not scrolling the grid).

My other question involves rows/columns that I want to be hidden. Something
like, rows with 0 height, or columns with 0 width. Is there a way to prevent
a row or column from being visible?

Set them to 0 height/width.

The custom renderer example and the custom tree example have been very
helpful in getting my "treeGrid" to work. I would be happy to submit it as
an example, when it is a bit more polished.

Congratulations, I look forward to seeing it.

Regards, Vern Muhr

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Telly,

nice.

Vern

···

-----Original Message-----
From: Telly Williams [mailto:TWilliams001@elp.rr.com]
Sent: Tuesday, February 13, 2007 3:57 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] a few questions about wx.Grid

Vern,

  Check out HotScripts.com for a nice example of a simple MySQL query
grid. You should find some use in it.

Telly

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

I am having trouble with this code. Please feel free to run it as it does work.

All i want it to do is create a frame with a sub window however i want the sub window to contain a splitter window as a child of it. That is what i have tried to do below but it just creates a little square at the top left of the screen with my splitter window and sub panels squashed up into it

Something to note: The splitter window works fine if i add the splitter window to the top level frame instead of my sub window (RootWindow)

but i really need the splitter window to be a child of wx.Window or even wx.Panel but i dont know how to avoid this squashing problem that is specific to working with wx.Window or wx.Panel as apposed to wx.Frame.

Any thoughts?

Mark

#Code Starts

import wx

ID_ABOUT = 101

class MainFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(200, 150))

        #add Container window that holds the splitter window and sub panels
        self.RootWindow = RootWindow(self, -1)

class MainApp(wx.App):
    def OnInit(self):
        frame = MainFrame(None, -1, "Hello from wxPython")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

# Container window to hold a splitter window
class RootWindow(wx.Window):
    def __init__(self, parent, id):
        wx.Window.__init__(self, parent, id)

        self.initpos = 200
        #Create Splitter window
        self.SplitWinRootV = wx.SplitterWindow(self, -1, size = (-1, -1))

        #Add sub elements
        self.SideWindow = Pnl1(self.SplitWinRootV)
        self.MainWindow = Pnl2(self.SplitWinRootV)

        #Split Vertically
        self.SplitWinRootV.SplitVertically(self.SideWindow, self.MainWindow, self.initpos)

#Define two sub panels for the above splitter window
class Pnl1(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER, size = (-1,-1))
        st = wx.StaticText(self, -1,"panel 1 sdd",(50, 50))
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(st, 2, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)
        self.Layout()

class Pnl2(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER, size = (-1,-1))
        st = wx.StaticText(self, -1,"You can put nearly any type of window here,\n",(50, 50))
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(st, 2, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)
        self.Layout()

app = MainApp(0)
app.MainLoop()

#code Ends

Mark wrote:

I am having trouble with this code. Please feel free to run it as it does work.

All i want it to do is create a frame with a sub window however i want the sub window to contain a splitter window as a child of it. That is what i have tried to do below but it just creates a little square at the top left of the screen with my splitter window and sub panels squashed up into it

You don't do anything to tell the splitter how to be sized or positioned. The easiest thing to do is to use a sizer.

Something to note: The splitter window works fine if i add the splitter window to the top level frame instead of my sub window (RootWindow)

Because the default behavior of a frame when it has only one child is to resize it to fill the client area, which is what it is doing with your RootWindow. But other types of windows don't do that by default, you need to tell it how to size the children.

# Container window to hold a splitter window
class RootWindow(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)

        self.initpos = 200
        #Create Splitter window
        self.SplitWinRootV = wx.SplitterWindow(self, -1, size = (-1, -1))

        sizer = wx.BoxSizer()
        sizer.Add(self.SplitWinRootV, 1, wx.EXPAND)
        self.SetSizer(sizer)

        #Add sub elements
        self.SideWindow = Pnl1(self.SplitWinRootV)
        self.MainWindow = Pnl2(self.SplitWinRootV)

        #Split Vertically
        self.SplitWinRootV.SplitVertically(self.SideWindow, self.MainWindow, self.initpos)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks for that tip. I did try adding it to a sizer but it does not fix it. I tried adding like this.

        self.SplitWinRootV = wx.SplitterWindow(self, -1, size = (-1, -1))

        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.SplitWinRootV, 2, wx.EXPAND)
        self.SetAutoLayout(True)
        self.SetSizer(box)
        self.Layout()

not sure what im doing wrong :-/

I also tried adding the sub panels and even the root wx.Window to a sizer but it didnt help.

Cheers,

Mark

Robin Dunn wrote:

···

Mark wrote:

I am having trouble with this code. Please feel free to run it as it does work.

All i want it to do is create a frame with a sub window however i want the sub window to contain a splitter window as a child of it. That is what i have tried to do below but it just creates a little square at the top left of the screen with my splitter window and sub panels squashed up into it

You don't do anything to tell the splitter how to be sized or positioned. The easiest thing to do is to use a sizer.

Something to note: The splitter window works fine if i add the splitter window to the top level frame instead of my sub window (RootWindow)

Because the default behavior of a frame when it has only one child is to resize it to fill the client area, which is what it is doing with your RootWindow. But other types of windows don't do that by default, you need to tell it how to size the children.

# Container window to hold a splitter window
class RootWindow(wx.Panel):
   def __init__(self, parent, id):
       wx.Panel.__init__(self, parent, id)

       self.initpos = 200
       #Create Splitter window
       self.SplitWinRootV = wx.SplitterWindow(self, -1, size = (-1, -1))

       sizer = wx.BoxSizer()
       sizer.Add(self.SplitWinRootV, 1, wx.EXPAND)
       self.SetSizer(sizer)

       #Add sub elements
       self.SideWindow = Pnl1(self.SplitWinRootV)
       self.MainWindow = Pnl2(self.SplitWinRootV)

       #Split Vertically
       self.SplitWinRootV.SplitVertically(self.SideWindow, self.MainWindow, self.initpos)

Mark wrote:

Thanks for that tip. I did try adding it to a sizer but it does not fix it. I tried adding like this.

       self.SplitWinRootV = wx.SplitterWindow(self, -1, size = (-1, -1))

       box = wx.BoxSizer(wx.VERTICAL)
       box.Add(self.SplitWinRootV, 2, wx.EXPAND)
       self.SetAutoLayout(True)
       self.SetSizer(box)
       self.Layout()

not sure what im doing wrong :-/

Did you also change RootWindow to derive from wx.Panel instead of wx.Window as I showed in the code in my reply?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I cant believe I Didn't notice that. really sorry about that. It works well now.. thank you for your help. :slight_smile:

Mark

Robin Dunn wrote:

···

Mark wrote:

Thanks for that tip. I did try adding it to a sizer but it does not fix it. I tried adding like this.

       self.SplitWinRootV = wx.SplitterWindow(self, -1, size = (-1, -1))

       box = wx.BoxSizer(wx.VERTICAL)
       box.Add(self.SplitWinRootV, 2, wx.EXPAND)
       self.SetAutoLayout(True)
       self.SetSizer(box)
       self.Layout()

not sure what im doing wrong :-/

Did you also change RootWindow to derive from wx.Panel instead of wx.Window as I showed in the code in my reply?