Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions fletx/cli/templates/project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Python-generated files
**__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info

# Virtual environments
.venv
.environments
*.lock
.env

.DS_Store
Empty file.
47 changes: 47 additions & 0 deletions fletx/cli/templates/project/app/utils/theme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import flet as ft

#### APP LIGHT THEME
light_theme = ft.Theme(
color_scheme=ft.ColorScheme(
primary="#4F46E5", # Indigo 600 (accent color)
primary_container="#EEF2FF", # Light indigo background
secondary="#64748B", # Slate 500
secondary_container="#F1F5F9", # Light slate background
surface="#FFFFFF",
background="#F9FAFB",
error="#DC2626", # Red 600
on_primary="#FFFFFF",
on_secondary="#FFFFFF",
on_surface="#1F2937", # Gray 800 (text on white)
on_background="#1F2937",
on_error="#FFFFFF"
),
use_material3=True,
scaffold_bgcolor = "#F9FAFB",
visual_density=ft.VisualDensity.COMFORTABLE,
font_family="Roboto"
)


#### APP DARK THEME
dark_theme = ft.Theme(
color_scheme=ft.ColorScheme(
primary="#4F46E5", # Indigo 500
primary_container = "#FCECD5", # Indigo background
secondary="#94A3B8", # Slate 400
secondary_container="#253745", # Dark slate background
surface="#16191C", # Gray 900
background="#191918", # Gray 950
error="#F87171", # Red 400
on_primary="#FFFFFF",
on_secondary="#000000",
on_surface="#E5E7EB", # Gray 200
on_background="#E5E7EB",
on_error="#000000"
),
# brightness=ft.Brightness.DARK,
scaffold_bgcolor = "#0F1319",
use_material3=True,
visual_density=ft.VisualDensity.COMFORTABLE,
font_family="Roboto"
)
11 changes: 5 additions & 6 deletions fletx/cli/templates/project/main.py.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Version: {{ version }}
import flet as ft
from fletx.app import FletXApp
from app.routes import {{ project_name | pascal_case }}Router
from app.utils.theme import light_theme, dark_theme

def main():
"""Main entry point for the {{ project_name | pascal_case }} application."""
Expand All @@ -23,14 +24,12 @@ def main():

# App Configuration
app = FletXApp(
title="{{ project_name | pascal_case }}",
title = "{{ project_name | pascal_case }}",
initial_route = "/",
debug = True,
theme = ft.Theme(color_scheme_seed = ft.Colors.GREEN),
dark_theme = ft.Theme(
color_scheme_seed = ft.Colors.BLUE_800,
scaffold_bgcolor = ft.Colors.BLACK
),
theme = light_theme,
dark_theme = dark_theme,
theme_mode= ft.ThemeMode.SYSTEM,
window_config = {
"width": 400,
"height": 810,
Expand Down
2 changes: 2 additions & 0 deletions fletx/cli/templates/project/pyproject.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ description = "{{ description }}"
readme = "README.md"
authors = [{ name = "{{ author }}", email = "" }]
requires-python = ">={{ python_version }}"

# Dependencies
dependencies = [
"fletxr=={{ fletx_version }}",
"flet[all]==0.28.3",
Expand Down
8 changes: 6 additions & 2 deletions fletx/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from importlib import import_module

from fletx.utils.context import AppContext
from fletx.utils.logger import SharedLogger

# FletX Logger Utility
def get_logger(name: str) -> logging.Logger:
Expand All @@ -16,8 +17,11 @@ def get_logger(name: str) -> logging.Logger:
if base_logger is None:

# Fallback if the context is not initialized
logger = logging.getLogger(name)
logger.addHandler(logging.NullHandler())
SharedLogger._initialize_logger(
name = 'FletX',
)

logger = SharedLogger.get_logger(__name__)
return logger
return base_logger.getChild(name)

Expand Down
20 changes: 14 additions & 6 deletions fletx/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class SharedLogger:
_logger: Optional[logging.Logger] = None
_lock = threading.Lock()
debug_mode = os.getenv('FLETX_DEBUG','0') == '1'
_env_log_level = os.getenv('FLETX_LOG_LEVEL', 'NOTSET').upper()
_env_log_level = os.getenv('FLETX_LOG_LEVEL', 'INFO').upper()
_logging_enabled = os.getenv('FLETX_ENABLE_LOGGING','0') == '1'

@classmethod
def get_logger(cls, name: str = "FletX") -> logging.Logger:
Expand All @@ -35,10 +36,14 @@ def logger(self) -> logging.Logger:
return self.get_logger()

@classmethod
def _initialize_logger(cls, name: str,debug: bool = False):
def _initialize_logger(cls, name: str,debug: bool = debug_mode):
"""One-time logger configuration"""

# Setup debug mode
cls.debug_mode = debug

logger = logging.getLogger(name)

# Determine level: env overrides, else fallback to debug flag
level_name = cls._env_log_level if cls._env_log_level in {
'CRITICAL','ERROR','WARNING','INFO','DEBUG','NOTSET'
Expand All @@ -57,17 +62,20 @@ def _initialize_logger(cls, name: str,debug: bool = False):
handler.setLevel(level)
logger.addHandler(handler)

# Enable or disable logging
logging.disable(logging.CRITICAL) if not cls._logging_enabled else logging.disable(logging.NOTSET)

cls._logger = logger

def debug(self, message: str):
"""Log a debug message"""
if self.debug_mode:
self.logger.debug(message)
# if self.debug_mode:
self.logger.debug(message)

def info(self, message: str):
"""Log an info level message"""
if self.logger.isEnabledFor(logging.INFO):
self.logger.info(message)
# if self.logger.isEnabledFor(logging.INFO):
self.logger.info(message)

def warning(self, message: str):
"""Log a warning level message"""
Expand Down