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

2017-11-26 Thread Eric Cashon via gtk-app-devel-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
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


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

2017-11-26 Thread 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
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list