Merge branch 'master' of git+ssh://danw@dev.laptop.org/git/sugar
This commit is contained in:
		
						commit
						a1302ccbb2
					
				| @ -28,29 +28,29 @@ import pango | |||||||
| from sugar import env | from sugar import env | ||||||
| 
 | 
 | ||||||
| class MultiLogView(gtk.VBox): | class MultiLogView(gtk.VBox): | ||||||
|     def __init__(self, path): |     def __init__(self, path, extra_files): | ||||||
|         self._active_log = None |         self._active_log = None | ||||||
|         self._iters = [] |         self._extra_files = extra_files | ||||||
| 
 | 
 | ||||||
|         # Creating Main treeview with Actitivities list |         # Creating Main treeview with Actitivities list | ||||||
|         tv_menu = gtk.TreeView() |         self._tv_menu = gtk.TreeView() | ||||||
|         tv_menu.connect('cursor-changed', self._load_log) |         self._tv_menu.connect('cursor-changed', self._load_log) | ||||||
|         tv_menu.set_rules_hint(True) |         self._tv_menu.set_rules_hint(True) | ||||||
|          |          | ||||||
|         # Set width |         # Set width | ||||||
|         box_width = gtk.gdk.screen_width() * 80 / 100 |         box_width = gtk.gdk.screen_width() * 80 / 100 | ||||||
|         tv_menu.set_size_request(box_width*25/100, 0) |         self._tv_menu.set_size_request(box_width*25/100, 0) | ||||||
|      |      | ||||||
|         self.store_menu = gtk.TreeStore(str) |         self._store_menu = gtk.TreeStore(str) | ||||||
|         tv_menu.set_model(self.store_menu) |         self._tv_menu.set_model(self._store_menu) | ||||||
| 
 | 
 | ||||||
|         self._add_column(tv_menu, 'Sugar logs', 0) |         self._add_column(self._tv_menu, 'Sugar logs', 0) | ||||||
|         self._logs_path = os.path.join(env.get_profile_path(), 'logs') |         self._logs_path = os.path.join(env.get_profile_path(), 'logs') | ||||||
|         self._activity = {} |         self._activity = {} | ||||||
| 
 | 
 | ||||||
|         # Activities menu |         # Activities menu | ||||||
|         self.hbox = gtk.HBox(False, 3) |         self.hbox = gtk.HBox(False, 3) | ||||||
|         self.hbox.pack_start(tv_menu, True, True, 0) |         self.hbox.pack_start(self._tv_menu, True, True, 0) | ||||||
|          |          | ||||||
|         # Activity log, set width |         # Activity log, set width | ||||||
|         self._view = LogView() |         self._view = LogView() | ||||||
| @ -59,52 +59,62 @@ class MultiLogView(gtk.VBox): | |||||||
|         self.hbox.pack_start(self._view, True, True, 0)		 |         self.hbox.pack_start(self._view, True, True, 0)		 | ||||||
|         self.hbox.show_all() |         self.hbox.show_all() | ||||||
|          |          | ||||||
|         gobject.timeout_add(1000, self._update, tv_menu) |         gobject.timeout_add(1000, self._update) | ||||||
|      |      | ||||||
|     # Load the log information in View (textview) |     # Load the log information in View (textview) | ||||||
|     def _load_log(self, treeview): |     def _load_log(self, treeview): | ||||||
|         treeselection = treeview.get_selection() |         treeselection = treeview.get_selection() | ||||||
| 
 |  | ||||||
|         treestore, iter = treeselection.get_selected() |         treestore, iter = treeselection.get_selected() | ||||||
| 
 | 
 | ||||||
|         # Get current selection |         # Get current selection | ||||||
|         act_log = self.store_menu.get_value(iter, 0) |         act_log = self._store_menu.get_value(iter, 0) | ||||||
| 
 | 
 | ||||||
|         # Set buffer and scroll down |         # Set buffer and scroll down | ||||||
|         self._view.textview.set_buffer(self._activity[act_log]) |         self._view.textview.set_buffer(self._activity[act_log]) | ||||||
|         self._view.textview.scroll_to_mark(self._activity[act_log].get_insert(), 0); |         self._view.textview.scroll_to_mark(self._activity[act_log].get_insert(), 0); | ||||||
|         self._active_log = act_log |         self._active_log = act_log | ||||||
| 
 | 
 | ||||||
