File tree Expand file tree Collapse file tree 4 files changed +102
-24
lines changed Expand file tree Collapse file tree 4 files changed +102
-24
lines changed Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ from sys import argv
3
+ from time import sleep
4
+
5
+ from pyrilla import core
6
+
7
+
8
+ def main (file_handle ):
9
+ if len (argv ) != 2 :
10
+ print """
11
+ usage: program filename"
12
+ """
13
+ exit (1 )
14
+
15
+ else :
16
+ filename = argv [1 ]
17
+ ext = filename .rpartition ('.' )[2 ]
18
+
19
+ print ("will load %s as %s" % (filename , ext ))
20
+ file_handle (filename , ext )
21
+
22
+
23
+ def update_till_interrupt (on_interrupt = None ):
24
+ while True :
25
+ try :
26
+ core .update ()
27
+ sleep (0.001 )
28
+ except KeyboardInterrupt :
29
+ print ("interrupted" )
30
+
31
+ if on_interrupt :
32
+ on_interrupt ()
33
+ else :
34
+ print ("unhandled" )
35
+ break
36
+
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
+ from pyrilla import core
3
+
4
+ from base import main , update_till_interrupt
5
+
6
+ again = 0
7
+
8
+ def file_handle (filename , ext ):
9
+ sound = core .Sound (filename , ext )
10
+ voice = core .Voice (sound , loop = True )
11
+
12
+ voice .play ()
13
+
14
+ def on_interrupt ():
15
+ """
16
+ Handle subsequent keyboard interrupts:
17
+ * 1st - toggle voice
18
+ * 2nd - toggle voice again
19
+ * 3rd - quit
20
+ """
21
+ global again
22
+
23
+ if again >= 2 :
24
+ print ("quiting" )
25
+ quit ()
26
+
27
+ else :
28
+ again += 1
29
+ voice .toggle ()
30
+
31
+ print (on_interrupt .__doc__ )
32
+
33
+ update_till_interrupt (on_interrupt )
34
+
35
+
36
+ if __name__ == "__main__" :
37
+ main (file_handle )
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
- from sys import argv
3
- from pyrilla import internal
4
- from time import sleep
2
+ from pyrilla import core
3
+
4
+ from base import main , update_till_interrupt
5
+
5
6
6
7
def finished (sound ):
7
8
print ("finished:" , sound )
8
9
quit ()
9
10
10
- go_on = False
11
-
12
- def main ():
13
- if len (argv ) != 2 :
14
- print """
15
- usage: program filename"
16
- """
17
- exit (1 )
18
- else :
19
- filename = argv [1 ]
20
- ext = filename .rpartition ('.' )[2 ]
21
11
22
- print ("will load %s as %s" % (filename , ext ))
23
- s = internal .Sound (filename , ext )
12
+ def file_handle (filename , ext ):
13
+ print ("will load %s as %s" % (filename , ext ))
14
+ sound = core .Sound (filename , ext )
15
+ sound .play (finished )
24
16
25
- s . play ( on_finish = finished )
17
+ update_till_interrupt ( )
26
18
27
- try :
28
- while True :
29
- internal .update ()
30
- sleep (0.001 )
31
- except KeyboardInterrupt :
32
- print ("quiting" )
33
19
34
20
if __name__ == "__main__" :
35
- main ()
21
+ main (file_handle )
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
+ from pyrilla import core
3
+
4
+ from base import main , update_till_interrupt
5
+
6
+
7
+ def finished (sound ):
8
+ print ("finished:" , sound )
9
+ quit ()
10
+
11
+
12
+ def file_handle (filename , ext ):
13
+ sound = core .Sound (filename , ext )
14
+ voice = core .Voice (sound )
15
+
16
+ voice .play (finished )
17
+ update_till_interrupt ()
18
+
19
+
20
+ if __name__ == "__main__" :
21
+ main (file_handle )
You can’t perform that action at this time.
0 commit comments