Created
August 29, 2012 12:21
-
-
Save aumouvantsillage/3511722 to your computer and use it in GitHub Desktop.
GTK entry icons with PyGObject and GTK3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gi.repository import Gtk | |
# | |
# See https://gist.github.com/3508693 for the version with PyGTK and GTK2 | |
# | |
# Create a GTK entry with a primary and secondary icons. | |
# Both icons are set sensitive. | |
# | |
# With GTK 2.24, if the entry is insensitive before the window is showed, | |
# icons will appear grayed even when the entry becomes sensitive. | |
# However, in all states, icons respond to clicks as expected. | |
# | |
# With GTK 3.4.4, icons are displayed correctly. | |
# | |
entry = Gtk.Entry() | |
# Icons are displayed correctly when this line is commented | |
entry.set_sensitive(False) | |
entry.set_icon_from_stock(Gtk.EntryIconPosition.PRIMARY, Gtk.STOCK_GO_BACK) | |
entry.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True) | |
entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, Gtk.STOCK_GO_FORWARD) | |
entry.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True) | |
def on_icon_pressed(entry, icon_pos, event): | |
if icon_pos == Gtk.EntryIconPosition.PRIMARY: | |
entry.set_text("Left") | |
elif icon_pos == Gtk.EntryIconPosition.SECONDARY: | |
entry.set_text("Right") | |
entry.connect("icon-press", on_icon_pressed) | |
entry.show() | |
# | |
# Create a window with the given entry | |
# | |
window = Gtk.Window() | |
window.set_title("Entry icon test") | |
window.add(entry) | |
window.connect("destroy", Gtk.main_quit) | |
window.show() | |
entry.set_sensitive(True) | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment