4 import xmmsclient
.glib
as xg
5 import xmmsclient
.collections
as xc
10 from xml
.dom
.ext
.reader
import Sax2
11 from xml
.dom
.NodeFilter
import NodeFilter
14 from xmms_search
import XSearch
15 from xmms_eq
import XQSettings
16 from xmms_pl
import XPList
, XPListCurrent
17 from xmms_status
import XStatus
18 from xmms_config
import XConfig
24 <window name='Main Window' vertical='True' homo='False' maximize='vert' start='True'>
27 <status title='show' quality='show' album='show'/>
28 <playlist current='True' />
29 <box vertical='False'>
37 <window name='Basic Search' vertical='True' homo='False' start='False'>
38 <title>Search...</title>
40 <box vertical='False'>
48 <window name='Equalizer'>
49 <title>Equalizer</title>
54 <window name='Playlist Editor' maximize='vert'>
55 <title>Playlist Editor</title>
57 <playlist position='hide' album='hide'/>
60 <window name='Configuration Editor' maximize='vert' start='False'>
61 <title>Configuration Editor</title>
71 xmms
= xmmsclient
.XMMS("uber-cool")
72 xmms
.connect(os
.getenv("XMMS_PATH"))
73 conn
= xg
.GLibConnector(xmms
)
75 except IOError, detail
:
76 common
.show_error("Connection failed: " + str(detail
))
84 def __init__(self
, node
, parent
= None):
91 if self
.widget
is not None:
93 self
.widget
= self
.create_widget()
96 self
.widget
.connect('destroy', reset_widget
)
97 for attrnode
in self
.node
.attributes
:
98 value
= attrnode
.nodeValue
101 self
.process_attrib(attrnode
.nodeName
, value
)
102 for child
in self
.node
.childNodes
:
103 self
.process_child(child
)
105 def create_widget(self
):
108 def process_attrib(self
, name
, value
):
111 def process_child(self
, child
):
117 class BoxNode(WidgetNode
):
118 def create_widget(self
):
119 return gnt
.Box(False, False)
121 def process_attrib(self
, name
, value
):
122 if name
== 'vertical':
123 self
.widget
.set_property('vertical', bool(value
))
125 self
.widget
.set_property('homogeneous', bool(value
))
127 def process_child(self
, child
):
128 if child
.nodeName
== 'title':
129 self
.widget
.set_title(child
.firstChild
.nodeValue
)
130 elif child
.nodeName
== 'widgets':
131 for widget
in child
.childNodes
:
132 wn
= process_node(widget
, self
)
135 if wn
.widget
is not None:
136 self
.widget
.add_widget(wn
.widget
)
138 class WindowNode(BoxNode
):
139 def __init__(self
, node
, parent
):
141 BoxNode
.__init
__(self
, node
, parent
)
142 for attrnode
in self
.node
.attributes
:
143 value
= attrnode
.nodeValue
144 if attrnode
.nodeName
== 'start':
147 elif attrnode
.nodeName
== 'name':
150 def create_widget(self
):
153 def process_attrib(self
, name
, value
):
154 BoxNode
.process_attrib(self
, name
, value
)
155 if name
== 'maximize':
157 self
.widget
.set_maximize(gnt
.WINDOW_MAXIMIZE_Y | gnt
.WINDOW_MAXIMIZE_X
)
158 elif value
== 'horiz':
159 self
.widget
.set_maximize(gnt
.WINDOW_MAXIMIZE_X
)
160 elif value
== 'vert':
161 self
.widget
.set_maximize(gnt
.WINDOW_MAXIMIZE_Y
)
164 elif name
== 'start':
170 class SearchNode(WidgetNode
):
171 def create_widget(self
):
174 class EqualizerNode(WidgetNode
):
175 def __init__(self
, node
, parent
):
176 WidgetNode
.__init
__(self
, node
, parent
)
177 while parent
.parent
is not None:
178 parent
= parent
.parent
179 self
.widget
.win
= parent
.widget
181 def create_widget(self
):
182 return XQSettings(xmms
)
184 class PlaylistNode(WidgetNode
):
185 def process_attrib(self
, name
, value
):
186 hash = {'position': XPList
.POSITION
,
187 'title' : XPList
.TITLE
,
188 'album' : XPList
.ALBUM
,
189 'artist' : XPList
.ARTIST
,
190 'time' : XPList
.TIME
,
195 self
.widget
.hide_column(col
)
197 def create_widget(self
):
198 for attr
in self
.node
.attributes
:
199 if attr
.nodeName
== 'current':
200 return XPListCurrent(xmms
)
203 class StatusNode(WidgetNode
):
204 def create_widget(self
):
207 def process_attrib(self
, name
, value
):
208 hash = {'title': XStatus
.PROP_TITLE
,
209 'album' : XStatus
.PROP_ALBUM
,
210 'artist' : XStatus
.PROP_ARTIST
,
211 'time' : XStatus
.PROP_DURATION
,
212 'quality' : XStatus
.PROP_QUALITY
,
213 'url' : XStatus
.PROP_URL
218 self
.widget
.fields
= self
.widget
.fields
& ~field
219 elif value
== 'show':
220 self
.widget
.fields
= self
.widget
.fields | field
221 self
.widget
.update_fields()
223 class ConfigNode(WidgetNode
):
224 def create_widget(self
):
228 'window' : WindowNode
,
229 'search' : SearchNode
,
230 'equalizer' : EqualizerNode
,
231 'playlist' : PlaylistNode
,
232 'status' : StatusNode
,
234 'config' : ConfigNode
,
237 def process_node(node
, parent
, dep
= 0):
238 if node
.nodeType
in [node
.DOCUMENT_NODE
]:
239 for child
in node
.childNodes
:
240 process_node(child
, parent
, dep
)
241 elif node
.nodeType
== node
.ELEMENT_NODE
:
242 if node
.nodeName
in maps
:
243 type = maps
[node
.nodeName
]
244 ret
= type(node
, parent
)
247 print "\t" * dep
, node
.nodeName
,
249 for attr
in node
.attributes
.keys():
250 print node
.attributes
[attr
].nodeValue
,
252 for child
in node
.childNodes
:
253 process_node(child
, parent
, dep
+ 1)
257 xml
= path
.expanduser("~/.config/xmms2/clients/pygnt.xml")
258 if not path
.exists(xml
): return gui
259 file = open(xml
, "r")
267 reader
= Sax2
.Reader()
268 doc
= reader
.fromString(gui
)
269 process_node(doc
, None)
271 def create_menu(winnode
):
272 def show_winnode(item
, win
):
274 win
.widget
.set_menu(create_menu(win
))
278 menu
= gnt
.Menu(gnt
.MENU_TOPLEVEL
)
279 item
= gnt
.MenuItem("Windows")
281 sub
= gnt
.Menu(gnt
.MENU_POPUP
)
282 item
.set_submenu(sub
)
283 for window
in windows
:
284 if window
== winnode
:
286 item
= gnt
.MenuItem(window
.name
)
288 item
.connect('activate', show_winnode
, window
)
291 for window
in windows
:
293 window
.widget
.set_menu(create_menu(window
))