Skip to content

Commit 5ab6d3b

Browse files
Improves color management in Panels and Help/Doc popups (#2566)
* Fix using defined color in help and HTML content * Fix persistance of color settings in File Explorer and Project Tree
1 parent 24346eb commit 5ab6d3b

File tree

8 files changed

+235
-200
lines changed

8 files changed

+235
-200
lines changed

CHANGELOG.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to http://semver.org/spec/v2.0.0.html[Semantic Versioni
1010

1111
== Fixed
1212

13+
-- Fixed selection and persistance of colors in File Explorer and Project Tree panels
14+
15+
-- Fixed not using defined color for help and HTML content
16+
1317
-- Fixed missing newlines in sections separation
1418

1519

src/robotide/application/releasenotes.py

Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os
18+
import re
19+
import time
1720
import wx
1821
from wx import Colour
1922
from wx.lib.ClickableHtmlWindow import PyClickableHtmlWindow
@@ -22,7 +25,8 @@
2225
from ..action import ActionInfo
2326
from ..version import VERSION
2427
from ..widgets import HtmlDialog
25-
# from ..widgets.htmlwnd import HTML_BACKGROUND
28+
29+
HTML_FOREGROUND = 'foreground text'
2630

2731

2832
class ReleaseNotes(object):
@@ -57,19 +61,30 @@ def show_if_updated(self):
5761
self.application.settings['version_shown'] = VERSION
5862

5963
def show(self, event=None):
64+
_ = event
6065
if not self._view:
6166
self._view = self._create_view()
6267
self.application.frame.notebook.AddPage(self._view, "Release Notes", select=False)
6368
self.application.frame.notebook.show_tab(self._view)
6469

6570
def show_changelog(self, event=None):
71+
_ = event
6672
if not self._dialog:
6773
self._dialog = HtmlDialog('Offline Change Log', f"Check the online version at https://github.com/"
6874
f"robotframework/RIDE/blob/v{VERSION}/CHANGELOG.adoc")
6975
self._dialog.SetSize(800, 800)
70-
self._dialog.html_wnd.LoadFile(join(dirname(abspath(__file__)), "CHANGELOG.html"))
76+
# DEBUG: If we LoadFile, we cannot change the foreground color
77+
# self._dialog.html_wnd.LoadFile(join(dirname(abspath(__file__)), "CHANGELOG.html"))
78+
with open(join(dirname(abspath(__file__)), "CHANGELOG.html"), 'r', encoding='utf-8') as change_log:
79+
content = change_log.read()
80+
fgcolor = self.general_settings[HTML_FOREGROUND]
81+
if isinstance(fgcolor, tuple):
82+
fgcolor = '#' + ''.join(hex(item)[2:] for item in fgcolor)
83+
new_content = content.replace("<body>", f'<body><div><font color="{fgcolor}">') \
84+
.replace("</body>", "</font></div></body>")
85+
self._dialog.html_wnd.SetPage(new_content)
7186
self._dialog.html_wnd.SetBackgroundColour(self.general_settings['background help'])
72-
self._dialog.html_wnd.SetForegroundColour(self.general_settings['foreground text'])
87+
self._dialog.html_wnd.SetForegroundColour(fgcolor)
7388
self._dialog.Show()
7489

7590
def bring_to_front(self):
@@ -80,35 +95,26 @@ def _create_view(self):
8095
panel = wx.Panel(self.application.frame.notebook)
8196
html_win = PyClickableHtmlWindow(panel, -1)
8297
html_win.SetStandardFonts()
83-
fgcolor = self.general_settings.get('foreground text', Colour(7, 0, 70))
84-
"""
85-
panel.SetBackgroundColour(Colour(200, 222, 40))
86-
"""
98+
fgcolor = self.general_settings.get(HTML_FOREGROUND, Colour(7, 0, 70))
8799
panel.SetForegroundColour(fgcolor)
88100
html_win.SetOwnForegroundColour(fgcolor)
89101
self.set_content(html_win, WELCOME_TEXT + RELEASE_NOTES)
90102
sizer = wx.BoxSizer(wx.VERTICAL)
91-
sizer.Add(html_win, 1, wx.EXPAND|wx.ALL, border=8)
103+
sizer.Add(html_win, 1, wx.EXPAND | wx.ALL, border=8)
92104
panel.SetSizer(sizer)
93105
return panel
94106

95107
def set_content(self, html_win, content):
96108
bkgcolor = self.general_settings.get('background help', Colour(240, 242, 80))
97-
fgcolor = self.general_settings.get('foreground text', Colour(7, 0, 70))
98-
# print(f"DEBUG: set_content bkg={bkgcolor} bkg={type(bkgcolor)} fg={fgcolor} fg={type(fgcolor)}")
99-
try:
100-
# tuple(bkgcolor)
101-
bcolor = ''.join(hex(item)[2:] for item in bkgcolor)
102-
fcolor = ''.join(hex(item)[2:] for item in fgcolor)
103-
_content = '<body "bgcolor=#%s;" "color=#%s;">%s</body>' % (bcolor, fcolor, content)
104-
# print(f"DEBUG: set_content after bkg={bcolor} bkg={type(bcolor)} fg={fcolor} fg={type(fcolor)}")
105-
except TypeError:
106-
_content = '<body bgcolor=%s>%s</body>' % (bkgcolor, content)
109+
fgcolor = self.general_settings.get(HTML_FOREGROUND, Colour(7, 0, 70))
110+
if isinstance(bkgcolor, tuple):
111+
bkgcolor = '#' + ''.join(hex(item)[2:] for item in bkgcolor)
112+
if isinstance(fgcolor, tuple):
113+
fgcolor = '#' + ''.join(hex(item)[2:] for item in fgcolor)
114+
_content = f'<body bgcolor="{bkgcolor}"><div><font color="{fgcolor}">' + content + "</font></div></body>"
107115
html_win.SetPage(_content)
108116

109117

110-
import time, os, re
111-
112118
date = time.strftime('%d/%m/%Y', time.localtime(os.path.getmtime(__file__)))
113119
version = VERSION
114120
milestone = re.split('[ab-]', VERSION)[0]
@@ -138,8 +144,11 @@ def set_content(self, html_win, content):
138144
<div class="document">
139145
140146
141-
<p><a class="reference external" href="https://github.com/robotframework/RIDE/">RIDE (Robot Framework IDE)</a> v{VERSION} is a new release with major enhancements and bug fixes.
142-
This version v{VERSION} includes removal of Python 2.7 support. The reference for valid arguments is <a class="reference external" href="http://robotframework.org">Robot Framework</a> installed version, which is at this moment 6.0.2. However, internal library is based on version 3.1.2, to keep compatibility with old formats.</p>
147+
<p><a class="reference external" href="https://github.com/robotframework/RIDE/">RIDE (Robot Framework IDE)</a>
148+
v{VERSION} is a new release with major enhancements and bug fixes.
149+
This version v{VERSION} includes removal of Python 2.7 support. The reference for valid arguments is
150+
<a class="reference external" href="http://robotframework.org">Robot Framework</a> installed version, which is at this
151+
moment 6.0.2. However, internal library is based on version 3.1.2, to keep compatibility with old formats.</p>
143152
<p></p>
144153
<ul class="simple">
145154
<li>This is the <strong>first version without support for Python 2.7</strong>.</li>
@@ -148,13 +157,16 @@ def set_content(self, html_win, content):
148157
<li>There are some important changes, or known issues:<ul>
149158
<li>On MacOS to call autocomplete in Grid and Text Editors, you have to use Alt-Space (not Command-Space).</li>
150159
<li>On Linux and Windows to call autocomplete in Grid and Text Editors, you have to use Ctrl-Space.</li>
151-
<li>On Text Editor the TAB key adds the defined number of spaces. With Shift moves to the left, and together with Control selects text.</li>
152-
<li>Text Editor also accepts the old <strong>: FOR</strong> loop structure, but recommended is <strong>FOR</strong> and <strong>END</strong>.</li>
160+
<li>On Text Editor the TAB key adds the defined number of spaces. With Shift moves to the left, and together with
161+
Control selects text.</li>
162+
<li>Text Editor also accepts the old <strong>: FOR</strong> loop structure, but recommended is <strong>FOR</strong>
163+
and <strong>END</strong>.</li>
153164
<li>On Grid Editor and Linux the auto enclose is only working on cell selection, but not on cell content edit.</li>
154165
<li>On Text Editor when Saving the selection of tests in Test Suites (Tree) is cleared.</li>
155166
<li>Test Suite with <em>*** Comments ***</em> can be edited but newlines are introduced.</li>
156167
<li>Some argument types detection (and colorization) is not correct in Grid Editor.</li>
157-
<li>RIDE <strong>DOES NOT KEEP</strong> Test Suites formatting or structure, causing differences in files when used on other IDE or Editors.</li>
168+
<li>RIDE <strong>DOES NOT KEEP</strong> Test Suites formatting or structure, causing differences in files when used
169+
on other IDE or Editors.</li>
158170
</ul>
159171
</li>
160172
</ul>
@@ -172,23 +184,33 @@ def set_content(self, html_win, content):
172184
</ol>
173185
</li>
174186
<li>Persistence of the position and state of detached panels, File Explorer and Test Suites</li>
175-
<li>File Explorer and Test Suites panels are now Plugins and can be disabled or enabled and made Visible with F11 ( Test Suites with F12, but disabled for now)</li>
187+
<li>File Explorer and Test Suites panels are now Plugins and can be disabled or enabled and made Visible with F11 (
188+
Test Suites with F12, but disabled for now)</li>
176189
<li>File Explorer now shows selected file when RIDE starts</li>
177190
<li>Block comment and uncomment on both Grid and Text editors</li>
178191
<li>Extensive color customization of panel elements via <cite>Tools&gt;Preferences</cite></li>
179192
<li>Color use on Console and Messages Log panels on Test Run tab</li>
180-
<li>In Text Editor the same commands as in Grid Editor are now supported: Move Up/Down Rows, Insert or Delete Rows and Insert or Delete 'Cells'</li>
193+
<li>In Text Editor the same commands as in Grid Editor are now supported: Move Up/Down Rows, Insert or Delete Rows and
194+
Insert or Delete 'Cells'</li>
181195
</ul>
182196
<p>We hope to implement or complete features and make fixes on next version 2.1 (in the end of 2023).</p>
183197
<p><strong>The minimal wxPython version is, 4.0.7, and RIDE supports the current version, 4.2.0.</strong></p>
184-
<p><em>Linux users are advised to install first wxPython from .whl package at</em> <a class="reference external" href="https://extras.wxpython.org/wxPython4/extras/linux/gtk3/">wxPython.org</a>, or by using the system package manager.</p>
185-
<p>The <a class="reference external" href="https://github.com/robotframework/RIDE/blob/master/CHANGELOG.adoc">CHANGELOG.adoc</a> lists the changes done on the different versions.</p>
198+
<p><em>Linux users are advised to install first wxPython from .whl package at</em> <a class="reference external"
199+
href="https://extras.wxpython.org/wxPython4/extras/linux/gtk3/">wxPython.org</a>, or by using the system package
200+
manager.</p>
201+
<p>The <a class="reference external" href="https://github.com/robotframework/RIDE/blob/master/CHANGELOG.adoc">
202+
CHANGELOG.adoc</a> lists the changes done on the different versions.</p>
186203
<p>All issues targeted for RIDE v2.0 can be found
187-
from the <a class="reference external" href="https://github.com/robotframework/RIDE/issues?q=milestone%3Av2.0">issue tracker milestone</a>.</p>
204+
from the <a class="reference external" href="https://github.com/robotframework/RIDE/issues?q=milestone%3Av2.0">issue
205+
tracker milestone</a>.</p>
188206
<p>Questions and comments related to the release can be sent to the
189-
<a class="reference external" href="http://groups.google.com/group/robotframework-users">robotframework-users</a> mailing list or to the channel #ride on
190-
<a class="reference external" href="https://robotframework-slack-invite.herokuapp.com">Robot Framework Slack</a>, and possible bugs submitted to the <a class="reference external" href="https://github.com/robotframework/RIDE/issues">issue tracker</a>.
191-
You should see <a class="reference external" href="https://forum.robotframework.org/c/tools/ride/">Robot Framework Forum</a> if your problem is already known.</p>
207+
<a class="reference external" href="http://groups.google.com/group/robotframework-users">robotframework-users</a>
208+
mailing list or to the channel #ride on
209+
<a class="reference external" href="https://robotframework-slack-invite.herokuapp.com">Robot Framework Slack</a>,
210+
and possible bugs submitted to the <a class="reference external" href="https://github.com/robotframework/RIDE/issues">
211+
issue tracker</a>.
212+
You should see <a class="reference external" href="https://forum.robotframework.org/c/tools/ride/">Robot Framework
213+
Forum</a> if your problem is already known.</p>
192214
<p>To install with <a class="reference external" href="http://pip-installer.org">pip</a> installed, just run</p>
193215
<pre class="literal-block">
194216
pip install --upgrade robotframework-ride=={VERSION}
@@ -199,14 +221,19 @@ def set_content(self, html_win, content):
199221
</pre>
200222
201223
<p>Alternatively you can download the source
202-
distribution from <a class="reference external" href="https://pypi.python.org/pypi/robotframework-ride">PyPI</a> and install it manually. For more details and other
203-
installation approaches, see the <a class="reference external" href="https://github.com/robotframework/RIDE/wiki/Installation-Instructions">installation instructions</a>.
204-
If you want to help in the development of RIDE, by reporting issues in current development version, you can install with:</p>
224+
distribution from <a class="reference external" href="https://pypi.python.org/pypi/robotframework-ride">PyPI</a> and
225+
install it manually. For more details and other
226+
installation approaches, see the <a class="reference external"
227+
href="https://github.com/robotframework/RIDE/wiki/Installation-Instructions">installation instructions</a>.
228+
If you want to help in the development of RIDE, by reporting issues in current development version, you can install
229+
with:</p>
205230
<pre class="literal-block">
206231
pip install -U https://github.com/robotframework/RIDE/archive/master.zip
207232
</pre>
208-
<p>Important document for helping with development is the <a class="reference external" href="https://github.com/robotframework/RIDE/blob/master/CONTRIBUTING.adoc">CONTRIBUTING.adoc</a>.</p>
209-
<p>See the <a class="reference external" href="https://github.com/robotframework/RIDE/wiki/F.A.Q.">FAQ</a> for important info about <cite>: FOR</cite> changes and other known issues and workarounds.</p>
233+
<p>Important document for helping with development is the <a class="reference external"
234+
href="https://github.com/robotframework/RIDE/blob/master/CONTRIBUTING.adoc">CONTRIBUTING.adoc</a>.</p>
235+
<p>See the <a class="reference external" href="https://github.com/robotframework/RIDE/wiki/F.A.Q.">FAQ</a> for
236+
important info about <cite>: FOR</cite> changes and other known issues and workarounds.</p>
210237
<p>A possible way to start RIDE is:</p>
211238
<pre class="literal-block">
212239
python -m robotide.__init__

src/robotide/editor/popupwindow.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class _PopupWindowBase(wx.Frame):
2323

2424
def __init__(self, size, detachable=True, autohide=False, color_background=POPUP_BACKGROUND,
2525
color_foreground=POPUP_FOREGROUND):
26-
# print("DEBUG: PopupWindow at init")
26+
self._current_details = None
27+
self._details = None
28+
self._detached_title = None
2729
self.color_background = color_background
2830
self.color_foreground = color_foreground
2931
self.panel = self._create_ui(size)
@@ -35,7 +37,7 @@ def __init__(self, size, detachable=True, autohide=False, color_background=POPUP
3537

3638
def _create_ui(self, size):
3739
panel = wx.MiniFrame(self)
38-
#TODO: Make this colour dependent on colours cycle or by Library
40+
# DEBUG: Make this colour dependent on colours cycle or by Library
3941
panel.SetBackgroundColour(self.color_background)
4042
panel.SetForegroundColour(self.color_foreground)
4143
szr = VerticalSizer()
@@ -63,6 +65,7 @@ def show_at(self, position):
6365
self.Show()
6466

6567
def hide(self, event=None):
68+
_ = event
6669
self.Show(False)
6770

6871
@property
@@ -75,20 +78,30 @@ def size(self):
7578

7679
def set_content(self, content, title=None):
7780
if isinstance(self.color_background, tuple):
78-
color = '#' + ''.join(hex(item)[2:] for item in self.color_background)
81+
bgcolor = '#' + ''.join(hex(item)[2:] for item in self.color_background)
7982
else:
80-
color = self.color_background
81-
self._current_details = '<body bgcolor=%s>%s</body>' % (color, content)
83+
bgcolor = self.color_background
84+
if isinstance(self.color_foreground, tuple):
85+
fgcolor = '#' + ''.join(hex(item)[2:] for item in self.color_foreground)
86+
else:
87+
fgcolor = self.color_foreground
88+
if content.startswith('<table>'):
89+
new_content = content.replace("<table>", f'<div><font color="{fgcolor}"><table>')\
90+
.replace("</table>", "</table></font></div>")
91+
else:
92+
new_content = f'<p><font color="{fgcolor}">' + content + '</font></p>'
93+
self._current_details = '<body bgcolor=%s style="color:%s;">%s</body>' % (bgcolor, fgcolor, new_content)
8294
self._details.SetPage(self._current_details)
8395
self._detached_title = title
8496

97+
def _set_auto_hiding(self):
98+
raise NotImplementedError
99+
85100

86101
class RidePopupWindow(wx.PopupWindow, _PopupWindowBase):
87102

88103
def __init__(self, parent, size):
89-
wx.PopupWindow.__init__(self, parent,
90-
flags=wx.CAPTION | wx.RESIZE_BORDER | wx.DEFAULT_FRAME_STYLE)
91-
# _PopupWindowBase.__init__(self, size, color_background=(40,40,10), color_foreground=(255,120,0))
104+
wx.PopupWindow.__init__(self, parent, flags=wx.CAPTION | wx.RESIZE_BORDER | wx.DEFAULT_FRAME_STYLE)
92105
self.SetSize(size)
93106

94107
def _set_auto_hiding(self):
@@ -110,12 +123,11 @@ def __init__(self, parent, size, detachable=True, autohide=False):
110123
color_foreground=self.color_foreground_text)
111124

112125

113-
# TODO: See if we need to have Mac specific window
126+
# DEBUG: See if we need to have Mac specific window
114127
class MacRidePopupWindow(wx.MiniFrame, _PopupWindowBase):
115128

116129
def __init__(self, parent, size, detachable=True, autohide=False):
117-
wx.MiniFrame.__init__(self, parent, style=wx.SIMPLE_BORDER
118-
|wx.RESIZE_BORDER)
130+
wx.MiniFrame.__init__(self, parent, style=wx.SIMPLE_BORDER | wx.RESIZE_BORDER)
119131
# set Left to Right direction (while we don't have localization)
120132
self.SetLayoutDirection(wx.Layout_LeftToRight)
121133
from ..preferences import RideSettings
@@ -131,6 +143,7 @@ def _set_auto_hiding(self):
131143
self._details.Bind(wx.EVT_MOTION, lambda evt: self.hide())
132144

133145
def OnKey(self, *params):
146+
""" In the event we need to process key events"""
134147
pass
135148

136149

src/robotide/preferences/settings.cfg

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,15 @@ secondary foreground = 'black'
9696
secondary background = 'light grey'
9797
background help = (240, 242, 80)
9898
foreground text = (7, 0, 70)
99+
own colors = False
100+
101+
[[Tree]]
102+
font size = 11
103+
font face = ''
104+
foreground = 'black'
105+
background = 'light grey'
106+
secondary foreground = 'black'
107+
secondary background = 'light grey'
108+
background help = (240, 242, 80)
109+
foreground text = (7, 0, 70)
110+
own colors = False

0 commit comments

Comments
 (0)