Package elisa :: Package plugins :: Package bad :: Package helper_frontend :: Module helper_startup_view
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.bad.helper_frontend.helper_startup_view

  1  # -*- coding: utf-8 -*- 
  2  # Elisa - Home multimedia server 
  3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  4  # All rights reserved. 
  5  # 
  6  # This file is available under one of two license agreements. 
  7  # 
  8  # This file is licensed under the GPL version 3. 
  9  # See "LICENSE.GPL" in the root of this distribution including a special 
 10  # exception to use Elisa with Fluendo's plugins. 
 11  # 
 12  # The GPL part of Elisa is also available under a commercial licensing 
 13  # agreement from Fluendo. 
 14  # See "LICENSE.Elisa" in the root directory of this distribution package 
 15  # for details on that license. 
 16   
 17   
 18  __maintainer__ = 'Lionel Martin <lionel@fluendo.com>' 
 19  __maintainer2__ = 'Florian Boucault <florian@fluendo.com>' 
 20   
 21   
 22  from elisa.base_components.view import View 
 23  from twisted.internet import reactor 
 24  from report_tools import ReportTools 
 25   
 26  import pygtk 
 27  pygtk.require('2.0') 
 28  import gtk 
 29   
 30  import gc 
 31  import inspect 
 32   
33 -class HelperStartupView(View):
34 """ 35 This class implements gtk list view support 36 """ 37 38 supported_controllers = ('raval:elisa_controller',) 39
40 - def __init__(self):
41 View.__init__(self) 42 self.context_path = 'helper:glade_context' 43 self.menu = None 44 self.player = None 45 self._refresh_rate = 1.0 46 self.report_tools = ReportTools() 47 self.object_tree_view = None 48 self._auto_refresh = False 49 self._use_snapshots = False 50 self._use_startup_snapshot = True 51 self._startup_snapshot = None 52 self._current_snapshot = None 53 54 """ 55 self.box = gtk.VBox() 56 self.context_handle = self.box 57 """
58
59 - def controller_changed(self, old_controller, new_controller):
60 self.context_handle = self.frontend.context.glade_tree.get_widget("MainBox") 61 glade_tree = self.frontend.context.glade_tree 62 63 dic = { 64 "on_InfoRefreshRate1_value_changed" : self.change_info_refresh_rate, 65 "on_InfoAutoRefresh1_toggled" : self.toggle_info_refresh, 66 "on_InfoRefreshbutton1_clicked" : self.refresh_clicked, 67 "on_InfoUseSnapshot1_toggled" : self.toggle_use_snapshots, 68 "on_InfoSnapshotButton1_clicked" : self.take_snapshot_clicked, 69 "on_InfoSnapshotCombo1_changed" : self.combo_Snapshot_changed, 70 "on_ObjectTreeView1_row_expanded" : self.row_expanded, 71 } 72 glade_tree.signal_autoconnect(dic) 73 InfoSnapshotCombo = self.frontend.context.glade_tree.get_widget("InfoSnapshotCombo1") 74 InfoSnapshotCombo.set_active(0) 75 self._use_startup_snapshot = True 76 77 self.instance_tree_view = glade_tree.get_widget("ObjectTreeView1") 78 self.create_table_columns(self.instance_tree_view, 79 ['class name', 'count or instance id'], 1) 80 treestore = gtk.TreeStore(str, int, object) 81 self.instance_tree_view.set_model(treestore) 82 treestore.set_sort_column_id(1, gtk.SORT_DESCENDING) 83 self._startup_snapshot = self.report_tools.get_instance_infos() 84 self._current_snapshot =self._startup_snapshot 85 86 self.refresh()
87 88
89 - def refresh_clicked(self, bt):
90 self.refresh()
91 92
93 - def refresh(self):
94 #Refresh the instance infos 95 self.debug("Refresh the instance infos") 96 if self._use_snapshots == True: 97 if self._use_startup_snapshot == True: 98 snapshot = self._startup_snapshot 99 else: 100 snapshot = self._current_snapshot 101 else: 102 snapshot = None 103 104 current_instances = self.report_tools.get_instance_infos(snapshot) 105 self.refresh_table(self.instance_tree_view, current_instances) 106 if self._auto_refresh: 107 reactor.callLater(self._refresh_rate, self.refresh)
108 109
110 - def refresh_table(self, treeview, data):
111 treestore = treeview.get_model() 112 if treestore != None: 113 treestore.clear() 114 for key, value in data.iteritems(): 115 line = [key, value[0], value[1]] 116 parent = treestore.append(None, line) 117 treestore.append(parent, ["Loading", 0, None])
118
119 - def create_table_columns(self, treeview, columns, ordered_column=0):
120 i=0 121 for name in columns: 122 tvcolumn = gtk.TreeViewColumn(name) 123 treeview.append_column(tvcolumn) 124 cell = gtk.CellRendererText() 125 #cell.set_property('cell-background', 'cyan') 126 tvcolumn.pack_start(cell, True) 127 tvcolumn.set_attributes(cell, text=i) 128 tvcolumn.set_sort_column_id(i) 129 i +=1 130 131 treeview.set_search_column(0) 132 treeview.set_reorderable(True)
133
134 - def row_expanded(self, treeview, treeiter, path):
135 treestore = treeview.get_model() 136 obj = treestore.get_value(treeiter, 2) 137 138 if obj == None: 139 return 140 141 if len(path) <= 1: 142 referrers = obj 143 else: 144 gc.collect() 145 referrers = gc.get_referrers(obj) 146 147 loading = treestore.iter_children(treeiter) 148 for ref in referrers: 149 if inspect.isframe(ref): 150 continue 151 elif isinstance(ref, list): 152 if len(ref) > 1000: 153 continue 154 if isinstance(id(ref), long): 155 continue 156 157 child = treestore.append(treeiter, [str(ref)[0:80], id(ref), ref]) 158 treestore.append(child, ["Loading", 0, None]) 159 treestore.remove(loading)
160
161 - def change_info_refresh_rate(self, hscale):
162 self._refresh_rate = hscale.get_value() 163 self.debug("refresh rate changed to %s" % self._refresh_rate)
164
165 - def toggle_info_refresh(self, checkbox):
166 self._auto_refresh = checkbox.get_active() 167 self.debug("refresh checkbox changed to %s" % self._auto_refresh) 168 if self._auto_refresh: 169 reactor.callLater(self._refresh_rate, self.refresh)
170
171 - def toggle_use_snapshots(self, checkbox):
172 self._use_snapshots = checkbox.get_active() 173 self.debug("_use_snapshots changed to %s" % self._use_snapshots)
174 175
176 - def take_snapshot_clicked(self, bt):
177 self.debug("take new snapshot") 178 self._current_snapshot = self.report_tools.get_instance_infos()
179 180
181 - def combo_Snapshot_changed(self, c):
182 self.debug("change snapshot combo") 183 if c.get_active() == 0: 184 self._use_startup_snapshot = True 185 else: 186 self._use_startup_snapshot = False
187