Skip to content

Commit 2810f61

Browse files
Merge pull request #1863 from HelioGuilherme66/pre_release_win
Cell Sizes fixes
2 parents 15f9f82 + 8ccfeb8 commit 2810f61

File tree

9 files changed

+161
-109
lines changed

9 files changed

+161
-109
lines changed

src/robotide/contrib/testrunner/testrunner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363

6464
ATEXIT_LOCK = threading.RLock()
6565

66-
6766
# Solution from https://stackoverflow.com/questions/10009753/python-dealing-with-mixed-encoding-files
6867
def mixed_decoder(unicodeError):
6968
errStr = unicodeError[1]
@@ -296,7 +295,7 @@ def _write_argfile(argfile, args):
296295
f = codecs.open(argfile, "wb")
297296
for item in args:
298297
if is_unicode(item):
299-
enc_arg = item.encode(encoding.OUTPUT_ENCODING)
298+
enc_arg = item.encode(encoding.CONSOLE_ENCODING) # DEBUG .OUTPUT_ENCODING)
300299
else:
301300
enc_arg = item
302301
f.write(enc_arg+"\n")

src/robotide/contrib/testrunner/testrunnerplugin.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,9 @@ def _format_command(self, argv):
488488
"""
489489
result = []
490490
for arg in argv:
491-
# if PY2 and is_unicode(arg):
492-
# arg = arg.encode(encoding.OUTPUT_ENCODING) # DEBUG "utf-8")
491+
if PY2 and is_unicode(arg):
492+
arg = arg.encode(encoding.CONSOLE_ENCODING) # DEBUG "utf-8")
493+
# print("DEBUG: PY2 unicode args %s" % arg)
493494
if "'" in arg or " " in arg or "&" in arg:
494495
# for windows, if there are spaces we need to use
495496
# double quotes. Single quotes cause problems
@@ -521,14 +522,20 @@ def _AppendText(self, textctrl, string, source="stdout"):
521522
try:
522523
if PY2:
523524
# textctrl.AppendText(string.encode(encoding.OUTPUT_ENCODING)) # DEBUG encoding.CONSOLE_ENCODING)) # DEBUG 'utf-8'))
524-
textctrl.AppendText(string.encode('utf-8')) # encoding.SYSTEM_ENCODING))
525+
textctrl.AppendText(string.encode(encoding.SYSTEM_ENCODING)) # encoding.SYSTEM_ENCODING)) 'utf-8'
525526
else:
526527
textctrl.AppendText(str(string)) # DEBUG
527528
except UnicodeDecodeError as e:
528529
# I'm not sure why I sometimes get this, and I don't know what I
529530
# can do other than to ignore it.
530531
textctrl.AppendTextRaw(bytes(string)) # DEBUG .encode('utf-8'))
531-
# print("DEBUG UnicodeDecodeError appendtext string=%s\n" % string)
532+
# print(r"DEBUG UnicodeDecodeError appendtext string=%s\n" % string)
533+
pass
534+
except UnicodeEncodeError as e:
535+
# I'm not sure why I sometimes get this, and I don't know what I
536+
# can do other than to ignore it.
537+
textctrl.AppendText(string.encode('utf-8')) # DEBUG .encode('utf-8'))
538+
# print(r"DEBUG UnicodeDecodeError appendtext string=%s\n" % string)
532539
pass
533540
# raise # DEBUG
534541

src/robotide/editor/cellrenderer.py

100644100755
Lines changed: 49 additions & 25 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,35 +89,27 @@ 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-
if len(text) > 0:
65-
w_sz = w * len(text) + 2 * w
66-
else:
67-
return wx.Size(2 * w, h) # self.default_width
92+
if len(text) == 0:
93+
return dc.GetTextExtent(" ") # self.default_width
6894

95+
w, h = dc.GetTextExtent(text)
6996
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
97+
col_width = min(w, self.max_width)
7398
else:
74-
col_width = min(w_sz, self.default_width)
75-
99+
col_width = min(w, self.default_width)
100+
row_height = h
76101
if self.word_wrap:
77-
text = wordwrap.wordwrap(text, col_width, dc, breakLongWords=False,
78-
margin=margin)
102+
suggest_width = max(grid.GetColSize(col), col_width)
103+
text = self._wordwrap(text, suggest_width, dc, breakLongWords=False)
79104
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)
105+
row_height = h
106+
if self.auto_fit:
107+
col_width = min(w, col_width)
108+
else:
109+
col_width = min(w, self.default_width)
110+
# do not shrink col size (subtract col margin which is 10 pixels )
111+
col_width = max(grid.GetColSize(col) - 10, col_width)
112+
return wx.Size(col_width, row_height)
89113

90114
def Clone(self): # real signature unknown; restored from __doc__
91115
""" 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/customsourceeditor.py

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def SetUpEditor(self):
491491

