[pygtk] Removing the cursor

Edward Catmur ed at catmur.co.uk
Mon Aug 21 09:18:37 WST 2006


On Sun, 2006-08-20 at 19:40 -0400, Mike Bernson wrote:
> It look like I cannot do what I want.
> 
> That is remove the insert cursor from an entry widget that can get the
> focus but does not allow editing. I want to be able to stop off while
> tabbing thought the screen at the entry widget but attach signal handler
> to grab the input character and use them for something else other then
> altering the display. When I am doing this I have a message in the text
> area tilling the use what to do.

Then that isn't a Gtk.EntryBox. You want to construct a custom widget
that looks similar to a Gtk.EntryBox but behaves differently. How about
wrapping a Gtk.EntryBox in a Gtk.EventArea?

> I have it all working except removing the insert cursor. Since it is not
> a window/X11 cursor but is draw by the entry using a helper function in
> the style that I do not have access to I was looking for a way around
> having the insert cursor show up.

It's up to the style (indeed, the theme engine) how to draw the widget.
Second-guessing the theme engine isn't a good long-term strategy.


Ed

> Entry widget uses gtk_draw_insertion_cursor  inside the gtkstyle. I see
> no way of accessing this function/method from python.
> 
> Here is the header from that function:
> /**
>  * gtk_draw_insertion_cursor:
>  * @widget:  a #GtkWidget
>  * @drawable: a #GdkDrawable
>  * @area: rectangle to which the output is clipped, or %NULL if the
>  *        output should not be clipped
>  * @location: location where to draw the cursor (@location->width is
> ignored)
>  * @is_primary: if the cursor should be the primary cursor color.
>  * @direction: whether the cursor is left-to-right or
>  *             right-to-left. Should never be #GTK_TEXT_DIR_NONE
>  * @draw_arrow: %TRUE to draw a directional arrow on the
>  *        cursor. Should be %FALSE unless the cursor is split.
>  *
>  * Draws a text caret on @drawable at @location. This is not a style
> function
>  * but merely a convenience function for drawing the standard cursor shape.
>  *
>  * Since: 2.4
>  **/
> void
> gtk_draw_insertion_cursor (GtkWidget        *widget,
>                            GdkDrawable      *drawable,
>                            GdkRectangle     *area,
>                            GdkRectangle     *location,
>                            gboolean          is_primary,
>                            GtkTextDirection  direction,
>                            gboolean          draw_arrow)
> 
> 
> Edward Catmur wrote:
> > On Sun, 2006-08-20 at 18:10 -0400, Mike Bernson wrote:
> >> I set use the following to make the widget uneditable.
> >>
> >> widget.props.editable = False
> >>
> >> widget is gtk.Entry widget has an Editable interface and this should set
> >> the widget to non-editable.
> >>
> >> The entry widget does not allow any edit which I thought should also
> >> turn off the insert cursor. This is not the case
> >>
> >> Here is a simple program that show the problem
> >>
> >> import gtk
> >>
> >> window = gtk.Window()
> >> entry = gtk.Entry()
> >> entry.props.editable = False
> >> window.add(entry)
> >> window.show_all()
> >>
> >> gtk.main()
> > 
> > Ah, yeah. Use
> > 
> > entry.props.editable = False
> > entry.props.can_focus = False
> > entry.props.has_focus = False
> > 
> > Alternatively if you want to prevent selecting text and copying the
> > entry content, just use 
> > 
> > entry.props.sensitive = False
> > 
> > However the latter is not to be preferred; allowing users to select and
> > copy text is more friendly.
> > 
> > 
> > Ed
> > 



More information about the pygtk mailing list