liveConsole 1.7.5__py3-none-any.whl → 1.7.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of liveConsole might be problematic. Click here for more details.
- liveconsole-1.7.7.dist-info/METADATA +217 -0
- {liveconsole-1.7.5.dist-info → liveconsole-1.7.7.dist-info}/RECORD +9 -9
- pysole/pysole.py +31 -15
- pysole/suggestionManager.py +5 -2
- pysole/utils.py +33 -1
- liveconsole-1.7.5.dist-info/METADATA +0 -161
- {liveconsole-1.7.5.dist-info → liveconsole-1.7.7.dist-info}/WHEEL +0 -0
- {liveconsole-1.7.5.dist-info → liveconsole-1.7.7.dist-info}/entry_points.txt +0 -0
- {liveconsole-1.7.5.dist-info → liveconsole-1.7.7.dist-info}/licenses/LICENSE +0 -0
- {liveconsole-1.7.5.dist-info → liveconsole-1.7.7.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: liveConsole
|
|
3
|
+
Version: 1.7.7
|
|
4
|
+
Summary: An IDLE-like debugger to allow for real-time command injection for debugging and testing python code
|
|
5
|
+
Author-email: Tzur Soffer <tzur.soffer@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/TzurSoffer/Pysole
|
|
8
|
+
Project-URL: Repository, https://github.com/TzurSoffer/Pysole
|
|
9
|
+
Requires-Python: >=3.7
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: customtkinter
|
|
13
|
+
Requires-Dist: pygments
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# PYSOLE
|
|
17
|
+
|
|
18
|
+
## You can finally test your code in real time without using idle!
|
|
19
|
+
### If you found [this repository](https://github.com/TzurSoffer/Pysole) useful, please give it a ⭐!.
|
|
20
|
+
|
|
21
|
+
## Showcase (click to watch on Youtube)
|
|
22
|
+
[](https://www.youtube.com/shorts/pjoelNjc3O0)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Table of contents
|
|
26
|
+
|
|
27
|
+
- Features
|
|
28
|
+
- Installation
|
|
29
|
+
- Usage
|
|
30
|
+
- Parameters
|
|
31
|
+
- Keyboard Shortcuts
|
|
32
|
+
- Troubleshooting/Notes
|
|
33
|
+
- Contributing
|
|
34
|
+
- License
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
Pysole provides a compact but powerful set of features designed to make interactive debugging and live testing fast and pleasant.
|
|
39
|
+
|
|
40
|
+
1. Live GUI console (syntax highlighting)
|
|
41
|
+
- Real-time syntax highlighting using Pygments.
|
|
42
|
+
- Monokai style by default, configurable through themes.
|
|
43
|
+
|
|
44
|
+
2. Autocomplete & suggestions
|
|
45
|
+
- Autocomplete for Python keywords, built-ins and variables in scope.
|
|
46
|
+
- Popup suggestions after typing (configurable behavior) and insert-on-confirm.
|
|
47
|
+
|
|
48
|
+
3. Run remaining script code at startup
|
|
49
|
+
- `runRemainingCode=True` will execute the remainder of the calling script after `probe()` is invoked.
|
|
50
|
+
- `printStartupCode=True` prints the captured code chunks as they execute.
|
|
51
|
+
|
|
52
|
+
4. Thread-safe execution + output capture
|
|
53
|
+
- User code runs in a background thread to avoid blocking the GUI.
|
|
54
|
+
- `stdout` and `stderr` are redirected into the GUI console output area.
|
|
55
|
+
|
|
56
|
+
5. Multi-line input, indentation & history
|
|
57
|
+
- Shift+Enter inserts a newline with proper indentation.
|
|
58
|
+
- Command history with clickable entries for easy reuse.
|
|
59
|
+
|
|
60
|
+
6. Integrated Help Panel and Features tab
|
|
61
|
+
- Right-hand help panel shows `help(obj)` output.
|
|
62
|
+
- A Features view is available from the File menu and shows the built-in features summary.
|
|
63
|
+
|
|
64
|
+
7. Themes & persistent settings
|
|
65
|
+
- Theme picker in the File menu; selected theme is written to `settings.json`.
|
|
66
|
+
- Settings (THEME, BEHAVIOR, FONT) are loaded at startup from `src/pysole/settings.json`.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Installation
|
|
70
|
+
|
|
71
|
+
Quick install
|
|
72
|
+
|
|
73
|
+
```powershell
|
|
74
|
+
pip install liveConsole
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Notes: the package is published under the name `liveConsole` (see `pyproject.toml`).
|
|
78
|
+
|
|
79
|
+
If you prefer to install from source, clone this repo and run:
|
|
80
|
+
|
|
81
|
+
```powershell
|
|
82
|
+
pip install -e .
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Command-line entry points
|
|
86
|
+
|
|
87
|
+
After installation, two console commands are provided:
|
|
88
|
+
|
|
89
|
+
- `pysole` — open the GUI console (same as `liveconsole`)
|
|
90
|
+
- `liveconsole` — open the GUI console
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
## Usage
|
|
94
|
+
|
|
95
|
+
Programmatic usage (embed in scripts):
|
|
96
|
+
|
|
97
|
+
- Basic, automatic caller capture:
|
|
98
|
+
```python
|
|
99
|
+
import pysole
|
|
100
|
+
pysole.probe()
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- Run the remaining code in the current file inside the console and print the code as it executes
|
|
104
|
+
```python
|
|
105
|
+
pysole.probe(runRemainingCode=True, printStartupCode=True)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- Override appearance and prompt
|
|
109
|
+
```python
|
|
110
|
+
pysole.probe(primaryPrompt='PY> ', font='Consolas', fontSize=14)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Parameters
|
|
114
|
+
|
|
115
|
+
This section documents the parameters accepted by `pysole.probe()` and the `InteractiveConsole` constructor in `src/pysole/pysole.py`. Most of these parameters are optional; reasonable defaults are taken from the calling frame and `settings.json`.
|
|
116
|
+
|
|
117
|
+
Note: `probe(...)` forwards its arguments to `InteractiveConsole(...)` so you can pass any of the parameters below to `probe()` directly.
|
|
118
|
+
|
|
119
|
+
runRemainingCode
|
|
120
|
+
- Meaning: When `True`, Pysole will read the remainder of the source file that contains the `probe()` call and run those lines inside the console's namespace.
|
|
121
|
+
- Type: bool
|
|
122
|
+
- Default: `False`
|
|
123
|
+
- Behavior: The implementation inspects `callerFrame.f_code.co_filename` for the filename and `callerFrame.f_lineno` for the line number where `probe()` was called. Lines after that line are captured into `startupCode` and executed on console startup.
|
|
124
|
+
- Caution: This requires the source file to be readable from disk (not packaged/compiled away). Large files will be read into memory.
|
|
125
|
+
|
|
126
|
+
printStartupCode
|
|
127
|
+
- Meaning: Controls how the startup code (captured by `runRemainingCode=True`) is executed: printed chunk-by-chunk to the console and executed interactively, or executed silently.
|
|
128
|
+
- Type: bool
|
|
129
|
+
- Default: `False`
|
|
130
|
+
- Behavior: If `True`, the startup code is split into logical top-level chunks (top-level statements and their indented blocks). Each chunk is printed and executed sequentially so you can see what runs. If `False`, the entire remaining code is executed silently in one go (but output is still captured and shown).
|
|
131
|
+
|
|
132
|
+
primaryPrompt
|
|
133
|
+
- Meaning: Overrides the primary prompt string (for example `>>>`). This updates the in-memory `BEHAVIOR['PRIMARY_PROMPT']` used by the console and the default can also be changed in the settings file directly.
|
|
134
|
+
- Type: string
|
|
135
|
+
- Default: The prompt value defined in `settings.json` under `BEHAVIOR -> PRIMARY_PROMPT`.
|
|
136
|
+
- Notes: Passing this parameter changes the prompt for the current session only.
|
|
137
|
+
|
|
138
|
+
font
|
|
139
|
+
- Meaning: Overrides the font family used in console widgets.
|
|
140
|
+
- Type: string (font family name, e.g. "Consolas", "Courier New")
|
|
141
|
+
- Default: The font specified by `settings.json` -> `THEME` -> `FONT`.
|
|
142
|
+
|
|
143
|
+
fontSize
|
|
144
|
+
- Meaning: Overrides the font size used in console widgets.
|
|
145
|
+
- Type: int (font size in points / pixels depending on the platform and Tk configuration)
|
|
146
|
+
- Default: Value from `settings.json` -> `THEME` -> `FONT_SIZE`.
|
|
147
|
+
|
|
148
|
+
removeWaterMark
|
|
149
|
+
- Meaning: Controls whether a short welcome watermark message (with a GitHub link and request to star the project) is printed at startup.
|
|
150
|
+
- Type: bool
|
|
151
|
+
- Default: `False` (watermark shown)
|
|
152
|
+
|
|
153
|
+
userGlobals
|
|
154
|
+
- Meaning: The `globals()` mapping that the console will use as its global namespace. Variables, functions, and imports in this mapping will be visible to code executed in the console.
|
|
155
|
+
- Type: dict-like (typically the dict returned by `globals()`)
|
|
156
|
+
- Default: If omitted, the console infers the caller's globals using `callerFrame.f_globals` (or from `inspect.currentframe().f_back` if `callerFrame` is also omitted).
|
|
157
|
+
- When to pass: Provide this when you want the console to operate on a specific module or custom namespace.
|
|
158
|
+
|
|
159
|
+
userLocals
|
|
160
|
+
- Meaning: The `locals()` mapping used as the console's local namespace. Local variables available at the call site will be visible here.
|
|
161
|
+
- Type: dict-like (typically the dict returned by `locals()`)
|
|
162
|
+
- Default: Inferred from the caller's frame (`callerFrame.f_locals`) if not provided.
|
|
163
|
+
|
|
164
|
+
callerFrame
|
|
165
|
+
- Meaning: An `inspect` frame object used to infer both `userGlobals` and `userLocals` when they are not supplied. It's also used to determine the source file and line number for the "run remaining code" feature.
|
|
166
|
+
- Type: frame object (as returned by `inspect.currentframe()` and `frame.f_back`)
|
|
167
|
+
- Default: If omitted, `probe()` sets `callerFrame = inspect.currentframe().f_back` to automatically capture the frame of the caller.
|
|
168
|
+
- When to pass: Use an explicit frame when calling `probe()` from helper wrappers or non-standard contexts where automatic frame detection would be wrong.
|
|
169
|
+
|
|
170
|
+
Behavioral notes and edge cases
|
|
171
|
+
- `probe()` replaces `sys.stdout`, `sys.stderr`, and `sys.stdin` with console-aware redirectors while the console is running. These streams are restored when the console's `onClose()` runs (but be mindful when embedding Pysole in larger apps).
|
|
172
|
+
- If `runRemainingCode=True` but the source file cannot be read (packaged app, missing file, permission issues), the attempt to read the file will fail — in that case either run Pysole without `runRemainingCode` or pass an explicit `startupCode` (if you extend the API).
|
|
173
|
+
- When `printStartupCode=True`, chunks are determined by top-level lines (zero indent) and their following indented lines. This makes printed execution easier to follow for functions, classes and loops.
|
|
174
|
+
|
|
175
|
+
## Keyboard Shortcuts
|
|
176
|
+
|
|
177
|
+
| Key | Action |
|
|
178
|
+
| --- | --- |
|
|
179
|
+
| `Enter` | Execute command (if complete) |
|
|
180
|
+
| `Shift+Enter` | Insert newline with auto-indent |
|
|
181
|
+
| `Tab` | Complete the current word / show suggestions |
|
|
182
|
+
| `Up/Down` | Navigate suggestion list |
|
|
183
|
+
| `Escape` | Hide suggestions |
|
|
184
|
+
| `Ctrl Click` | open help panel on the current method/func/class... |
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
## Troubleshooting/Notes
|
|
188
|
+
|
|
189
|
+
Behavioral notes and edge cases
|
|
190
|
+
|
|
191
|
+
- `probe()` temporarily replaces `sys.stdout`, `sys.stderr` and `sys.stdin` with redirectors that send text to the GUI console. These are restored on close (`onClose()`). Embedding Pysole in larger apps should take this into account.
|
|
192
|
+
- `runRemainingCode=True` requires the calling module's source file to be available on disk. Running this in frozen/packaged environments may fail.
|
|
193
|
+
- `printStartupCode=True` prints chunks determined by top-level statements (zero indent) and their indented blocks so function/class/loop definitions are grouped with their bodies.
|
|
194
|
+
|
|
195
|
+
Settings and themes
|
|
196
|
+
|
|
197
|
+
Default UI and behavior settings are loaded from `src/pysole/settings.json` (path built from `src/pysole/utils.py`). Themes are listed in `src/pysole/themes.json`. The in-app Theme Picker writes the selected theme back to `settings.json` to persist across sessions.
|
|
198
|
+
|
|
199
|
+
Troubleshooting
|
|
200
|
+
|
|
201
|
+
- If the GUI doesn't start, make sure `customtkinter` is installed for your Python version.
|
|
202
|
+
- On Linux, ensure your Tk/Tcl support is present (system package) and `DISPLAY` is set when running headful UIs.
|
|
203
|
+
- If `runRemainingCode` appears to run the wrong code, check where `probe()` is called (wrappers can shift the caller frame). Use `callerFrame=` to pass an explicit frame if needed.
|
|
204
|
+
|
|
205
|
+
## Contributing
|
|
206
|
+
|
|
207
|
+
- Bug reports and PRs welcome. Please open issues on the upstream GitHub repository: https://github.com/TzurSoffer/Pysole
|
|
208
|
+
- Keep test changes small and focused. Include a short description of the error / feature and steps to reproduce.
|
|
209
|
+
|
|
210
|
+
Changelog (high level)
|
|
211
|
+
|
|
212
|
+
- See `pyproject.toml` for the current package version.
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
This project is available under the MIT license — see the `LICENSE` file in the repository root.
|
|
217
|
+
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
liveConsole/__init__.py,sha256=GyV_Y3iiiS12JoEiqE55uZPQ8ZDYfOSKvxh5rcfaD1U,20
|
|
2
|
-
liveconsole-1.7.
|
|
2
|
+
liveconsole-1.7.7.dist-info/licenses/LICENSE,sha256=7dZ0zL72aGaFE0C9DxacOpnaSkC5jajhG6iL7lqhWmU,1064
|
|
3
3
|
pysole/__init__.py,sha256=0Jq2s5WxFVveZW-pGwThGZLt_mVSdGcsT9lpJNEZ6ds,124
|
|
4
4
|
pysole/__main__.py,sha256=QvVFH8J2yzgQaF9MosQ6ajCW67uiRbYliePsTEUCIAg,82
|
|
5
5
|
pysole/commandHistory.py,sha256=xJtWbJ_vgJo2QGgaZJsApTOi_Hm8Yz0V9_zqQUCItj8,1084
|
|
6
6
|
pysole/helpTab.py,sha256=o0uSY-8sw7FuuBrt0FQwcgK6ljNVx3IgRnW7heZ6GvY,2454
|
|
7
7
|
pysole/liveConsole.py,sha256=lzS3dphAQ1i8pQC4E2FY-FyMMSKi-dAN0xr6XUgrNmo,168
|
|
8
8
|
pysole/mainConsole.py,sha256=t_ijaSm2rTxM5CrLqjxT5Oq_OFwxk7JsPOAXxo9dbdE,15357
|
|
9
|
-
pysole/pysole.py,sha256=
|
|
9
|
+
pysole/pysole.py,sha256=8hDTU7wRcWvg3Hsnz84o1HXoy69nrFgSMyCAJnGitb0,13778
|
|
10
10
|
pysole/settings.json,sha256=cmOtIhRDWHMwmQMESuykWuzJd_jG6iT2tJ-uhSps_3U,722
|
|
11
11
|
pysole/styledTextbox.py,sha256=qWnwGAKjl7R2HYPXQOr8GrGYIr4JC8PzmeioOCH7hGo,2236
|
|
12
|
-
pysole/suggestionManager.py,sha256=
|
|
12
|
+
pysole/suggestionManager.py,sha256=CGR1wsRIU4le3Bq_6CPAytM1CzTQAV_jUl5KZbg9LPU,6544
|
|
13
13
|
pysole/themes.json,sha256=2KvEfxm-eDsfVKIdBhWk-Qd93wYQub3YwkxbS6CGKH0,2525
|
|
14
|
-
pysole/utils.py,sha256=
|
|
15
|
-
liveconsole-1.7.
|
|
16
|
-
liveconsole-1.7.
|
|
17
|
-
liveconsole-1.7.
|
|
18
|
-
liveconsole-1.7.
|
|
19
|
-
liveconsole-1.7.
|
|
14
|
+
pysole/utils.py,sha256=cKsSPWeYRxPhkiM8Xrb-aMW6w0SU5Xuu9WCgsu6_xtA,1364
|
|
15
|
+
liveconsole-1.7.7.dist-info/METADATA,sha256=gUfCtoVEBonZ-rH3dJz3GOHsIgEdPZxgDJBUHOk2RTI,10407
|
|
16
|
+
liveconsole-1.7.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
+
liveconsole-1.7.7.dist-info/entry_points.txt,sha256=qtvuJHcex4QqM97x_UawFWJYnfhQRl0jhqLcWRpnAGo,84
|
|
18
|
+
liveconsole-1.7.7.dist-info/top_level.txt,sha256=YGhC2H7bvcDnMwEtvLXF6qQNIZT2Saayyk1KOJyndN8,19
|
|
19
|
+
liveconsole-1.7.7.dist-info/RECORD,,
|
pysole/pysole.py
CHANGED
|
@@ -8,7 +8,7 @@ import sys
|
|
|
8
8
|
import io
|
|
9
9
|
import json
|
|
10
10
|
|
|
11
|
-
from .utils import settingsPath, themesPath, stdPrint
|
|
11
|
+
from .utils import settingsPath, themesPath, stdPrint, normalizeWhitespace, findUnindentedLine
|
|
12
12
|
from .helpTab import HelpTab
|
|
13
13
|
from .mainConsole import InteractiveConsoleText
|
|
14
14
|
|
|
@@ -73,6 +73,7 @@ class InteractiveConsole(ctk.CTk):
|
|
|
73
73
|
if userLocals is None:
|
|
74
74
|
userLocals = callerFrame.f_locals
|
|
75
75
|
|
|
76
|
+
self.callerFrame = callerFrame
|
|
76
77
|
self.userGlobals = userGlobals
|
|
77
78
|
self.userLocals = userLocals
|
|
78
79
|
|
|
@@ -87,20 +88,30 @@ class InteractiveConsole(ctk.CTk):
|
|
|
87
88
|
self.runRemainingCode = runRemainingCode
|
|
88
89
|
self.printStartupCode = printStartupCode
|
|
89
90
|
self.removeWaterMark = removeWaterMark
|
|
90
|
-
self.startupCode =
|
|
91
|
+
self.startupCode = []
|
|
91
92
|
if runRemainingCode:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
93
|
+
self.startupCode = self._getStartupCode()
|
|
94
|
+
|
|
95
|
+
def _getStartupCode(self):
|
|
96
|
+
code_obj = self.callerFrame.f_code
|
|
97
|
+
callStartLineIndex = inspect.getframeinfo(self.callerFrame).positions.lineno #< start of the probe call
|
|
98
|
+
callEndLineIndex = inspect.getframeinfo(self.callerFrame).positions.end_lineno #< end of the probe call
|
|
99
|
+
filename = code_obj.co_filename
|
|
100
|
+
|
|
101
|
+
# Read the rest of the file after the call to probe()
|
|
102
|
+
with open(filename, "r", encoding="utf-8") as f:
|
|
103
|
+
lines = f.readlines()
|
|
104
|
+
|
|
105
|
+
startLine = lines[callStartLineIndex-1]
|
|
106
|
+
for line in lines[callStartLineIndex:callEndLineIndex]:
|
|
107
|
+
startLine += line.strip()
|
|
108
|
+
|
|
109
|
+
startupCode = normalizeWhitespace(lines[callEndLineIndex:]) #< ensure the code is not indented too much (egg if in __name__ == "__main__")
|
|
110
|
+
firstUnindentedLine = findUnindentedLine(startupCode)
|
|
111
|
+
while firstUnindentedLine != 0 and firstUnindentedLine != None: #< handle if probe is inside a loop/if/etc by simply unindenting the call (while is for nested calls)
|
|
112
|
+
startupCode[:firstUnindentedLine] = normalizeWhitespace(startupCode[:firstUnindentedLine])
|
|
113
|
+
firstUnindentedLine = findUnindentedLine(startupCode)
|
|
114
|
+
return(startupCode)
|
|
104
115
|
|
|
105
116
|
def _createMenu(self):
|
|
106
117
|
"""Create a menu bar using CTkOptionMenu."""
|
|
@@ -327,7 +338,8 @@ class InteractiveConsole(ctk.CTk):
|
|
|
327
338
|
self.mainloop(*args, **kwargs)
|
|
328
339
|
|
|
329
340
|
def probe(userGlobals=None, userLocals=None, callerFrame=None,
|
|
330
|
-
runRemainingCode=False, printStartupCode=False,
|
|
341
|
+
runRemainingCode=False, printStartupCode=False,
|
|
342
|
+
primaryPrompt=None, font=None, fontSize=None, **kwargs):
|
|
331
343
|
if callerFrame == None:
|
|
332
344
|
callerFrame = inspect.currentframe().f_back
|
|
333
345
|
InteractiveConsole(userGlobals=userGlobals,
|
|
@@ -335,6 +347,10 @@ def probe(userGlobals=None, userLocals=None, callerFrame=None,
|
|
|
335
347
|
callerFrame=callerFrame,
|
|
336
348
|
runRemainingCode=runRemainingCode,
|
|
337
349
|
printStartupCode=printStartupCode,
|
|
350
|
+
primaryPrompt=primaryPrompt,
|
|
351
|
+
font=font,
|
|
352
|
+
fontSize=fontSize,
|
|
353
|
+
removeWaterMark=False,
|
|
338
354
|
**kwargs).probe()
|
|
339
355
|
|
|
340
356
|
def _standalone():
|
pysole/suggestionManager.py
CHANGED
|
@@ -107,8 +107,11 @@ class CodeSuggestionManager:
|
|
|
107
107
|
self.suggestionListbox.selection_set(0)
|
|
108
108
|
|
|
109
109
|
# Position window near cursor
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
try: #< some weird errors idk
|
|
111
|
+
self._positionSuggestionWindow()
|
|
112
|
+
self.suggestionWindow.deiconify()
|
|
113
|
+
except:
|
|
114
|
+
pass
|
|
112
115
|
|
|
113
116
|
def _createSuggestionWindow(self):
|
|
114
117
|
"""Create the suggestion popup window."""
|
pysole/utils.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import sys
|
|
3
|
+
import re
|
|
3
4
|
|
|
4
5
|
settingsPath = os.path.join(os.path.dirname(__file__), "settings.json")
|
|
5
6
|
themesPath = os.path.join(os.path.dirname(__file__), "themes.json")
|
|
@@ -10,4 +11,35 @@ def stdPrint(text):
|
|
|
10
11
|
sys.__stdout__.write(f"{text}\n")
|
|
11
12
|
sys.__stdout__.flush()
|
|
12
13
|
except:
|
|
13
|
-
pass
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
def normalizeWhitespace(lines):
|
|
17
|
+
"""
|
|
18
|
+
Normalize leading whitespace across a list of code lines.
|
|
19
|
+
Removes common leading indentation and trims excess on over-indented lines.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
if type(lines) == str:
|
|
23
|
+
lines = lines.split('\n')
|
|
24
|
+
|
|
25
|
+
# Remove empty lines and preserve original line endings
|
|
26
|
+
strippedLines = [line.rstrip('\n') for line in lines if line.strip()]
|
|
27
|
+
if not strippedLines:
|
|
28
|
+
return []
|
|
29
|
+
|
|
30
|
+
# Find minimum indentation across non-empty lines
|
|
31
|
+
indentLevels = [
|
|
32
|
+
len(re.match(r'^[ \t]*', line).group())
|
|
33
|
+
for line in strippedLines
|
|
34
|
+
]
|
|
35
|
+
minIndent = min(indentLevels)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
normalized = [line[minIndent:] if len(line) >= minIndent else line for line in lines] #< Normalize by removing minIndent from each line
|
|
39
|
+
return(normalized)
|
|
40
|
+
|
|
41
|
+
def findUnindentedLine(lines):
|
|
42
|
+
for i, line in enumerate(lines):
|
|
43
|
+
if re.match(r'^\S', line): # Line starts with non-whitespace
|
|
44
|
+
return(i)
|
|
45
|
+
return(None)
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: liveConsole
|
|
3
|
-
Version: 1.7.5
|
|
4
|
-
Summary: An IDLE-like debugger to allow for real-time command injection for debugging and testing python code
|
|
5
|
-
Author-email: Tzur Soffer <tzur.soffer@gmail.com>
|
|
6
|
-
License: MIT
|
|
7
|
-
Requires-Python: >=3.7
|
|
8
|
-
Description-Content-Type: text/markdown
|
|
9
|
-
License-File: LICENSE
|
|
10
|
-
Requires-Dist: customtkinter
|
|
11
|
-
Requires-Dist: pygments
|
|
12
|
-
Dynamic: license-file
|
|
13
|
-
|
|
14
|
-
# PYSOLE
|
|
15
|
-
|
|
16
|
-
## You can finally test your code in real time without using idle!
|
|
17
|
-
### If you found [this repository](https://github.com/TzurSoffer/Pysole) useful, please give it a ⭐!.
|
|
18
|
-
|
|
19
|
-
## Showcase (click to watch on Youtube)
|
|
20
|
-
[](https://www.youtube.com/shorts/pjoelNjc3O0)
|
|
21
|
-
|
|
22
|
-
A fully-featured, **live Python console GUI** built with **CustomTkinter** and **Tkinter**, featuring:
|
|
23
|
-
|
|
24
|
-
* Python syntax highlighting via **Pygments**
|
|
25
|
-
|
|
26
|
-
* Autocomplete for **keywords, built-ins, and local/global variables**
|
|
27
|
-
|
|
28
|
-
* Run code at startup for easier debugging
|
|
29
|
-
|
|
30
|
-
* Thread-safe execution of Python code
|
|
31
|
-
|
|
32
|
-
* Output capturing for `stdout` and `stderr`
|
|
33
|
-
|
|
34
|
-
* Multi-line input with auto-indentation
|
|
35
|
-
|
|
36
|
-
* History of previous commands
|
|
37
|
-
|
|
38
|
-
* **Integrated Help Panel** for quick access to Python object documentation
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
## Installation
|
|
42
|
-
|
|
43
|
-
`pip install liveConsole`
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## Features
|
|
47
|
-
|
|
48
|
-
### Standalone Launch
|
|
49
|
-
|
|
50
|
-
* Once installed, you can launch the console directly by simply typing ```pysole``` or ```liveconsole``` in the terminal
|
|
51
|
-
|
|
52
|
-
* This opens the full GUI without needing to write any code. Perfect for quick debugging and experimenting.
|
|
53
|
-
|
|
54
|
-
### Syntax Highlighting
|
|
55
|
-
|
|
56
|
-
* Real-time syntax highlighting using **Pygments** and the **Monokai** style.
|
|
57
|
-
|
|
58
|
-
* Highlights Python keywords, built-ins, and expressions in the console.
|
|
59
|
-
|
|
60
|
-
### Run Code at Startup
|
|
61
|
-
|
|
62
|
-
* Pysole can automatically execute Python code when the console launches.
|
|
63
|
-
|
|
64
|
-
* Use the runRemainingCode=True argument in pysole.probe() to run all remaining lines in the calling script after the probe() call.
|
|
65
|
-
|
|
66
|
-
* The printStartupCode flag controls whether these lines are printed in the console as they execute (True) or run silently (False).
|
|
67
|
-
|
|
68
|
-
* Useful for initializing variables, importing libraries, or setting up your environment automatically.
|
|
69
|
-
|
|
70
|
-
### Autocomplete
|
|
71
|
-
|
|
72
|
-
* Suggests **keywords**, **built-in functions**, and **variables** in scope.
|
|
73
|
-
|
|
74
|
-
* Popup list appears after typing at least 2 characters.
|
|
75
|
-
|
|
76
|
-
* Only inserts the **missing portion** of a word.
|
|
77
|
-
|
|
78
|
-
* Navigate suggestions with **Up/Down arrows**, confirm with **Tab/Return**.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
### Multi-Line Input
|
|
82
|
-
|
|
83
|
-
* Supports **Shift+Enter** for inserting a new line with proper indentation.
|
|
84
|
-
|
|
85
|
-
* Automatically detects incomplete statements and continues the prompt.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
### Thread-Safe Execution
|
|
89
|
-
|
|
90
|
-
* Executes user code in a separate thread to prevent GUI freezing.
|
|
91
|
-
|
|
92
|
-
* Captures both `stdout` and `stderr` output and prints them in the console.
|
|
93
|
-
|
|
94
|
-
* Supports both **expressions (`eval`)** and **statements (`exec`)**.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
### Clickable History
|
|
98
|
-
|
|
99
|
-
* Hover previous commands to see them highlighted.
|
|
100
|
-
|
|
101
|
-
* Click to copy them back to the prompt for editing or re-execution.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
### Help Panel
|
|
105
|
-
|
|
106
|
-
* A resizable right-hand panel that displays Python documentation (help()) for any object.
|
|
107
|
-
|
|
108
|
-
* Opens when clicking ctrl+click on a function/method and can be closed with the "X" button.
|
|
109
|
-
|
|
110
|
-
* Scrollable and syntax-styled.
|
|
111
|
-
|
|
112
|
-
* Perfect for quick reference without leaving the console.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
### Easy Integration
|
|
116
|
-
|
|
117
|
-
* Automatically grabs **caller frame globals and locals** if not provided.
|
|
118
|
-
|
|
119
|
-
* Can be used standalone or embedded in larger CustomTkinter applications.
|
|
120
|
-
|
|
121
|
-
## Usage
|
|
122
|
-
|
|
123
|
-
```
|
|
124
|
-
import pysole
|
|
125
|
-
pysole.probe()
|
|
126
|
-
```
|
|
127
|
-
or for also running some code at the startup of the pysole
|
|
128
|
-
```
|
|
129
|
-
import pysole
|
|
130
|
-
pysole.probe(runRemainingCode=True, #< for executing the code below probe
|
|
131
|
-
printStartupCode=True #< for printing the command as well as it output
|
|
132
|
-
)
|
|
133
|
-
x = 1 #< initialize some variable
|
|
134
|
-
print(x) #< print the variable on the console
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
* Type Python commands in the `>>>` prompt and see live output.
|
|
138
|
-
|
|
139
|
-
## Keyboard Shortcuts
|
|
140
|
-
|
|
141
|
-
| Key | Action |
|
|
142
|
-
| --- | --- |
|
|
143
|
-
| `Enter` | Execute command (if complete) |
|
|
144
|
-
| `Shift+Enter` | Insert newline with auto-indent |
|
|
145
|
-
| `Tab` | Complete the current word / show suggestions |
|
|
146
|
-
| `Up/Down` | Navigate suggestion list |
|
|
147
|
-
| `Escape` | Hide suggestions |
|
|
148
|
-
| `Mouse Click` | Select previous command from history |
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
## Customization
|
|
152
|
-
|
|
153
|
-
* **Appearance mode**: Dark mode is default, but can be changed via files menu
|
|
154
|
-
|
|
155
|
-
* **Themes**: Pysole has multiple preconfigured themes. You can choose a theme via the Theme Picker, which updates the console colors and appearance. Preconfigured themes are loaded from themes.json and the selected theme is saved in settings.json so it persists across sessions.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
## License
|
|
160
|
-
|
|
161
|
-
MIT License – free to use, modify, and distribute.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|