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') 34195 19636 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', 'bitrate', 'totalbytes', 'url'): 114 self.registerLabel('stream-' + type) 115 for type in ('current', 'average', 'max', 'peak', 'peak-time'): 116 self.registerLabel('clients-' + type) 117 for type in ('bitrate', 'totalbytes'): 118 self.registerLabel('consumption-' + type) 119 120 if self._stats: 121 self.shown = True 122 self.updateLabels(self._stats) 123 self.statistics.show_all() 124 125 # add signal handler for Stream URL only if we have gnomevfs 126 # also signal handler to notify when mouse has gone over label 127 # so cursor changes 128 # add popup menu to let you open url or copy link location 129 130 if self._hasgnomevfs: 131 streamurl_widget_eventbox = self.wtree.get_widget('eventbox-stream-url') 132 streamurl_widget_eventbox.set_visible_window(False) 133 streamurl_widget_eventbox.connect('button-press-event', self._streamurl_clicked) 134 streamurl_widget_eventbox.connect('enter-notify-event', self._streamurl_enter) 135 streamurl_widget_eventbox.connect('leave-notify-event', self._streamurl_leave) 136 self._streamurl_popupmenu = gtk.Menu() 137 item = gtk.ImageMenuItem('_Open Link') 138 image = gtk.Image() 139 image.set_from_stock(gtk.STOCK_JUMP_TO, gtk.ICON_SIZE_MENU) 140 item.set_image(image) 141 item.show() 142 item.connect('activate', self._streamurl_openlink, streamurl_widget_eventbox) 143 self._streamurl_popupmenu.add(item) 144 item = gtk.ImageMenuItem('Copy _Link Address') 145 image = gtk.Image() 146 image.set_from_stock(gtk.STOCK_COPY, gtk.ICON_SIZE_MENU) 147 item.set_image(image) 148 item.show() 149 item.connect('activate', self._streamurl_copylink, streamurl_widget_eventbox) 150 self._streamurl_popupmenu.add(item) 151 152 return self.statistics153 154 # signal handler for button press on stream url156 # check if left click 157 if event.button == 1: 158 url = widget.get_children()[0].get_text() 159 import gnomevfs 160 if self._stats: 161 app_to_run = gnomevfs.mime_get_default_application( 162 self._stats.get('stream-mime')) 163 if app_to_run: 164 os.system("%s %s &" % (app_to_run[2],url)) 165 elif event.button == 3: 166 self._streamurl_popupmenu.popup(None, None, None, event.button, event.time)167 168 # signal handler for open link menu item activation 169 # eventbox is the eventbox that contains the label the url is in171 url = eventbox.get_children()[0].get_text() 172 import gnomevfs 173 if self._stats: 174 app_to_run = gnomevfs.mime_get_default_application( 175 self._stats.get('stream-mime')) 176 if app_to_run: 177 os.system("%s %s &" % (app_to_run[2],url))178 179 # signal handler for copy link menu item activation 180 # eventbox is the eventbox that contains the label the url is in182 url = eventbox.get_children()[0].get_text() 183 clipboard = gtk.Clipboard() 184 clipboard.set_text(url)185 186 # motion event handles188 cursor = gtk.gdk.Cursor(widget.get_display(), gtk.gdk.HAND2) 189 window = widget.window 190 window.set_cursor(cursor)191215 216 GUIClass = HTTPStreamerAdminGtk 217199 statistics = StatisticsAdminGtkNode(self.state, self.admin, 200 _("Statistics")) 201 self.nodes['Statistics'] = statistics 202 # FIXME: maybe make a protocol instead of overriding 203 return BaseAdminGtk.setup(self)204 207 208 # FIXME: tie this to the statistics node better 212214 self.nodes['Log'].logMessage(message)
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Apr 11 07:40:33 2008 | http://epydoc.sourceforge.net |