4

I'm adding two icons to a gtk.Entry in PyGTK. The icons signals are handled by the following method

def entry_icon_event(self, widget, position, event)

I'm trying to differentiate between the two of them:

<enum GTK_ENTRY_ICON_PRIMARY of type GtkEntryIconPosition>
<enum GTK_ENTRY_ICON_SECONDARY of type GtkEntryIconPosition>

How can I do this? I've been digging through the documentation of PyGTK but there's no object GtkEntryIconPosition nor any definition for this enums.

Thanks

Cœur
  • 37,241
  • 25
  • 195
  • 267
Eldelshell
  • 6,683
  • 7
  • 44
  • 63
  • 1
    Well, it seems as I can compare using position.value_name which returns the name of the enum. Also, by creating a new object like: x = gtk._gtk.EntryIconPosition(0) for PRIMARY x = gtk._gtk.EntryIconPosition(1) for SECONDARY And then compare the objects. – Eldelshell Feb 03 '10 at 11:01

2 Answers2

2

Alright, since no one gave an answer, I'll do with what I actually found. A method to use this icons would look like this:

def entry_icon_event(self, widget, icon, event):
    if icon.value_name == "GTK_ENTRY_ICON_PRIMARY":
        print "First Button"
        if event.button == 0:
            print "Left Click":
        else:
            print "Right Click"
    elif icon.value_name == "GTK_ENTRY_ICON_SECONDARY":
        print "Second Button"
        if event.button == 0:
            print "Left Click":
        else:
            print "Right Click"
Eldelshell
  • 6,683
  • 7
  • 44
  • 63
1

There is better way to do it:

def entry_icon_event(self, widget, icon, event):
    if icon == gtk.ENTRY_ICON_PRIMARY:
        ...
    elif icon == gtk.ENTRY_ICON_SECONDARY:
        ...
user285176
  • 594
  • 3
  • 7