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='both' start='True' pad='0' noborder='1'>
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 if attrnode
.nodeName
== 'noborder':
103 gnt
.set_flag(self
.widget
, gnt
.WIDGET_NO_BORDER
)
104 for child
in self
.node
.childNodes
:
105 self
.process_child(child
)
108 def create_widget(self
):
111 def process_attrib(self
, name
, value
):
114 def process_child(self
, child
):
120 class BoxNode(WidgetNode
):
121 def create_widget(self
):
122 return gnt
.Box(False, False)
124 def process_attrib(self
, name
, value
):
125 if name
== 'vertical':
126 self
.widget
.set_property('vertical', bool(value
))
128 self
.widget
.set_property('homogeneous', bool(value
))
130 self
.widget
.set_pad(int(value
))
132 def process_child(self
, child
):
133 if child
.nodeName
== 'title':
134 self
.widget
.set_title(child
.firstChild
.nodeValue
)
135 elif child
.nodeName
== 'widgets':
136 for widget
in child
.childNodes
:
137 wn
= process_node(widget
, self
)
140 if wn
.widget
is not None:
141 self
.widget
.add_widget(wn
.widget
)
143 class WindowNode(BoxNode
):
144 def __init__(self
, node
, parent
):
146 BoxNode
.__init
__(self
, node
, parent
)
147 for attrnode
in self
.node
.attributes
:
148 value
= attrnode
.nodeValue
149 if attrnode
.nodeName
== 'start':
152 elif attrnode
.nodeName
== 'name':
155 def create_widget(self
):
158 def process_attrib(self
, name
, value
):
159 BoxNode
.process_attrib(self
, name
, value
)
160 if name
== 'maximize':
162 self
.widget
.set_maximize(gnt
.WINDOW_MAXIMIZE_Y | gnt
.WINDOW_MAXIMIZE_X
)
163 elif value
== 'horiz':
164 self
.widget
.set_maximize(gnt
.WINDOW_MAXIMIZE_X
)
165 elif value
== 'vert':
166 self
.widget
.set_maximize(gnt
.WINDOW_MAXIMIZE_Y
)
169 elif name
== 'start':
175 class SearchNode(WidgetNode
):
176 def create_widget(self
):
179 class EqualizerNode(WidgetNode
):
181 if self
.widget
is None: return
183 while parent
.parent
is not None:
184 parent
= parent
.parent
185 self
.widget
.win
= parent
.widget
187 def create_widget(self
):
188 return XQSettings(xmms
)
190 class PlaylistNode(WidgetNode
):
191 def process_attrib(self
, name
, value
):
192 hash = {'position': XPList
.POSITION
,
193 'title' : XPList
.TITLE
,
194 'album' : XPList
.ALBUM
,
195 'artist' : XPList
.ARTIST
,
196 'time' : XPList
.TIME
,
201 self
.widget
.hide_column(col
)
203 def create_widget(self
):
204 for attr
in self
.node
.attributes
:
205 if attr
.nodeName
== 'current':
206 return XPListCurrent(xmms
)
209 class StatusNode(WidgetNode
):
210 def create_widget(self
):
213 def process_attrib(self
, name
, value
):
214 hash = {'title': XStatus
.PROP_TITLE
,
215 'album' : XStatus
.PROP_ALBUM
,
216 'artist' : XStatus
.PROP_ARTIST
,
217 'time' : XStatus
.PROP_DURATION
,
218 'quality' : XStatus
.PROP_QUALITY
,
219 'url' : XStatus
.PROP_URL
224 self
.widget
.fields
= self
.widget
.fields
& ~field
225 elif value
== 'show':
226 self
.widget
.fields
= self
.widget
.fields | field
227 self
.widget
.update_fields()
229 class ConfigNode(WidgetNode
):
230 def create_widget(self
):
234 'window' : WindowNode
,
235 'search' : SearchNode
,
236 'equalizer' : EqualizerNode
,
237 'playlist' : PlaylistNode
,
238 'status' : StatusNode
,
240 'config' : ConfigNode
,
243 def process_node(node
, parent
, dep
= 0):
244 if node
.nodeType
in [node
.DOCUMENT_NODE
]:
245 for child
in node
.childNodes
:
246 process_node(child
, parent
, dep
)
247 elif node
.nodeType
== node
.ELEMENT_NODE
:
248 if node
.nodeName
in maps
:
249 type = maps
[node
.nodeName
]
250 ret
= type(node
, parent
)
253 print "\t" * dep
, node
.nodeName
,
255 for attr
in node
.attributes
.keys():
256 print node
.attributes
[attr
].nodeValue
,
258 for child
in node
.childNodes
:
259 process_node(child
, parent
, dep
+ 1)
263 xml
= path
.expanduser("~/.config/xmms2/clients/pygnt.xml")
264 if not path
.exists(xml
): return gui
265 file = open(xml
, "r")
273 reader
= Sax2
.Reader()
274 doc
= reader
.fromString(gui
)
275 process_node(doc
, None)
277 def create_menu(winnode
):
278 def show_winnode(item
, win
):
280 win
.widget
.set_menu(create_menu(win
))
284 menu
= gnt
.Menu(gnt
.MENU_TOPLEVEL
)
285 item
= gnt
.MenuItem("Windows")
287 sub
= gnt
.Menu(gnt
.MENU_POPUP
)
288 item
.set_submenu(sub
)
289 for window
in windows
:
290 if window
== winnode
:
292 item
= gnt
.MenuItem(window
.name
)
294 item
.connect('activate', show_winnode
, window
)
297 for window
in windows
:
299 window
.widget
.set_menu(create_menu(window
))