492492
# Global default style
493493
if wx.Platform == '__WXMSW__':
494-
print("DEBUG: Setup on Windows")
494+
# print("DEBUG: Setup on Windows")
495495
self.StyleSetSpec(stc.STC_STYLE_DEFAULT,
496496
'fore:#000000,back:#FFFFFF,face:Space Mono') # Courier New')
497497
elif wx.Platform == '__WXMAC__':
@@ -584,16 +584,17 @@ class CodeEditorPanel(wx.Panel):
584584
"""Panel for the 'Code Editor' tab"""
585585
def __init__(self, parent, mainFrame, path=None):
586586
self.log = sys.stdout # From FileDialog
587+
self.path = path
587588
wx.Panel.__init__(self, parent, size=(1,1))
588589
self.mainFrame = mainFrame
589590
self.editor = SourceCodeEditor(self)
590591
self.editor.RegisterModifiedEvent(self.OnCodeModified)
591592

592593
self.btnSave = wx.Button(self, -1, "Save Changes")
593-
self.btnRestore = wx.Button(self, -1, "Delete Modified")
594+
# self.btnRestore = wx.Button(self, -1, "Delete Modified")
594595
self.btnSave.Enable(False)
595596
self.btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
596-
self.btnRestore.Bind(wx.EVT_BUTTON, self.OnRestore)
597+
# self.btnRestore.Bind(wx.EVT_BUTTON, self.OnRestore)
597598

598599
# From FileDialog
599600
self.btnOpen = wx.Button(self, -1, "Open...")
@@ -615,7 +616,7 @@ def __init__(self, parent, mainFrame, path=None):
615616
radioButton.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton)
616617

617618
self.controlBox.Add(self.btnSave, 0, wx.RIGHT, 5)
618-
self.controlBox.Add(self.btnRestore, 0, wx.RIGHT, 5)
619+
# self.controlBox.Add(self.btnRestore, 0, wx.RIGHT, 5)
619620
self.controlBox.Add(self.btnOpen, 0, wx.RIGHT, 5)
620621
self.controlBox.Add(self.btnSaveAs, 0)
621622

@@ -626,8 +627,9 @@ def __init__(self, parent, mainFrame, path=None):
626627

627628
self.box.Fit(self)
628629
self.SetSizer(self.box)
629-
if path:
630-
self.LoadFile(path)
630+
if self.path:
631+
# print("DEBUG: path is init = %s" % self.path)
632+
self.LoadFile(self.path)
631633

632634
def LoadFile(self, path):
633635
# Open
@@ -691,19 +693,26 @@ def ReloadDemo(self):
691693
def OnCodeModified(self, event):
692694
self.btnSave.Enable(self.editor.IsModified())
693695

694-
def OnSave(self, modifiedFilename):
695-
if os.path.isfile(modifiedFilename):
696-
overwriteMsg = "You are about to overwrite an existing file\n" + \
697-
"Do you want to continue?"
698-
dlg = wx.MessageDialog(self, overwriteMsg, "Editor Writer",
699-
wx.YES_NO | wx.NO_DEFAULT| wx.ICON_EXCLAMATION)
700-
result = dlg.ShowModal()
701-
if result == wx.ID_NO:
702-
return
703-
dlg.Destroy()
696+
def OnSave(self, event, path=None):
697+
if self.path is None:
698+
self.path = "noname"
699+
self.OnButton2(event)
700+
return
701+
# print("DEBUG: OnSave path is init = %s passado %s" % (self.path, path))
702+
if path:
703+
if path != self.path and os.path.isfile(path):
704+
overwriteMsg = "You are about to overwrite an existing file\n" + \
705+
"Do you want to continue?"
706+
dlg = wx.MessageDialog(self, overwriteMsg, "Editor Writer",
707+
wx.YES_NO | wx.NO_DEFAULT| wx.ICON_EXCLAMATION)
708+
result = dlg.ShowModal()
709+
if result == wx.ID_NO:
710+
return
711+
dlg.Destroy()
712+
self.path = path
704713

