This repository has been archived by the owner on Sep 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
default.py
2297 lines (1970 loc) · 86.9 KB
/
default.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding=utf-8 -*-
globalProgUpdate("启动第一批模块…")
import appuifw as appuifw_old
import appuifw2_fd8f9a7f as appuifw
import e32
# aotimertmp = e32.Ao_timer()
# aotimertmp.after(0,lambda:appuifw.note(('程序加载中…').decode('utf-8')))
import graphics_compatible as graphics
import sys, os
import topwindow as TopWindow
import logging
if MAIN_ON_PC:
MAIN_DEBUG_FOLDER = os.path.abspath(".\\neteaseDebug")
MAIN_CURR_FOLDER = os.path.abspath(".\\")
MAIN_NETEASE_FOLDER = os.path.abspath(".\\netease")
MAIN_NETEASE_MUSIC_FOLDER = os.path.abspath(".\\neteaseMusic")
sys.path.append(MAIN_CURR_FOLDER)
if MAIN_ON_PYCON:
MAIN_DEBUG_FOLDER = os.path.abspath("e:\\neteaseDebug2")
MAIN_CURR_FOLDER = os.path.abspath("e:\\python")
MAIN_NETEASE_FOLDER = os.path.abspath("e:\\netease2")
MAIN_NETEASE_MUSIC_FOLDER = os.path.abspath("e:\\music")
if sys.path[1] != MAIN_CURR_FOLDER:
sys.path[1:1] = [MAIN_CURR_FOLDER]
os.chdir(MAIN_CURR_FOLDER)
sys.path.append(os.path.abspath(".\\lib"))
sys.path.append(os.path.abspath("."))
if MAIN_ON_SIS:
MAIN_DEBUG_FOLDER = os.path.abspath("e:\\neteaseDebug2")
MAIN_CURR_FOLDER = os.path.abspath(".\\")
MAIN_NETEASE_FOLDER = os.path.abspath("e:\\netease2")
MAIN_NETEASE_MUSIC_FOLDER = os.path.abspath("e:\\music")
if sys.path[1] != MAIN_CURR_FOLDER:
sys.path[1:1] = [MAIN_CURR_FOLDER]
sys.path.append(os.path.abspath(".\\lib"))
os.chdir(MAIN_CURR_FOLDER)
import tools
from tools import s, us
import util
from util import *
def pj(a, b): #pathjoin
if b[0] == '\\':
b = b[1:]
return os.path.abspath(os.path.join(a, b))
if MAIN_ON_PYCON:
reload(util)
reload(tools)
globalProgUpdate("文件夹…")
createFolders(globals())
globalProgUpdate("日志句柄…")
logHandler = logging.FileHandler(pj(MAIN_DEBUG_FOLDER, "log.txt"), mode="w")
logHandler.setFormatter(LOG_FORMATTER)
logHandler.setLevel(logging.WARNING)
apiLogHandler = logging.FileHandler(pj(MAIN_DEBUG_FOLDER, "apilog.txt"), mode="w")
apiLogHandler.setLevel(logging.WARNING)
httpLogHandler = logging.FileHandler(pj(MAIN_DEBUG_FOLDER, "httplog.txt"), mode="w")
httpLogHandler.setLevel(15)
setUtilLogHandler(logHandler)
mainLogger = logging.getLogger("mainLogger")
mainLogger.setLevel(logging.WARNING)
mainLogger.addHandler(logHandler)
logs = mainLogger.info
foreground = True
# def switchForeground_(whetherForeground):
# global foreground, splashScreen
# if whetherForeground:
# foreground = True
# splashScreen.show()
# else:
# foreground = False
# splashScreen.hide()
# globalProgUpdate("SPLASH…")
#程序开始时,先显示splash Screen
# splashScreen = TopWindow.TopWindow()
# splashScreen.size = (200,65)
CANVASSIZE=appuifw.Canvas().size
(screen_x, screen_y) = CANVASSIZE
# splashScreen.position = (CANVASSIZE[0] / 2 - 100, CANVASSIZE[1] / 2 - 32)
# splashScreen.background_color=0xffffff
# splashScreen.add_image(graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\SplashScreen.scale-100.bmp')), (0,0))
# splashScreen.show()
# appuifw.app.focus = switchForeground_
# logs(u'splashScreen Loaded')
# import sys
# import os
globalProgUpdate("第二批模块…")
import neapi
import playlist
import httplib
#import socket_compat as socket
import socket, btsocket
socket.setdefaulttimeout(8)
import e32
from audio_bugfix_vars import PY2_BUG_DELAY_TIME
import key_codes
import audio
import time
import copy
import math
import simplejson as json
import audio
if MAIN_ON_PYCON:
reload(neapi)
reload(playlist)
logs(u'modules Imported')
globalProgUpdate("定义变量函数…")
'''
一些重要变量定义
'''
d = neapi.getItem
threadRunning = True
#rotatingUnit * 4 = 旋转图片的数量
rotatingUnit = 4
rotatingImages = rotatingUnit * 4
#AngleSins = [sin(0), sin(pi/2 * 1/n), sin(pi/2 * 2/n) ...]
AngleSins = [math.sin(Pi /2. * (x) / rotatingUnit) for x in range(rotatingUnit)]
AngleCoss = [math.cos(Pi /2. * (x) / rotatingUnit) for x in range(rotatingUnit)]
logs(u'vars Defined')
'''
画图函数
'''
def definePlots():
#初始时:画图元素的载入
#关于屏幕适配像素点数列plots的说明
#plots[0]: img1的宽高,为plots[1]宽高的73/112
#plots[1]: img3的宽高,为画布高的50%
#plots[2]: img7的宽,为plots[1]39/112,img7高以51:39换算过来
#plots[3]: img3的mask的边距留空,为plots[1]宽高的1/56
#plots[4]: canvas的宽高,是一个tuple
#plots[5]: 唱盘的圆心,在(0.5x, 0.45y),是一个tuple
#plots[6]: img1的开始绘制位置,按照圆心和img1宽高换算得到
#plots[7]: img3的开始绘制位置,参照上条
#plots[8]: img5的开始绘制位置,位于圆心上33/56,右3/16的位置
#plots[9]: img7的开始绘制位置,位于圆心上33/56,右59/112的位置
#plots[10]: Text的开始绘制位置,位于画布的(0.06x, 0)的位置
#plots[11]: 提示Toast的宽度,等于120
#plots[12]: 提示Toast的高度,等于40
#plots[13]: 提示Toast开始绘制的位置,位于画布的(0.5x-plots[11]/2, 0.8y - plots[12]/2)的位置
#plots[15]是红心图标等的开始绘制的纵坐标 0.75y
#plots[16]是红心等图标的宽和高 plots[1]*0.1
#plots[17]是左图标开始绘制的横坐标 0.15x-plots[16]*0.5
#plots[18]是右图标开始绘制的横坐标 0.85x-plots[16]*0.5
# plots[19]是中图标开始绘制的横坐标 0.5x-plots[16]*0.5
# plots[20]是进度条的纵坐标 y * 0.72
global buf, plots, img, screen_x, screen_y
buf = graphics.Image.new(CANVASSIZE)
plots = range(0,100)
logs("start defining plots")
plots[1] = screen_y /2
plots[0] = plots[1] * 75 /112
plots[2] = plots[1] * 30 /112
plots[3] = plots[1] * 1 /56
plots[4] = CANVASSIZE
plots[5] = (screen_x * 0.5, screen_y * 0.45)
plots[6] = (plots[5][0] - plots[0] / 2. -0.5, plots[5][1] - plots[0] / 2. -0.5)
plots[7] = (plots[5][0] - plots[1] / 2, plots[5][1] - plots[1] / 2)
plots[8] = (plots[5][0] + plots[1] * 4 / 16, plots[5][1] - plots[1] * 28 / 56)
plots[9] = (plots[5][0] + plots[1] * 57 / 112, plots[5][1] - plots[1] * 28 / 56)
plots[10] = (screen_x * 0.06, 0)
plots[11] = screen_x
plots[12] = 70
plots[13] = (0.5*screen_x-plots[11]/2, 0.85*screen_y - plots[12]/2)
plots[14] = plots[12] * 1. * 3 / 5
plots[15] = screen_y * 0.75
plots[16] = int(plots[1] * 0.4)
plots[17] = 0.15 * screen_x - plots[16]/2
plots[18] = 0.85 * screen_x - plots[16]/2
plots[19] = 0.5 * screen_x - plots[16]/2
plots[20] = 0.72 * screen_y
img = range(0,100)
logs("the type of plot14 : %s" % type(plots[14]))
for i, x in enumerate(plots):
if isinstance(x, float):
plots[i] = int(x)
if isinstance(x, tuple):
plots[i] = tuple(int(y) for y in x)
#img1为AlbumArt,img2作为裁切其为圆形的mask
#img3是唱盘,img4作为其mask
#img5是唱针,img6作为其mask,img6_是临时图片,blit到8位img6上用的
#img7 img8 是img5 img6的副本,在下面会将img5和img6旋转270°作为播放时的唱针
#img10是模糊化的AlbumArt,作为背景;img11是黯淡化遮罩
#img12是模糊化的AlbumArt,作为背景2;img13是黯淡化遮罩
#img14和img15分别为提示Toast和其遮罩
#img21-24是空的红心图标 遮罩 红的红心图标 遮罩
#img25-30是播放顺序图标: 列循 单循 随机 和其遮罩(间)
#img31-32是待定图标
#buf是缓冲图形,blit到canvas用
logs("start loading images")
img[0] = graphics.Image.open( pj(MAIN_CURR_FOLDER,'\\pic\\pic.bmp')).resize((plots[0],plots[0]))
img[1] = img[0]
img[2] = graphics.Image.new((plots[0],plots[0]),mode='1')
img[3] = graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\play_disc.png')).resize((plots[1] ,plots[1]))
img[4] = graphics.Image.new((plots[1],plots[1]),mode='1')
img[5] = graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\play_needle.png')).resize((plots[2] ,plots[2] * 51 / 39))
img6_ = graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\play_needle_.png')).resize((plots[2] ,plots[2] * 51 / 39))
img[6] = graphics.Image.new(img6_.size, 'L')
img[6].blit(img6_)
img[7] = graphics.Image.new(img[5].size)
img[7].blit(img[5])
img[8] = graphics.Image.new(img[6].size, 'L')
img[8].blit(img[6])
img[5] = img[5].transpose(graphics.ROTATE_270)
img[6] = img[6].transpose(graphics.ROTATE_270)
img[10] = img[1].resize((16,16)).resize(CANVASSIZE)
img[11] = graphics.Image.new(CANVASSIZE, 'L')
img[11].clear(0x303030)
img[12] = img[1].resize((22,22)).resize(CANVASSIZE)
img[13] = graphics.Image.new(CANVASSIZE, 'L')
img[13].clear(0x7A7A7A)
img[14] = graphics.Image.new((plots[11], plots[12]))
img[15] = graphics.Image.new((plots[11], plots[12]), 'L')
img[14].clear(0x000000)
img[15].clear(0xC1C1C1)
logs("start loading images 16")
#表示进度的扇形及其中的进度数字, 还有三个临时图层, plots[14] 表示扇形宽高
img[16] = graphics.Image.new((plots[14],plots[14]), 'L')
img[17] = graphics.Image.new((plots[14],plots[14]), 'L')
img[18] = graphics.Image.new((plots[14],plots[14]), 'L')
img[19] = graphics.Image.new((plots[14],plots[14]), 'L')
img[20] = graphics.Image.new((plots[14],plots[14]), '1')
logs("start loading images 21")
img[21] = graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\play_icn_love.bmp'))
img[22] = graphics.Image.new(img[21].size, 'L')
img[22].load(pj(MAIN_CURR_FOLDER, '\\pic\\play_icn_love_.bmp'))
img[21] = img[21].resize((plots[16], plots[16]))
img[22] = img[22].resize((plots[16], plots[16]))
img[23] = graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\play_icn_loved.bmp'))
img[24] = graphics.Image.new(img[23].size, 'L')
img[24].load(pj(MAIN_CURR_FOLDER, '\\pic\\play_icn_loved_.bmp'))
img[23] = img[23].resize((plots[16], plots[16]))
img[24] = img[24].resize((plots[16], plots[16]))
logs("start loading images 25")
img[25] = graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\play_icn_loop.bmp'))
img[26] = graphics.Image.new(img[25].size, 'L')
img[26].load(pj(MAIN_CURR_FOLDER, '\\pic\\play_icn_loop_.bmp'))
img[25] = img[25].resize((plots[16], plots[16]))
img[26] = img[26].resize((plots[16], plots[16]))
logs("start loading images 27")
img[27] = graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\play_icn_one.bmp'))
img[28] = graphics.Image.new(img[27].size, 'L')
img[28].load(pj(MAIN_CURR_FOLDER, '\\pic\\play_icn_one_.bmp'))
img[27] = img[27].resize((plots[16], plots[16]))
img[28] = img[28].resize((plots[16], plots[16]))
img[29] = graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\play_icn_shuffle.bmp'))
img[30] = graphics.Image.new(img[29].size, 'L')
img[30].load(pj(MAIN_CURR_FOLDER, '\\pic\\play_icn_shuffle_.bmp'))
img[29] = img[29].resize((plots[16], plots[16]))
img[30] = img[30].resize((plots[16], plots[16]))
img[31] = graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\list_detail_icn_fav.bmp'))
img[32] = graphics.Image.new(img[31].size, 'L')
img[32].load(pj(MAIN_CURR_FOLDER, '\\pic\\list_detail_icn_fav_.bmp'))
img[31] = img[31].resize((plots[16], plots[16]))
img[32] = img[32].resize((plots[16], plots[16]))
img[33] = graphics.Image.open(pj(MAIN_CURR_FOLDER, '\\pic\\list_detail_icn_faved.bmp'))
img[34] = graphics.Image.new(img[33].size, 'L')
img[34].load(pj(MAIN_CURR_FOLDER, '\\pic\\list_detail_icn_faved_.bmp'))
img[33] = img[33].resize((plots[16], plots[16]))
img[34] = img[34].resize((plots[16], plots[16]))
logs("start loading images 35")
#img35是一个List,包括旋转过的专辑封面图片
img[35] = range(rotatingImages)
#img36是进度条
img[36] = graphics.Image.new((screen_x, 5))
img[36].clear(0x000000)
img[37] = graphics.Image.new((screen_x, 5), 'L')
img[37].clear(0xFFFFFF)
buf = graphics.Image.new(CANVASSIZE)
FONT_MEDIUM = int((screen_x + screen_y)/ 2 * 20 / 300)
FONT_SMALL = int(FONT_MEDIUM * 0.8)
def initDraw():
global img,buf, plots
#此时开始画img1的mask
img[2].clear(0x000000)
img[2].ellipse((0,0,plots[0],plots[0]),fill=0xffffff)
#此时开始画img3的mask
img[4].clear(0x000000)
img[4].ellipse((plots[3],plots[3],plots[1] - plots[3],plots[1] - plots[3]),fill=0xffffff)
img[4].ellipse((plots[1]/2 - plots[0] /2,plots[1]/2 - plots[0] /2,plots[1]/2 + plots[0] /2,plots[1]/2 + plots[0] /2),fill=0x000000)
#正式开始画buf
buf.clear(0x303030)
buf.blit(img[10],mask=img[11])
buf.blit(img[3],target = plots[7], source=((0,0),(plots[1],plots[1])),mask=img[4])
buf.blit(img[1],target = plots[6], source=((0,0),(plots[0],plots[0])),mask=img[2])
# buf.blit(img5,target = (185,20), source=((0,0),(51,39)),mask=img6)
#开始时的默认唱针,暂停时
buf.blit(img[7],target = plots[9], source=((0,0),(plots[2] ,plots[2] * 51 / 39)),mask=img[8])
# buf.blit(img9,target = (5,20))
buf.blit(img[12],target = (0,0), source=((0,0),(plots[4][0],plots[4][1] *0.18)),mask=img[13])
buf.text((plots[10][0],plots[10][1]+FONT_MEDIUM + 3), cn('网易云音乐'),fill=0xffffff,font=("normal",FONT_MEDIUM,graphics.FONT_BOLD|graphics.FONT_ANTIALIAS))
buf.text((plots[10][0]+15,plots[10][1]+FONT_MEDIUM +FONT_SMALL + 6), cn('请选择左键菜单中的启动连接') ,fill=0xffffff,font=("normal",FONT_SMALL,None))
buf.text((plots[10][0]+15,plots[10][1]+FONT_MEDIUM+FONT_SMALL+FONT_SMALL + 9), cn('选项-设置-帮助关于 可以看使用帮助'),fill=0xffffff,font=("normal",FONT_SMALL,None))
lyricBlit(currLrc)
redraw()
drawRotationToWhere = -1
def drawRotation():
global img, drawRotationToWhere
R = img[1].size[0]
# pixelEdited = [ [False for a in range(R)] for b in range(R)]
for x in range(rotatingImages):
img[35][x] = img[0]
#aotimer3.cancel()
#aotimer3.after(0, loopRotate)
img[35][0] = img[1]
drawRotationToWhere = 0
for x in range(1, rotatingImages):
img[35][x] = graphics.Image.new(img[1].size)
img[35][x].clear(0x000000)
rgb = range(img[1].size[1])
for i in range(img[1].size[0]):
rgb[i] = img[1].getpixel([(i,k) for k in range(img[1].size[1])])
# logs("About to ao_yield in function %s" % sys._getframe().f_code.co_name)
e32.ao_yield()
# logs("End ao_yield-ing in function %s" % sys._getframe().f_code.co_name)
for x in range(1, rotatingUnit):
cos = AngleCoss[x]
sin = AngleSins[x]
for i in range(img[1].size[0]):
icos = (i - R / 2.) * cos
isin = (i - R / 2.) * sin
for j in range(img[1].size[1]):
jcos = (j - R / 2.) * cos
jsin = (j - R / 2.) * sin
thisPlotX = int(icos - jsin + R / 2.)
thisPlotY = int(jcos + isin + R / 2.)
if thisPlotX >= R or thisPlotY >=R or thisPlotX <0 or thisPlotY <0:
pass
else:
img[35][x].point((thisPlotX, thisPlotY), width = 2, outline = rgb[i][j])
# logs("About to ao_yield in function %s" % sys._getframe().f_code.co_name)
e32.ao_yield()
# logs("End ao_yield-ing in function %s" % sys._getframe().f_code.co_name)
drawRotationToWhere = x
# logs('drawn to %s' % drawRotationToWhere)
del rgb
for x in range(rotatingUnit, rotatingImages):
img[35][x] = img[35][x-rotatingUnit].transpose(graphics.ROTATE_270)
drawRotationToWhere = x
# logs('drawn to %s' % drawRotationToWhere)
rotateCycle = 2 #REFRESH ROTATE EVERY 3 SECONDS
tmpRotateVar = 0
def loopRotate():
global img, currRotation,tmpRotateVar
if not('npl' in globals()):
return
if npl.player and npl.player.state() == audio.EPlaying and not(toastVisibility):
if tmpRotateVar == 0:
# logs('currRotate to %s, drawn to %s' % (currRotation, drawRotationToWhere))
if currRotation <= drawRotationToWhere:
# logs('draw')
redrawRotate()
currRotation = (currRotation + 1) % rotatingImages
else:
pass
tmpRotateVar = (tmpRotateVar + 1) % rotateCycle
else:
pass
# logs('loopRotated - %s' % readableTime2(npl.player.current_position()/1000))
redrawPosition()
redraw()
# if npl.player != False and npl.player.state() == audio.EPlaying and not(toastVisibility) and foreground:
# aotimer3.cancel()
# aotimer3.after(1, loopRotate)
def redrawRotate():
global img,buf,plots
buf.blit(img[35][currRotation],target = plots[6], source=((0,0),(plots[0],plots[0])),mask=img[2])
# redraw((plots[6][0],plots[6][1],plots[6][0]+plots[0],plots[6][1]+plots[0]))
def redrawPosition():
#计算播放进度
if not('npl' in globals()) or not(npl.player):
return
if npl.player.state() == audio.ENotReady:
return
duration = npl.player.duration()
if npl.player and npl.player.state() == audio.EPlaying:
position = npl.player.current_position()
else:
position = npl.currPos
posScale = position * 1. / duration
#img11: 临时图像,全黑供clear buf用
img11 = graphics.Image.new(mainCanvas.size)
img11.clear(0x303030)
#给buf相应部分clear,然后重绘背景
buf.blit(img11, target = (0,plots[20]), source=((0,0), (mainCanvas.size[0], 9)))
buf.blit(img[10], target = (0,plots[20]), source=((0,plots[20]), (mainCanvas.size[0], plots[20] +9)))
img[37].clear(0x5E5E5E)
buf.blit(img[36], target = (0,plots[20]), source=((0,0), (mainCanvas.size[0], 2)), mask=img[37])
buf.blit(img[36], target = (0,plots[20] + 2 + 5), source=((0,0), (mainCanvas.size[0], 2)), mask=img[37])
img[37].clear(0x989898)
buf.blit(img[36], target = (posScale * mainCanvas.size[0],plots[20] + 2), source=((0,0), (mainCanvas.size[0], 5)), mask=img[37])
buf.text((10+1,plots[20] +9+1), cn(readableTime2(position / 1000)),fill=0x000000,font=("normal",FONT_SMALL,None))
buf.text((mainCanvas.size[0] - 10 - 20 +1,plots[20] +9+1), u'-' + cn(readableTime2((duration - position) / 1000)),fill=0x000000,font=("normal",FONT_SMALL,None))
buf.text((mainCanvas.size[0] / 2 - 10+1,plots[20] +9+1),cn(readableTime2((duration ) / 1000)),fill=0x000000,font=("normal",FONT_SMALL,None))
buf.text((10,plots[20] +9), cn(readableTime2(position / 1000)),fill=0xffffff,font=("normal",FONT_SMALL,None))
buf.text((mainCanvas.size[0] - 10 - 20,plots[20] +9), u'-' + cn(readableTime2((duration - position) / 1000)),fill=0xffffff,font=("normal",FONT_SMALL,None))
buf.text((mainCanvas.size[0] / 2 - 10,plots[20] +9),cn(readableTime2((duration ) / 1000)),fill=0xffffff,font=("normal",FONT_SMALL,None))
redraw()
if npl.player != False and npl.player.state() == audio.EPlaying and not(toastVisibility) and foreground:
aotimer3.cancel()
aotimer3.after(1, redrawPosition)
liked = False
faved = False
currOrder = 0
def refreshButtonsStatus():
global liked, faved, currOrder
songIndex = npl.songIndex
if npl.player and npl.player.state() == audio.EPlaying:
position = npl.player.current_position()
else:
position = npl.currPos
position = position / 1000000L
logs('position : %s' % position)
likeResult, likeFunc = nma.NE_likeFMSong(npl.songList[songIndex], "itembased", True, position)
if likeResult.get('songs') == []:
#表示之前没有喜欢
likeResult, likeFunc = nma.NE_likeFMSong(npl.songList[songIndex], "itembased", False, position)
liked = False
else:
#之前已经喜欢了
liked = True
currOrder = npl.order
def drawButtons():
#重画下面的三个图标
if liked:
buf.blit(img[23],target = (plots[19],plots[15]),mask=img[24])
else:
buf.blit(img[21],target = (plots[19],plots[15]),mask=img[22])
if False and faved:
buf.blit(img[33],target = (plots[17],plots[15]),mask=img[34])
else:
buf.blit(img[31],target = (plots[17],plots[15]),mask=img[32])
buf.blit(img[25+currOrder*2],target = (plots[18],plots[15]),mask=img[25+currOrder*2 +1])
def fetchPicImage(self):
try:
picImage = graphics.Image.open(self.fetchPic())
self.logs.info("panic checkpoint b0 : coverpic Loaded")
except Exception, e:
picImage = img[0]
import traceback
self.logs.error(traceback.format_exc())
try:
if os.path.exists(self.picPath):
os.remove(self.picPath)
except Exception, e:
self.logs.error(traceback.format_exc())
return picImage
currRotation = 0
def redrawSong(pl):
#在切歌时重画画布,更换AlbumArt
global img,buf,plots
songDict, songFunc = pl.getCurrentInfo()
#重获取img1
img[1] = fetchPicImage(pl)
logs("panic checkpoint b1")
img[35][0] = img[1]
logs("panic checkpoint b2")
#img[1] = img[35][1]
img[10] = img[1].resize((16,16)).resize(mainCanvas.size)
logs("panic checkpoint b3")
img[11].clear(0x303030)
img[12] = img[1].resize((22,22)).resize(mainCanvas.size)
img[13] = graphics.Image.new(mainCanvas.size, 'L')
img[13].clear(0x303030)
logs("panic checkpoint b4")
#开始画buf
buf.clear(0x303030)
buf.blit(img[10],mask=img[11])
buf.blit(img[3],target = plots[7], source=((0,0),(plots[1],plots[1])),mask=img[4])
buf.blit(img[35][currRotation],target = plots[6], source=((0,0),(plots[0],plots[0])),mask=img[2])
#根据播放暂停状态选择唱针
if pl.player.state() == audio.EPlaying:
buf.blit(img[5],target = plots[8], source=((0,0),(plots[2] * 51 / 39, plots[2])),mask=img[6])
else:
buf.blit(img[7],target = plots[9], source=((0,0),(plots[2] ,plots[2] * 51 / 39)),mask=img[8])
# buf.blit(img9,target = (5,20))
buf.blit(img[12],target = (0,0), source=((0,0),(plots[4][0],plots[4][1] *0.18)),mask=img[13])
logs("panic checkpoint b5")
redrawPosition()
drawButtons()
buf.text((plots[10][0],plots[10][1]+FONT_MEDIUM + 3), s(d(songFunc, songDict, "songName")),fill=0xffffff,font=("normal",FONT_MEDIUM,graphics.FONT_BOLD|graphics.FONT_ANTIALIAS))
buf.text((plots[10][0]+15,plots[10][1]+FONT_MEDIUM+FONT_SMALL + 6), s(' & '.join(d(songFunc, songDict, "songArtistsName"))) ,fill=0xffffff,font=("normal",FONT_SMALL,None))
buf.text((plots[10][0]+15,plots[10][1]+FONT_MEDIUM+FONT_SMALL + FONT_SMALL +9), cn(s(d(songFunc, songDict, "songAlbumName"))) + cn(' #') + str(songDict['no']),fill=0xffffff,font=("normal",FONT_SMALL,None))
logs("panic checkpoint b6")
#e32.ao_sleep(0, drawRotation)
redrawPosition()
redraw()
logs("panic checkpoint b7")
def redrawPause(pl):
#在暂停和继续播放时更新画布使唱针旋转
#修正使其只更新(plots[8][0], plots[8][1])-(plots[9][0] + plots[2], plots[7][1] + plots[2] * 51 / 39)部分的内容
global img,buf,plots
songDict = pl.getCurrentInfo()
if songDict == None:return
#img11: 临时图像,全黑供clear buf用
img11 = graphics.Image.new(mainCanvas.size)
img11.clear(0x303030)
#给buf相应部分clear,然后重绘背景
buf.blit(img11, target = (plots[8][0], plots[8][1]), source=((plots[8][0], plots[8][1]), (plots[9][0] + plots[2], plots[9][1] + plots[2] * 51 / 39)))
buf.blit(img[10], target = (plots[8][0], plots[8][1]), source=((plots[8][0], plots[8][1]), (plots[9][0] + plots[2], plots[9][1] + plots[2] * 51 / 39)), mask=img[11])
#画唱盘
buf.blit(img[3],target = plots[7], source=((0,0),(plots[1],plots[1])),mask=img[4])
buf.blit(img[35][currRotation],target = plots[6], source=((0,0),(plots[0],plots[0])),mask=img[2])
#画唱针
if pl.player.state() == audio.EPlaying:
buf.blit(img[5],target = plots[8], source=((0,0),(plots[2] * 51 / 39, plots[2])),mask=img[6])
else:
buf.blit(img[7],target = plots[9], source=((0,0),(plots[2] ,plots[2] * 51 / 39)),mask=img[8])
#redraw指定区域(是否还需要在之前重绘文字?)
redraw((plots[8][0], plots[8][1], plots[9][0] + plots[2], plots[9][1] + plots[2] * 51 / 39))
def redraw(rect=(0,0,appuifw.Canvas().size[0],appuifw.Canvas().size[1])):
#将buf最终blit到画布上
global tabIndex, buf
if tabIndex == 2:
mainCanvas.blit(buf, target = (rect[0],rect[1]), source=((rect[0],rect[1]), (rect[2], rect[3])))
'''
画图函数结束
'''
logs(u"before plots defining")
definePlots()
logs(u'plots Defined')
'''
在播放器界面弹出的小提示框Toast的画图函数
包括下载进度的显示函数
'''
toastVisibility = False
def setToastVisible(visibility, needBlit = True):
#显示或隐藏Toast,visibility分别为True或False
global img, plots, toastVisibility, tmpWhetherThereIsProgressBar
if (visibility ^ toastVisibility):
toastVisibility = visibility
if needBlit:
if visibility:
buf.blit(img[14], target = plots[13], mask=img[15])
else:
#img11: 临时图像,全黑供clear buf用
img11 = graphics.Image.new(mainCanvas.size)
img11.clear(0x303030)
#给buf相应部分clear,然后重绘背景
buf.blit(img11, target = plots[13], source=((0,0), (plots[11], plots[12])))
buf.blit(img[10], target = plots[13], source=(plots[13], (plots[13][0] + plots[11], plots[13][1] + plots[12])), mask=img[11])
#重画下面的三个图标
drawButtons()
#aotimer3.cancel()
#aotimer3.after(0, loopRotate)
redraw((plots[13][0], plots[13][1], plots[13][0] + plots[11], plots[13][1] + plots[12]))
if toastVisibility == False:
redrawPosition()
def refreshToast():
setToastVisible(False)
setToastVisible(True)
def setToastText(strList, fontScale = 0.3, secondFontScale = 0.2):
#设置Toast
img[14].clear(0x000000)
textHeight = fontScale + secondFontScale * 1.1 * (len(strList) -1)
img[14].text((plots[11] *0.18, plots[12] * ((1-textHeight)/2 + fontScale)), s(strList[0]),fill=0xffffff,font=("normal",plots[12]*fontScale,None))
for k,v in enumerate(strList[1:]):
logs(u"toastLine:%s"%s(v))
img[14].text((int(plots[11] *0.22), int(plots[12] * ((1-textHeight)/2 + fontScale + secondFontScale * 1.1 * (k+1))) ), s(v) ,fill=0xffffff,font=("normal",int(plots[12]*secondFontScale),None))
refreshToast()
progRunning = False
def downProgWrapper(strList_):
global img, plots, Pi
global nowProg, nowTime, nowTimeGap, nowSpeed, nowSize, nowSizeGap, progRunning
progRunning = False
strList = copy.copy(strList_)
def progBlit(percent, strList):
if not foreground: return
img[14].clear(0x000000)
img[16].clear(0x000000)
img[17].clear(0x000000)
img[19].clear(0x000000)
img[20].clear(0x000000)
if percent != 0:
img[16].pieslice((0,0,plots[14],plots[14]), Pi /2 - Pi * 2 * percent / 100, Pi /2, fill=0xFFFFFF)
if percent == 100:percent = ''
img[17].text((plots[14] * (1./2 - 1./(2*1.4142)), plots[14] * (1. / 2 + 1./ (2*1.4142))) , unicode(percent) ,fill=0xffffff,font=("normal",plots[14] / 1.4142,graphics.FONT_BOLD|graphics.FONT_ANTIALIAS) )
img[19].blit(img[17])
img[17].blit(img[20], mask=img[16])
img[16].blit(img[17], mask=img[19])
img[14].blit(img[16], target=(plots[11] *0.03, (plots[12] - plots[14])/2), mask=img[16])
img[14].text((plots[11] *0.22, plots[12]*0.18 + plots[12]*0.24), strList[0],fill=0xffffff,font=("normal",plots[12]*0.2,None))
for k,v in enumerate(strList[1:]):
img[14].text((plots[11] *0.25, plots[12]*0.18 + plots[12]*0.24 +plots[12]*0.17*(k+1)), v,fill=0xffffff,font=("normal",plots[12]*0.15,None))
refreshToast()
def loopProg():
global nowProg, nowTime, nowTimeGap, nowSpeed, nowSize, nowSizeGap, progRunning, nowBlockNum, nowBlockSize, nowTotalSize
nowProg_ = nowProg
nowTime_ = nowTime
nowTimeGap_ = nowTimeGap
nowSize_ = nowSize
nowBlockNum_ = nowBlockNum
nowBlockSize_ = nowBlockSize
nowTotalSize_ = nowTotalSize
strList = copy.copy(strList_)
percent = nowBlockNum_ * nowBlockSize_ * 100 / nowTotalSize_
# logs('percent: %s nowProg: %s ' % (percent, nowProg))
if percent > 100:
percent = 100
totalinmb = float(nowTotalSize_) /1024 /1024
if nowProg != percent:
if nowBlockNum_ == 0:
downToast = cn('%.2f MB, -- KB/s, -- %%, ') % (totalinmb ) + cn('还剩 -- ')
strList.append(downToast)
progBlit(percent, strList)
else:
nowTimeGap = time.clock() - nowTime_
nowTime = time.clock()
nowSizeGap = nowBlockNum_ * nowBlockSize_ - nowSize_
nowSize = nowBlockNum_ * nowBlockSize_ #每更新1%便刷新一次,以总文件的1%需要多少秒来计算即时速度
if nowTimeGap != 0:
nowSpeed = float(nowSizeGap)/1024/nowTimeGap
else:
nowSpeed = 1
nowProg = percent
downToast = cn('%.2f MB, %.2f KB/s, %s %%, ') % (totalinmb, nowSpeed, percent ) + cn('还剩') + unicode(readableTime( long((nowTotalSize_ - nowBlockNum_ * nowBlockSize_) * 1. / (nowSpeed * 1024) * 1000) ))
strList.append(downToast)
progBlit(percent, strList)
# logs('progRunning: %s percent: %s ' % (progRunning, percent))
if progRunning:
# logs('will refresh prog')
# e32.ao_sleep(0.5, loopProg)
aotimer4.cancel()
aotimer4.after(0.8, loopProg)
if percent == 100:
progRunning = False
setToastVisible(False)
def downProgUpdater(blocknum, blocksize, totalsize):
global nowProg, nowTime, nowTimeGap, nowSpeed, nowSize, nowSizeGap, progRunning, nowBlockNum, nowBlockSize, nowTotalSize
nowBlockNum = blocknum
nowBlockSize = blocksize
nowTotalSize = totalsize
if blocknum == 0:
nowProg = -1
nowTime = time.clock()
nowTimeGap = 0
nowSpeed = 0
nowSize = -1
nowSizeGap = 0
progRunning = True
loopProg()
logs('Reset Progress Bar')
# logs('updater: progress %s %s' % (nowBlockNum * nowBlockSize, nowTotalSize))
#logs("About to ao_yield in function %s" % sys._getframe().f_code.co_name)
#e32.ao_sleep(PY2_BUG_DELAY_TIME)
e32.ao_yield()
#logs("End ao_yield-ing in function %s" % sys._getframe().f_code.co_name)
return downProgUpdater
'''
Toast结束
'''
'''
按钮控制
播放操作
'''
def selOrder():
order = npl.order
orderList = [cn('列表循环'), cn('单曲循环'), cn('随机播放')]
orderList[order] = cn('→') + orderList[order]
selOrderIndex = appuifw.popup_menu(orderList, cn('选择播放顺序'))
if selOrderIndex is not None:
if currentFM and selOrderIndex == 2:
appuifw.note(cn('私人FM不能随机播放哦'))
return
npl.updateOrder(selOrderIndex)
refreshButtonsStatus()
setToastText([cn('成功选择') + orderList[npl.order]])
# aotimer.cancel()
e32.ao_sleep(1, lambda:setToastVisible(False))
def pressButton(buttonDict):
global npl
if buttonDict['type']==appuifw.EEventKey:
try:
if buttonDict['keycode']==key_codes.EKeySelect:
pauseCont()
if buttonDict['keycode']==key_codes.EKey5:
pauseCont()
if buttonDict['keycode']==key_codes.EKey4:
prevSong()
if buttonDict['keycode']==key_codes.EKey6:
nextSong()
if buttonDict['keycode']==key_codes.EKey2:
volumeUp()
if buttonDict['keycode']==key_codes.EKey8:
volumeDown()
except:
pass
def pauseCont():
if 'npl' in globals():
npl.pauseCont()
redrawPause(npl)
aotimer3.cancel()
aotimer3.after(0, redrawPosition)
# aotimer3.after(0, loopRotate)
def pause():
if 'npl' in globals():
npl.pause()
redrawPause(npl)
aotimer3.cancel()
aotimer3.after(0, redrawPosition)
# aotimer3.after(0, loopRotate)
def cont():
if 'npl' in globals():
npl.cont()
redrawPause(npl)
aotimer3.cancel()
aotimer3.after(0, redrawPosition)
# aotimer3.after(0, loopRotate)
songSwitchHangedon = False
def nextSong(manual = True):
global checkLI, songSwitchHangedon
logs('nextSong, sSH: '+repr(songSwitchHangedon))
if not songSwitchHangedon:
if 'npl' in globals():
songSwitchHangedon = True
if not(currentFM):
npl.next(manual)
else:
npl.nextFM(manual)
checkLI = -3
songSwitchHangedon = False
def prevSong():
global checkLI, songSwitchHangedon
logs('prevSong, sSH: '+repr(songSwitchHangedon))
if not songSwitchHangedon:
if 'npl' in globals():
songSwitchHangedon = True
if not(currentFM):
npl.previous()
else:
setToastText([cn('私人FM不能播放上一曲哦')])
e32.ao_sleep(1, lambda:setToastVisible(False))
checkLI = -3
songSwitchHangedon = False
def volumeUp():
if 'npl' in globals():
npl.volumeAdjust(1)
currConfig['volume'] = npl.volume
writeConfig()
setToastText([cn('音量 ') + unicode(npl.volume)])
e32.ao_sleep(1, lambda:setToastVisible(False))
def volumeDown():
if 'npl' in globals():
npl.volumeAdjust(-1)
currConfig['volume'] = npl.volume
writeConfig()
setToastText([cn('音量 ') + unicode(npl.volume)])
e32.ao_sleep(1, lambda:setToastVisible(False))
def setVolume():
inputVolume = appuifw.query(cn('输入音量(s60v3 0-10, s^3 0-10000)'), 'number', currConfig['volume'])
if inputVolume==None:
return
currConfig['volume'] = inputVolume
writeConfig()
if 'npl' in globals():
npl.volumeAdjustTo(currConfig['volume'])
setToastText([cn('音量 ') + unicode(npl.volume)])
currConfig['volume'] = npl.volume
e32.ao_sleep(1, lambda:setToastVisible(False))
appuifw.note(cn('成功。当前音量为 ') + unicode(currConfig['volume']))
def insertSong():
currPlaylistIndex = currPlaylistListbox.current()
if 'npl' in globals():
npl.insertSong(currPlaylistIndex)
refreshCurrPlaylist()
# setToastText([cn('下一首播放设置成功')])
# e32.ao_sleep(1, lambda:setToastVisible(False))
appuifw.note(cn('下一首播放设置成功'))
#在播放暂停和切歌操作时audio自动调用的callback
#可以控制歌词界面的显示和是否刷新
currentPlaying = -1
def playCallback():
global npl, lyricText, lyricCanvas, lyricPage, checkLI, currentPlaying, currRotation, drawRotationToWhere
if (len(npl.songList) > (npl.songIndex) and npl.songList[npl.songIndex] != currentPlaying) or not(bool(npl.songList[npl.songIndex])) or currentPlaying == -1:
logs('id Different')
if npl.isScroll == False:
lyricPage = lyricText
lyricText.set(cn(npl.lrcList))
else:
lyricPage = lyricCanvas
currentPlaying = npl.songList[npl.songIndex]
checkLI = -3
currRotation = 0
drawRotationToWhere = -1
if tabType[3] == 0: tab[3] = lyricPage
changeTabs()
aotimer3.cancel()
refreshButtonsStatus()
logs('panic checkpoint a3')
redrawSong(npl)
logs('panic checkpoint a4')
aotimer2.cancel()
if npl.isScroll:
refreshLyric()
refreshCurrPlaylist()
else:
pass
def songCallback(prevState, nowState, errCode):
#changeTabs(1)
logs('songCallback: %s, %s, %s' % (repr(prevState), repr(nowState), repr(errCode)))
if prevState == audio.EPlaying and nowState == audio.EOpen:
nextSong(False)
else:
refreshLyric()
aotimer3.cancel()
aotimer3.after(0, redrawPosition)
#aotimer3.after(0, loopRotate)
aotimer_tmp = e32.Ao_timer()
aotimer_tmp.after(0, playCallback)
'''
按钮控制结束
'''
'''
关于UI的一系列函数
包括各个Tab的变换函数;切换界面(包括页面和左右键操作所调用的函数/菜单);刷新界面等重要函数
tabIndex存储当前tab的编号
tab为各个tab对应页面组成数组
tabKey存储各个tab对应的左右选项键操作
tabBackup为界面的备份存储list,存储了之前状态的tab和tabKey,在退出当前一个界面后可以还原到上一个界面
'''
tabLabelOptions = [[cn('查找')], [cn('歌单'), cn('详情')],[cn('播放')],[cn('歌词'), cn('列表'), cn('评论')]]
def changeTabs(i = -1):
global tabIndex, tabLabelOptions, tab
#不带参数的时候可以用来在不清楚当前Tab是什么时刷新目标Tabs
#删掉最左边
if i != -1:
i = i + 1
tabIndex = i
else:
i = tabIndex
refreshKeyHandler(i)
appuifw.app.body = tab[i]
def refreshTabTag():
tabLabels = [tabLabelOptions[x][tabType[x]] for x in [0,1,2,3]]
logs(tabLabels)
# appuifw.app.set_tabs(tabLabels,changeTabs)
appuifw.app.set_tabs(tabLabels[1:],changeTabs)
def refreshAllTabs():
#从python命令行载入这个py的时候会有错位,用这个refresh一下,可能打包后这个问题就不存在了
for x in range(0,4-1):
changeTabs(x)
return
pass
def printHandler():
logs('tab[2] exit_key_handler: (variable)' + repr(tabKey[2][1]))
logs('tabKey: ' + repr(tabKey))
logs('now exit_key_handler: (real)' + repr(appuifw.app.exit_key_handler))
#将tabKey中存储的左右选项键操作同步到当前的左右键
def refreshKeyHandler(i=-1):
if i == -1:
i = tabIndex
appuifw.app.menu = tabKey[i][0]
appuifw.app.exit_key_handler = tabKey[i][1]
appuifw.app.menu_key_text = tabKey[i][2]
appuifw.app.exit_key_text = tabKey[i][3]
appuifw.app.menu_key_handler = tabKey[i][4]
appuifw.app.title = tabKey[i][5]
#打开如评论详情的临时页面时候会备份页面到tabBackup,此处将其还原,一般用作tab的exit_key_handler