Package flumotion :: Package wizard :: Module worker
[hide private]

Source Code for Module flumotion.wizard.worker

  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: 6577 $" 
 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 -class WorkerList(gtk.HBox):
63 gsignal('worker-selected', str) 64 _combobox = None 65 _label = None 66
67 - def __init__(self):
68 gtk.HBox.__init__(self) 69 70 self._combobox = gtk.ComboBox() 71 self._label = gtk.Label(_('Worker:')) 72 73 self._label.show() 74 self.pack_start(self._label, False, False, 0) 75 vb = gtk.VBox() 76 self.pack_start(vb, False, False, 10) 77 vb.show() 78 a = gtk.Alignment(0.5, 0.5) 79 a.show() 80 vb.pack_start (a, True, False, 0) 81 cell = gtk.CellRendererText() 82 self._combobox.pack_start(cell, True) 83 self._combobox.add_attribute(cell, 'text', 0) 84 85 def onChanged(cb): 86 self.emit('worker-selected', self.getWorker())
87 88 self._combobox.connect('changed', onChanged) 89 self._combobox.show() 90 # GTK 2.4 91 try: 92 self._combobox.set_property('focus-on-click', False) 93 self._combobox.set_property('has-frame', False) 94 except TypeError: 95 pass 96 a.add(self._combobox)
97
98 - def setWorkerHeavenState(self, whs):
99 self._combobox.set_model(WorkerListStore(whs)) 100 self.selectWorker(None) 101 102 def onModelChanged(model): 103 if not self.getWorker(): 104 # need to select a new worker 105 self.selectWorker(None) # will emit if worker selected 106 if not self.getWorker(): 107 # no workers present! 108 self.emit('worker-selected', None)
109 110 self._combobox.get_model().connect('changed', onModelChanged) 111
112 - def selectWorker(self, worker):
113 # worker == none means select first worker 114 for r in self._combobox.get_model(): 115 if not worker or r.model.get_value(r.iter, 0) == worker: 116 self._combobox.set_active_iter(r.iter) 117 return 118 119 if worker: 120 # FIXME: let's not print, have correct logging 121 print 'warning: worker %s not available' % worker
122
123 - def getWorker(self):
124 i = self._combobox.get_active_iter() 125 if i: 126 return self._combobox.get_model().get_value(i, 0) 127 128 return None
129
130 - def notifySelected(self):
131 self.emit('worker-selected', self.getWorker())
132 133 gobject.type_register(WorkerList) 134