Package flumotion :: Package admin :: Package gtk :: Module workerlist
[hide private]

Source Code for Module flumotion.admin.gtk.workerlist

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  import gettext 
 23   
 24  import gobject 
 25  import gtk 
 26  from zope.interface import implements 
 27   
 28  from flumotion.common.pygobject import gsignal 
 29  from flumotion.twisted import flavors 
 30   
 31  __version__ = "$Rev: 7239 $" 
 32  _ = gettext.gettext 
 33   
 34   
35 -class WorkerListStore(gtk.ListStore):
36 implements(flavors.IStateListener) 37 gsignal('changed') 38
39 - def __init__(self, whs):
40 gtk.ListStore.__init__(self, str) 41 for x in whs.get('names'): 42 i = self.append() 43 self.set_value(i, 0, x) 44 whs.addListener(self, append=self.stateAppend, 45 remove=self.stateRemove)
46
47 - def stateAppend(self, state, key, val):
48 if key == 'names': 49 i = self.append() 50 self.set_value(i, 0, val) 51 self.emit('changed')
52
53 - def stateRemove(self, state, key, val):
54 if key == 'names': 55 for r in self: 56 if self.get_value(r.iter, 0) == val: 57 self.remove(r.iter) 58 self.emit('changed') 59 return
60 gobject.type_register(WorkerListStore) 61 62
63 -class WorkerList(gtk.HBox):
64 gsignal('worker-selected', str) 65 _combobox = None 66 _label = None 67
68 - def __init__(self):
69 gtk.HBox.__init__(self) 70 71 self._combobox = gtk.ComboBox() 72 self._label = gtk.Label(_('Worker:')) 73 74 self._label.show() 75 self.pack_start(self._label, False, False, 0) 76 vb = gtk.VBox() 77 self.pack_start(vb, False, False, 10) 78 vb.show() 79 a = gtk.Alignment(0.5, 0.5) 80 a.show() 81 vb.pack_start(a, True, False, 0) 82 cell = gtk.CellRendererText() 83 self._combobox.pack_start(cell, True) 84 self._combobox.add_attribute(cell, 'text', 0) 85 86 def onChanged(cb): 87 self.emit('worker-selected', self.getWorker())
88 89 self._combobox.connect('changed', onChanged) 90 self._combobox.show() 91 # GTK 2.4 92 try: 93 self._combobox.set_property('focus-on-click', False) 94 self._combobox.set_property('has-frame', False) 95 except TypeError: 96 pass 97 a.add(self._combobox)
98
99 - def setWorkerHeavenState(self, whs):
100 self._combobox.set_model(WorkerListStore(whs)) 101 self.selectWorker(None) 102 103 def onModelChanged(model): 104 if not self.getWorker(): 105 # need to select a new worker 106 self.selectWorker(None) # will emit if worker selected 107 if not self.getWorker(): 108 # no workers present! 109 self.emit('worker-selected', None)
110 111 self._combobox.get_model().connect('changed', onModelChanged) 112
113 - def selectWorker(self, worker):
114 # worker == none means select first worker 115 for r in self._combobox.get_model(): 116 if not worker or r.model.get_value(r.iter, 0) == worker: 117 self._combobox.set_active_iter(r.iter) 118 return 119 120 if worker: 121 # FIXME: let's not print, have correct logging 122 print 'warning: worker %s not available' % worker
123
124 - def getWorker(self):
125 i = self._combobox.get_active_iter() 126 if i: 127 return self._combobox.get_model().get_value(i, 0) 128 129 return None
130
131 - def notifySelected(self):
132 self.emit('worker-selected', self.getWorker())
133 134 gobject.type_register(WorkerList) 135