705714
# Save
706-
f = open(modifiedFilename, "wb")
715+
f = open(self.path, "wb")
707716
source = self.editor.GetTextRaw()
708717
# print("DEBUG: Test is Unicode %s",isUTF8Strict(source))
709718
if isUTF8Strict(source):
@@ -723,23 +732,8 @@ def OnSave(self, modifiedFilename):
723732
f.write(''.join(data))
724733
finally:
725734
f.close()
726-
# idx = 0
727-
# while source[idx]:
728-
# try:
729-
# s = bytes(source[idx:-1].encoding('UTF-8'))
730-
# bsource.append(s)
731-
# idx += len(s)
732-
# except:
733-
# print("DEBUG: index=%d" % idx)
734-
# idx += 1
735-
# bsource.append(source[idx])
736-
# try:
737-
# f.write(bsource)
738-
# print("DEBUG: Saved bytes")
739-
# finally:
740-
# f.close()
741-
742-
# busy = wx.BusyInfo("Reloading Code module...")
735+
736+
# busy = wx.BusyInfo("Reloading Code module...")
743737
# self.CodeModules.LoadFromFile(modModified, modifiedFilename)
744738
#self.ActiveModuleChanged()
745739

@@ -766,9 +760,13 @@ def OnButton(self, evt):
766760
#
767761
# Finally, if the directory is changed in the process of getting files, this
768762
# dialog is set up to change the current working directory to the path chosen.
763+
if self.path:
764+
cwd = os.path.dirname(self.path)
765+
else:
766+
cwd = os.getcwd()
769767
dlg = wx.FileDialog(
770768
self, message="Choose a file",
771-
defaultDir=os.getcwd(),
769+
defaultDir=cwd,
772770
defaultFile="",
773771
wildcard=wildcard,
774772
style=wx.FD_OPEN |
@@ -796,6 +794,8 @@ def OnButton(self, evt):
796794
finally:
797795
f.close()
798796

797+
# store the new path
798+
self.path = path
799799
# self.log.write('%s\n' % source)
800800
self.LoadSource(source) # Just the last file
801801
# Compare this with the debug above; did we change working dirs?
@@ -817,9 +817,16 @@ def OnButton2(self, evt):
817817
# Unlike the 'open dialog' example found elsewhere, this example does NOT
818818
# force the current working directory to change if the user chooses a different
819819
# directory than the one initially set.
820+
fname = ""
821+
if self.path:
822+
cwd = os.path.dirname(self.path)
823+
fname = os.path.basename(self.path)
824+
else:
825+
cwd = os.getcwd()
826+
self.path = "noname"
820827
dlg = wx.FileDialog(
821-
self, message="Save file as ...", defaultDir=os.getcwd(),
822-
defaultFile="", wildcard=wildcard, style=wx.FD_SAVE
828+
self, message="Save file as ...", defaultDir=cwd,
829+
defaultFile=fname, wildcard=wildcard, style=wx.FD_SAVE
823830
) # | wx.FD_OVERWRITE_PROMPT
824831

825832
# This sets the default filter that the user will initially see. Otherwise,
@@ -846,7 +853,9 @@ def OnButton2(self, evt):
846853
#
847854
# You might want to add some error checking :-)
848855
#
849-
self.OnSave(path)
856+
# store the new path
857+
# self.path = path
858+
self.OnSave(evt, path)
850859
# Note that the current working dir didn't change. This is good since
851860
# that's the way we set it up.
852861
# self.log.WriteText("CWD: %s\n" % os.getcwd())

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)

0 commit comments

Comments
 (0)