1
## icon and progress in a GtkEntry
3
search_progress_id <- 0
6
show_find_button <- function()
8
notebook$setCurrentPage(0)
11
show_cancel_button <- function()
13
notebook$setCurrentPage(1)
16
search_progress <- function(data)
22
search_progress_done <- function(entry)
24
entry$setProgressFraction(0.0)
27
finish_search <- function(entry)
31
gSourceRemove(search_progress_id)
32
search_progress_id <<- 0
33
search_progress_done(entry)
38
start_search_feedback <- function(data)
40
search_progress_id <<- gTimeoutAdd(100, search_progress, data)
44
start_search <- function(button, entry)
47
search_progress_id <<- gTimeoutAdd(1000, start_search_feedback, entry)
48
finish_search_id <<- gTimeoutAdd(15000, finish_search, entry)
51
stop_search <- function(entry, data) {
52
gSourceRemove(finish_search_id)
56
clear_entry <- function(entry)
61
search_by_name <-function(item, entry)
63
entry$setIconFromStock(GtkEntryIconPosition["primary"], GTK_STOCK_FIND)
64
entry$setIconTooltipText(GtkEntryIconPosition["primary"],
65
"Search by name\nClick here to change the search type")
68
search_by_description <- function(item, entry)
70
entry$setIconFromStock(GtkEntryIconPosition["primary"], GTK_STOCK_EDIT)
71
entry$setIconTooltipText(GtkEntryIconPosition["primary"],
72
"Search by description\nClick here to change the search type")
75
search_by_file <- function(item, entry)
78
entry$setIconFromStock(GtkEntryIconPosition["primary"], GTK_STOCK_OPEN)
79
entry$setIconTooltipText(GtkEntryIconPosition["primary"],
80
"Search by file name\nClick here to change the search type")
83
create_search_menu <- function(entry)
87
item <- gtkImageMenuItemNewWithMnemonic("Search by _name")
88
image <- gtkImage(stock = GTK_STOCK_FIND, size = GtkIconSize["menu"])
90
item$setAlwaysShowImage(TRUE)
91
gSignalConnect(item, "activate", search_by_name, entry)
94
item <- gtkImageMenuItemNewWithMnemonic("Search by _description")
95
image <- gtkImage(stock = GTK_STOCK_EDIT, size = GtkIconSize["menu"])
97
item$setAlwaysShowImage(TRUE)
98
gSignalConnect(item, "activate", search_by_description, entry)
101
item <- gtkImageMenuItemNewWithMnemonic("Search by _file name")
102
image <- gtkImage(stock = GTK_STOCK_OPEN, size = GtkIconSize["menu"])
104
item$setAlwaysShowImage(TRUE)
105
gSignalConnect(item, "activate", search_by_file, entry)
112
icon_press_cb <- function(entry, position, event, data)
114
if (position == GtkEntryIconPosition["primary"])
115
menu$popup(NULL, NULL, NULL, NULL, event[["button"]], event[["time"]])
116
else clear_entry(entry)
119
text_changed_cb <- function(entry, pspec, button)
121
has_text <- entry$getTextLength() > 0
122
entry$setIconSensitive(GtkEntryIconPosition["secondary"], has_text)
123
button["sensitive"] <- has_text
126
activate_cb <- function(entry, button)
128
if (search_progress_id != 0)
130
start_search(button, entry)
133
search_entry_destroyed <- function(widget)
135
if (finish_search_id != 0)
136
gSourceRemove(finish_search_id)
138
if (search_progress_id != 0)
139
gSourceRemove(search_progress_id)
144
entry_populate_popup <- function(entry, menu, user_data)
146
has_text <- entry$getTextLength() > 0
148
item <- gtkSeparatorMenuItem()
151
item <- gtkMenuItemNewWithMnemonic("C_lear")
152
gSignalConnect(item, "activate", clear_entry, entry, user.data.first=TRUE)
154
item["sensitive"] <- has_text
156
search_menu <- create_search_menu(entry)
157
item <- gtkMenuItem("Search by")
158
item$setSubmenu(search_menu)
162
window <- gtkDialog("Search Entry", NULL, 0, GTK_STOCK_CLOSE,
163
GtkResponseType["none"])
164
window["resizable"] <- FALSE
166
gSignalConnect(window, "response", gtkWidgetDestroy)
168
content_area <- window$getContentArea()
170
vbox <- gtkVBox(FALSE, 5)
171
content_area$packStart(vbox)
172
vbox$setBorderWidth(5)
175
label$setMarkup("Search entry demo")
176
vbox$packStart(label, FALSE, FALSE)
178
hbox <- gtkHBox(FALSE, 10)
180
vbox$setBorderWidth(0)
184
hbox$packStart(entry, FALSE, FALSE)
186
## Create the find and cancel buttons
187
notebook <- gtkNotebook()
188
notebook$setShowTabs(FALSE)
189
notebook$setShowBorder(FALSE)
190
hbox$packStart(notebook, FALSE, FALSE)
192
find_button <- gtkButton("Find")
193
gSignalConnect(find_button, "clicked", start_search, entry)
194
notebook$appendPage(find_button)
196
cancel_button <- gtkButton("Cancel")
197
gSignalConnect(cancel_button, "clicked", stop_search, entry,
198
user.data.first=TRUE)
199
notebook$appendPage(cancel_button)
201
## Set up the search icon
202
search_by_name(NULL, entry)
204
## Set up the clear icon
205
entry$setIconFromStock(GtkEntryIconPosition["secondary"], GTK_STOCK_CLEAR)
206
text_changed_cb (entry, NULL, find_button)
208
gSignalConnect(entry, "icon-press", icon_press_cb)
209
gSignalConnect(entry, "notify::text", text_changed_cb, find_button)
210
gSignalConnect(entry, "activate", activate_cb)
213
menu <- create_search_menu(entry)
214
menu$attachToWidget(entry)
216
## add accessible alternatives for icon functionality
217
gSignalConnect(entry, "populate-popup", entry_populate_popup)