Skip to content

Commit c74bcfe

Browse files
committed
refactor: 增加Windows特定依赖(CI用)并优化日志输出
new: 新增UI按钮
1 parent 9c57679 commit c74bcfe

File tree

8 files changed

+349
-78
lines changed

8 files changed

+349
-78
lines changed

.github/workflows/desktop-and-mobile-builds.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
- name: Install Python Dependencies
124124
run: |
125125
python -m pip install --upgrade pip
126-
pip install -r requirements.txt
126+
pip install -r requirements-win.txt
127127
128128
- name: Setup Flutter ${{ env.FLUTTER_VERSION }}
129129
uses: subosito/flutter-action@v2

.vscode/launch.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7-
7+
{
8+
"name": "Python 调试程序: 使用进程 ID 附加",
9+
"type": "debugpy",
10+
"request": "attach",
11+
"processId": "${command:pickProcess}"
12+
},
813
{
914
"name": "Flet Web+桌面调试",
1015
"type": "debugpy",
1116
"request": "launch",
1217
"python": "${command:python.interpreterPath}",
13-
1418
}
1519
]
1620
}

requirements-win.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flet==0.25.2
2+
# flet-audio

src/PhiControls.py

Lines changed: 202 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import random
33
import flet as ft
44
import flet.canvas as cv
5+
import datetime
56

67

78
def hum_convert(value, bit=2):
@@ -24,7 +25,7 @@ def hum_convert(value, bit=2):
2425
value = value / size
2526

2627

27-
async def lottery_core(datashow,page: ft.Page, lottery_list={}):
28+
async def lottery_core(datashow, page: ft.Page, lottery_list={}):
2829
# TODO: 不重复抽奖
2930
def chance_prize(prize_list):
3031
"""
@@ -153,7 +154,7 @@ async def storage(
153154
page.session.remove(key)
154155
else:
155156
raise LookupError("Key not found in session storage")
156-
print(f"[Log]{key}值为: {page.session.get(key)}")
157+
print(f"[log-", datetime.datetime.now(), "]{key}值为: {page.session.get(key)}")
157158
elif type == "c":
158159
if mode == "r":
159160
if await page.client_storage.contains_key_async(key):
@@ -277,8 +278,7 @@ def __init__(self, n=0.7):
277278
),
278279
col=1.32,
279280
alignment=ft.alignment.top_right,
280-
margin=ft.margin.only(
281-
top=12 * n, right=19 * n),
281+
margin=ft.margin.only(top=12 * n, right=19 * n),
282282
height=70 * n,
283283
),
284284
],
@@ -291,16 +291,17 @@ def __init__(self, n=0.7):
291291
)
292292
]
293293

294-
def on_data_change(self, data:str, page=ft.Page, n=0.7):
294+
def on_data_change(self, data: str, page=ft.Page, n=0.7):
295295
"""_summary_: 数据改变时调用
296296
297297
Args:
298298
data (_type_): _description_
299299
page (_type_, optional): _description_. Defaults to ft.Page.
300300
n (float, optional): _description_. Defaults to 0.7.
301301
"""
302+
print(f"[log-{datetime.datetime.now()}]获取到的缩放比例:{n}")
302303
try:
303-
len(data)
304+
print(f"[log-{datetime.datetime.now()}]当前Data字符串长度:{len(data)}")
304305
except TypeError:
305306
raise ValueError("Data 数值过大!")
306307
else:
@@ -309,19 +310,50 @@ def on_data_change(self, data:str, page=ft.Page, n=0.7):
309310
or page.platform == ft.PagePlatform.IOS
310311
):
311312
# 缩放倍数
312-
n *= 0.747
313+
if len(data) == 7:
314+
# 7位数
315+
# SHIT 1GB
316+
n *= 1.1
317+
self.DATA = data
318+
self.controls[0].controls[1].controls[1].content.spans[
319+
0
320+
].text = self.DATA
321+
self.controls[0].controls[1].controls[1].margin = ft.margin.only(
322+
top=(12 + (2 * (len(self.DATA) - 7))) * n * 1.1,
323+
right=(19 - (3 * (len(self.DATA) - 7))) * n * 2,
324+
)
325+
self.controls[0].controls[1].controls[1].content.spans[
326+
0
327+
].style.size = ((35 - (2.5 * (len(self.DATA) - 7))) * n * 0.92)
328+
page.update()
329+
else:
330+
n *= 0.666
331+
self.DATA = data
332+
self.controls[0].controls[1].controls[1].content.spans[
333+
0
334+
].text = self.DATA
335+
self.controls[0].controls[1].controls[1].margin = ft.margin.only(
336+
top=(12 + (2 * (len(self.DATA) - 7))) * n * 1.1,
337+
right=(19 - (3 * (len(self.DATA) - 7))) * n * 2,
338+
)
339+
self.controls[0].controls[1].controls[1].content.spans[
340+
0
341+
].style.size = ((35 - (2.5 * (len(self.DATA) - 7))) * n * 0.92)
342+
page.update()
313343
else:
314-
n *= 1.2
315-
self.DATA = data
316-
self.controls[0].controls[1].controls[1].content.spans[0].text = self.DATA
317-
self.controls[0].controls[1].controls[1].margin = ft.margin.only(
318-
top=(12 + (2 * (len(self.DATA) - 7))) * n * 1.1,
319-
right=(19 - (3 * (len(self.DATA) - 7))) * n * 2,
320-
)
321-
self.controls[0].controls[1].controls[1].content.spans[0].style.size = (
322-
(35 - (2.5 * (len(self.DATA) - 7))) * n * 0.92
323-
)
324-
page.update()
344+
n *= 1.1
345+
self.DATA = data
346+
self.controls[0].controls[1].controls[1].content.spans[
347+
0
348+
].text = self.DATA
349+
self.controls[0].controls[1].controls[1].margin = ft.margin.only(
350+
top=(12 + (2 * (len(self.DATA) - 7))) * n * 1.1,
351+
right=(19 - (3 * (len(self.DATA) - 7))) * n * 2.2,
352+
)
353+
self.controls[0].controls[1].controls[1].content.spans[0].style.size = (
354+
(35 - (2.5 * (len(self.DATA) - 7))) * n * 0.92
355+
)
356+
page.update()
325357

326358

327359
class PhiLottery(ft.Stack):
@@ -331,7 +363,7 @@ class PhiLottery(ft.Stack):
331363
ft (_type_): _description_
332364
"""
333365

