home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / gedit-2 / plugins / externaltools / outputpanel.py < prev    next >
Encoding:
Python Source  |  2009-04-14  |  3.3 KB  |  102 lines

  1. # -*- coding: utf-8 -*-
  2. #    Gedit External Tools plugin
  3. #    Copyright (C) 2005-2006  Steve Fr√©cinaux <steve@istique.net>
  4. #
  5. #    This program is free software; you can redistribute it and/or modify
  6. #    it under the terms of the GNU General Public License as published by
  7. #    the Free Software Foundation; either version 2 of the License, or
  8. #    (at your option) any later version.
  9. #
  10. #    This program is distributed in the hope that it will be useful,
  11. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #    GNU General Public License for more details.
  14. #
  15. #    You should have received a copy of the GNU General Public License
  16. #    along with this program; if not, write to the Free Software
  17. #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  18.  
  19. __all__ = ('OutputPanel', 'UniqueById')
  20.  
  21. import gtk, gedit
  22. import pango
  23. import gobject
  24. import os
  25. from weakref import WeakKeyDictionary
  26. from capture import *
  27.  
  28. class UniqueById:
  29.     __shared_state = WeakKeyDictionary()
  30.  
  31.     def __init__(self, i):
  32.         if i in self.__class__.__shared_state:
  33.             self.__dict__ = self.__class__.__shared_state[i]
  34.             return True
  35.         else:
  36.             self.__class__.__shared_state[i] = self.__dict__
  37.             return False
  38.  
  39.     def states(self):
  40.         return self.__class__.__shared_state
  41.  
  42. class OutputPanel(UniqueById):
  43.     def __init__(self, datadir, window):
  44.         if UniqueById.__init__(self, window):
  45.             return
  46.  
  47.         callbacks = {
  48.             'on_stop_clicked' : self.on_stop_clicked
  49.         }
  50.  
  51.         self.window = window
  52.         self.ui = gtk.Builder()
  53.         self.ui.add_from_file(os.path.join(datadir, 'ui', 'outputpanel.ui'))
  54.         self.ui.connect_signals(callbacks)
  55.  
  56.         self.panel = self["output-panel"]
  57.         self['view'].modify_font(pango.FontDescription('Monospace'))
  58.  
  59.         buffer = self['view'].get_buffer()
  60.         self.normal_tag = buffer.create_tag("normal")
  61.         self.error_tag  = buffer.create_tag("error")
  62.         self.error_tag.set_property("foreground", "red")
  63.         self.italic_tag = buffer.create_tag('italic')
  64.         self.italic_tag.set_property('style', pango.STYLE_OBLIQUE)
  65.         self.bold_tag = buffer.create_tag('bold')
  66.         self.bold_tag.set_property('weight', pango.WEIGHT_BOLD)
  67.  
  68.         self.process = None
  69.  
  70.     def __getitem__(self, key):
  71.         # Convenience function to get an object from its name
  72.         return self.ui.get_object(key)
  73.  
  74.     def on_stop_clicked(self, widget, *args):
  75.         if self.process is not None:
  76.             self.write("\n" + _('Stopped.') + "\n",
  77.                        self.italic_tag)
  78.             self.process.stop(-1)
  79.  
  80.     def scroll_to_end(self):
  81.         iter = self['view'].get_buffer().get_end_iter()
  82.         self['view'].scroll_to_iter(iter, 0.0)
  83.         return False  # don't requeue this handler
  84.  
  85.     def clear(self):
  86.         self['view'].get_buffer().set_text("")
  87.  
  88.     def write(self, text, tag = None):
  89.         buffer = self['view'].get_buffer()
  90.         if tag is None:
  91.             buffer.insert(buffer.get_end_iter(), text)
  92.         else:
  93.             buffer.insert_with_tags(buffer.get_end_iter(), text, tag)
  94.         gobject.idle_add(self.scroll_to_end)
  95.  
  96.     def show(self):
  97.         panel = self.window.get_bottom_panel()
  98.         panel.show()
  99.         panel.activate_item(self.panel)
  100.  
  101. # ex:ts=4:et:
  102.