Skip to content

Commit e5925e1

Browse files
Merge branch 'grid_sizes_fixes' into pre_release_win
2 parents 4cba95a + 7985e13 commit e5925e1

File tree

11 files changed

+115
-93
lines changed

11 files changed

+115
-93
lines changed

.whitesource

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
##########################################################
2+
#### WhiteSource Integration configuration file ####
3+
##########################################################
4+
5+
# Configuration #
6+
#---------------#
7+
ws.repo.scan=true
8+
vulnerable.check.run.conclusion.level=failure

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
SOURCE_DIR = 'src'
2525
REQUIREMENTS = ['wxPython']
2626

27+
#Windows specific requirements
2728
if sys.platform == 'win32':
2829
REQUIREMENTS.append('Pywin32')
2930

@@ -62,7 +63,9 @@ class CustomInstallCommand(install):
6263
def run(self):
6364
install.run(self)
6465
_ = sys.stderr.write("Creating Desktop Shortcut to RIDE...\n")
65-
os.system(sys.executable + " -m robotide.postinstall -install")
66+
postinstaller_file = join(ROOT_DIR, 'src', 'robotide', 'postinstall', '__main__.py')
67+
command = sys.executable + " " +postinstaller_file + " -install"
68+
os.system(command)
6669

6770
setup(
6871
name='robotframework-ride',

src/robotide/contrib/testrunner/TestRunnerAgent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,9 @@ def __init__(self, pause_on_failure=False):
295295

296296
@staticmethod
297297
def is_breakpoint(name, attrs):
298-
return name == 'BuiltIn.Comment' and\
299-
str(attrs['args'][0]).upper().startswith(u"PAUSE")
298+
if len(attrs['args']) > 0:
299+
return name == 'BuiltIn.Comment' and \
300+
str(attrs['args'][0]).upper().startswith(u"PAUSE")
300301

301302
def pause(self):
302303
self._resume.clear()

src/robotide/editor/cellrenderer.py

100644100755
Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,42 @@ def __init__(self, default_width, max_width, auto_fit, word_wrap=True):
3030
self.auto_fit = auto_fit
3131
self.word_wrap = word_wrap
3232

33+
def _wordwrap(self, text, width, dc, breakLongWords=True, margin=0):
34+
''' modification of ofiginal wordwrap function without extra space'''
35+
wrapped_lines = []
36+
text = text.split('\n')
37+
for line in text:
38+
pte = dc.GetPartialTextExtents(line)
39+
wid = (width - (2 * margin + 1) * dc.GetTextExtent(' ')[0])
40+
idx = 0
41+
start = 0
42+
startIdx = 0
43+
spcIdx = -1
44+
while idx < len(pte):
45+
# remember the last seen space
46+
if line[idx] == ' ':
47+
spcIdx = idx
48+
49+
# have we reached the max width?
50+
if pte[idx] - start > wid and (spcIdx != -1 or breakLongWords):
51+
if spcIdx != -1:
52+
idx = min(spcIdx + 1, len(pte) - 1)
53+
wrapped_lines.append(' ' * margin + line[startIdx: idx] + ' ' * margin)
54+
start = pte[idx]
55+
startIdx = idx
56+
spcIdx = -1
57+
58+
idx += 1
59+
60+
wrapped_lines.append(' ' * margin + line[startIdx: idx] + ' ' * margin)
61+
62+
return '\n'.join(wrapped_lines)
63+
3364
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
3465
text = grid.GetCellValue(row, col)
3566
dc.SetFont(attr.GetFont())
36-
text = wordwrap.wordwrap(text, grid.GetColSize(col), dc, breakLongWords=False)
67+
suggest_width = grid.GetColSize(col)
68+
text = self._wordwrap(text, suggest_width, dc, breakLongWords=False)
3769
hAlign, vAlign = attr.GetAlignment()
3870
if isSelected:
3971
bg = grid.GetSelectionBackground()
@@ -57,39 +89,30 @@ def GetBestSize(self, grid, attr, dc, row, col):
5789
_font = attr.GetFont()
5890
dc.SetFont(_font)
5991

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-
h = max(h, 8) # Probably h==0 on MSW, w==0 means width auto
65-
w = max(w, 8)
66-
if len(text) > 0:
67-
w_sz = w * len(text) # + 2 * w
68-
else:
69-
return wx.Size(w, h) # self.default_width
92+
if len(text) == 0:
93+
return dc.GetTextExtent(" ") # self.default_width
7094

71-
if self.auto_fit:
72-
col_width = min(w_sz, col_width)
73-
if col_width > self.max_width:
74-
col_width = self.max_width
75-
else:
76-
col_width = min(w_sz, self.default_width)
95+
w, h = dc.GetTextExtent(text)
7796

7897
if self.word_wrap:
79-
text = wordwrap.wordwrap(text, col_width, dc, breakLongWords=False,
80-
margin=margin)
98+
if self.auto_fit:
99+
col_width = min(w, self.max_width)
100+
else:
101+
col_width = min(w, self.default_width)
102+
suggest_width = grid.GetColSize(col)
103+
text = self._wordwrap(text, suggest_width, dc, breakLongWords=False)
81104
w, h = dc.GetMultiLineTextExtent(text)
82-
h = max(h, 8) # Probably h==0 on MSW, w==0 means width auto
83-
w = max(w, 8)
105+
row_height = h
84106
else:
85-
w = col_width
107+
row_height = h
86108
if self.auto_fit:
87-
if w_sz > self.max_width:
88-
w_sz = self.max_width
89-
w = max(w, w_sz)
109+
col_width = min(w, self.max_width)
90110
else:
91-
return wx.Size(self.default_width, h)
92-
return wx.Size(w, h)
111+
col_width = grid.GetColSize(col)
112+
113+
# do not shrink col size (subtract col margin which is 10 pixels )
114+
col_width = max(grid.GetColSize(col) - 10, col_width)
115+
return wx.Size(col_width, row_height)
93116

94117
def Clone(self): # real signature unknown; restored from __doc__
95118
""" Clone(self) -> GridCellRenderer """

src/robotide/editor/contentassist.py

100644100755
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, suggestion_source):
3838
self.Bind(wx.EVT_KEY_DOWN, self.OnChar)
3939
self.Bind(wx.EVT_KILL_FOCUS, self.OnFocusLost)
4040
self.Bind(wx.EVT_MOVE, self.OnFocusLost)
41+
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
4142
self._showing_content_assist = False
4243
self._row = None
4344
self.gherkin_prefix = '' # Store gherkin prefix from input to add \
@@ -91,8 +92,8 @@ def _variable_creator_value(self, value, symbol, from_, to_):
9192
return value[:from_]+symbol+'{'+value[from_:to_]+'}'+value[to_:]
9293