334-
nodata=False
366+
nodata = False
335367

336368
def __init__(self, n=1, page=ft.Page):
337369
if (
@@ -393,9 +425,7 @@ async def on_click(
393425
datashow=PhiData(),
394426
datakey="data",
395427
):
396-
async with (
397-
lock
398-
): # 确保只有一个 on_click 在执行
428+
async with lock: # 确保只有一个 on_click 在执行
399429
n2 = n
400430
if page and (
401431
page.platform == ft.PagePlatform.ANDROID
@@ -425,7 +455,12 @@ async def on_click(
425455
- datadelta,
426456
mode="w",
427457
)
428-
print("[Log]当前Data:", await storage(page=page, key=datakey, mode="r"))
458+
print(
459+
"[log-",
460+
datetime.datetime.now(),
461+
"]当前Data:",
462+
await storage(page=page, key=datakey, mode="r"),
463+
)
429464
PhiData.on_data_change(
430465
datashow,
431466
hum_convert(await storage(page=page, key=datakey, mode="r")),
@@ -437,8 +472,10 @@ async def on_click(
437472
self.controls[1].offset = ft.transform.Offset(0, 0)
438473
detailText.value = ""
439474
# 对接抽奖函数
440-
result = await lottery_core(datashow=datashow,page=page, lottery_list=lottery_list)
441-
print("[Log]抽奖结果:", result)
475+
result = await lottery_core(
476+
datashow=datashow, page=page, lottery_list=lottery_list
477+
)
478+
print("[log-", datetime.datetime.now(), "]抽奖结果:", result)
442479
text = str(result[0])
443480
if result[1] == "White":
444481
detailText.color = ft.Colors.WHITE
@@ -452,7 +489,8 @@ async def on_click(
452489

453490
for i in range(1, 24):
454491
detail.scale = ft.transform.Scale(
455-
scale_x=0.7, scale_y=0.7 / 23 * i)
492+
scale_x=0.7, scale_y=0.7 / 23 * i
493+
)
456494
page.update()
457495
await asyncio.sleep(0.016)
458496
# scale_x和scale_y无法使用动画,只能用这种方法
@@ -466,7 +504,7 @@ async def on_click(
466504
elif await storage(page=page, key="data") < datadelta:
467505
self.nodata = True
468506
self.controls[0].visible = not self.controls[0].visible # ?图
469-
print("[Log]余额不足")
507+
print("[log-", datetime.datetime.now(), "]余额不足")
470508
# TODO: 前端日志输出失效,待修复
471509
page.snack_bar = ft.SnackBar(ft.Text("余额不足"))
472510
page.snack_bar.open = True
@@ -478,16 +516,150 @@ async def on_click(
478516
self.controls[1].animate_opacity = 300
479517
page.update()
480518
self.controls[1].opacity = 0
481-
offset_x = -1 * \
482-
abs((page.width // 4 / (350 * n2) - 1)) * 0.05 - 0.25
519+
offset_x = (
520+
-1 * abs((page.width // 4 / (350 * n2) - 1)) * 0.05 - 0.25
521+
)
483522
if offset_x >= -0.15:
484523
offset_x -= 0.1
485524
if offset_x < -0.3:
486525
offset_x += 0.1
487526
self.controls[1].offset = ft.transform.Offset(offset_x, 0)
488-
print("[Log]Offset:", self.controls[1].offset.x)
527+
print(
528+
"[log-",
529+
datetime.datetime.now(),
530+
"]Offset:",
531+
self.controls[1].offset.x,
532+
)
489533
page.update()
490534
if multi:
491535
await asyncio.sleep(0.1)
492536
else:
493537
await asyncio.sleep(0.5)
538+
539+
540+
class PhiLotteryButton(ft.Stack):
541+
"""_summary_: 抽奖按钮
542+
543+
Args:
544+
ft (_type_): _description_
545+
"""
546+
547+
def __init__(self, n=1):
548+
super().__init__()
549+
self.controls = [
550+
ft.Container(
551+
cv.Canvas(
552+
[
553+
cv.Path(
554+
[
555+
cv.Path.MoveTo(25.4551733 * n, 0),
556+
cv.Path.LineTo(472 * n, 0),
557+
cv.Path.LineTo(446.5448267 * n, 90 * n),
558+
cv.Path.LineTo(0, 90 * n),
559+
cv.Path.Close(),
560+
],
561+
paint=ft.Paint(
562+
style=ft.PaintingStyle.STROKE,
563+
color=ft.Colors.WHITE,
564+
stroke_width=2,
565+
),
566+
),
567+
cv.Path(
568+
[
569+
cv.Path.MoveTo(25.4551733 * n, 0),
570+
cv.Path.LineTo(472 * n, 0),
571+
cv.Path.LineTo(446.5448267 * n, 90 * n),
572+
cv.Path.LineTo(0, 90 * n),
573+
cv.Path.Close(),
574+
],
575+
paint=ft.Paint(
576+
style=ft.PaintingStyle.FILL,
577+
color="#90000000",
578+
),
579+
),
580+
],
581+
width=472 * n,
582+
height=90 * n,
583+
expand=True,
584+
),
585+
padding=0,
586+
),
587+
ft.Row(
588+
controls=[
589+
ft.Image(
590+
"dataicon.png",
591+
width=70 * n,
592+
height=70 * n,
593+
offset=ft.transform.Offset(0, -0.08 * n),
594+
),
595+
ft.Text(
596+
"1024 KB ",
597+
color=ft.Colors.WHITE,
598+
size=35 * n,
599+
# text_align=ft.TextAlign.CENTER,
600+
),
601+
],
602+
expand=True,
603+
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
604+
width=472 * n,
605+
height=90 * n,
606+
spacing=0,
607+
),
608+
]
609+
610+
611+
class PhiLotteryButtonM(ft.Stack):
612+
"""_summary_: 抽奖按钮-连抽
613+
614+
Args:
615+
ft (_type_): _description_
616+
"""
617+
618+
def __init__(self, n=1):
619+
super().__init__()
620+
self.controls = [
621+
ft.Container(
622+
cv.Canvas(
623+
[
624+
cv.Path(
625+
[
626+
cv.Path.MoveTo(25.4551733 * n, 0),
627+
cv.Path.LineTo(472 * n, 0),
628+
cv.Path.LineTo(446.5448267 * n, 90 * n),
629+
cv.Path.LineTo(0, 90 * n),
630+
cv.Path.Close(),
631+
],
632+
paint=ft.Paint(
633+
style=ft.PaintingStyle.FILL,
634+
color="#EEAFB0B1",
635+
),
636+
),
637+
],
638+
width=472 * n,
639+
height=90 * n,
640+
expand=True,
641+
),
642+
padding=0,
643+
),
644+
ft.Row(
645+
controls=[
646+
ft.Image(
647+
"dataicon.png",
648+
width=70 * n,
649+
height=70 * n,
650+
offset=ft.transform.Offset(0, -0.08 * n),
651+
),
652+
ft.Text(
653+
"8 MB ",
654+
color=ft.Colors.BLACK,
655+
size=35 * n,
656+
# text_align=ft.TextAlign.CENTER,
657+
),
658+
],
659+
expand=True,
660+
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
661+
width=472 * n,
662+
height=90 * n,
663+
spacing=0,
664+
),
665+
]

0 commit comments

Comments
 (0)