Skip to content

Commit 9e4f225

Browse files
committed
kPad 1.1.1 RC2 "Memorian" Recent Files fix
1 parent c6f676d commit 9e4f225

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

.DS_Store

6 KB
Binary file not shown.

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ kPad is a Notepad app made in Python and CustomTkinter.
33

44
**If you want to compile for your platform or just run the file, you will need customtkinter installed.**
55

6+
### kPad 1.1.1 (RC2)
7+
68
## Description
79
kPad is a lightweight and user-friendly text editor designed for quick note-taking and editing. Built using Python and the CustomTkinter library, it offers a modern interface with essential features for everyday text editing tasks.
810

@@ -32,7 +34,7 @@ Make sure you have Python 3.13+.
3234

3335
**Cmd-N** -> New file
3436

35-
I hope to add config files / config dictionary in the next releases.
37+
Config files in their respective folder.
3638
- Responsive window resizing.
3739

3840
## Running the App
@@ -54,4 +56,11 @@ Requests features with a new **issue**.
5456

5557
---
5658

57-
Feel free to contribute or report issues on the **project repository**.
59+
Feel free to contribute or report issues on the **project repository**.
60+
61+
## TODO
62+
- [ ] Add syntax highlighting for Python
63+
- [ ] Implement recent files menu
64+
- [ ] Add find/search dialog
65+
- [ ] Improve autosave with dirty flag
66+
- [ ] Implement extensions

main.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from tkinter import simpledialog
66
import time, threading
77
import os, json, platform
8+
import markdown
9+
from tkinterweb import HtmlFrame
810

911

1012
# ██╗░░██╗██████╗░░█████╗░██████╗░
@@ -160,15 +162,34 @@ def save_config():
160162
CONFIGURATION['window_geometry'] = [self.winfo_width(), self.winfo_height()]
161163
with open(CONFIG_PATH, 'w') as f:
162164
json.dump(CONFIGURATION, f, indent=4)
165+
166+
def auto_indent(event):
167+
tb = event.widget
168+
cursor_index = tb.index("insert")
169+
line_number = int(cursor_index.split('.')[0])
170+
if line_number > 1:
171+
prev_line = tb.get(f"{line_number-1}.0", f"{line_number-1}.end")
172+
indent = len(prev_line) - len(prev_line.lstrip(' '))
173+
if prev_line.strip().endswith(":") or prev_line.strip().endswith("{"):
174+
indent += 4
175+
prev_line_num = line_number - 1
176+
while prev_line_num > 0:
177+
prev_line_text = tb.get(f"{prev_line_num}.0", f"{prev_line_num}.end")
178+
if prev_line_text.strip() != "":
179+
break
180+
prev_line_num -= 1
181+
indent = len(prev_line_text) - len(prev_line_text.lstrip(' '))
182+
tb.insert("insert", "\n" + " " * indent)
183+
return "break"
163184

164185
menu = Menu(self)
165186
file_menu = Menu(menu, tearoff=0)
166187
file_menu.add_command(label='Open', command=open_from_file)
167188
file_menu.add_command(label='Save As...', command=save_as)
168189
file_menu.add_command(label='Save...', command=save_file)
169190
file_menu.add_separator()
170-
for index, path in CONFIGURATION['recent_files']['recent_files_paths']:
171-
file_menu.add_command(label=f'Open {path} ({index+1})...')
191+
for index, path in enumerate(CONFIGURATION['recent_files']['recent_file_paths']):
192+
file_menu.add_command(label=f'Open {path} ({index+1})...', command=lambda p=path: open_from_file(p))
172193
file_menu.add_separator()
173194
file_menu.add_command(label='Exit', command=self.destroy)
174195
menu.add_cascade(label='File', menu=file_menu)
@@ -212,6 +233,7 @@ def update_cursor_info(event=None):
212233

213234
self.textbox.bind('<KeyRelease>', update_cursor_info)
214235
self.textbox.bind('<ButtonRelease>', update_cursor_info)
236+
self.textbox.bind('<Return>', auto_indent)
215237

216238
# Cross-platform key bindings
217239
system = platform.system()
@@ -235,7 +257,9 @@ def update_cursor_info(event=None):
235257
self.stats_line_col = ctk.CTkLabel(self.stats_text_frame, text='Ln: 1 Col: 1 Ch: 0')
236258
self.stats_line_col.pack(side=ctk.RIGHT)
237259

260+
self.html = markdown.markdown()
238261
self.textbox.pack(fill='both', expand=True)
262+
self.html_frame.pack(fill='both', expand=True)
239263
self.protocol('WM_DELETE_WINDOW', lambda: [save_file(), save_config(), self.destroy()])
240264

241265

0 commit comments

Comments
 (0)