Skip to content

Commit df877d7

Browse files
2Eagle2HelioGuilherme66
authored andcommitted
fix cells size in Grid editor (#1848)
* fix contents Assistant to restore original cell value after hitting ESC * Wip fix win encoding (#1838) * Adds DEBUG for encoding, Chinese test OK in Linux * Fixed latin filenames or directories. * WIP try to fix non-unicode tags in python 2.7 * WIP fix latin chars tags * Clean up DEBUGs. All OK in Linux * Runs OK with python3 on Windows with directories with chinese or latin chars * fix bug when tooltip window from grid editor show on different tab after switch * improve contentassist handling * improve keyword information showing (work on single crtl hodl + hovering through grid cells) but the ctrl + m still persist * remove debug log * fix - pass RETURN key to contentAssist for selecting keyword from list * fix idle event return -1 error in some cases (window destroy events should be always skipped to properly disable all idle events / callLater events ) * fix contents Assistant to restore original cell value after hitting ESC * fix bug when tooltip window from grid editor show on different tab after switch * improve contentassist handling * improve keyword information showing (work on single crtl hodl + hovering through grid cells) but the ctrl + m still persist * remove debug log * fix - pass RETURN key to contentAssist for selecting keyword from list * fix idle event return -1 error in some cases (window destroy events should be always skipped to properly disable all idle events / callLater events ) * fix non invokable content assist while editing cell in grid editor * add custom cellrenderer for managing cell size and autoresize * allov to delete whole field in setting editor to write new num from scratch * small clean-ups in renderer * fix GridEditor to work also with FieldEditor with new renderer made some clean-ups * Fix movement of Cell Cursor with Return and Backscape Changes in AutoCol resize and Fixed Size (need comments from 2Eagle2) * Ajustments to auto col fit. Added Copyright. * Settings to have word wrap and row height auto adjusted. * improve keyword information showing (work on single crtl hodl + hovering through grid cells) but the ctrl + m still persist * add custom cellrenderer for managing cell size and autoresize * allov to delete whole field in setting editor to write new num from scratch * small clean-ups in renderer * fix GridEditor to work also with FieldEditor with new renderer made some clean-ups * Fix movement of Cell Cursor with Return and Backscape Changes in AutoCol resize and Fixed Size (need comments from 2Eagle2) * Ajustments to auto col fit. Added Copyright. * Settings to have word wrap and row height auto adjusted.
1 parent cee74d4 commit df877d7

File tree

9 files changed

+1611
-88
lines changed

9 files changed

+1611
-88
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright 2019- Robot Framework Foundation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from wx.lib import wordwrap
16+
import wx.grid
17+
18+
19+
class CellRenderer(wx.grid.GridCellRenderer):
20+
"""
21+
GridCellAutoWrapStringRenderer()
22+
23+
This class may be used to format string data in a cell.
24+
"""
25+
26+
def __init__(self, default_width, max_width, auto_fit, word_wrap=True):
27+
wx.grid.GridCellRenderer.__init__(self)
28+
self.default_width = default_width
29+
self.max_width = max_width
30+
self.auto_fit = auto_fit
31+
self.word_wrap = word_wrap
32+
33+
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
34+
text = grid.GetCellValue(row, col)
35+
dc.SetFont(attr.GetFont())
36+
text = wordwrap.wordwrap(text, grid.GetColSize(col), dc, breakLongWords=False)
37+
hAlign, vAlign = attr.GetAlignment()
38+
if isSelected:
39+
bg = grid.GetSelectionBackground()
40+
fg = grid.GetSelectionForeground()
41+
else:
42+
bg = attr.GetBackgroundColour()
43+
fg = attr.GetTextColour()
44+
dc.SetTextBackground(bg)
45+
dc.SetTextForeground(fg)
46+
dc.SetBrush(wx.Brush(bg, wx.SOLID))
47+
dc.SetPen(wx.TRANSPARENT_PEN)
48+
dc.DrawRectangle(rect)
49+
grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign)
50+
51+
def GetBestSize(self, grid, attr, dc, row, col):
52+
"""The width will be between values `col size` and `max col size`
53+
These can be changed in user preferences.
54+
"""
55+
text = grid.GetCellValue(row, col)
56+
57+
_font = attr.GetFont()
58+
dc.SetFont(_font)
59+
60+
col_width = grid.GetColSize(col)
61+
# margin = 2 # get border width into account when submitting optimal col size
62+
margin = 0
63+
w, h = _font.GetPixelSize()
64+
if len(text) > 0:
65+
w_sz = w * len(text) + 2 * w
66+
else:
67+
return wx.Size(2 * w, h) # self.default_width
68+
69+
if self.auto_fit:
70+
col_width = min(w_sz, col_width)
71+
if col_width > self.max_width:
72+
col_width = self.max_width
73+
else:
74+
col_width = min(w_sz, self.default_width)
75+
76+
if self.word_wrap:
77+
text = wordwrap.wordwrap(text, col_width, dc, breakLongWords=False,
78+
margin=margin)
79+
w, h = dc.GetMultiLineTextExtent(text)
80+
else:
81+
w = col_width
82+
if self.auto_fit:
83+
if w_sz > self.max_width:
84+
w_sz = self.max_width
85+
w = max(w, w_sz)
86+
else:
87+
return wx.Size(self.default_width, h)
88+
return wx.Size(w, h)
89+
90+
def Clone(self): # real signature unknown; restored from __doc__
91+
""" Clone(self) -> GridCellRenderer """
92+
return CellRenderer

0 commit comments

Comments
 (0)