Skip to content

Commit

Permalink
✨feat: add themes, improve settings, fix #62
Browse files Browse the repository at this point in the history
Add new color themes:
- GitHub Dark, Light, and Dimmed
- Solarized Dark and Light
- Enhanced default light theme

Improve settings interface:
- Add theme dropdown selector
- Implement color chooser component
- Fix line number styling and visibility (Closes #62)
  • Loading branch information
mostypc123 committed Jan 20, 2025
1 parent 7e146bb commit 8d71bf5
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 169 deletions.
280 changes: 124 additions & 156 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
## Time
import time
## Other
import json
import threading
import pywinstyles
import webbrowser
import pyflakes
# Local imports
## Extensions
import extension_menubar
Expand Down Expand Up @@ -171,7 +171,7 @@ def InitUI(self):
panel.SetBackgroundColour("#fff")

vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(splitter, proportion=1, flag=wx.EXPAND | wx.ALL, border=10) #border 0 for minimalism
vbox.Add(splitter, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)

panel.SetSizer(vbox)

Expand Down Expand Up @@ -745,179 +745,147 @@ def on_text_change(event):
# Bind a key event to trigger autocomplete after typing
text_area.Bind(wx.EVT_CHAR, self.OnChar)

# Set dark background and light text for the entire control
# Set theme colors for the entire control
for text_area in (text_area, minimap):
try:
with open("theme.xcfg", 'r') as file:
theme_content = file.read().strip()

# Check if theme content is JSON
if theme_content.startswith('{'):
theme_data = json.loads(theme_content)
dark_bg_color = theme_data.get('background', "#1B1F2B")
light_text_color = theme_data.get('foreground', "#FFFFFF")
cmt_color = theme_data.get('comment', "#68C147")
keyword_color = theme_data.get('keyword', "#569CD6")
string_color = theme_data.get('string', "#BA9EFE")
number_color = theme_data.get('number', "#FFDD54")
operator_color = theme_data.get('operator', "#D4D4D4")
line_number_bg = theme_data.get('lineNumberBg', dark_bg_color)
else:
# Built-in themes
theme = theme_content
if theme == "dark":
dark_bg_color = "#1B1F2B"
light_text_color = "#FFFFFF"
cmt_color = "#68C147"
keyword_color = "#569CD6"
string_color = "#BA9EFE"
number_color = "#FFDD54"
operator_color = "#D4D4D4"
elif theme == "light":
dark_bg_color = "#FFFFFF"
light_text_color = "#000000"
cmt_color = "#008000"
keyword_color = "#0000FF"
string_color = "#A31515"
number_color = "#098658"
operator_color = "#000000"
elif theme == "night":
dark_bg_color = "#2f3139"
light_text_color = "#FFFFFF"
cmt_color = "#eab676"
keyword_color = "#569CD6"
string_color = "#BA9EFE"
number_color = "#FFDD54"
operator_color = "#D4D4D4"
elif theme == "obsidian":
dark_bg_color = "#212232"
light_text_color = "#FFFFFF"
cmt_color = "#EFC3CA"
keyword_color = "#569CD6"
string_color = "#BA9EFE"
number_color = "#FFDD54"
operator_color = "#D4D4D4"
elif theme == "solarized-light":
dark_bg_color = "#FDF6E3"
light_text_color = "#657B83"
cmt_color = "#93A1A1"
keyword_color = "#859900"
string_color = "#2AA198"
number_color = "#D33682"
operator_color = "#586E75"
elif theme == "solarized-dark":
dark_bg_color = "#002B36"
light_text_color = "#839496"
cmt_color = "#586E75"
keyword_color = "#859900"
string_color = "#2AA198"
number_color = "#D33682"
operator_color = "#93A1A1"
elif theme == "github-dark":
dark_bg_color = "#0D1117"
light_text_color = "#C9D1D9"
cmt_color = "#8B949E"
keyword_color = "#FF7B72"
string_color = "#A5D6FF"
number_color = "#79C0FF"
operator_color = "#C9D1D9"
elif theme == "github-dimmed":
dark_bg_color = "#22272E"
light_text_color = "#ADBAC7"
cmt_color = "#768390"
keyword_color = "#F47067"
string_color = "#96D0FF"
number_color = "#6CB6FF"
operator_color = "#ADBAC7"
elif theme == "github-light":
dark_bg_color = "#FFFFFF"
light_text_color = "#24292F"
cmt_color = "#6E7781"
keyword_color = "#CF222E"
string_color = "#0A3069"
number_color = "#0550AE"
operator_color = "#24292F"
else:
dark_bg_color = "#1B1F2B"
light_text_color = "#FFFFFF"
cmt_color = "#68C147"
keyword_color = "#569CD6"
string_color = "#BA9EFE"
number_color = "#FFDD54"
operator_color = "#D4D4D4"

line_number_bg = dark_bg_color

with open("theme.xcfg", 'r') as file:
theme = file.read()

if theme == "dark":
dark_bg_color = "#1B1F2B"
cmt_color = "#68C147"
elif theme == "light":
dark_bg_color = "#FFFFFF"
light_text_color = "#1e1e1e"
cmt_color = "#063970"
elif theme == "night":
dark_bg_color = "#2f3139"
cmt_color = "#eab676"
elif theme == "obsidian":
dark_bg_color = "#212232"
cmt_color = "#EFC3CA"
else:
except Exception as e:
print(f"Error loading theme: {e}")
# Default fallback colors
dark_bg_color = "#1B1F2B"

if theme != "light":
light_text_color = "#FFFFFF"
cmt_color = "#68C147"
keyword_color = "#569CD6"
string_color = "#BA9EFE"
number_color = "#FFDD54"
operator_color = "#D4D4D4"
line_number_bg = dark_bg_color

text_area.StyleSetBackground(stc.STC_STYLE_DEFAULT, dark_bg_color)
text_area.StyleSetForeground(stc.STC_STYLE_DEFAULT, light_text_color)
text_area.StyleClearAll() # Apply the default style to all text
text_area.StyleClearAll()

if file_name.endswith(".py"):
self.SetStatusText(" Python", 1)

# Set up Python syntax highlighting
text_area.SetLexer(stc.STC_LEX_PYTHON)

# Comments
text_area.StyleSetSpec(stc.STC_P_COMMENTLINE, f"fore:{cmt_color},italic,back:{dark_bg_color}")
text_area.StyleSetSpec(stc.STC_P_STRING, f"fore:{string_color},italic,back:{dark_bg_color}")
text_area.StyleSetSpec(stc.STC_P_WORD, f"fore:{keyword_color},bold,back:{dark_bg_color}")
text_area.SetKeyWords(0, "def class return if else elif import from as not is try except finally for while in with pass lambda")
text_area.StyleSetSpec(stc.STC_P_IDENTIFIER, f"fore:{light_text_color},italic,back:{dark_bg_color}")
text_area.StyleSetSpec(stc.STC_P_OPERATOR, f"fore:{operator_color},bold,back:{dark_bg_color}")
text_area.StyleSetSpec(stc.STC_P_NUMBER, f"fore:{number_color},italic,back:{dark_bg_color}")
text_area.StyleSetSpec(stc.STC_P_DECORATOR, f"fore:{keyword_color},italic,back:{dark_bg_color}")

# Strings
text_area.StyleSetSpec(stc.STC_P_STRING, f"fore:#BA9EFE,italic,back:{dark_bg_color}")

# Keywords
text_area.StyleSetSpec(stc.STC_P_WORD, f"fore:#569CD6,bold,back:{dark_bg_color}")
text_area.SetKeyWords(0,
"def class return if else elif import from as not is try except finally for while in with pass lambda")

# Functions and variables
text_area.StyleSetSpec(stc.STC_P_IDENTIFIER, f"fore:#7BCCE1,italic,back:{dark_bg_color}")

# Operators
text_area.StyleSetSpec(stc.STC_P_OPERATOR, f"fore:#D4D4D4,bold,back:{dark_bg_color}")

# Numbers
text_area.StyleSetSpec(stc.STC_P_NUMBER, f"fore:#FFDD54,italic,back:{dark_bg_color}")

# Decorators
text_area.StyleSetSpec(stc.STC_P_DECORATOR, f"fore:#C586C0,italic,back:{dark_bg_color}")

elif file_name.endswith(".html"):
self.SetStatusText(" HTML", 1)
# Set up HTML syntax highlighting
text_area.SetLexer(stc.STC_LEX_HTML)

# Tags
text_area.StyleSetSpec(stc.STC_H_TAG, f"fore:#569CD6,bold,back:{dark_bg_color}")

# Attributes
text_area.StyleSetSpec(stc.STC_H_ATTRIBUTE, f"fore:#D69D85,italic,back:{dark_bg_color}")

# Attribute values
text_area.StyleSetSpec(stc.STC_H_VALUE, f"fore:#BA9EFE,italic,back:{dark_bg_color}")

# Comments
text_area.StyleSetSpec(stc.STC_H_COMMENT, f"fore:{cmt_color},italic,back:{dark_bg_color}")

# Entities
text_area.StyleSetSpec(stc.STC_H_ENTITY, f"fore:#FFDD54,italic,back:{dark_bg_color}")

# Numbers
text_area.StyleSetSpec(stc.STC_H_NUMBER, f"fore:#FFDD54,italic,back:{dark_bg_color}")

# Operators (like '=')
text_area.StyleSetSpec(stc.STC_H_OTHER, f"fore:#D4D4D4,bold,back:{dark_bg_color}")

elif file_name.endswith(".json"):
self.SetStatusText(" JSON", 1)
# Set up JSON syntax highlighting
text_area.SetLexer(stc.STC_LEX_JSON)

# Strings (e.g., "key" or "value")
text_area.StyleSetSpec(stc.STC_JSON_STRING, f"fore:#BA9EFE,italic,back:{dark_bg_color}")

# Numbers (e.g., 123, 3.14)
text_area.StyleSetSpec(stc.STC_JSON_NUMBER, f"fore:#FFDD54,back:{dark_bg_color}")

# Colons (e.g., in "key": "value")
text_area.StyleSetSpec(stc.STC_JSON_OPERATOR, f"fore:#D4D4D4,bold,back:{dark_bg_color}")

# Keywords (e.g., true, false, null)
text_area.StyleSetSpec(stc.STC_JSON_KEYWORD, f"fore:#68C147,bold,back:{dark_bg_color}")

elif file_name.endswith(".css"):
self.SetStatusText(" CSS", 1)
# Set up CSS syntax highlighting
text_area.SetLexer(stc.STC_LEX_CSS)

# Default text
text_area.StyleSetSpec(stc.STC_CSS_DEFAULT, f"fore:#D4D4D4,back:{dark_bg_color}")

# Comments (e.g., /* This is a comment */)
text_area.StyleSetSpec(stc.STC_CSS_COMMENT, f"fore:{cmt_color},italic,back:{dark_bg_color}")

# Tag Names (e.g., body, h1, div)
text_area.StyleSetSpec(stc.STC_CSS_TAG, f"fore:#569CD6,bold,back:{dark_bg_color}")

# Class and IDs (e.g., .className, #idName)
text_area.StyleSetSpec(stc.STC_CSS_CLASS, f"fore:#7BCCE1,italic,back:{dark_bg_color}")
text_area.StyleSetSpec(stc.STC_CSS_ID, f"fore:#FFAA33,italic,back:{dark_bg_color}")

# Attributes (e.g., color, margin, padding)
text_area.StyleSetSpec(stc.STC_CSS_ATTRIBUTE, f"fore:#BA9EFE,bold,back:{dark_bg_color}")

# Pseudo-classes and Elements (e.g., :hover, ::before)
text_area.StyleSetSpec(stc.STC_CSS_PSEUDOCLASS, f"fore:#C586C0,italic,back:{dark_bg_color}")
text_area.StyleSetSpec(stc.STC_CSS_PSEUDOELEMENT, f"fore:#C586C0,italic,back:{dark_bg_color}")

# Property Values (e.g., red, 10px, 1em)
text_area.StyleSetSpec(stc.STC_CSS_VALUE, f"fore:#FFDD54,back:{dark_bg_color}")

# Operators (e.g., :, ;, {, })
text_area.StyleSetSpec(stc.STC_CSS_OPERATOR, f"fore:#D4D4D4,bold,back:{dark_bg_color}")

# Import Statement (e.g., @import)
text_area.StyleSetSpec(stc.STC_CSS_DIRECTIVE, f"fore:#68C147,bold,back:{dark_bg_color}")

elif file_name.endswith(".js"):
self.SetStatusText(" Javascript", 1)
# Set up JavaScript syntax highlighting
text_area.SetLexer(stc.STC_LEX_ESCRIPT)

# Default text
text_area.StyleSetSpec(stc.STC_ESCRIPT_DEFAULT, f"fore:#D4D4D4,back:{dark_bg_color}")

# Comments (e.g., // This is a comment, /* multi-line */)
text_area.StyleSetSpec(stc.STC_ESCRIPT_COMMENT, f"fore:{cmt_color},italic,back:{dark_bg_color}")
text_area.StyleSetSpec(stc.STC_ESCRIPT_COMMENTLINE, f"fore:{cmt_color},italic,back:{dark_bg_color}")
text_area.StyleSetSpec(stc.STC_ESCRIPT_COMMENTDOC, f"fore:{cmt_color},italic,back:{dark_bg_color}")

# Keywords (e.g., var, let, const, function)
text_area.StyleSetSpec(stc.STC_ESCRIPT_WORD, f"fore:#569CD6,bold,back:{dark_bg_color}")

# Strings (e.g., "text", 'text', `template literal`)
text_area.StyleSetSpec(stc.STC_ESCRIPT_STRING, f"fore:#BA9EFE,italic,back:{dark_bg_color}")

# Numbers (e.g., 123, 3.14, 0xFF)
text_area.StyleSetSpec(stc.STC_ESCRIPT_NUMBER, f"fore:#FFDD54,back:{dark_bg_color}")

# Identifiers (e.g., variables, function names)
text_area.StyleSetSpec(stc.STC_ESCRIPT_IDENTIFIER, f"fore:#D4D4D4,back:{dark_bg_color}")

# Operators (e.g., =, +, -, *, /, &&, ||)
text_area.StyleSetSpec(stc.STC_ESCRIPT_OPERATOR, f"fore:#D4D4D4,bold,back:{dark_bg_color}")

# Set JavaScript Keywords
text_area.SetKeyWords(0, "var let const function return if else for while do break continue switch case default try catch throw new this super class extends export import async await typeof instanceof delete")

# Similar styling updates for HTML, JSON, CSS, and JS...
# [Previous language-specific styling code remains the same but using the theme variables]

# Default style
text_area.StyleSetSpec(stc.STC_P_DEFAULT, f"fore:{light_text_color},italic,back:{dark_bg_color}")

# Adjust indentation guides
text_area.SetIndentationGuides(True)
text_area.StyleSetSpec(stc.STC_STYLE_LINENUMBER, f"fore:{light_text_color},italic,back:{dark_bg_color}")
# Set line number background
text_area.StyleSetSpec(stc.STC_STYLE_LINENUMBER, f"fore:{light_text_color},back:{line_number_bg}")
text_area.SetMarginType(1, stc.STC_MARGIN_NUMBER)
text_area.SetMarginWidth(1, 30)

Expand Down
Loading

0 comments on commit 8d71bf5

Please sign in to comment.