9394
def OnFocusLost(self, event, set_value=True):
95+
event.Skip()
9496
if not self._popup.is_shown():
95-
event.Skip()
9697
return
9798
if self.gherkin_prefix:
9899
value = self.gherkin_prefix + self._popup.get_value() or self.GetValue()
@@ -104,7 +105,12 @@ def OnFocusLost(self, event, set_value=True):
104105
else:
105106
self.Clear()
106107
self.hide()
107-
event.Skip()
108+
109+
def OnDestroy(self, event):
110+
# all pushed eventHandlers need to be popped before close
111+
# the last event handler is window object itself - do not pop itself
112+
while self.GetEventHandler() is not self:
113+
self.PopEventHandler()
108114

109115
def reset(self):
110116
self._popup.reset()

src/robotide/editor/gridbase.py

100644100755
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def _bind_to_events(self):
4242
self.Bind(grid.EVT_GRID_SELECT_CELL, self.OnSelectCell)
4343
self.Bind(grid.EVT_GRID_RANGE_SELECT, self.OnRangeSelect)
4444
self.Bind(grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnCellRightClick)
45-
self.Bind(grid.EVT_GRID_CMD_COL_SIZE, self.OnCellColSizeChanged)
4645

4746
def register_context_menu_hook(self, callable):
4847
self._popup_creator.add_hook(callable)
@@ -159,8 +158,8 @@ def _write_data(self, data, update_history=True):
159158
for row_index, row_data in enumerate(data):
160159
for col_index, cell_value in enumerate(row_data):
161160
self.write_cell(row_index, col_index, cell_value, update_history)
162-
self.AutoSizeColumns()
163-
self.AutoSizeRows()
161+
# self.AutoSizeColumns()
162+
# self.AutoSizeRows()
164163
self.EndBatch()
165164

