""" テキストエディタフレームワークデモ 再利用可能なコンポーネントの使用例 """ import flet as ft import sqlite3 import signal import sys import logging from components.text_editor import TextEditor, create_draft_editor, create_memo_editor, create_note_editor def main(page: ft.Page): """メイン関数""" try: # ログ設定 logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[ logging.FileHandler('app.log'), logging.StreamHandler() ] ) # シグナルハンドラ設定 def signal_handler(signum, frame): print(f"\nシグナル {signum} を受信しました") print("✅ 正常終了処理完了") logging.info("アプリケーション正常終了") sys.exit(0) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) # データベース初期化 conn = sqlite3.connect('sales.db') cursor = conn.cursor() cursor.execute(''' CREATE TABLE IF NOT EXISTS text_storage ( id INTEGER PRIMARY KEY AUTOINCREMENT, category TEXT NOT NULL, title TEXT NOT NULL, content TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) ''') conn.commit() conn.close() logging.info("データベース初期化完了") # ウィンドウ設定 page.title = "テキストエディタフレームワークデモ" page.window_width = 800 page.window_height = 600 page.theme_mode = ft.ThemeMode.LIGHT # ウィンドウクローズイベント page.on_window_close = lambda _: signal_handler(0, None) # ナビゲーション設定 current_editor = [0] editors = [] # エディタ作成 draft_editor = create_draft_editor(page) memo_editor = create_memo_editor(page) note_editor = create_note_editor(page) editors = [draft_editor, memo_editor, note_editor] # タブ切り替え tabs = ft.Tabs( selected_index=0, tabs=[ ft.Tab( text="下書き", content=draft_editor.build() ), ft.Tab( text="メモ", content=memo_editor.build() ), ft.Tab( text="ノート", content=note_editor.build() ) ], expand=True ) # ページ構築 page.add( ft.Column([ ft.Text("テキストエディタフレームワーク", size=24, weight=ft.FontWeight.BOLD), ft.Text("再利用可能なコンポーネントのデモ", size=16, color=ft.Colors.GREY_600), ft.Divider(), tabs ], expand=True, spacing=10) ) logging.info("テキストエディタフレームワーク起動完了") print("🚀 テキストエディタフレームワーク起動完了") except Exception as e: logging.error(f"アプリケーション起動エラー: {e}") print(f"❌ アプリケーション起動エラー: {e}") if __name__ == "__main__": import flet as ft ft.run(main)