home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / gedit-2 / plugins / externaltools / outputpanel.py < prev    next >
Encoding:
Python Source  |  2006-08-27  |  3.1 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. from gtk import glade
  23. import pango
  24. import gobject
  25. import os
  26. import gnomevfs
  27. from weakref import WeakKeyDictionary
  28. from capture import *
  29.  
  30. GLADE_FILE = os.path.join(os.path.dirname(__file__), "tools.glade")
  31.  
  32. class UniqueById:
  33.     __shared_state = WeakKeyDictionary()
  34.     
  35.     def __init__(self, i):
  36.         if i in self.__class__.__shared_state:
  37.             self.__dict__ = self.__class__.__shared_state[i]
  38.             return True
  39.         else:
  40.             self.__class__.__shared_state[i] = self.__dict__
  41.             return False
  42.  
  43.     def states(self):
  44.         return self.__class__.__shared_state
  45.  
  46. class OutputPanel(UniqueById):
  47.     def __init__(self, window):
  48.         if UniqueById.__init__(self, window):
  49.             return
  50.         
  51.         callbacks = {
  52.             'on_stop_clicked' : self.on_stop_clicked
  53.         }
  54.  
  55.         self.window = window
  56.         self.ui = glade.XML(GLADE_FILE, "output-panel")
  57.         self.ui.signal_autoconnect(callbacks)
  58.         self.panel = self["output-panel"]
  59.         self['view'].modify_font(pango.FontDescription('Monospace'))
  60.         
  61.         buffer = self['view'].get_buffer()
  62.         self.normal_tag = buffer.create_tag("normal")
  63.         self.error_tag  = buffer.create_tag("error")
  64.         self.error_tag.set_property("foreground", "red")
  65.         self.italic_tag = buffer.create_tag('italic')
  66.         self.italic_tag.set_property('style', pango.STYLE_OBLIQUE)
  67.         self.bold_tag = buffer.create_tag('bold')
  68.         self.bold_tag.set_property('weight', pango.WEIGHT_BOLD)
  69.  
  70.         self.process = None
  71.  
  72.     def __getitem__(self, key):
  73.         # Convenience function to get a widget from its name
  74.         return self.ui.get_widget(key)
  75.     
  76.     def on_stop_clicked(self, widget, *args):
  77.         if self.process is not None:
  78.             self.write("\n" + _('Stopped.') + "\n",
  79.                        self.italic_tag)
  80.             self.process.stop(-1)
  81.         
  82.     def scroll_to_end(self):
  83.         iter = self['view'].get_buffer().get_end_iter()
  84.         self['view'].scroll_to_iter(iter, 0.0)
  85.         return False  # don't requeue this handler
  86.  
  87.     def clear(self):
  88.         self['view'].get_buffer().set_text("")
  89.  
  90.     def write(self, text, tag = None):
  91.         buffer = self['view'].get_buffer()
  92.         if tag is None:
  93.             buffer.insert(buffer.get_end_iter(), text)
  94.         else:
  95.             buffer.insert_with_tags(buffer.get_end_iter(), text, tag)
  96.         gobject.idle_add(self.scroll_to_end)
  97.  
  98.     def show(self):
  99.         panel = self.window.get_bottom_panel()
  100.         panel.show()
  101.         panel.activate_item(self.panel)
  102.