Theme switcher implemented
This commit is contained in:
parent
d6d09ba405
commit
cc8aaca206
89
main.py
89
main.py
@ -317,7 +317,12 @@ class MarkdownEditor(QMainWindow):
|
|||||||
view_menu = menu_bar.addMenu("&View")
|
view_menu = menu_bar.addMenu("&View")
|
||||||
self.add_actions_to_menu(view_menu, [
|
self.add_actions_to_menu(view_menu, [
|
||||||
("Toggle Split View Mode", self.toggle_split_view),
|
("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")
|
window_menu = menu_bar.addMenu("&Window")
|
||||||
@ -335,17 +340,17 @@ class MarkdownEditor(QMainWindow):
|
|||||||
])
|
])
|
||||||
|
|
||||||
def add_actions_to_menu(self, menu, actions):
|
def add_actions_to_menu(self, menu, actions):
|
||||||
"""
|
for action_text, action_func in actions:
|
||||||
Add actions to a given menu.
|
if isinstance(action_func, list): # Submenu
|
||||||
|
submenu = menu.addMenu(action_text)
|
||||||
Args:
|
for sub_action_text, sub_action_func in action_func:
|
||||||
menu (QMenu): The menu to which actions will be added.
|
sub_action = QAction(sub_action_text, self)
|
||||||
actions (list of tuples): Each tuple contains the text for the menu item and the handler function.
|
sub_action.triggered.connect(sub_action_func)
|
||||||
"""
|
submenu.addAction(sub_action)
|
||||||
for action_text, action_handler in actions:
|
else:
|
||||||
action = QAction(action_text, self)
|
action = QAction(action_text, self)
|
||||||
action.triggered.connect(action_handler)
|
action.triggered.connect(action_func)
|
||||||
menu.addAction(action)
|
menu.addAction(action)
|
||||||
|
|
||||||
def create_tool_bar(self):
|
def create_tool_bar(self):
|
||||||
"""
|
"""
|
||||||
@ -666,8 +671,64 @@ class MarkdownEditor(QMainWindow):
|
|||||||
else:
|
else:
|
||||||
QMessageBox.critical(self, "Directory Selection Error", "Invalid directory path")
|
QMessageBox.critical(self, "Directory Selection Error", "Invalid directory path")
|
||||||
|
|
||||||
def change_theme(self):
|
def change_theme(self, theme):
|
||||||
pass
|
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):
|
def open_settings(self):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user