Skip to content

Commit 348b2f4

Browse files
Important restore of code to solve missing save content from kweditor to texteditor
1 parent 9cd6736 commit 348b2f4

File tree

4 files changed

+75
-54
lines changed

4 files changed

+75
-54
lines changed

src/robotide/__init__.py

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,41 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import argparse
16+
"""RIDE -- Robot Framework test data editor
17+
18+
Usage: ride.py [--noupdatecheck] [--debugconsole] [--settingspath <full path|settings filename>] [--version] [inpath]
19+
20+
RIDE can be started either without any arguments or by giving a path to a test
21+
data file or directory to be opened.
22+
23+
To disable update checker use --noupdatecheck.
24+
25+
To start debug console for RIDE problem debugging use --debugconsole option.
26+
27+
To use different settings use the option --settingspath followed by the path to the settings file or file name.
28+
29+
To see RIDE's version use --version.
30+
31+
RIDE's API is still evolving while the project is moving towards the 1.0
32+
release. The most stable, and best documented, module is `robotide.pluginapi`.
33+
"""
34+
1735
import os
1836
import sys
37+
from string import Template
1938

20-
try:
21-
from robotide import version
22-
except ImportError:
23-
print("Error getting RIDE version!")
24-
sys.exit(1)
25-
26-
errorMessage = """wxPython not found.\n
27-
RIDE depends on wx (wxPython). Known versions for Python3 are: 4.0.7.post2, 4.1.1 and 4.2.3.\
28-
At the time of this release the current wxPython version is 4.2.3.\
39+
errorMessageTemplate = Template("""$reason
40+
RIDE depends on wx (wxPython). Known versions for Python3 are: 4.0.7.post2, 4.1.1 and 4.2.1.\
41+
At the time of this release the current wxPython version is 4.2.1.\
2942
You can install with 'pip install wxPython' on most operating systems, or find the \
30-
the download link from https://wxPython.org/"""
31-
32-
if __name__ == '__main__' and 'robotide' not in sys.modules:
33-
from pathlib import Path
34-
robotide_dir = Path(__file__).absolute().parent # zipsafe
35-
sys.path = [str(robotide_dir.parent)] + [p for p in sys.path if Path(p) != robotide_dir]
36-
37-
parser = argparse.ArgumentParser(prog='ride', description='RIDE is an IDE for Robot Framework test cases and tasks.',
38-
epilog='See information about Robot Framework ecosystem at https://robotframewok.org/',
39-
add_help=False)
40-
parser.add_argument('inpath', nargs='?', help='Path to a test data file or'
41-
' directory to be opened.')
42-
parser.add_argument('-n', '--noupdatecheck', action='store_true', help='To disable update check.')
43-
parser.add_argument('-d', '--debugconsole', action='store_true',
44-
help='To start debug console for RIDE problem debugging, and wxPython inspection tool.')
45-
parser.add_argument('-s', '--settingspath', default=None, help='<full path|settings filename>\n'
46-
'To use different settings use the option --settingspath followed by'
47-
' the path to the settings file or file name.')
48-
parser.add_argument('-v', '--version', action='version', version=f'{version.VERSION}',
49-
help='To see RIDE\'s version.')
50-
parser.add_argument('-h', '--help', action='help', help='RIDE can be started either without any '
51-
'arguments or by giving a path to a test data file or'
52-
' directory to be opened.')
53-
# arguments = parser.parse_args()
43+
the download link from https://wxPython.org/""")
5444

5545
try:
5646
import wx
5747
import wx.lib.inspection
58-
from wx import Colour, Size
48+
from wx import Colour
5949
except ModuleNotFoundError:
60-
print(errorMessage)
50+
print(errorMessageTemplate.substitute(reason="wxPython not found."))
6151
sys.exit(1)
6252

6353
# Insert bundled robot to path before anything else
@@ -67,20 +57,47 @@
6757

6858
def main(*args):
6959
_replace_std_for_win()
70-
arguments = parser.parse_args()
71-
noupdatecheck = arguments.noupdatecheck
72-
debugconsole = arguments.debugconsole
73-
settingspath = arguments.settingspath
74-
inpath = arguments.inpath # _parse_args(*args)
75-
# print(f"DEBUG: main.py {noupdatecheck=} {debugconsole=} {settingspath=} {inpath=}")
60+
if '--version' in args:
61+
try:
62+
from . import version
63+
except ImportError:
64+
print("Error getting RIDE version!")
65+
sys.exit(1)
66+
print(version.VERSION)
67+
sys.exit(0)
68+
noupdatecheck, debug_console, settings_path, inpath = _parse_args(args)
69+
if len(args) > 3 or '--help' in args:
70+
print(__doc__)
71+
sys.exit()
7672
try:
77-
_run(inpath, not noupdatecheck, debugconsole, settingspath=settingspath)
73+
_run(inpath, not noupdatecheck, debug_console, settingspath=settings_path)
7874
except Exception: # DEBUG
7975
import traceback
8076
traceback.print_exception(*sys.exc_info())
8177
sys.stderr.write('\n\nUse --help to get usage information.\n')
8278

