160 lines
6.4 KiB
Python
160 lines
6.4 KiB
Python
import flet as ft
|
|
import logging
|
|
from modules import backend, product_filter, export
|
|
|
|
class MainWindow:
|
|
def __init__(self, page: ft.Page):
|
|
self.page = page
|
|
self.logger = logging.getLogger("FletLogger")
|
|
self.logger.debug("MainWindow initialized")
|
|
self.market_list = []
|
|
self.sold_products = []
|
|
self.filtered_products = []
|
|
self.sourced_products = []
|
|
self.controls = self.build_layout()
|
|
|
|
def build_layout(self):
|
|
self.logger.debug("Building main window layout")
|
|
# 마켓 탭
|
|
self.market_table = ft.DataTable(
|
|
columns=[
|
|
ft.DataColumn(ft.Text("마켓이름")),
|
|
ft.DataColumn(ft.Text("마켓 URL")),
|
|
ft.DataColumn(ft.Text("메모"))
|
|
],
|
|
rows=[],
|
|
expand=True,
|
|
key="market_table"
|
|
)
|
|
market_tab_content = ft.Column([
|
|
ft.Row([
|
|
ft.ElevatedButton("마켓목록 가져오기", on_click=self.load_market_list),
|
|
ft.ElevatedButton("팔린상품 가져오기", on_click=self.load_sold_products),
|
|
ft.ElevatedButton("마켓추가하기", on_click=self.add_market)
|
|
]),
|
|
self.market_table
|
|
], scroll=ft.ScrollMode.AUTO)
|
|
|
|
# 상품 탭
|
|
self.product_table = ft.DataTable(
|
|
columns=[
|
|
ft.DataColumn(ft.Text("상품명")),
|
|
ft.DataColumn(ft.Text("카테고리")),
|
|
ft.DataColumn(ft.Text("이미지 URL")),
|
|
ft.DataColumn(ft.Text("소싱 URL"))
|
|
],
|
|
rows=[],
|
|
expand=True,
|
|
key="product_table"
|
|
)
|
|
self.sourcing_market_dropdown = ft.Dropdown(
|
|
label="소싱몰 목록",
|
|
options=[
|
|
ft.dropdown.Option("타오바오"),
|
|
ft.dropdown.Option("1688")
|
|
],
|
|
key="sourcing_market"
|
|
)
|
|
product_tab_content = ft.Column([
|
|
ft.Row([
|
|
ft.ElevatedButton("금지어필터링", on_click=self.filter_forbidden),
|
|
ft.ElevatedButton("카테고리 필터링", on_click=self.filter_category),
|
|
self.sourcing_market_dropdown,
|
|
ft.ElevatedButton("소싱하기", on_click=self.sourcing_products),
|
|
ft.ElevatedButton("출력", on_click=self.export_products)
|
|
]),
|
|
self.product_table
|
|
], scroll=ft.ScrollMode.AUTO)
|
|
|
|
# 기타 탭
|
|
forbidden_tab_content = ft.Column([ft.Text("금지어 관리 탭 (추후 구현)")])
|
|
category_tab_content = ft.Column([ft.Text("카테고리 관리 탭 (추후 구현)")])
|
|
|
|
self.tabs = ft.Tabs(
|
|
selected_index=0,
|
|
tabs=[
|
|
ft.Tab(text="마켓", content=market_tab_content),
|
|
ft.Tab(text="상품", content=product_tab_content),
|
|
ft.Tab(text="금지어 관리", content=forbidden_tab_content),
|
|
ft.Tab(text="카테고리 관리", content=category_tab_content)
|
|
],
|
|
key="main_tabs"
|
|
)
|
|
|
|
# 로그 출력
|
|
self.log_display = ft.Text(value="", size=12)
|
|
def append_log(message: str):
|
|
self.log_display.value += message + "\n"
|
|
self.page.update()
|
|
self.page.session.set("append_log", append_log)
|
|
|
|
layout = [self.tabs, self.log_display]
|
|
self.logger.debug("Main window layout built")
|
|
return layout
|
|
|
|
# 이하 메서드들은 모두 디버그 로깅 + 기능 수행
|
|
def load_market_list(self, e):
|
|
self.logger.debug("load_market_list() 호출됨")
|
|
self.page.session.get("append_log")("Fetching market list...")
|
|
self.market_list = backend.get_market_list()
|
|
rows = []
|
|
for m in self.market_list:
|
|
row = ft.DataRow(cells=[
|
|
ft.DataCell(ft.Text(m.get("name", ""))),
|
|
ft.DataCell(ft.Text(m.get("url", ""))),
|
|
ft.DataCell(ft.Text(m.get("memo", "")))
|
|
])
|
|
rows.append(row)
|
|
self.market_table.rows = rows
|
|
self.page.session.get("append_log")("Market list loaded.")
|
|
self.page.update()
|
|
|
|
def load_sold_products(self, e):
|
|
self.logger.debug("load_sold_products() 호출됨")
|
|
self.page.session.get("append_log")("Fetching sold products for each market...")
|
|
self.sold_products = backend.get_sold_products(self.market_list)
|
|
self.filtered_products = self.sold_products.copy()
|
|
self.page.session.get("append_log")("Sold products loaded. Switching to 상품 탭.")
|
|
self.update_product_table(self.filtered_products)
|
|
self.tabs.selected_index = 1
|
|
self.page.update()
|
|
|
|
def update_product_table(self, products):
|
|
self.logger.debug("update_product_table() 호출됨")
|
|
rows = []
|
|
for p in products:
|
|
row = ft.DataRow(cells=[
|
|
ft.DataCell(ft.Text(p.get("name", ""))),
|
|
ft.DataCell(ft.Text(p.get("category", ""))),
|
|
ft.DataCell(ft.Text(p.get("image_url", ""))),
|
|
ft.DataCell(ft.Text(p.get("sourcing_url", "")))
|
|
])
|
|
rows.append(row)
|
|
self.product_table.rows = rows
|
|
self.page.update()
|
|
|
|
def add_market(self, e):
|
|
self.logger.debug("add_market() 호출됨")
|
|
self.page.session.get("append_log")("Add market functionality not implemented yet.")
|
|
self.page.update()
|
|
|
|
def filter_forbidden(self, e):
|
|
self.logger.debug("filter_forbidden() 호출됨")
|
|
self.page.session.get("append_log")("Filtering products with forbidden words...")
|
|
self.filtered_products = product_filter.filter_forbidden_words(self.filtered_products)
|
|
self.update_product_table(self.filtered_products)
|
|
self.page.session.get("append_log")("Forbidden words filtering applied.")
|
|
self.page.update()
|
|
|
|
def filter_category(self, e):
|
|
self.logger.debug("filter_category() 호출됨")
|
|
self.page.session.get("append_log")("Filtering products with forbidden categories...")
|
|
self.filtered_products = product_filter.filter_forbidden_categories(self.filtered_products)
|
|
self.update_product_table(self.filtered_products)
|
|
self.page.session.get("append_log")("Category filtering applied.")
|
|
self.page.update()
|
|
|
|
def sourcing_products(self, e):
|
|
self.logger.debug("sourcing_products() 호출됨")
|
|
self
|