Skip to content

Commit

Permalink
Changed the GUI library to ttkbootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonZhang2024 committed May 19, 2024
1 parent f6248e8 commit f42a269
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 37 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pillow
ttkbootstrap
13 changes: 9 additions & 4 deletions src/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def convert_str(markdown: list, preview=False, file_path='./') -> str:
<!This is the preview.>
<style>
html {
font-family: 'Courier';
font-family: 'Sans Mono';
}
</style>
'''\
Expand Down Expand Up @@ -193,7 +193,7 @@ def convert_single_line(line: str) -> str:
line = line.replace(i, s)
have_style = True

link = re.search(r'\[[\w\s]+?\]\([\w\s]+?\)', line)
link = re.search(r'\[[\w\W\s]+?\]\([\w\s]+?\)', line)
if link:
link = str(link.group(0))
text = re.match(r'\[[\w\s]+?\]', link).group(0)
Expand All @@ -206,14 +206,19 @@ def convert_single_line(line: str) -> str:
line = line.replace(link, html_link)
have_style = True

img = re.search(r'!\[[\w\s]+?\]\([\w\W]+?\)', line)
img = re.search(r'!\[[\w\W\s]+?\]\([\w\W]+?\)', line)
if img:
img = str(img.group(0))
description = re.search(r'!\[[\w\s]+?\]', img)
description = description.group(0)
if description:
description = description.group(0)
else:
description = ''

src = img.replace(description, '')\
.replace('(', '')\
.replace(')', '')

description = description.replace('![', '')\
.replace(']', '')
image = f'<img src={src} alt={description}/>'
Expand Down
34 changes: 19 additions & 15 deletions src/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
module main
The main program of tkMarker
"""

import tkinter
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
import webbrowser
import os
from tkinter import filedialog, scrolledtext
from tkinter import filedialog
import uuid

from converter import convert
from get_help import show_project_info
import get_help

"""
tkMarker
Expand Down Expand Up @@ -45,6 +45,9 @@
]


def show_project_info():
get_help.show_project_info()

def load_preview():
# Load the preview
markdown_text_for_preview = text.get('1.0', 'end') # Get the text
Expand Down Expand Up @@ -114,8 +117,8 @@ def open_file():
t = f.read()

# Insert the text into the editor
text.delete(1.0, tkinter.END)
text.insert(tkinter.END, t)
text.delete(1.0, ttk.END)
text.insert(ttk.END, t)
editor.title(filename)


Expand All @@ -141,36 +144,35 @@ def new_file():
global filename
filename = 'New File'
global editor
editor = tkinter.Tk()
editor = ttk.Window(themename='lumen')
editor.title(filename)
editor.wm_title('tkMarker')

# Set full screen
width = editor.winfo_screenwidth()
height = editor.winfo_screenheight()
editor.geometry(f'{width}x{height}')
menubar = tkinter.Menu(editor)
#editor.geometry('1000x1000')
menubar = ttk.Menu(editor)

# Add the 'File' menubar
file = tkinter.Menu(menubar, tearoff=0)
file = ttk.Menu(menubar, tearoff=0)
menubar.add_cascade(label='File', menu=file)

# Add the 'Edit' menubar
global edit
edit = tkinter.Menu(menubar, tearoff=0)
edit = ttk.Menu(menubar, tearoff=0)
menubar.add_cascade(label='Edit', menu=edit)

# Add the 'Help' menubar
help_menu = tkinter.Menu(editor, tearoff=0)
help_menu = ttk.Menu(editor, tearoff=0)
menubar.add_cascade(label='Help', menu=help_menu)

# Add the 'Preview' button
menubar.add_command(label='Preview', command=load_preview)

# Add the text area
global text
text = scrolledtext.ScrolledText(editor, undo=True, font=('Sans Mono', 15))
text = ttk.ScrolledText(editor, undo=True, font=('Sans Mono', 15))
text.pack(fill='both', expand=True)

# Set focus
text.focus_set()

Expand All @@ -184,6 +186,8 @@ def new_file():
edit.add_command(label='Paste', command=paste)
edit.add_command(label='Copy', command=copy)
edit.add_command(label='Cut', command=cut)
edit.add_separator()
edit.add_command(label='Hide this menu')

# Pack the menubar
editor.config(menu=menubar)
Expand Down
32 changes: 14 additions & 18 deletions src/get_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
Get the help
"""

import tkinter
from tkinter import ttk
import webbrowser
import ttkbootstrap as ttk
from ttkbootstrap.constants import *

"""
tkMarker
Expand Down Expand Up @@ -43,50 +43,46 @@ def show_project_info():
Function show_project_info()
Show the project infomation
"""
info_page = tkinter.Tk()
info_page.title('About')
info_page.config(cursor='star')
info_page = ttk.Window(title='About', themename='lumen')
label = ttk.Label(
info_page,
text='tkMarker\n',
font=('Consolas', 20)
)
label.pack()

description = tkinter.Label(
description = ttk.Label(
info_page,
text='A Markdown editor using tkinter',
font=('Consolas', 10)
)
description.pack()

github_repos = ttk.Button(
info_page,
text='GitHub',
command=open_github_repos
command=open_github_repos,
bootstyle=PRIMARY
)
github_repos.pack()

website = tkinter.Button(
website = ttk.Button(
info_page,
text='Website',
bg='cyan',
command=open_website
command=open_website,
bootstyle=(INFO, OUTLINE)
)
website.pack()

issue_tracker = ttk.Button(
info_page,
text='Report an issue',
command=open_issue_url
command=open_issue_url,
bootstyle=SECONDARY
)

github_repos.pack()
website.pack()
issue_tracker.pack()

feel_free_label = tkinter.Label(
feel_free_label = ttk.Label(
info_page,
text='Feel free to report an issue or start a pull request.',
font=('Consolas', 10)
)
feel_free_label.pack()

Expand Down

0 comments on commit f42a269

Please sign in to comment.