forked from qpython-android/dl.qpy.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipython2.py
More file actions
executable file
·74 lines (57 loc) · 2.06 KB
/
Copy pathipython2.py
File metadata and controls
executable file
·74 lines (57 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#-*coding:utf8;-*-
__doc__ = """
IPython for QPython
@version: 0.9
@Author: River
"""
def op(msg):
print(msg)
def main():
from IPython.terminal.prompts import Prompts, Token
class CustomPrompt(Prompts):
def in_prompt_tokens(self, cli=None):
return [
(Token.Prompt, 'In <'),
(Token.PromptNum, str(self.shell.execution_count)),
(Token.Prompt, '>: '),
]
def out_prompt_tokens(self):
return [
(Token.OutPrompt, 'Out<'),
(Token.OutPromptNum, str(self.shell.execution_count)),
(Token.OutPrompt, '>: '),
]
from traitlets.config.loader import Config
try:
get_ipython
except NameError:
nested = 0
cfg = Config()
cfg.TerminalInteractiveShell.prompts_class=CustomPrompt
else:
print("Running nested copies of IPython.")
print("The prompts for the nested copy have been modified")
cfg = Config()
nested = 1
# First import the embeddable shell class
from IPython.terminal.embed import InteractiveShellEmbed
# Now create an instance of the embeddable shell. The first argument is a
# string with options exactly as you would type them if you were starting
# IPython at the system command line. Any parameters you want to define for
# configuration can thus be specified here.
ipshell = InteractiveShellEmbed(config=cfg,
banner1 = 'IPython on QPython',
exit_msg = '')
ipshell("""IPython 5.5.0 - An enhanced Interactive Python
Type 'copyright', 'credits' or 'license' for more information, Type '?' for help, 'exit' for exit.
""")
try:
import platform
if int(''.join(platform.python_version().split('.')[:-1]))<27:
op(__doc__)
op("You must switch to Python2.7, please install Python2 in setting")
else:
main()
except ImportError:
op(__doc__)
op("QPY> IPython library not found, please install it from QPYPI first.")