Esempio n. 1
0
    def __init__(self, filename, mimetype=None):
        self.filename = filename
        if SV2:
            self.buffer = gtksourceview2.Buffer()
            self.buffer.set_highlight_syntax(True)
        else:
            self.buffer = gtksourceview.SourceBuffer()
            self.buffer.set_highlight(True)
        self.buffer.set_max_undo_levels(1000)
        if SV2:
            self.view = gtksourceview2.View(self.buffer)
        else:
            self.view = gtksourceview.SourceView(self.buffer)
        self.view.set_auto_indent(True)
        self.view.modify_font(pango.FontDescription('Ubuntu Mono 12'))

        self.view.connect('key_press_event', self.on_key_press_event)

        self.touch()
        language = self.get_language(mimetype)
        if language:
            self.buffer.set_language(language)

        self.file_signature = None
        self.file_text = ''
        self.sync_from_disk()
Esempio n. 2
0
    def __init__(self, filename):
        self.filename = filename
        if SV2:
            self.buffer = gtksourceview2.Buffer()
            self.buffer.set_highlight_syntax(True)
        else:
            self.buffer = gtksourceview.SourceBuffer()
            self.buffer.set_highlight(True)
        self.buffer.set_max_undo_levels(1000)
        if SV2:
            self.view = gtksourceview2.View(self.buffer)
        else:
            self.view = gtksourceview.SourceView(self.buffer)
        self.view.set_auto_indent(True)
        self.view.modify_font(pango.FontDescription('monospace'))

        mimetype = mimetypes.guess_type(filename)[0]
        if mimetype:
            self.buffer.set_language(get_language_from_mime_type(mimetype))

        if not os.path.exists(filename):
            open(filename, 'wb').close()

        self.file_signature = None
        self.file_text = ''
        self.sync_from_disk()
Esempio n. 3
0
    def __init__(self, widget=None, value=""):
        if HAS_GTKSOURCEVIEW:
            if widget is None:
                self.view = gtksourceview.SourceView(self.buffer)
            else:
                self.view = widget
            self.buffer = gtksourceview.SourceBuffer()
            self.buffer.set_text(value)

            if HAS_GTKSPELL:
                gtkspell.Spell(self.view)

            self.view.show()
        else:
            TextView.__init__(self, widget, value)
Esempio n. 4
0
    def _init_gtksourceview1(self):
        try:
            import gtksourceview
            srcbuf = gtksourceview.SourceBuffer()
            langman = gtksourceview.SourceLanguagesManager()
            lang = langman.get_language_from_mime_type("text/x-csrc")
            srcbuf.set_language(lang)
            srcbuf.set_highlight(True)
            srcview = gtksourceview.SourceView(srcbuf)
            srcview.set_show_line_numbers(True)
            return (1, srcview, srcbuf)

        except:
            L.warning('Cannot load gtksourceview 1')
            return None
Esempio n. 5
0
def main(args=[]):
    # create buffer
    lm = gtksourceview.SourceLanguagesManager()
    buffer = gtksourceview.SourceBuffer()
    buffer.set_data('languages-manager', lm)

    # parse arguments
    if len(args) > 2:
        open_file(buffer, args[1])
    else:
        open_file(buffer, args[0])

    # create first window
    window = create_main_window(buffer)
    window.set_default_size(500, 500)
    window.show()

    # main loop
    gtk.main()
Esempio n. 6
0
 def __init__(self):
     buffer_ = gtksourceview.SourceBuffer()
     gtksourceview.SourceView.__init__(self, buffer_)
Esempio n. 7
0
class Editor:
    """Wraps a gtrksourceview widget and adds a few abstraction methods."""
    def __init__(self,parent,title=''):
        self.parent = parent
        self.logger = logging.getLogger("gvr.Editors.Editor")
        self.logger.debug("Using gtksourceview version %s" % SRCVIEW)
        # remove any children from previous sessions
        for child in self.parent.get_children():
            self.parent.remove(child)       
        # Look for the locale to which the syntax highlighting should be set
        # We assume the locale is available, if not there won't be any higlighting.
        try:
            loc = utils.get_locale()[:2]
        except Exception,info:
            self.logger.exception("Error in checking locale")
            loc = ''
        if loc:
            mime = 'gvr_%s' % loc
        else:
            mime = 'gvr_en'
        
        if SRCVIEW == 1:
            srctagtable = gtksourceview.SourceTagTable()
            self.srcbuffer = gtksourceview.SourceBuffer(table=srctagtable)
            man = gtksourceview.SourceLanguagesManager()
            lang = man.get_language_from_mime_type('text/x-'+mime)
            self.logger.debug("gtksourceview buffer syntax higlight set to %s" % mime)
            self.srcbuffer.set_language(lang)
            self.srcbuffer.set_highlight(True)
            self.srcview = gtksourceview.SourceView(buffer=self.srcbuffer)
            self.srcview.set_tabs_width(4)
        else:
            self.srcbuffer = gtksourceview2.Buffer()
            self.srcview = gtksourceview2.View(buffer=self.srcbuffer)
            man = gtksourceview2.LanguageManager()
            self.logger.debug("set search path to %s" % utils.GTKSOURCEVIEWPATH)
            man.set_search_path([utils.GTKSOURCEVIEWPATH])
            #man.set_search_path(["/tmp/language-specs"])
            #print dir(man)
            # Horrible hacks, gtksourceview2 on XO differs from Ubuntu :-(
            # Reminder, if XO changes their gtksourceview2 again it will probably
            # break GvRng here.
            # And of course the 767 version changes gtksourceview2 again :-(
            # You should never change existing programs and leave the original name unchanged.
            # I commented out the XO bit in case we need it when there's another change.
##            if utils.platform == 'XO':
##                langs = man.list_languages()
##                self.srcbuffer.set_highlight(True)
##                for lang in langs:
##                    for m in lang.get_mime_types():
##                        if m == 'text/x-'+mime:
##                            self.logger.debug("XO gtksourceview buffer syntax higlight set to %s" % lang)
##                            self.srcbuffer.set_language(lang)
##            else:
            langs = man.get_language_ids()
            self.srcbuffer.set_highlight_syntax(True)
            self.logger.debug("Found language files:%s" % langs)
            for id in langs:
                if id == mime:
                    self.logger.debug("gtksourceview buffer syntax higlight set to %s" % mime)
                    self.srcbuffer.set_language(man.get_language(id))
                    break
            self.srcview.set_tab_width(4)
            
        # some methods that are the same on version 1 and 2    
        self.tag_h = self.srcbuffer.create_tag(background='lightblue')
        self.srcbuffer.set_max_undo_levels(10)
        self.srcview.set_show_line_numbers(True)
        self.srcview.set_insert_spaces_instead_of_tabs(True)
        #self.srcview.set_wrap_mode(gtk.WRAP_CHAR)        
        self.parent.add(self.srcview)
        self.parent.show_all()
        
        self.old_start_iter = None