How would I change the text style in a gedit plugin?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How would I change the text style in a gedit plugin?

ALLOW THERE
I'm a GTK noob, so sorry if I'm asking too much.



I'm trying to change the style of text in gedit through a plugin (sort of like underlining text as in a spellcheck, or change the color of text).

I have a document like this:

doc = self.window.get_active_document()
Then I get bounds

start, end = doc.get_bounds() num_lines = end.get_line() - start.get_line() + 1 line_start = start.copy() for i in range(0, num_lines): line_end = line_start.copy() line_end.forward_to_line_end() doc.create_tag().background="blue" line = line_start.get_slice(line_end) if line.startswith('\n'): line='\n' lines.append(line) line_start.forward_line()
But the background doesn't change. Is there something else I should do?



Thank you very much

Sent using Zoho Mail





_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How would I change the text style in a gedit plugin?

Gtk+ - Apps Dev mailing list

 
This is similar but just using GTK. You get the iters for the start and end of the range that you want to tag and apply the tag to it.

Eric

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class TextBox(Gtk.TextView):
    def __init__(self):
        Gtk.TextView.__init__(self)
        textbuffer = self.get_buffer()
        textbuffer.set_text("Some text to tag.\nAnother line to tag.")
        start = textbuffer.get_start_iter()
        end = textbuffer.get_end_iter()
        tag = textbuffer.create_tag("blue_tag", background="blue", foreground="yellow")
        textbuffer.apply_tag(tag, start, end)
           
class MainWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Text Tag")
        self.set_default_size(300, 100)
        self.tb = TextBox()
        self.tb.set_hexpand(True)
        self.tb.set_vexpand(True)
        self.grid = Gtk.Grid()
        self.grid.attach(self.tb, 0, 0, 1, 1)
        self.add(self.grid)

win = MainWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

 


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list