liuyuqi-dellpc 1 year ago
parent
commit
197b7b58c7
8 changed files with 381 additions and 0 deletions
  1. 158 0
      demo/.gitignore
  2. 12 0
      demo/Home.py
  3. 47 0
      demo/PlotlyChart.py
  4. 15 0
      demo/README.md
  5. 38 0
      demo/Todo.py
  6. 83 0
      demo/main.py
  7. 8 0
      demo/requirements.txt
  8. 20 0
      demo/setup.py

+ 158 - 0
demo/.gitignore

@@ -0,0 +1,158 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+*.log
+[Dd]ebug/
+[Rr]elease/
+x64/
+build/
+[Bb]in/
+[Oo]bj/
+__pycache__/
+.idea/
+
+# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
+!packages/*/build/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.log
+*.scc
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+*.cachefile
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+*.ncrunch*
+.*crunch*.local.xml
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.Publish.xml
+
+# NuGet Packages Directory
+## TODO: If you have NuGet Package Restore enabled, uncomment the next line
+#packages/
+
+# Windows Azure Build Output
+csx
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+sql/
+*.Cache
+ClientBin/
+[Ss]tyle[Cc]op.*
+~$*
+*~
+*.dbmdl
+*.[Pp]ublish.xml
+*.pfx
+*.publishsettings
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+App_Data/*.mdf
+App_Data/*.ldf
+
+
+#LightSwitch generated files
+GeneratedArtifacts/
+_Pvt_Extensions/
+ModelManifest.xml
+
+# =========================
+# Windows detritus
+# =========================
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Mac desktop service store files
+.DS_Store

+ 12 - 0
demo/Home.py

@@ -0,0 +1,12 @@
+from flet_core import UserControl, Column, Row, FloatingActionButton, icons, TextField, Tabs, Tab, Text, \
+    MainAxisAlignment
+
+
+class HomePage(Column):
+    ''''''
+    def __init__(self):
+        ''''''
+        super().__init__()
+        self.controls.clear()
+        self.controls.append(Column([Text("Body!")], alignment=MainAxisAlignment.START, expand=True))
+    

+ 47 - 0
demo/PlotlyChart.py

@@ -0,0 +1,47 @@
+from flet_core import Column, MainAxisAlignment, Row
+import plotly.express as px
+from flet.plotly_chart import PlotlyChart
+import plotly.graph_objects as go
+import matplotlib
+import matplotlib.pyplot as plt
+from flet.matplotlib_chart import MatplotlibChart
+
+matplotlib.use("svg")
+
+class ChartPage():
+    ''''''
+    
+    def DrawChart(self):
+        ''''''
+        x = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1',
+             'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2']
+
+        fig = go.Figure()
+
+        fig.add_trace(go.Box(
+            y=[0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3],
+            x=x,
+            name='kale',
+            marker_color='#3D9970'
+        ))
+        fig.add_trace(go.Box(
+            y=[0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2],
+            x=x,
+            name='radishes',
+            marker_color='#FF4136'
+        ))
+        fig.add_trace(go.Box(
+            y=[0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5],
+            x=x,
+            name='carrots',
+            marker_color='#FF851B'
+        ))
+
+        fig.update_layout(
+            yaxis_title='normalized moisture',
+            boxmode='group'  # group together boxes of the different traces for each value of x
+        )
+        return fig
+
+    def __init__(self):
+        super().__init__()

+ 15 - 0
demo/README.md

@@ -0,0 +1,15 @@
+# flet demo
+
+
+```
+virtualenv .venv
+source .venv/bin/activate
+
+.venv\Scripts\activate.bat
+
+pip install -r requirements.txt
+
+python main.py
+```
+
+

+ 38 - 0
demo/Todo.py

@@ -0,0 +1,38 @@
+import flet as ft
+from flet_core import Column, MainAxisAlignment
+
+
+class TodoPage(Column):
+
+    def add_clicked(self, e):
+        if self.new_task.value:
+            self.list.controls.append(ft.Checkbox(label=self.new_task.value))
+            self.new_task.value = ""
+            self.new_task.focus()
+            self.new_task.update()
+            self.page.update()
+            # self.page.update()
+        else:
+            self.page.dialog = self.dlg
+            self.dlg.open = True
+            self.page.update()
+
+    def __init__(self):
+        super().__init__()
+        self.controls.clear()
+        self.dlg = ft.AlertDialog(title=ft.Text("请输入内容!"), on_dismiss=lambda e: print("关闭提示!"))
+        self.new_task = ft.TextField(hint_text="添加想要干的事情", width=300,on_submit=self.add_clicked)
+        # self.add_btn = ft.IconButton(ft.icons.ADD, tooltip="添加", icon_color=ft.colors.BLACK87,
+        self.add_btn = ft.FloatingActionButton(icon=ft.icons.ADD, bgcolor=ft.colors.LIME_300, on_click=self.add_clicked)
+        # // ft.ElevatedButton("Add", on_click=self.add_clicked)
+        self.list = ft.Column(alignment=ft.alignment.top_left)
+        self.list.controls.append(ft.Checkbox(label='Java'))
+        self.list.controls.append(ft.Checkbox(label='Python'))
+        self.list.controls.append(ft.Checkbox(label='AI'))
+        self.list.controls.append(ft.Checkbox(label='开源项目计划'))
+
+        content = ft.Column([
+            ft.Row(controls=[self.new_task, self.add_btn]),
+            self.list
+        ])
+        self.controls.append(content)

+ 83 - 0
demo/main.py

@@ -0,0 +1,83 @@
+import logging
+
+import flet as ft
+from Home import HomePage
+from Todo import TodoPage
+import plotly.graph_objects as go
+from flet.plotly_chart import PlotlyChart
+
+from PlotlyChart import ChartPage
+
+
+def main(page: ft.Page):
+    log_format = "%(asctime)s - %(levelname)s - %(message)s"
+    logging.basicConfig(filename='app.log', level=logging.DEBUG, format=log_format)
+    logging.info('程序启动')
+    content = HomePage()
+    def menu_changed(e):
+        content.controls.clear()
+        print("Selected destination:", e.control.selected_index)
+        if e.control.selected_index == 0:
+            content.controls.append(HomePage())
+        elif e.control.selected_index == 1:
+            # content.controls.append(ft.Text("One!"))
+            content.controls.append(TodoPage())
+        elif e.control.selected_index == 2:
+            content.controls.append(ft.Text("商品库!"))
+        elif e.control.selected_index == 3:
+            fig = ChartPage().DrawChart()
+            # fig.show()
+            content.controls.append(PlotlyChart(fig, expand=True))
+        elif e.control.selected_index == 4:
+            content.controls.append(ft.Text("Setting!"))
+        page.update()
+
+    rail = ft.NavigationRail(
+        selected_index=0,
+        label_type=ft.NavigationRailLabelType.ALL,
+        # extended=True,
+        min_width=100,
+        min_extended_width=400,
+        # leading=ft.FloatingActionButton(icon=ft.icons.CREATE, text="Add"),
+        group_alignment=-0.9,
+        destinations=[
+            ft.NavigationRailDestination(
+                icon=ft.icons.HOME, selected_icon=ft.icons.HOME, label="首页"
+            ),
+            ft.NavigationRailDestination(
+                icon_content=ft.Icon(ft.icons.FAVORITE),
+                selected_icon_content=ft.Icon(name=ft.icons.FAVORITE, color=ft.colors.PINK),
+                label="关键词",
+            ),
+            ft.NavigationRailDestination(
+                icon_content=ft.Icon(ft.icons.SHOPIFY),
+                selected_icon_content=ft.Icon(name=ft.icons.SHOPIFY, color=ft.colors.PINK),
+                label="商品库",
+            ),
+            ft.NavigationRailDestination(
+                icon_content=ft.Icon(ft.icons.BAR_CHART),
+                selected_icon_content=ft.Icon(name=ft.icons.BAR_CHART, color=ft.colors.PINK),
+                label="数据分析",
+            ),
+            ft.NavigationRailDestination(
+                icon=ft.icons.SETTINGS_OUTLINED,
+                selected_icon_content=ft.Icon(ft.icons.SETTINGS),
+                label_content=ft.Text("Settings"),
+            ),
+        ],
+        on_change=menu_changed,
+    )
+    page.title = 'First App'
+
+    page.add(
+        ft.Row(
+            [
+                rail,
+                ft.VerticalDivider(width=1),
+                content,
+            ],
+            expand=True,
+        )
+    )
+
+ft.app(target=main)

+ 8 - 0
demo/requirements.txt

@@ -0,0 +1,8 @@
+flet
+plotly
+pandas
+matplotlib
+
+
+
+

+ 20 - 0
demo/setup.py

@@ -0,0 +1,20 @@
+from cx_Freeze import setup, Executable
+
+script_path = "main.py"
+
+build_exe_options = {
+    "includes": [],
+    "excludes": ['tkinter'],
+    "packages": [],
+    'include_files': [],
+}
+
+setup(
+    name="电商大数据工具",
+    version="1.0",
+    description="电商大数据工具",
+    options={
+        "build_exe": build_exe_options
+    },
+    executables=[Executable(script_path, base="Win32GUI")]
+)