From 2a28c6b971fe4ff0e0907fd2e71135ee698643cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lio=20Guilherme?= Date: Sat, 26 Oct 2024 03:30:01 +0100 Subject: [PATCH 1/3] Cleanup code (#154) * Refactor TextEdit, WIP * Fix unit tests with language transform * Separated key commands in TextEdit. Breaks some, TAB functions, Enter.. * Delete commented code, renamve arguments * Refactor change_locale * Increase unit tests --- src/robotide/application/application.py | 95 ++++-------------------- src/robotide/editor/kweditor.py | 3 - src/robotide/preferences/editors.py | 5 -- src/robotide/ui/preferences_dialogs.py | 35 +++++---- utest/application/test_app_main.py | 14 ++++ utest/contrib/testrunner/test_process.py | 21 +++++- 6 files changed, 67 insertions(+), 106 deletions(-) diff --git a/src/robotide/application/application.py b/src/robotide/application/application.py index 835a1ab2c..1cf9df50e 100644 --- a/src/robotide/application/application.py +++ b/src/robotide/application/application.py @@ -26,7 +26,6 @@ from ..ui.mainframe import RideFrame from .. import publish from .. import context, contrib -# from ..context import coreplugins from ..preferences import Preferences, RideSettings from ..application.pluginloader import PluginLoader from ..application.editorprovider import EditorProvider @@ -176,27 +175,14 @@ def _ApplyThemeToWidget(widget, fore_color=wx.BLUE, back_color=wx.LIGHT_GREY, th aui_default_tool_bar_art = AuiDefaultToolBarArt() aui_default_tool_bar_art.SetDefaultColours(wx.GREEN) widget.SetBackgroundColour(background) - # widget.SetOwnBackgroundColour(background) widget.SetForegroundColour(foreground) - # widget.SetOwnForegroundColour(foreground) - """ - widget.SetBackgroundColour(Colour(200, 222, 40)) - widget.SetOwnBackgroundColour(Colour(200, 222, 40)) - widget.SetForegroundColour(Colour(7, 0, 70)) - widget.SetOwnForegroundColour(Colour(7, 0, 70)) - """ - # or elif isinstance(widget, wx.Control): if not isinstance(widget, (wx.Button, wx.BitmapButton, ButtonWithHandler)): widget.SetForegroundColour(foreground) widget.SetBackgroundColour(background) - # widget.SetOwnBackgroundColour(background) - # widget.SetOwnForegroundColour(foreground) else: widget.SetForegroundColour(secondary_foreground) widget.SetBackgroundColour(secondary_background) - # widget.SetOwnBackgroundColour(secondary_background) - # widget.SetOwnForegroundColour(secondary_foreground) elif isinstance(widget, (wx.TextCtrl, TabFrame, AuiTabCtrl)): widget.SetForegroundColour(foreground_text) # or fore_color widget.SetBackgroundColour(background_help) # or back_color @@ -206,19 +192,14 @@ def _ApplyThemeToWidget(widget, fore_color=wx.BLUE, back_color=wx.LIGHT_GREY, th elif isinstance(widget, wx.MenuItem): widget.SetTextColour(foreground) widget.SetBackgroundColour(background) - # print(f"DEBUG: Application ApplyTheme wx.MenuItem {type(widget)}") else: widget.SetBackgroundColour(background) - # widget.SetOwnBackgroundColour(background) widget.SetForegroundColour(foreground) - # widget.SetOwnForegroundColour(foreground) def _WalkWidgets(self, widget, indent=0, indent_level=4, theme=None): - # print(' ' * indent + widget.__class__.__name__) if theme is None: theme = {} widget.Freeze() - # print(f"DEBUG Application General : _WalkWidgets background {theme['background']}") self._ApplyThemeToWidget(widget=widget, theme=theme) for child in widget.GetChildren(): if not child.IsTopLevel(): # or isinstance(child, wx.PopupWindow)): @@ -230,7 +211,6 @@ def _WalkWidgets(self, widget, indent=0, indent_level=4, theme=None): def SetGlobalColour(self, message): if message.keys[0] != "General": return - # print(f"DEBUG Application General : Enter SetGlobalColour message= {message.keys[0]}") app = wx.App.Get() _root = app.GetTopWindow() theme = self.settings.get_without_default('General') @@ -241,7 +221,6 @@ def SetGlobalColour(self, message): font.SetPointSize(font_size) _root.SetFont(font) self._WalkWidgets(_root, theme=theme) - # print(f"DEBUG Application General : SetGlobalColour AppliedWidgets check Filexplorer and Tree") if theme['apply to panels'] and self.fileexplorerplugin.settings['_enabled']: self.fileexplorerplugin.settings['background'] = theme['background'] self.fileexplorerplugin.settings['foreground'] = theme['foreground'] @@ -260,69 +239,12 @@ def SetGlobalColour(self, message): self.treeplugin.settings[FONT_FACE] = theme[FONT_FACE] if self.treeplugin.settings['opened']: self.treeplugin.on_show_tree(None) - """ - all_windows = list() - general = self.settings.get('General', None) - # print(f"DEBUG: Application General {general['background']} Type message {type(message)}") - # print(f"DEBUG: Application General message keys {message.keys} old {message.old} new {message.new}") - background = general['background'] - foreground = general['foreground'] - background_help = general[BACKGROUND_HELP] - foreground_text = general[FOREGROUND_TEXT] - font_size = general[FONT_SIZE] - font_face = general[FONT_FACE] - font = _root.GetFont() - font.SetFaceName(font_face) - font.SetPointSize(font_size) - _root.SetFont(font) - - def _iterate_all_windows(root): - if hasattr(root, 'GetChildren'): - children = root.GetChildren() - if children: - for c in children: - _iterate_all_windows(c) - all_windows.append(root) - - _iterate_all_windows(_root) - - for w in all_windows: - if hasattr(w, 'SetHTMLBackgroundColour'): - w.SetHTMLBackgroundColour(wx.Colour(background_help)) - w.SetForegroundColour(wx.Colour(foreground_text)) # 7, 0, 70)) - elif hasattr(w, 'SetBackgroundColour'): - w.SetBackgroundColour(wx.Colour(background)) # 44, 134, 179)) - - # if hasattr(w, 'SetOwnBackgroundColour'): - # w.SetOwnBackgroundColour(wx.Colour(background)) # 44, 134, 179)) - - if hasattr(w, 'SetForegroundColour'): - w.SetForegroundColour(wx.Colour(foreground)) # 7, 0, 70)) - - # if hasattr(w, 'SetOwnForegroundColour'): - # w.SetOwnForegroundColour(wx.Colour(foreground)) # 7, 0, 70)) - - if hasattr(w, 'SetFont'): - w.SetFont(font) - """ def change_locale(self, message): if message.keys[0] != "General": return initial_locale = self._locale.GetName() - if languages: - from ..preferences import Languages - names = [n for n in Languages.names] - else: - names = [('English', 'en', wx.LANGUAGE_ENGLISH)] - general = self.settings.get_without_default('General') - language = general.get('ui language', 'English') - try: - idx = [lang[0] for lang in names].index(language) - code = names[idx][2] - except (IndexError, ValueError): - print(f"DEBUG: application.py RIDE change_locale ERROR: Could not find {language=}") - code = wx.LANGUAGE_ENGLISH_WORLD + code = self._get_language_code() del self._locale self._locale = wx.Locale(code) if not self._locale.IsOk(): @@ -352,6 +274,21 @@ def change_locale(self, message): except FileNotFoundError: pass + def _get_language_code(self) -> str: + if languages: + from ..preferences import Languages + names = [n for n in Languages.names] + else: + names = [('English', 'en', wx.LANGUAGE_ENGLISH)] + general = self.settings.get_without_default('General') + language = general.get('ui language', 'English') + try: + idx = [lang[0] for lang in names].index(language) + code = names[idx][2] + except (IndexError, ValueError): + print(f"DEBUG: application.py RIDE change_locale ERROR: Could not find {language=}") + code = wx.LANGUAGE_ENGLISH_WORLD + return code @staticmethod def update_excludes(message): diff --git a/src/robotide/editor/kweditor.py b/src/robotide/editor/kweditor.py index dcf66db8e..9826959a3 100755 --- a/src/robotide/editor/kweditor.py +++ b/src/robotide/editor/kweditor.py @@ -845,7 +845,6 @@ def _call_alt_function(self, event, keycode: int): return True def on_key_down(self, event): - # print(f"DEBUG: KeywordEditor on_key_down event={event} focus={self.is_focused()}") keycode = event.GetUnicodeKey() or event.GetKeyCode() if event.ControlDown(): if event.ShiftDown(): @@ -860,7 +859,6 @@ def on_key_down(self, event): event.Skip() def on_char(self, event): - # print(f"DEBUG: KeywordEditor on_char event={event} focus={self.is_focused()}") key_char = event.GetUnicodeKey() if key_char < ord(' '): return @@ -950,7 +948,6 @@ def move_grid_cursor_and_edit(self): self.open_cell_editor() def on_key_up(self, event): - # print(f"DEBUG: KeywordEditor on_key_up event={event} focus={self.is_focused()}") event.Skip() # DEBUG seen this skip as soon as possible self._tooltips.hide() self._hide_link_if_necessary() diff --git a/src/robotide/preferences/editors.py b/src/robotide/preferences/editors.py index d156d35e7..e25e44deb 100644 --- a/src/robotide/preferences/editors.py +++ b/src/robotide/preferences/editors.py @@ -16,19 +16,14 @@ from os.path import abspath, dirname, join import builtins import wx -from wx import Colour from wx.lib.masked import NumCtrl from .settings import RideSettings -# from robotide.ui.preferences_dialogs import PreferencesPanel from ..ui import preferences_dialogs as pdiag -# from . import (PreferencesPanel, SpinChoiceEditor, IntegerChoiceEditor, boolean_editor, -# StringChoiceEditor, PreferencesColorPicker) from robotide.ui.preferences_dialogs import PreferencesPanel from ..widgets import Label from .managesettingsdialog import SaveLoadSettings -from ..context import IS_WINDOWS from functools import lru_cache try: # import installed version first diff --git a/src/robotide/ui/preferences_dialogs.py b/src/robotide/ui/preferences_dialogs.py index dc3208d88..881bba2d7 100644 --- a/src/robotide/ui/preferences_dialogs.py +++ b/src/robotide/ui/preferences_dialogs.py @@ -18,7 +18,6 @@ import wx -# from ..preferences.settings import RideSettings # DEBUG Removed to fix "cicular import" from ..context import IS_LINUX from ..widgets import HelpLabel, Label, TextField @@ -66,13 +65,11 @@ def Separator(self, parent, title): class PreferencesComboBox(wx.ComboBox): """A combobox tied to a specific setting. Saves value to disk after edit.""" - def __init__(self, parent, id, settings, key, choices): + def __init__(self, parent, elid, settings, key, choices): self.settings = settings self.key = key - # wx.ComboBox(self, parent, id, self._get_value(), size=self._get_size(choices), - # choices=choices, style=wx.CB_READONLY) from ..preferences.settings import RideSettings - super(PreferencesComboBox, self).__init__(parent, id, self._get_value(), + super(PreferencesComboBox, self).__init__(parent, elid, self._get_value(), size=self._get_size(choices), choices=choices, style=wx.CB_READONLY) self._gsettings = RideSettings() @@ -86,13 +83,14 @@ def __init__(self, parent, id, settings, key, choices): def _get_value(self): return self.settings[self.key] - def _get_size(self, choices=[]): + @staticmethod + def _get_size(choices=None): """ In Linux with GTK3 wxPython 4, there was not enough spacing. The value 72 is there for 2 digits numeric lists, for IntegerPreferenceComboBox. This issue only occurs in Linux, for Mac and Windows using default size. """ - if IS_LINUX and choices: + if IS_LINUX and isinstance(choices, list): return wx.Size(max(max(len(str(s)) for s in choices) * 9, 144), 30) return wx.DefaultSize @@ -117,11 +115,11 @@ def _set_value(self, value): class PreferencesSpinControl(wx.SpinCtrl): """A spin control tied to a specific setting. Saves value to disk after edit.""" - def __init__(self, parent, id, settings, key, choices): + def __init__(self, parent, elid, settings, key, choices): self.settings = settings self.key = key from ..preferences.settings import RideSettings - super(PreferencesSpinControl, self).__init__(parent, id, + super(PreferencesSpinControl, self).__init__(parent, elid, size=self._get_size(choices[-1])) self._gsettings = RideSettings() @@ -138,7 +136,8 @@ def __init__(self, parent, id, settings, key, choices): def _get_value(self): return self.settings[self.key] - def _get_size(self, max_value): + @staticmethod + def _get_size(max_value): """ In Linux with GTK3 wxPython 4, there was not enough spacing. The value 72 is there for 2 digits numeric lists, for IntegerPreferenceComboBox. @@ -158,13 +157,13 @@ def _set_value(self, value): class PreferencesColorPicker(wx.ColourPickerCtrl): """A colored button that opens a color picker dialog""" - def __init__(self, parent, id, settings, key): + def __init__(self, parent, elid, settings, key): self.settings = settings self.key = key # print(f"DEBUG: Preferences ColourPicker value type {type(settings[key])}") value = wx.Colour(settings[key]) from ..preferences.settings import RideSettings - super(PreferencesColorPicker, self).__init__(parent, id, colour=value) + super(PreferencesColorPicker, self).__init__(parent, elid, colour=value) self._gsettings = RideSettings() self.psettings = self._gsettings['General'] background_color = self.psettings['background'] @@ -189,12 +188,12 @@ def SetColour(self, colour): class _ChoiceEditor(object): _editor_class = None - def __init__(self, settings, setting_name, label, choices, help=''): + def __init__(self, settings, setting_name, label, choices, elhelp=''): self._settings = settings self._setting_name = setting_name self._label = label self._choices = choices - self._help = help + self._help = elhelp from ..preferences.settings import RideSettings self._gsettings = RideSettings() self.csettings = self._gsettings['General'] @@ -233,8 +232,8 @@ class SpinChoiceEditor(_ChoiceEditor): _editor_class = PreferencesSpinControl -def boolean_editor(parent, settings, name, label, help=''): - editor = _create_checkbox_editor(parent, settings, name, help) +def boolean_editor(parent, settings, name, label, elhelp=''): + editor = _create_checkbox_editor(parent, settings, name, elhelp) from ..preferences.settings import RideSettings _gsettings = RideSettings() bsettings = _gsettings['General'] @@ -248,12 +247,12 @@ def boolean_editor(parent, settings, name, label, help=''): return blabel, editor -def _create_checkbox_editor(parent, settings, name, help): +def _create_checkbox_editor(parent, settings, name, elhelp): initial_value = settings.get(name, "") editor = wx.CheckBox(parent) editor.SetValue(initial_value) editor.Bind(wx.EVT_CHECKBOX, lambda evt: settings.set(name, editor.GetValue())) - editor.SetToolTip(help) + editor.SetToolTip(elhelp) return editor diff --git a/utest/application/test_app_main.py b/utest/application/test_app_main.py index fcf5b9e2f..c4d9d951d 100644 --- a/utest/application/test_app_main.py +++ b/utest/application/test_app_main.py @@ -230,5 +230,19 @@ def test_replace_std_for_win(self): robotide._replace_std_for_win() +class TestMisc(unittest.TestCase): + + def tearDown(self): + builtins.__import__ = real_import + + def test_get_code(self): + import wx + from robotide.application import RIDE + + main_app = RIDE() + code = main_app._get_language_code() + assert code in (175, wx.LANGUAGE_ENGLISH_WORLD, wx.LANGUAGE_PORTUGUESE) + + if __name__ == '__main__': unittest.main() diff --git a/utest/contrib/testrunner/test_process.py b/utest/contrib/testrunner/test_process.py index ff0bdf3f4..616f8bd17 100644 --- a/utest/contrib/testrunner/test_process.py +++ b/utest/contrib/testrunner/test_process.py @@ -20,7 +20,25 @@ from robotide.contrib.testrunner.testrunner import Process -if VERSION >= '4.0': +if VERSION >= '7.1.1': + console_out = b"==============================================================================\n" \ + b"Small Test \n" \ + b"==============================================================================\n" \ + b"Small Test.Test \n" \ + b"==============================================================================\n" \ + b"Passing | PASS |\n" \ + b"------------------------------------------------------------------------------\n" \ + b"Failing | FAIL |\n" \ + b"this fails\n" \ + b"------------------------------------------------------------------------------\n" \ + b"Small Test.Test | FAIL |\n" \ + b"2 tests, 1 passed, 1 failed\n" \ + b"==============================================================================\n" \ + b"Small Test | FAIL |\n" \ + b"2 tests, 1 passed, 1 failed\n" \ + b"==============================================================================\n" \ + b"Output: NONE\n" +elif VERSION >= '4.0': console_out = b"==============================================================================\n" \ b"Small Test \n" \ b"==============================================================================\n" \ @@ -73,6 +91,7 @@ def test_running_robot_test(self): print(output, errors) parsed_output = bytes(output.replace(b'\r', b'')) parsed_errors = bytes(errors.replace(b'\r', b'')) + assert parsed_output == console_out self.assertTrue(parsed_output.startswith(console_out), msg=repr(output)) # Because of deprecation messages in RF 3.1, from Equal to Regex self.assertRegex(parsed_errors, b".*\\[ WARN \\] this passes\n") From 778ef347a4c3d2cf71e1457a480d64d1e4bb91ed Mon Sep 17 00:00:00 2001 From: HelioGuilherme66 Date: Sat, 26 Oct 2024 23:39:12 +0100 Subject: [PATCH 2/3] Improve unit test --- utest/application/test_app_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utest/application/test_app_main.py b/utest/application/test_app_main.py index c4d9d951d..09a31e2c4 100644 --- a/utest/application/test_app_main.py +++ b/utest/application/test_app_main.py @@ -241,7 +241,7 @@ def test_get_code(self): main_app = RIDE() code = main_app._get_language_code() - assert code in (175, wx.LANGUAGE_ENGLISH_WORLD, wx.LANGUAGE_PORTUGUESE) + assert code in (wx.LANGUAGE_ENGLISH, wx.LANGUAGE_ENGLISH_WORLD, wx.LANGUAGE_PORTUGUESE) if __name__ == '__main__': From e80acfcab446c67cb3ddfe98f532ce259f492d0b Mon Sep 17 00:00:00 2001 From: HelioGuilherme66 Date: Sun, 27 Oct 2024 00:19:43 +0100 Subject: [PATCH 3/3] Change update from develop branch --- src/robotide/application/updatenotifier.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/robotide/application/updatenotifier.py b/src/robotide/application/updatenotifier.py index 2cf3949ca..ec3ecfcd2 100644 --- a/src/robotide/application/updatenotifier.py +++ b/src/robotide/application/updatenotifier.py @@ -102,12 +102,12 @@ def _get_rf_pypi_data(self): def upgrade_from_dev_dialog(version_installed, notebook, show_no_update=False): dev_version = urllib2.urlopen('https://raw.githubusercontent.com/robotframework/' - 'RIDE/master/src/robotide/version.py', timeout=1).read().decode('utf-8') + 'RIDE/develop/src/robotide/version.py', timeout=1).read().decode('utf-8') matches = re.findall(r"VERSION\s*=\s*'([\w.]*)'", dev_version) version_latest = matches[0] if matches else None if cmp_versions(version_installed, version_latest) == -1: # Here is the Menu Help->Upgrade insertion part, try to highlight menu # wx.CANCEL_DEFAULT - command = sys.executable + " -m pip install -U https://github.com/robotframework/RIDE/archive/master.zip" + command = sys.executable + " -m pip install -U https://github.com/robotframework/RIDE/archive/develop.zip" _add_content_to_clipboard(command) if not _askyesno(_("Upgrade?"), f"{SPC}{_('New development version is available.')}{SPC}\n{SPC}" f"{_('You may install version %s with:') % version_latest}\n"