8379

80+
def _parse_args(args):
81+
if not args:
82+
return False, False, None, None
83+
arguments = list(args)
84+
noupdatecheck = '--noupdatecheck' in arguments
85+
if noupdatecheck:
86+
arguments.remove('--noupdatecheck')
87+
debug_console = '--debugconsole' in arguments
88+
if debug_console:
89+
arguments.remove('--debugconsole')
90+
settings_path = None
91+
if '--settingspath' in arguments:
92+
arguments.remove('--settingspath')
93+
if len(arguments) > 0:
94+
settings_path = arguments.pop(0)
95+
else:
96+
settings_path = None
97+
inpath = arguments[0] if arguments else None
98+
return noupdatecheck, debug_console, settings_path, inpath
99+
100+
84101
def _run(inpath=None, updatecheck=True, debug_console=False, settingspath=None):
85102
# print(f"DEBUG: ENTER _run {inpath=}, {updatecheck=}, {debug_console=}")
86103
try:
@@ -141,7 +158,7 @@ def _show_old_wxpython_warning_if_needed(parent=None):
141158
style = wx.ICON_EXCLAMATION
142159
if not parent:
143160
_ = wx.App()
144-
parent = wx.Frame(None, size=Size(0, 0))
161+
parent = wx.Frame(None, size=(0, 0))
145162
sys.stderr.write("{0}\n{1}\n".format(title, message))
146163
dlg = wx.MessageDialog(parent, message=message, caption=title, style=style)
147164
dlg.ShowModal()

src/robotide/__main__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18+
import sys
19+
20+
if __name__ == '__main__' and 'robotide' not in sys.modules:
21+
from pathlib import Path
22+
robotide_dir = Path(__file__).absolute().parent # zipsafe
23+
sys.path = [str(robotide_dir.parent)] + [p for p in sys.path if Path(p) != robotide_dir]
24+
1825
from robotide import main
1926

20-
main()
27+
main(*sys.argv[1:])

src/robotide/editor/texteditor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,11 @@ def on_data_changed(self, message):
535535

536536
def _on_timer(self, event):
537537
if not self.is_focused(): # Was reaching here with contentassist in kweditor
538-
event.Skip()
539-
return
538+
# event.Skip()
539+
# return
540+
# DEBUG: This is important to have changes done from kweditor reflected in texteditor
541+
# for example, a bad library import deleted from kweditor would remain in texteditor
542+
print(f"DEBUG: textedit in loop _on_timer event={event}")
540543
self._editor.store_position()
541544
self._open_tree_selection_in_editor()
542545
event.Skip()

utest/application/test_app_main.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,24 @@ class TestMain(unittest.TestCase):
7575
def tearDown(self):
7676
builtins.__import__ = real_import
7777

78-
@pytest.mark.skip("New main process uses sys.argv")
7978
def test_main_call_with_extra_args(self):
8079
from robotide import main
8180
with pytest.raises(SystemExit):
8281
main('--noupdatecheck', '--debugconsole', '--version', 'test.robot')
8382

84-
@pytest.mark.skip("New main process uses sys.argv")
8583
def test_main_call_with_help(self):
8684
from robotide import main
8785
with pytest.raises(SystemExit):
8886
result = main('--noupdatecheck', '--debugconsole', '--help')
89-
assert result.startswith('usage: ride')
87+
assert result.startswith('RIDE')
9088

91-
@pytest.mark.skip("New main process uses sys.argv")
9289
def test_main_call_with_version(self):
9390
from robotide import main
9491
with pytest.raises(SystemExit):
9592
result = main('--version')
9693
print(f"DEBUG: Result is {result}")
9794
assert result.startswith('v2.')
9895

99-
@pytest.mark.skip("New main process uses sys.argv")
10096
def test_main_call_with_fail_version(self):
10197
import robotide
10298
with (MonkeyPatch().context()):
@@ -105,7 +101,6 @@ def test_main_call_with_fail_version(self):
105101
result = robotide.main('--version') # Need to capture output
106102
assert result.startswith('v2.')
107103

108-
"""
109104
def test_parse_args(self):
110105
from robotide import _parse_args
111106
noupdatecheck, debug_console, settings_path, inpath = _parse_args(args=None)
@@ -123,7 +118,6 @@ def test_parse_args(self):
123118
noupdatecheck, debug_console, settings_path, inpath = _parse_args(args=('--garbagein', '--garbageout'))
124119
# returns always first arg
125120
assert (noupdatecheck, debug_console, settings_path, inpath) == (False, False, None, '--garbagein')
126-
"""
127121

128122
def test_run_call_with_fail_import(self):
129123
import robotide.application

0 commit comments

Comments
 (0)