Re: Need help in GTK3 Draw event

2018-04-30 Thread Marius Gedminas
On Thu, Apr 26, 2018 at 10:53:00AM +0530, Dhrubajyoti Doley wrote:
> I am developing an application where I have to show/draw whitespaces, tabs
> and enter.

Perhaps GtkSourceView could be useful here?  It can already draw
whitespace (and a lot of other things).

https://wiki.gnome.org/Projects/GtkSourceView

Marius Gedminas
-- 
I noticed that Open Source proponents using MacOS X have developed highly tuned
excuses, similar to those that smokers have about why cigarettes are good for
you.
-- Miguel de Icaza,
   http://primates.ximian.com/~miguel/archive/2004/Aug-03.html
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Need help in GTK3 Draw event

2018-04-28 Thread Eric Cashon via gtk-app-devel-list

 

 
Hi Dhrubajyoti,

The textview widget has text tags built in that you can use to draw rectangles 
around text. If you want to draw a rectangle to block out text you can match 
the background and foreground colors. This code works on Ubuntu16.04, GTK3.18 
and Python2.7. Give it a try and see if something similar will work for what 
you are working on.

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


Need help in GTK3 Draw event

2018-04-28 Thread Dhrubajyoti Doley
Hi,

I am developing an application where I have to show/draw whitespaces, tabs
and enter.

To achieve this I am trying to pass Cairo Context to TextView.

I am Attaching an example where on the TextView where I want to draw a
square over the texts.

I am using GTK3.18, Python2.7 and Windows7.

Please help me how to draw on textview
-- 
Dhrubajyoti Doley,

Mobile: 09220919356
Email: dhruba.do...@gmail.com,

Mumbai, India
#!/usr/bin/env python

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

def draw_cb(widget, cr):
  width = widget.get_allocated_width()
  height = widget.get_allocated_height()
  context = widget.get_style_context()
  Gtk.render_background(context, cr, 0, 0, width, height)
  cr.set_source_rgba(0,0,0,0.5)
  cr.rectangle(10,10, 100, 100)
  cr.fill()
  return False

window = Gtk.Window()
window.set_default_size(200, 200)
window.connect("destroy", Gtk.main_quit)

textview = Gtk.TextView()
textview.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
textbuffer = textview.get_buffer()
textbuffer.set_text("Hello world"*18, -1)
textview.connect('draw', draw_cb)
textview.queue_draw()

window.add(textview)
window.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