|     def _update(self, tv_menu): |     def _update(self): | ||||||
|         # Searching log files |         # Searching log files | ||||||
|         for logfile in os.listdir(self._logs_path): |         for logfile in os.listdir(self._logs_path): | ||||||
|             full_log_path = os.path.join(self._logs_path, logfile) |             full_log_path = os.path.join(self._logs_path, logfile) | ||||||
|  |             self._add_log_file(full_log_path) | ||||||
| 
 | 
 | ||||||
|             if os.path.isdir(full_log_path): |         for ext in self._extra_files: | ||||||
|                 continue |             self._add_log_file(ext) | ||||||
| 
 |  | ||||||
|             if not self._activity.has_key(logfile): |  | ||||||
|                 self._add_activity(logfile) |  | ||||||
|                 model = LogBuffer(full_log_path) |  | ||||||
|                 self._activity[logfile] = model |  | ||||||
|                  |  | ||||||
|             self._activity[logfile].update() |  | ||||||
|             written = self._activity[logfile]._written |  | ||||||
|                  |  | ||||||
|             # Load the first iter |  | ||||||
|             if self._active_log == None: |  | ||||||
|                 self._active_log = logfile |  | ||||||
|                 iter = tv_menu.get_model().get_iter_root() |  | ||||||
|                 tv_menu.get_selection().select_iter(iter) |  | ||||||
|                 self._load_log(tv_menu) |  | ||||||
|                  |  | ||||||
|             if written > 0 and self._active_log == logfile: |  | ||||||
|                 self._view.textview.scroll_to_mark(self._activity[logfile].get_insert(), 0); |  | ||||||
| 
 | 
 | ||||||
|         return True |         return True | ||||||
| 
 | 
 | ||||||
|  |     def _get_filename_from_path(self, path): | ||||||
|  |         return path.split('/')[-1] | ||||||
|  | 
 | ||||||
|  |     def _add_log_file(self, path): | ||||||
|  |         if os.path.isdir(path): | ||||||
|  |             return False | ||||||
|  | 
 | ||||||
|  |         logfile = self._get_filename_from_path(path) | ||||||
|  | 
 | ||||||
|  |         if not self._activity.has_key(logfile): | ||||||
|  |             self._add_activity(logfile) | ||||||
|  |             model = LogBuffer(path) | ||||||
|  |             self._activity[logfile] = model | ||||||
|  | 
 | ||||||
|  |         self._activity[logfile].update() | ||||||
|  |         written = self._activity[logfile]._written | ||||||
|  | 
 | ||||||
|  |         # Load the first iter | ||||||
|  |         if self._active_log == None: | ||||||
|  |             self._active_log = logfile | ||||||
|  |             iter = self._tv_menu.get_model().get_iter_root() | ||||||
|  |             self._tv_menu.get_selection().select_iter(iter) | ||||||
|  |             self._load_log(self._tv_menu) | ||||||
|  | 
 | ||||||
|  |         if written > 0 and self._active_log == logfile: | ||||||
|  |             self._view.textview.scroll_to_mark(self._activity[logfile].get_insert(), 0) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     def _add_activity(self, name): |     def _add_activity(self, name): | ||||||
|         self._insert_row(self.store_menu, None, name) |         self._insert_row(self._store_menu, None, name) | ||||||
|          |          | ||||||
|     # Add a new column to the main treeview, (code from Memphis) |     # Add a new column to the main treeview, (code from Memphis) | ||||||
|     def _add_column(self, treeview, column_name, index): |     def _add_column(self, treeview, column_name, index): | ||||||
| @ -171,9 +181,20 @@ class LogView(gtk.ScrolledWindow): | |||||||
|         self.textview.show() |         self.textview.show() | ||||||
| 
 | 
 | ||||||
| class Interface: | class Interface: | ||||||
| 
 |  | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         path = None |         path = None | ||||||
|         viewer = MultiLogView(path) |         xserver_logfile = self._get_xserver_logfile_path() | ||||||
|  |          | ||||||
|  |         # Aditional files to watch in logviewer | ||||||
|  |         ext_files = [] | ||||||
|  |         ext_files.append(xserver_logfile) | ||||||
|  | 
 | ||||||
|  |         viewer = MultiLogView(path, ext_files) | ||||||
|         self.widget = viewer.hbox |         self.widget = viewer.hbox | ||||||
| 
 | 
 | ||||||
|  |     # Get the Xorg log file path, we have two ways to get the path: do a system | ||||||
|  |     # call and exec a 'xset -q' or just read directly the file that we know  | ||||||
|  |     # always be the right one for a XO machine... | ||||||
|  |     def _get_xserver_logfile_path(self): | ||||||
|  |         path = "/var/log/Xorg.0.log" | ||||||
|  |         return path | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Dan Winship
						Dan Winship