1 import gui
, pygame
, os
, time
, mod
, playlist
, cfg
, random
2 from pygame
.locals import *
4 class Module(mod
.Module
):
5 def __init__(self
, screen
):
6 mod
.Module
.__init
__(self
, screen
)
11 self
.gui
['LIST'].liststart
, self
.gui
['LIST'].selected
= self
.history
[self
.path
]
14 if self
.filetypes
== '*':
15 self
.data
= os
.listdir(self
.path
)
17 for file in os
.listdir(self
.path
):
18 if os
.path
.isdir(os
.path
.join(self
.path
, file)):
19 self
.data
.append(file)
21 for ft
in self
.filetypes
:
22 if file[-3:].lower() == ft
:
23 self
.data
.append(file)
24 self
.data
.sort(key
=str.lower
)
25 if len(self
.data
) > 0:
26 for file in self
.data
:
27 self
.gui
['LIST'].add(file,os
.path
.join(self
.path
,file),self
._action
,self
._prevtrig
)
28 self
.gui
['LIST'].makelist()
30 self
.path
, d
= os
.path
.split(self
.path
)
34 self
.filetypes
= cfg
.modcf
['filetypes']
35 self
.path
= cfg
.modcf
['path']
36 self
.action
= cfg
.modcf
['action']
37 self
._path
= cfg
.modcf
['path']
41 self
.history
[self
.path
] = 0,0
42 self
.addloop('previewimg', self
._prevwait
)
45 cfg
.lastmodname
= cfg
.modname
47 def keyhandler(self
, event
):
48 if event
.type == KEYDOWN
:
49 if event
.key
== K_DOWN
: self
.gui
['LIST'].select_next()
50 if event
.key
== K_UP
: self
.gui
['LIST'].select_last()
51 if event
.key
== K_PAGEDOWN
: self
.gui
['LIST'].next_page()
52 if event
.key
== K_RIGHT
:
53 if os
.path
.isdir(self
.sel_path
):
55 self
.history
[self
.path
] = self
.gui
['LIST'].liststart
, self
.gui
['LIST'].selected
56 self
.gui
['LIST'].clear()
57 self
.path
= self
.sel_path
60 if event
.key
== K_LEFT
:
63 self
.gui
['LIST'].clear()
64 self
.path
, d
= os
.path
.split(self
.path
)
68 cfg
.modname
= 'mainmenu'
69 cfg
.modcf
= cfg
.cf
['modules'][cfg
.modname
]
70 self
.loadmodule
= 'mainmenu'
71 if event
.key
== K_RETURN
:
72 self
.gui
['LIST'].press()
73 if event
.key
== K_y
: playlist
.PLAYLIST
.super_add(self
._path
, self
.filetypes
)
75 def joyhandler(self
, joystick
):
77 tol1
= tol0
- (tol0
* 2)
78 if joystick
.get_axis(0) > tol0
or joystick
.get_axis(0) < tol1
:
79 if joystick
.get_axis(0) > 0:
81 elif joystick
.get_axis(0) < 0:
83 if joystick
.get_axis(1) > tol0
or joystick
.get_axis(1) < tol1
:
84 if joystick
.get_axis(1) > 0:
85 self
.gui
['LIST'].select_next()
86 elif joystick
.get_axis(1) < 0:
87 self
.gui
['LIST'].select_last()
89 def _nut(self
, value
=None):
92 def _action(self
, value
):
93 if self
.action
== 'PLAY_MUSIC':
94 if os
.path
.isdir(value
):
96 playlist
.PLAYLIST
.add_dir(path
, self
.filetypes
)
97 elif os
.path
.isfile(value
):
98 path
, fil
= os
.path
.split(value
)
99 playlist
.PLAYLIST
.add_dir(path
, self
.filetypes
, self
.gui
['LIST'].liststart
+ self
.gui
['LIST'].selected
)
100 elif self
.action
== 'SHOW_PICTURE':
103 # pygame stops. This was mainly necessary for ZSNES, which doesn't start with running
104 # pygame display, also it saves a lot cpu-time for the launched application
105 playlist
.PLAYLIST
.pause()
106 # quitting the display
107 # launching the application with filename parameters
108 os
.system(self
.action
+ ' "' + value
+ '"')
109 # bringing up the display again
110 playlist
.PLAYLIST
.playpause()
113 if os
.path
.isdir(self
.previmage
):
114 inp
= os
.listdir(self
.previmage
)
115 image
= cfg
.thpath('blank.png')
118 if self
._ispic
(os
.path
.join(self
.previmage
, line
)):
119 #image = os.path.join(self.previmage, line)
120 imagepool
.append(os
.path
.join(self
.previmage
, line
))
121 if len(imagepool
) > 0:
122 num
= random
.randint(0, len(imagepool
)-1)
123 image
= imagepool
[num
]
124 self
.changebykey('PREVIEW', image
)
125 elif self
._ispic
(self
.previmage
):
126 self
.changebykey('PREVIEW', self
.previmage
)
128 def _ispic(self
, filename
):
130 if os
.path
.isfile(filename
):
131 ext
= os
.path
.splitext(filename
)[1].lower().lstrip('.')
132 if ext
in self
.filetypes
138 if self
.prevcnt
== 15:
141 def _prevtrig(self
, value
):
142 self
.sel_path
= os
.path
.join(self
.path
, value
)
143 self
.previmage
= value