text-console 2.0.2__tar.gz → 2.0.4__tar.gz

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.
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: text_console
3
+ Version: 2.0.4
4
+ Summary: ('A customizable Tkinter-based text console widget, in which a user types in commands to be sent to the Python interpreter.',)
5
+ Home-page: https://github.com/Ircama/text_console
6
+ Author: Ircama
7
+ License: EUPL-1.2
8
+ Keywords: shell console tkinter
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: European Union Public Licence 1.2 (EUPL 1.2)
11
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Intended Audience :: Developers
16
+ Requires-Python: >3.6
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Dynamic: author
20
+ Dynamic: classifier
21
+ Dynamic: description
22
+ Dynamic: description-content-type
23
+ Dynamic: home-page
24
+ Dynamic: keywords
25
+ Dynamic: license
26
+ Dynamic: license-file
27
+ Dynamic: requires-python
28
+ Dynamic: summary
29
+
30
+ # text_console
31
+
32
+ *text_console* is a customizable, Tkinter-based interactive shell widget that lets users type commands into a console pane and have them evaluated in your application’s Python environment. It supports arrows and command history. It’s designed for embedding in GUI apps, debugging, scripting, and educational tools as an API Playground.
33
+
34
+ It can also be used as a standalone Python command interpreter.
35
+
36
+ This program reflects the core functionality of [wxPython Shell](https://github.com/wxWidgets/wxPython-Classic/blob/master/wx/py/shell.py), offering an even richer feature set.
37
+
38
+ ## Key Features
39
+
40
+ - **Live code execution**
41
+
42
+ Send single- or multi-line Python code to the interpreter and see results immediately.
43
+
44
+ - **Integrated application context**
45
+
46
+ Access and modify your app’s variables and functions via the console_locals namespace.
47
+
48
+ - **Advanced editing**
49
+ - **Keyboard shortcuts:** all standard keyboard shortcut are allowed
50
+ - **Multiline editing:** Single line and multiline editing is allowed, also with copy/paste features. When pressing enter within an edited line, a popup appears to ask the requested action (execute the command, add a new line, abort). Shift-Enter is also allowed.
51
+ - **Prompt Protection:** The prompt area (`>>> ` or `... `) is protected. The cursor cannot move into or before the prompt, and editing actions (insertion, deletion) are blocked in the prompt area.
52
+ - **Smart Arrow Navigation:** Left and right arrow keys skip over prompt tags and any protected regions, ensuring the cursor only lands in editable areas. Arrow navigation also respects line boundaries and prompt positions.
53
+ - **Home/End Navigation:** The `Home` and `End` keys move the cursor to the beginning or end of the current line, but never into the prompt area.
54
+ - **Undo/Redo Support:** Full undo/redo support is enabled (`Ctrl+Z`/`Ctrl+Y`), with fine-grained control for character-by-character undo.
55
+ - **Tab and Shift+Tab:** Pressing `Tab` inserts four spaces. Pressing `Shift+Tab` removes up to four spaces.
56
+ - **Selection Awareness:** Editing and navigation actions are aware of text selection. For example, custom arrow key logic is bypassed when a selection is active.
57
+ - **Clear Console:** The console can be cleared with a single command, automatically restoring the prompt and positioning the cursor for new input.
58
+
59
+ - **Command history**
60
+
61
+ Navigate previous commands with ↑/↓ arrows; history is saved to a file you choose.
62
+
63
+ - **Cut/Copy/Paste/Clear**
64
+
65
+ Right-click context menu (and customizable via context_menu_items) for text editing.
66
+
67
+ - **Customizable UI**
68
+
69
+ The package provides flexibility to customize:
70
+
71
+ - `history_file`: Change the location of the history file
72
+ - `console_locals`: Add custom variables and functions to the console's namespace
73
+ - `context_menu_items`: Modify the right-click context menu
74
+ - `show_about_message`: Customize the about dialog content
75
+ - `show_help_content`: Customize the help window content
76
+ - `create_menu`: Override to completely customize the menu bar
77
+
78
+ - **Subclass-friendly**
79
+
80
+ Extend the TextConsole class and override any of the above to fit your needs.
81
+
82
+ ## Keyboard shortcuts
83
+
84
+ | Shortcut | Description |
85
+ |-------------------------|--------------------------------------------------------------------------------------------------|
86
+ | Return | Execute current command; if editing mid-line or multiline, show modal allowing to select either to run the code or insert a linefeed in the cursor position. |
87
+ | Shift Return | Insert a new line within the edited multiline command. |
88
+ | Control Return | Move the cursor to the end of the last line of input. |
89
+ | Tab | Indent code (up to 4 spaces); if selection, indent all selected lines. |
90
+ | Shift Tab | Un-indent (remove up to 4 spaces before cursor). |
91
+ | Down Arrow | Navigate to next command in history. |
92
+ | Up Arrow | Navigate to previous command in history. |
93
+ | Left Arrow | Move to previous non-tagged character. |
94
+ | Right Arrow | Move to next non-tagged character. |
95
+ | Control Left Arrow | Move to previous word. |
96
+ | Control Right Arrow | Move to next word. |
97
+
98
+ | Escape | Jump to last blank command (empty input) in history. |
99
+ | BackSpace | Delete character before cursor. |
100
+ | Control C | Copy selected code, removing prompts first. |
101
+ | Control V | Paste text from clipboard, handling prompts and multiline input. |
102
+ | Button-3 (Right Click) | Show context menu (Cut, Copy, Paste, Clear). |
103
+ | Control Z | Undo last edit (safe, ignores errors). |
104
+ | Control Y | Redo last undone edit (safe, ignores errors). |
105
+ | Control K | Remove the current element from the history. |
106
+ | Home | Move cursor to start of current line. |
107
+ | End | Move cursor to end of current line. |
108
+ | Control + | Increase font size. |
109
+ | Control - | Decrease font size. |
110
+ | Control 0 | Reset font size. |
111
+
112
+
113
+ Full information and usage details at the [text_console GitHub repository](https://github.com/Ircama/text_console).
@@ -0,0 +1,265 @@
1
+ # text_console
2
+
3
+ *text_console* is a customizable, Tkinter-based interactive shell widget that lets users type commands into a console pane and have them evaluated in your application’s Python environment. It supports arrows and command history. It’s designed for embedding in GUI apps, debugging, scripting, and educational tools as an API Playground.
4
+
5
+ It can also be used as a standalone Python command interpreter.
6
+
7
+ This program reflects the core functionality of [wxPython Shell](https://github.com/wxWidgets/wxPython-Classic/blob/master/wx/py/shell.py), offering an even richer feature set.
8
+
9
+ ## Key Features
10
+
11
+ - **Live code execution**
12
+
13
+ Send single- or multi-line Python code to the interpreter and see results immediately.
14
+
15
+ - **Integrated application context**
16
+
17
+ Access and modify your app’s variables and functions via the console_locals namespace.
18
+
19
+ - **Advanced editing**
20
+ - **Keyboard shortcuts:** all standard keyboard shortcut are allowed
21
+ - **Multiline editing:** Single line and multiline editing is allowed, also with copy/paste features. When pressing enter within an edited line, a popup appears to ask the requested action (execute the command, add a new line, abort). Shift-Enter is also allowed.
22
+ - **Prompt Protection:** The prompt area (`>>> ` or `... `) is protected. The cursor cannot move into or before the prompt, and editing actions (insertion, deletion) are blocked in the prompt area.
23
+ - **Smart Arrow Navigation:** Left and right arrow keys skip over prompt tags and any protected regions, ensuring the cursor only lands in editable areas. Arrow navigation also respects line boundaries and prompt positions.
24
+ - **Home/End Navigation:** The `Home` and `End` keys move the cursor to the beginning or end of the current line, but never into the prompt area.
25
+ - **Undo/Redo Support:** Full undo/redo support is enabled (`Ctrl+Z`/`Ctrl+Y`), with fine-grained control for character-by-character undo.
26
+ - **Tab and Shift+Tab:** Pressing `Tab` inserts four spaces. Pressing `Shift+Tab` removes up to four spaces.
27
+ - **Selection Awareness:** Editing and navigation actions are aware of text selection. For example, custom arrow key logic is bypassed when a selection is active.
28
+ - **Clear Console:** The console can be cleared with a single command, automatically restoring the prompt and positioning the cursor for new input.
29
+
30
+ - **Command history**
31
+
32
+ Navigate previous commands with ↑/↓ arrows; history is saved to a file you choose.
33
+
34
+ - **Cut/Copy/Paste/Clear**
35
+
36
+ Right-click context menu (and customizable via context_menu_items) for text editing.
37
+
38
+ - **Customizable UI**
39
+
40
+ The package provides flexibility to customize:
41
+
42
+ - `history_file`: Change the location of the history file
43
+ - `console_locals`: Add custom variables and functions to the console's namespace
44
+ - `context_menu_items`: Modify the right-click context menu
45
+ - `show_about_message`: Customize the about dialog content
46
+ - `show_help_content`: Customize the help window content
47
+ - `create_menu`: Override to completely customize the menu bar
48
+
49
+ - **Subclass-friendly**
50
+
51
+ Extend the TextConsole class and override any of the above to fit your needs.
52
+
53
+ ## Keyboard shortcuts
54
+
55
+ | Shortcut | Description |
56
+ |-------------------------|--------------------------------------------------------------------------------------------------|
57
+ | Return | Execute current command; if editing mid-line or multiline, show modal allowing to select either to run the code or insert a linefeed in the cursor position. |
58
+ | Shift Return | Insert a new line within the edited multiline command. |
59
+ | Control Return | Move the cursor to the end of the last line of input. |
60
+ | Tab | Indent code (up to 4 spaces); if selection, indent all selected lines. |
61
+ | Shift Tab | Un-indent (remove up to 4 spaces before cursor). |
62
+ | Down Arrow | Navigate to next command in history. |
63
+ | Up Arrow | Navigate to previous command in history. |
64
+ | Left Arrow | Move to previous non-tagged character. |
65
+ | Right Arrow | Move to next non-tagged character. |
66
+ | Control Left Arrow | Move to previous word. |
67
+ | Control Right Arrow | Move to next word. |
68
+
69
+ | Escape | Jump to last blank command (empty input) in history. |
70
+ | BackSpace | Delete character before cursor. |
71
+ | Control C | Copy selected code, removing prompts first. |
72
+ | Control V | Paste text from clipboard, handling prompts and multiline input. |
73
+ | Button-3 (Right Click) | Show context menu (Cut, Copy, Paste, Clear). |
74
+ | Control Z | Undo last edit (safe, ignores errors). |
75
+ | Control Y | Redo last undone edit (safe, ignores errors). |
76
+ | Control K | Remove the current element from the history. |
77
+ | Home | Move cursor to start of current line. |
78
+ | End | Move cursor to end of current line. |
79
+ | Control + | Increase font size. |
80
+ | Control - | Decrease font size. |
81
+ | Control 0 | Reset font size. |
82
+
83
+ ## Installation
84
+
85
+ ```bash
86
+ pip install text-console
87
+ ```
88
+
89
+ ## Playground
90
+
91
+ ```
92
+ python -m text_console
93
+ ```
94
+
95
+ Available options:
96
+
97
+ ```
98
+ Python Console [-h] [-V]
99
+
100
+ optional arguments:
101
+ -h, --help show this help message and exit
102
+ -V, --version Print version and exit
103
+
104
+ A customizable Tkinter-based text console widget.
105
+ ```
106
+
107
+ ### Basic usage with default settings
108
+
109
+ ```python
110
+ import tkinter as tk
111
+ from text_console import TextConsole
112
+
113
+ class TkConsole(tk.Tk):
114
+ def __init__(self):
115
+ super().__init__()
116
+ self.title("Python Console")
117
+ self.geometry("800x400")
118
+
119
+ # Initialize the TextConsole widget
120
+ console = TextConsole(self, self)
121
+ console.pack(fill='both', expand=True)
122
+
123
+ # Configure grid resizing for the main window
124
+ self.grid_rowconfigure(0, weight=1)
125
+ self.grid_columnconfigure(0, weight=1)
126
+
127
+
128
+ app = TkConsole()
129
+ app.mainloop()
130
+ ```
131
+
132
+ ### Invoking TextConsole from a Master widget
133
+
134
+ ```python
135
+ import tkinter as tk
136
+ from text_console import TextConsole
137
+
138
+ class TkConsole(tk.Tk):
139
+ def __init__(self):
140
+ super().__init__()
141
+ self.title("Python Console")
142
+ self.geometry("100x70")
143
+
144
+ # Add a button to launch the TextConsole
145
+ run_console_button = tk.Button(
146
+ self,
147
+ text="Debug Console",
148
+ command=self.run_text_console
149
+ )
150
+ run_console_button.pack(pady=20) # Add some spacing around the button
151
+
152
+ # Configure grid resizing for the main window
153
+ self.grid_rowconfigure(0, weight=1)
154
+ self.grid_columnconfigure(0, weight=1)
155
+
156
+ def run_text_console(self):
157
+ """Launches the TextConsole in a new Toplevel window."""
158
+ console_window = tk.Toplevel(self)
159
+ console_window.title("Debug Console")
160
+ console_window.geometry("800x400")
161
+
162
+ # Initialize the TextConsole widget
163
+ console = TextConsole(self, console_window)
164
+ console.pack(fill='both', expand=True)
165
+
166
+ app = TkConsole()
167
+ app.mainloop()
168
+ ```
169
+
170
+ ### Customized console through subclassing
171
+
172
+ ```python
173
+ from text_console import TextConsole
174
+
175
+ class MyCustomConsole(TextConsole):
176
+
177
+ # Override class attributes
178
+ history_file = "my_custom_history.txt"
179
+
180
+ console_locals = {
181
+ "my_var": 42,
182
+ "my_function": lambda x: x * 2
183
+ }
184
+
185
+ context_menu_items = [
186
+ ("Custom Action", "custom_action"),
187
+ "-", # separator
188
+ ("Clear", "clear")
189
+ ]
190
+
191
+ show_about_message = "My Custom Console v1.0"
192
+ show_help_content = "This is my custom console help content"
193
+
194
+ def custom_action(self):
195
+ print("Custom action executed!")
196
+
197
+ def create_menu(self, master):
198
+ # Override to create a custom menu
199
+ super().create_menu(main, master)
200
+
201
+ # Add "Web Site" to the Help menu
202
+ menu_bar = master.nametowidget(master.cget('menu')) # Get the menu widget
203
+ help_menu = list(menu_bar.children.values())[2] # Access the Help menu (third = 2)
204
+ help_menu.insert_command(
205
+ help_menu.index("end"),
206
+ label="Web Site",
207
+ command=self.new_action
208
+ )
209
+
210
+ # Override to create a custom menu
211
+ menu_bar = Menu(master)
212
+ master.config(menu=menu_bar)
213
+
214
+ # Custom menu items
215
+ custom_menu = Menu(menu_bar, tearoff=0)
216
+ custom_menu.add_command(label="My Action", command=self.custom_action)
217
+ menu_bar.add_cascade(label="Custom", menu=custom_menu)
218
+
219
+ def new_action(self):
220
+ pass
221
+
222
+ """ Alternatively, override create_menu:
223
+ def create_menu(self, master):
224
+ # Override to create a custom menu
225
+ menu_bar = Menu(master)
226
+ master.config(menu=menu_bar)
227
+
228
+ # Custom menu items
229
+ custom_menu = Menu(menu_bar, tearoff=0)
230
+ custom_menu.add_command(label="My Action", command=self.custom_action)
231
+ menu_bar.add_cascade(label="Custom", menu=custom_menu)
232
+ """
233
+
234
+
235
+ # Use the custom console
236
+ text_console = MyCustomConsole(main, master)
237
+ ```
238
+
239
+ ## Key bindings
240
+
241
+ The text_console module provides the following key bindings for efficient navigation and interaction:
242
+
243
+ - `Ctrl + Enter (<Control-Return>)`
244
+
245
+ Submit a command while keeping the current context open.
246
+
247
+ - `Shift + Enter (<Shift-Return>)`
248
+
249
+ Insert a newline without triggering a default submission action.
250
+
251
+ - `Tab (<Tab>)`
252
+
253
+ Indent input.
254
+
255
+ - `Down Arrow (<Down>)`
256
+
257
+ Next command from the history.
258
+
259
+ - `Up Arrow (<Up>)`
260
+
261
+ Previous command from the history.
262
+
263
+ - `Right-Click (<Button-3>)`
264
+
265
+ Displays the context menu.
@@ -0,0 +1,5 @@
1
+ from .text_console import BaseTextConsole
2
+ from .history import History
3
+ from .__version__ import __version__
4
+
5
+ __all__ = ["BaseTextConsole", "History"]
@@ -3,11 +3,11 @@ import argparse
3
3
  import tkinter as tk
4
4
  import webbrowser
5
5
 
6
- from . import TextConsole
6
+ from . import BaseTextConsole
7
7
  from .__version__ import __version__
8
8
 
9
9
 
10
- class TkTextConsole(TextConsole):
10
+ class TkTextConsole(BaseTextConsole):
11
11
 
12
12
  """Subclass that adds the second element to the Help menu."""
13
13
  def create_menu(self, main, master):
@@ -0,0 +1 @@
1
+ __version__ = "2.0.4"