Trees | Indices | Help |
---|
|
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 os 23 import time 24 25 import gtk 26 27 from gettext import gettext as _ 28 29 from flumotion.component.base.admin_gtk import BaseAdminGtk, BaseAdminGtkNode 3032 glade_file = os.path.join('flumotion', 'component', 'consumers', 33 'httpstreamer', 'http.glade') 34203 20436 BaseAdminGtkNode.__init__(self, *args, **kwargs) 37 self.shown = False 38 self._stats = None 39 self._hasgnomevfs = False 40 try: 41 __import__('gnomevfs') 42 self._hasgnomevfs = True 43 except: 44 pass45 49 5355 # Set _stats regardless of if condition 56 # Used to be a race where _stats was 57 # not set if widget tree was gotten before 58 # ui state 59 self._stats = stats 60 if not hasattr(self, 'statistics'): 61 # widget tree not created yet 62 return 63 64 self.updateLabels(stats) 65 66 if not self.shown: 67 # widget tree created but not yet shown 68 self.shown = True 69 self.statistics.show_all()7072 #widgetname = name.replace('-', '_') 73 #FIXME: make object member directly 74 widget = self.wtree.get_widget('label-' + name) 75 if widget: 76 self.labels[name] = widget 77 else: 78 print "FIXME: no widget %s" % name79 8385 if not hasattr(self, 'labels'): 86 return 87 88 # changed in 0.1.9.1 to be int so we can localize time 89 peakTime = state.get('clients-peak-time') 90 if not isinstance(peakTime, str): 91 peakTime = time.strftime("%c", time.localtime(peakTime)) 92 93 self.labels['clients-peak-time'].set_text(peakTime) 94 95 for name in self.labels.keys(): 96 if name == 'clients-peak-time': 97 continue 98 text = state.get(name) 99 if text == None: 100 text = '' 101 # set http url with nice pango markup if gnomevfs present 102 # if not it should be black...so ppl dont click on it 103 if name == 'stream-url' and self._hasgnomevfs: 104 text = '<span foreground="blue">%s</span>' % text 105 self.labels[name].set_markup(text) 106 else: 107 self.labels[name].set_text(text)108110 self.labels = {} 111 self.statistics = self.wtree.get_widget('statistics-widget') 112 self.widget = self.statistics 113 for type in ('uptime', 'mime', 'current-bitrate', 'bitrate', 114 'totalbytes', 'url'): 115 self.registerLabel('stream-' + type) 116 for type in ('current', 'average', 'max', 'peak', 'peak-time'): 117 self.registerLabel('clients-' + type) 118 for type in ('bitrate', 'totalbytes'): 119 self.registerLabel('consumption-' + type) 120 121 if self._stats: 122 self.shown = True 123 self.updateLabels(self._stats) 124 self.statistics.show_all() 125 126 # add signal handler for Stream URL only if we have gnomevfs 127 # also signal handler to notify when mouse has gone over label 128 # so cursor changes 129 # add popup menu to let you open url or copy link location 130 131 if self._hasgnomevfs: 132 streamurl_widget_eventbox = self.wtree.get_widget( 133 'eventbox-stream-url') 134 streamurl_widget_eventbox.set_visible_window(False) 135 streamurl_widget_eventbox.connect('button-press-event', 136 self._streamurl_clicked) 137 streamurl_widget_eventbox.connect('enter-notify-event', 138 self._streamurl_enter) 139 streamurl_widget_eventbox.connect('leave-notify-event', 140 self._streamurl_leave) 141 self._streamurl_popupmenu = gtk.Menu() 142 item = gtk.ImageMenuItem('_Open Link') 143 image = gtk.Image() 144 image.set_from_stock(gtk.STOCK_JUMP_TO, gtk.ICON_SIZE_MENU) 145 item.set_image(image) 146 item.show() 147 item.connect('activate', self._streamurl_openlink, 148 streamurl_widget_eventbox) 149 self._streamurl_popupmenu.add(item) 150 item = gtk.ImageMenuItem('Copy _Link Address') 151 image = gtk.Image() 152 image.set_from_stock(gtk.STOCK_COPY, gtk.ICON_SIZE_MENU) 153 item.set_image(image) 154 item.show() 155 item.connect('activate', self._streamurl_copylink, 156 streamurl_widget_eventbox) 157 self._streamurl_popupmenu.add(item) 158 159 return self.statistics160 161 # signal handler for button press on stream url163 # check if left click 164 if event.button == 1: 165 url = widget.get_children()[0].get_text() 166 import gnomevfs 167 if self._stats: 168 app_to_run = gnomevfs.mime_get_default_application( 169 self._stats.get('stream-mime')) 170 if app_to_run: 171 os.system("%s %s &" % (app_to_run[2],url)) 172 elif event.button == 3: 173 self._streamurl_popupmenu.popup(None, None, None, event.button, 174 event.time)175 176 # signal handler for open link menu item activation 177 # eventbox is the eventbox that contains the label the url is in179 url = eventbox.get_children()[0].get_text() 180 import gnomevfs 181 if self._stats: 182 app_to_run = gnomevfs.mime_get_default_application( 183 self._stats.get('stream-mime')) 184 if app_to_run: 185 os.system("%s %s &" % (app_to_run[2],url))186 187 # signal handler for copy link menu item activation 188 # eventbox is the eventbox that contains the label the url is in190 url = eventbox.get_children()[0].get_text() 191 clipboard = gtk.Clipboard() 192 clipboard.set_text(url)193 194 # motion event handles196 cursor = gtk.gdk.Cursor(widget.get_display(), gtk.gdk.HAND2) 197 window = widget.window 198 window.set_cursor(cursor)199223 224 GUIClass = HTTPStreamerAdminGtk 225207 statistics = StatisticsAdminGtkNode(self.state, self.admin, 208 _("Statistics")) 209 self.nodes['Statistics'] = statistics 210 # FIXME: maybe make a protocol instead of overriding 211 return BaseAdminGtk.setup(self)212 215 216 # FIXME: tie this to the statistics node better 220
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Aug 7 15:45:51 2008 | http://epydoc.sourceforge.net |