166165
def OnSelectCell(self, event):
@@ -195,11 +194,6 @@ def OnCellRightClick(self, event):
195194
self._popup_creator.show(self, PopupMenuItems(self, self._popup_items),
196195
self.get_selected_content())
197196

198-
def OnCellColSizeChanged(self, event):
199-
self.ForceRefresh()
200-
self.AutoSizeRows()
201-
event.Skip()
202-
203197
# TODO This code is overriden at fieldeditors
204198
def OnInsertCells(self, event):
205199
self._insert_or_delete_cells(self._insert_cells, event)

src/robotide/editor/gridcolorizer.py

100644100755
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,16 @@ def close(self):
3434

3535
def colorize(self, selection_content):
3636
self._current_task_id += 1
37-
if self._timer is None:
38-
self._timer = wx.CallLater(1, self._coloring_task, self._current_task_id, selection_content)
39-
else:
40-
self._timer.Restart(50, self._current_task_id, selection_content)
37+
self._coloring_task(selection_content)
4138

42-
def _coloring_task(self, task_index, selection_content, row=0, col=0):
43-
# Since this is a callback in CallLater, the grid might have
44-
# been destroyed e.g. when changing tree nodes. In this case
45-
# self._grid points to a PyDeadObject, which is Falsy.
46-
if task_index != self._current_task_id or not(self._grid):
47-
return
39+
def _coloring_task(self, selection_content, row=0, col=0):
4840
if row >= self._grid.NumberRows:
4941
self._grid.ForceRefresh()
50-
self._grid.AutoSizeRows()
5142
elif col < self._grid.NumberCols:
5243
self._colorize_cell(row, col, selection_content)
53-
wx.CallAfter(self._coloring_task, task_index, selection_content, row, col+1)
44+
self._coloring_task(selection_content, row, col+1)
5445
else:
55-
self._coloring_task(task_index, selection_content, row+1, 0)
46+
self._coloring_task(selection_content, row+1, 0)
5647

5748
def _colorize_cell(self, row, col, selection_content):
5849
cell_info = self._controller.get_cell_info(row, col)

src/robotide/editor/kweditor.py

100644100755
Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def __init__(self, parent, controller, tree):
113113
self._marked_cell = None
114114
self._make_bindings()
115115
self._write_steps(self._controller)
116+
self.autosize()
116117
self._tree = tree
117118
self._has_been_clicked = False
118119
self._counter = 0 # Workaround for double delete actions
@@ -145,7 +146,16 @@ def _set_cells(self):
145146
CellRenderer(col_size, max_col_size, auto_col_size, word_wrap))
146147
self.SetRowLabelSize(wx.grid.GRID_AUTOSIZE)
147148
self.SetColLabelSize(0)
148-
self.SetDefaultColSize(col_size, resizeExistingCols=True)
149+
if not auto_col_size and not word_wrap:
150+
self.SetDefaultColSize(col_size, resizeExistingCols=True)
151+
else:
152+
self.SetDefaultColSize(wx.grid.GRID_AUTOSIZE, resizeExistingCols=True)
153+
154+
if auto_col_size:
155+
self.Bind(grid.EVT_GRID_CMD_COL_SIZE, self.OnCellColSizeChanged)
156+
else:
157+
self.Unbind(grid.EVT_GRID_CMD_COL_SIZE)
158+
149159
if word_wrap:
150160
self.SetDefaultRowSize(wx.grid.GRID_AUTOSIZE)
151161
self.SetDefaultCellOverflow(False) # DEBUG
@@ -195,15 +205,15 @@ def OnSettingsChanged(self, data):
195205
'''Redraw the colors if the color settings are modified'''
196206
section, setting = data.keys
197207
if section == 'Grid':
198-
if 'text' in setting or 'background' in setting:
199-
self._colorize_grid()
200-
elif 'font' in setting:
208+
if 'font' in setting:
201209
self._set_fonts(update_cells=True)
202210
elif ('col size' in setting
203211
or 'max col size' in setting
204-
or 'auto size cols' in setting):
212+
or 'auto size cols' in setting
213+
or 'word wrap' in setting):
205214
self._set_cells()
206-
self.ForceRefresh()
215+
self._colorize_grid()
216+
self.autosize()
207217

