Wx.Grid and popup over cells

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Massi

    Wx.Grid and popup over cells

    Hi everyone,

    I'm writing a python script which uses a grid (PyGridTableBas e) whose
    cells can contain very large values (not only numbers, but also
    strings). I've also written a custom renderer which dinamically shows
    only the first n characters (according to the width of the cell)
    replacing the last ones with dots. Now I would like to know if it is
    possible to have a popup which shows the whole contents of a certain
    cell when the mouse stops over the cell itself. Any ideas?
    Thanks in advance.

    Massi
  • Mike Driscoll

    #2
    Re: Wx.Grid and popup over cells

    On Oct 14, 5:21 am, Massi <massi_...@msn. comwrote:
    Hi everyone,
    >
    I'm writing a python script which uses a grid (PyGridTableBas e) whose
    cells can contain very large values (not only numbers, but also
    strings). I've also written a custom renderer which dinamically shows
    only the first n characters (according to the width of the cell)
    replacing the last ones with dots. Now I would like to know if it is
    possible to have a popup which shows the whole contents of a certain
    cell when the mouse stops over the cell itself. Any ideas?
    Thanks in advance.
    >
    Massi
    First off, let me recommend the wxPython mailing list for questions of
    this sort. You'll probably get more relevant help quicker if you go
    that route.

    Anyway, I've done tooltips on cells in a grid before and you'll need
    the same concept to use a pop-up dialog too. To begin, you'll want to
    bind to the mouse event, EVT_MOTION, like this:

    self.myGrid.Get GridWindow().Bi nd(wx.EVT_MOTIO N, self.onMouseOve r)

    Next, you'll need to do something like the following in your mouse
    over function:

    <code>

    def onMouseOver(sel f, event):
    '''
    Method to calculate where the mouse is pointing and
    then set the tooltip dynamically.
    '''

    # Use CalcUnscrolledP osition() to get the mouse position
    within the
    # entire grid including what's offscreen
    x, y =
    self.totals_she et.CalcUnscroll edPosition(even t.GetX(),event. GetY())

    coords = self.totals_she et.XYToCell(x, y)
    # you only need these if you need the value in the cell
    row = coords[0]
    col = coords[1]
    event.GetEventO bject().SetTool TipString("My amazing tooltip")

    </code>

    Hopefully that will get you going. If not, just ask more questions
    (here or at the wxPython list).

    -------------------
    Mike Driscoll

    Blog: http://blog.pythonlibrary.org
    Python Extension Building Network: http://www.pythonlibrary.org

    Comment

    • Massi

      #3
      Re: Wx.Grid and popup over cells

      On 14 Ott, 16:13, Mike Driscoll <kyoso...@gmail .comwrote:
      On Oct 14, 5:21 am, Massi <massi_...@msn. comwrote:
      >
      Hi everyone,
      >
      I'm writing a python script which uses a grid (PyGridTableBas e) whose
      cells can contain very large values (not only numbers, but also
      strings). I've also written a custom renderer which dinamically shows
      only the first n characters (according to the width of the cell)
      replacing the last ones with dots. Now I would like to know if it is
      possible to have a popup which shows the whole contents of a certain
      cell when the mouse stops over the cell itself. Any ideas?
      Thanks in advance.
      >
      Massi
      >
      First off, let me recommend the wxPython mailing list for questions of
      this sort. You'll probably get more relevant help quicker if you go
      that route.
      >
      Anyway, I've done tooltips on cells in a grid before and you'll need
      the same concept to use a pop-up dialog too. To begin, you'll want to
      bind to the mouse event, EVT_MOTION, like this:
      >
      self.myGrid.Get GridWindow().Bi nd(wx.EVT_MOTIO N, self.onMouseOve r)
      >
      Next, you'll need to do something like the following in your mouse
      over function:
      >
      <code>
      >
      def onMouseOver(sel f, event):
      '''
      Method to calculate where the mouse is pointing and
      then set the tooltip dynamically.
      '''
      >
      # Use CalcUnscrolledP osition() to get the mouse position
      within the
      # entire grid including what's offscreen
      x, y =
      self.totals_she et.CalcUnscroll edPosition(even t.GetX(),event. GetY())
      >
      coords = self.totals_she et.XYToCell(x, y)
      # you only need these if you need the value in the cell
      row = coords[0]
      col = coords[1]
      event.GetEventO bject().SetTool TipString("My amazing tooltip")
      >
      </code>
      >
      Hopefully that will get you going. If not, just ask more questions
      (here or at the wxPython list).
      >
      -------------------
      Mike Driscoll
      >
      Blog: http://blog.pythonlibrary.org
      Python Extension Building Network: http://www.pythonlibrary.org
      That's exactly what I needed, thank you!

      Comment

      Working...