Common commit
This commit is contained in:
131
modules/ui/gui/MainWindow.py
Normal file
131
modules/ui/gui/MainWindow.py
Normal file
@@ -0,0 +1,131 @@
|
||||
import os.path
|
||||
from pkgutil import extend_path
|
||||
|
||||
import flet as ft
|
||||
from Workspaces import *
|
||||
|
||||
MainWindowDarkTheme = {
|
||||
'logo_large_path': os.path.join('assets', 'logo_dark_large.png'),
|
||||
'logo_small_path': os.path.join('assets', 'logo_dark_small.png'),
|
||||
'background_color': "#1f1e23",
|
||||
'text_color': "#ffffff",
|
||||
'accent_color': "#7B1FA2",
|
||||
'icon': ft.Icons.NIGHTLIGHT_ROUNDED
|
||||
}
|
||||
|
||||
MainWindowLightTheme = {
|
||||
'logo_large_path': os.path.join('assets', 'logo_light_large.png'),
|
||||
'logo_small_path': os.path.join('assets', 'logo_light_small.png'),
|
||||
'background_color': "#ffffff",
|
||||
'text_color': "#1f1e23",
|
||||
'accent_color': "#9C27B0",
|
||||
'icon': ft.Icons.SUNNY
|
||||
}
|
||||
|
||||
class MainWindow:
|
||||
def __init__(self):
|
||||
self.title = 'Vaiola'
|
||||
self.themes = [MainWindowDarkTheme, MainWindowLightTheme]
|
||||
self.active_theme_number = 0
|
||||
self.active_theme = self.themes[self.active_theme_number]
|
||||
|
||||
self.side_bar = MainWindowSideBar(self)
|
||||
self.active_workspace = self.side_bar.get_active_workspace()
|
||||
self.page: ft.Page | None = None
|
||||
|
||||
def build(self, page: ft.Page):
|
||||
self.page = page
|
||||
page.clean()
|
||||
page.title = self.title
|
||||
page.padding = 0
|
||||
page.bgcolor = self.active_theme['background_color']
|
||||
self.active_workspace = self.side_bar.get_active_workspace()
|
||||
layout = ft.Row(controls=[self.side_bar.build(), ft.VerticalDivider(thickness=4, ), self.active_workspace.build()],
|
||||
spacing=0,
|
||||
vertical_alignment=ft.CrossAxisAlignment.START,
|
||||
alignment=ft.MainAxisAlignment.START,
|
||||
)
|
||||
|
||||
page.add(layout)
|
||||
|
||||
def set_theme(self):
|
||||
self.active_theme_number += 1
|
||||
if self.active_theme_number >= len(self.themes): self.active_theme_number = 0
|
||||
self.active_theme = self.themes[self.active_theme_number]
|
||||
self.side_bar.set_theme(self.active_theme)
|
||||
self.rebuild()
|
||||
|
||||
def rebuild(self):
|
||||
self.build(self.page)
|
||||
self.page.update()
|
||||
|
||||
|
||||
class MainWindowSideBar:
|
||||
logo_dark_large_path = os.path.join('assets', 'logo_dark_large.png')
|
||||
logo_dark_small_path = os.path.join('assets', 'logo_dark_small.png')
|
||||
logo_light_large_path = os.path.join('assets', 'logo_light_large.png')
|
||||
logo_light_small_path = os.path.join('assets', 'logo_light_small.png')
|
||||
|
||||
def __init__(self, parent):
|
||||
self.tabs: list[MainWindowSideBarTab] = list()
|
||||
self.active_tab: MainWindowSideBarTab = MainWindowSideBarTab()
|
||||
self.extended = True
|
||||
self.theme = parent.active_theme
|
||||
self.parent = parent
|
||||
|
||||
def set_theme(self, theme): self.theme = theme
|
||||
|
||||
def get_active_workspace(self) -> Workspace: return self.active_tab.get_active_workspace()
|
||||
|
||||
def build(self) -> ft.Container:
|
||||
logo = ft.Container(
|
||||
content=ft.Image(
|
||||
src=self.theme['logo_large_path'] if self.extended else self.theme['logo_small_path'],
|
||||
width=200 if self.extended else 60,
|
||||
fit=ft.ImageFit.CONTAIN
|
||||
),
|
||||
width=200 if self.extended else 60,
|
||||
# on_click
|
||||
)
|
||||
|
||||
theme_button = ft.Button(
|
||||
content=ft.Row(
|
||||
controls=[
|
||||
ft.Icon(self.theme['icon'], color=self.theme['background_color']),
|
||||
ft.Text('Переключить тему', color=self.theme['background_color'])
|
||||
] if self.extended else [
|
||||
ft.Icon(self.theme['icon'], color=self.theme['background_color'])
|
||||
|
||||
]
|
||||
),
|
||||
bgcolor=self.theme['text_color'],
|
||||
on_click=self.switch_theme
|
||||
|
||||
|
||||
)
|
||||
settings = ft.Container(content=theme_button, padding=8)
|
||||
|
||||
|
||||
|
||||
layout = ft.Column(
|
||||
controls=[logo, ft.Text('Область вкладок', color=self.theme['text_color']), settings]
|
||||
)
|
||||
return ft.Container(content=layout, width=200 if self.extended else 60,)
|
||||
|
||||
def switch_theme(self, e):
|
||||
self.parent.set_theme()
|
||||
|
||||
|
||||
class MainWindowSideBarTab:
|
||||
def __init__(self):
|
||||
self.workspace = Workspace()
|
||||
|
||||
def get_active_workspace(self) -> Workspace:
|
||||
return self.workspace
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ft.app(target=MainWindow().build)
|
||||
|
||||
Reference in New Issue
Block a user