Theme switcher implemented
This commit is contained in:
parent
d6d09ba405
commit
cc8aaca206
85
main.py
85
main.py
@ -317,7 +317,12 @@ class MarkdownEditor(QMainWindow):
|
||||
view_menu = menu_bar.addMenu("&View")
|
||||
self.add_actions_to_menu(view_menu, [
|
||||
("Toggle Split View Mode", self.toggle_split_view),
|
||||
("Toggle Toolbar", self.toggle_toolbar)
|
||||
("Toggle Toolbar", self.toggle_toolbar),
|
||||
("Theme", [
|
||||
("Dark", lambda: self.change_theme("dark")),
|
||||
("Light", lambda: self.change_theme("light")),
|
||||
("System", lambda: self.change_theme("system"))
|
||||
])
|
||||
])
|
||||
|
||||
window_menu = menu_bar.addMenu("&Window")
|
||||
@ -335,16 +340,16 @@ class MarkdownEditor(QMainWindow):
|
||||
])
|
||||
|
||||
def add_actions_to_menu(self, menu, actions):
|
||||
"""
|
||||
Add actions to a given menu.
|
||||
|
||||
Args:
|
||||
menu (QMenu): The menu to which actions will be added.
|
||||
actions (list of tuples): Each tuple contains the text for the menu item and the handler function.
|
||||
"""
|
||||
for action_text, action_handler in actions:
|
||||
for action_text, action_func in actions:
|
||||
if isinstance(action_func, list): # Submenu
|
||||
submenu = menu.addMenu(action_text)
|
||||
for sub_action_text, sub_action_func in action_func:
|
||||
sub_action = QAction(sub_action_text, self)
|
||||
sub_action.triggered.connect(sub_action_func)
|
||||
submenu.addAction(sub_action)
|
||||
else:
|
||||
action = QAction(action_text, self)
|
||||
action.triggered.connect(action_handler)
|
||||
action.triggered.connect(action_func)
|
||||
menu.addAction(action)
|
||||
|
||||
def create_tool_bar(self):
|
||||
@ -666,8 +671,64 @@ class MarkdownEditor(QMainWindow):
|
||||
else:
|
||||
QMessageBox.critical(self, "Directory Selection Error", "Invalid directory path")
|
||||
|
||||
def change_theme(self):
|
||||
pass
|
||||
def change_theme(self, theme):
|
||||
if theme == "dark":
|
||||
self.apply_dark_theme()
|
||||
elif theme == "light":
|
||||
self.apply_light_theme()
|
||||
elif theme == "system":
|
||||
self.apply_system_theme()
|
||||
|
||||
def apply_dark_theme(self):
|
||||
dark_stylesheet = """
|
||||
QMainWindow {
|
||||
background-color: #282c34; /* Dark gray background */
|
||||
color: #abb2bf; /* Light gray text */
|
||||
}
|
||||
QMenuBar {
|
||||
background-color: #21252b; /* Slightly darker gray for menu bar */
|
||||
color: #abb2bf;
|
||||
}
|
||||
QMenuBar::item {
|
||||
background-color: #21252b;
|
||||
color: #abb2bf;
|
||||
}
|
||||
QMenuBar::item:selected { /* when selected using mouse or keyboard */
|
||||
background-color: #282c34;
|
||||
}
|
||||
QTextEdit, QTreeView {
|
||||
background-color: #282c34;
|
||||
color: #abb2bf;
|
||||
}
|
||||
"""
|
||||
self.setStyleSheet(dark_stylesheet)
|
||||
|
||||
def apply_light_theme(self):
|
||||
light_stylesheet = """
|
||||
QMainWindow {
|
||||
background-color: #fafafa; /* Very light gray, almost white */
|
||||
color: #383a42; /* Dark gray text */
|
||||
}
|
||||
QMenuBar {
|
||||
background-color: #f0f0f0; /* Light gray for menu bar */
|
||||
color: #383a42;
|
||||
}
|
||||
QMenuBar::item {
|
||||
background-color: #f0f0f0;
|
||||
color: #383a42;
|
||||
}
|
||||
QMenuBar::item:selected {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
QTextEdit, QTreeView {
|
||||
background-color: #fafafa;
|
||||
color: #383a42;
|
||||
}
|
||||
"""
|
||||
self.setStyleSheet(light_stylesheet)
|
||||
|
||||
def apply_system_theme(self):
|
||||
self.setStyleSheet("")
|
||||
|
||||
def open_settings(self):
|
||||
pass
|
||||
|
||||
Loading…
Reference in New Issue
Block a user