Bug in SetToolTipString: '\n' is not always displayed ?

Hi Guys,

I think I may have found a bug in tooltips.
I’ve modified a demo that Mike Driscoll created to demonstrate that ‘\n’ is not always displayed in tooltips:

If I run (the attached) grid_header_tooltip_example_01.py with line 77 commented out (as seen below) then even though tool_tips[1] includes a ‘\n’, the tooltip for the second column is displayed on only one line.

71          displayed to give the user more information about what data should
72          go into that specific column
73          '''
74          pos = event.GetX()
75          print pos
76
77          #tool_tips = ('This is the \nFirst Column', 'This is the \nSecond Column')
78          tool_tips = ('This is the First Column', 'This is the \nSecond Column')
79          if pos > 0 and pos < 80:
80              self.grid.GetGridColLabelWindow().SetToolTipString(tool_tips[0])

Outlook.jpg

However, if I run grid_header_tooltip_example_01.py where line 78 is commented out, I get the expected behaviour:

71          displayed to give the user more information about what data should
72          go into that specific column
73          '''
74          pos = event.GetX()
75          print pos
76
77          tool_tips = ('This is the \nFirst Column', 'This is the \nSecond Column')
78          #tool_tips = ('This is the First Column', 'This is the \nSecond Column')
79          if pos > 0 and pos < 80:
80              self.grid.GetGridColLabelWindow().SetToolTipString(tool_tips[0])

Outlook.jpg

The frustrating thing is that this bug is not consistent!
It sometimes would not be manifested, and I cannot create a demo that will always show this buggy behaviour.

I use Python 2.5.2 on Windows XP (and cygwin).

Any help in resolving this bug is appreciated.

Bye,
Ron.

image001.jpg

image003.jpg

grid_header_tooltip_example_01.py (3.13 KB)

···

 1  import wx
 2  import wx.grid as  gridlib
 3
 4  class EditorsAndRenderersGrid(gridlib.Grid):
 5      def __init__(self, parent):
 6          gridlib.Grid.__init__(self, parent, -1)
 7          renCol = 1
 8          edCol = 1
 9
10          self.CreateGrid(25, 8)
11
12          editorDemoData = [('GridCellChoiceEditor', 'one',
13                            gridlib.GridCellChoiceEditor,
14                            (['one', 'two', 'three', 'four',
15                              'kick', 'Microsoft', 'out the',
16                              'door'],
17                             False))]
18          row = 2
19          for label, value, editorClass, args in editorDemoData:
20              editor = editorClass(*args)
21              self.SetCellValue(row, edCol, label)
22              self.SetCellValue(row, edCol+1, value)
23              self.SetCellEditor(row, edCol+1, editor)
24              row = row + 2
25          self.editor = editor
26          print dir(self.editor)
27          control = self.editor.GetControl()
28          print type(control)
29          print dir(control)
30
31          self.Bind(gridlib.EVT_GRID_SELECT_CELL, self.onSelectCell)
32
33      def onSelectCell(self, event):
34          print "cell selected!"
35          row = event.GetRow()
36          event.Skip()
37          self.SelectRow(row)
38         
39      def OnLeftDClick(self, event):
40          print dir(self.editor)
41
42  class MyForm(wx.Frame):
43  
44      def __init__(self):
45          wx.Frame.__init__(self, None, wx.ID_ANY, "Simple Grid")
46  
47          # Add a panel so it looks the correct on all platforms
48          panel = wx.Panel(self, wx.ID_ANY)
49          self.tooltip  = ''
50
51          txt = wx.TextCtrl(panel)
52          btn = wx.Button(panel, label="Press Me")
53          self.grid = EditorsAndRenderersGrid(panel)
54          self.grid.GetGridColLabelWindow().Bind(wx.EVT_MOTION, self.onMouseOver)
55         
56          vSizer = wx.BoxSizer(wx.VERTICAL)
57          hSizer = wx.BoxSizer(wx.HORIZONTAL)
58
59          hSizer.Add(txt, 0, wx.ALL, 5)
60          hSizer.Add((200,5), 1, wx.EXPAND)
61          hSizer.Add(btn, 0, wx.ALL|wx.ALIGN_RIGHT, 5)
62
63          vSizer.Add(hSizer, 0, wx.EXPAND)
64          vSizer.Add(self.grid, 1, wx.EXPAND, 5)
65         
66          panel.SetSizer(vSizer)
67
68      def onMouseOver(self, event):
69          '''
70          When the mouse is hovered over certain columns, a tooltip will be
71          displayed to give the user more information about what data should
72          go into that specific column
73          '''
74          pos = event.GetX()
75          print pos
76
77          #tool_tips = ('This is the \nFirst Column', 'This is the \nSecond Column')
78          tool_tips = ('This is the First Column', 'This is the \nSecond Column')
79          if pos > 0 and pos < 80:
80              self.grid.GetGridColLabelWindow().SetToolTipString(tool_tips[0])
81              self.tooltip = 'This is the First Column'
82          elif pos > 80 and pos < 160:
83              self.grid.GetGridColLabelWindow().SetToolTipString(tool_tips[1])
84              self.tooltip = 'This is the Second Column'
85          else:
86              if self.tooltip != '':
87                  self.grid.GetGridColLabelWindow().SetToolTipString('')
88                  self.tooltip = ''
89          event.Skip()
90
91             
92
93  # Run the program
94  if __name__ == "__main__":
95      app = wx.PySimpleApp()
96      frame = MyForm().Show()
97      app.MainLoop()
98