208218
def OnSelectCell(self, event):
209219
self._cell_selected = True
@@ -375,7 +385,11 @@ def _colorize_grid(self):
375385
self._parent.highlight(selection_content, expand=False)
376386

377387
def highlight(self, text, expand=True):
378-
self._colorizer.colorize(text)
388+
wx.CallAfter(self._colorizer.colorize, text)
389+
390+
def autosize(self):
391+
wx.CallAfter(self.AutoSizeColumns, False)
392+
wx.CallAfter(self.AutoSizeRows, False)
379393

380394
def _get_single_selection_content_or_none_on_first_call(self):
381395
if self._cell_selected:
@@ -395,6 +409,8 @@ def _format_comments(self, data):
395409

396410
def cell_value_edited(self, row, col, value):
397411
self._execute(ChangeCellValue(row, col, value))
412+
wx.CallAfter(self.AutoSizeColumn, col, False)
413+
wx.CallAfter(self.AutoSizeRow, row, False)
398414

399415
def get_selected_datafile_controller(self):
400416
return self._controller.datafile_controller
@@ -529,8 +545,7 @@ def OnKeyDown(self, event):
529545
# print("DEBUG: key pressed " + str(keycode) + " + " + str(control_down))
530546
# event.Skip() # DEBUG seen this skip as soon as possible
531547
if keycode == wx.WXK_CONTROL or \
532-
(keycode == ord('M') and (
533-
control_down or event.AltDown())): # keycode == wx.WXK_CONTROL
548+
(keycode == ord('M') and (control_down or event.AltDown())): # keycode == wx.WXK_CONTROL
534549
self.show_cell_information()
535550
elif keycode == ord('C') and control_down:
536551
# print("DEBUG: captured Control-C\n")
@@ -548,14 +563,14 @@ def OnKeyDown(self, event):
548563
event.Skip()
549564
elif event.AltDown() and keycode == wx.WXK_RETURN:
550565
self._move_cursor_down(event)
551-
# event.Skip() #DEBUG was moving down 2 rows
566+
# event.Skip()
552567
elif keycode == wx.WXK_WINDOWS_MENU:
553568
self.OnCellRightClick(event)
554569
elif keycode in [wx.WXK_RETURN, wx.WXK_BACK]:
555570
if _iscelleditcontrolshown:
556571
self.save()
557-
# event.Skip() #DEBUG was moving left and down with RETURN
558572
self._move_grid_cursor(event, keycode)
573+
# event.Skip()
559574
elif (control_down or event.AltDown()) and \
560575
keycode == wx.WXK_SPACE: # Avoid Mac CMD
561576
self._open_cell_editor_with_content_assist()
@@ -681,6 +696,10 @@ def OnCellRightClick(self, event):
681696
def OnSelectAll(self, event):
682697
self.SelectAll()
683698

699+
def OnCellColSizeChanged(self, event):
700+
wx.CallAfter(self.AutoSizeRows, False)
701+
event.Skip()
702+
684703
def OnCellLeftClick(self, event):
685704
self._tooltips.hide()
686705
# if event.GetModifiers() == wx.MOD_CONTROL:

src/robotide/editor/settingeditors.py

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,12 @@ def _mainframe_has_focus(self):
142142

143143
def OnWindowDestroy(self, event):
144144
self._stop_popup_timer()
145+
self._tooltip.hide()
145146
event.Skip()
146147

147148
def OnLeaveWindow(self, event):
148149
self._stop_popup_timer()
150+
self._tooltip.hide()
149151
event.Skip()
150152

151153
def OnPopupTimer(self, event):

src/robotide/postinstall/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def verify_install():
4545
"or pip install wxPython")
4646
return False
4747
else:
48-
sys.stderr.write("wxPython is installed.\n%s" % version())
48+
sys.stderr.write("wxPython is installed.\n%s\n" % version())
4949
return True
5050

5151

0 commit comments

Comments
 (0)